These examples cover the FRED source scripting commands: "Add" - add sources, source properties, and rays, "Delete" - deletes wavelengths or rays, "Get" - gets source properties, "Is" - Boolean query of source properties, "Read" - read source definition files, "Set" - sets source properties.
The structures listed below contain parameters required for source commands:
"Add" sources, rays or properties Use the "Add" commands to create new sources, add wavelength specifications, add user-defined rays or to add angles or positions to FRED Multiple sources.
A default source can be added with the script lines below. This default source is a "Detailed Optical Source" with the following properties:
•"Single Direction" pointing in the (0,0,1) direction, •"Grid Plane" with 21x21 rays, semi-aperture of 0.5, elliptical shape, •Location at 0,0,0 in the "Optical Sources" coordinate System, •Uniform position/direction apodization, •Power = 1, •Not coherent, •Not polarized, •wavelength of 0.5875618 mm (He d-line).
In this example, a new source is added to the FRED document with the name "MyNewSource", the parent set to "Optical Sources" and is traceable:
Dim sdata As T_ENTITY, newid As Long sdata.name="MyNewSource" sdata.parent=1 'source parent is "Optical Sources" node 1 sdata.traceable=True newid=AddSource(sdata) Update
In this example, the AddSourceWavelengthSpec command is used to add a group of evenly-spaced wavelengths to the new source created above. These wavelengths are weighted by a gaussian function with center wavelength=0.65 mm and a 1/e2 HW=0.1mm. Since the default source is originally created with one wavelength (0.5875618 mm), the DeleteSoureIthWavelengthSpec command is used to remove that default wavelength located at index=0.
Dim spec As T_WAVELENGTHSPEC success = DeleteSourceIthWavelengthSpec ( id, 0 ) 'remove the default wavelength at index 0
User-defined rays can also be added to a source. In the example below, a new source "MyGridSource" is added as shown in the above example. In the case of user-defined rays, the SetSourcePosUser command is required to notify FRED that this source in not of the standard type. An array of T_SOURCEUSERRAY structures must be declared to hold the individual ray position, direction, power and pathlength settings. Upon defining data for each ray, the AddSourceUserRays command loads the ray data into the source definition.
Dim sdata As T_ENTITY, newid As Long sdata.name="MyGridSource"
"Delete" wavelengths or rays
(see 2nd example in "Add" section)
"Get" source properties General information such as power, immersion material, phase and propagation specification can be retrieved from a specified source. For example, to find the material in which source "Blue Diode" is located,
sid=FindName("Blue Diode") mat = GetSourceMaterial ( sid ) Print "The Blue Diode rays are currently in ",GetMaterialName(mat)
For coherent sources, other properties such as beam overlap, polarization and number of secondary beams can be accessed with "Get" commands.
id=FindName("Source 1")
The visualization properties of a source may be of interest. They can be loaded into a T_SOURCEVISUALIZE structure for inspection or further use. In this example, the visualization properties of "Source 1" are retrieved using GetSourceVisualization. These visualization properties could be applied to other sources via the vspec structure by using a "Set" command discussed below.
Dim vspec As T_SOURCEVISUALIZE ids1=FindName("Source 1") GetSourceVisualization ids1, vspec Print "visualize every ", vspec.everyNth, "th ray for Source 1"
The wavelength list and properties of a source can also be accessed:
sid=FindName("Red LED") count = GetSourceWavelengthCount ( sid ) 'get the number of wavelengths for Red LED wavelength = GetSourceIthWavelength ( sid, 3 ) 'get the 4th wavelength in the list of Red LED
Dim wavedata As T_WAVELENGTHSPEC GetSourceIthWavelengthSpec sid, 12, wavedata 'load the data for the 13th wavelength into wavedata structure
The position/direction type as well as apodization type with associated data can be retrieved in the following manner:
Dim posType$,funcType$ posType = GetSourcePosFuncType ( 5 )
In the case of a surface made into a random emitting source, the data from that source can be loaded into a T_SOURCEPOSSURFACE structure for easy access using GetSourcePosSurface:
Dim sourcesurfdata As T_SOURCEPOSSURFACE
"Is" source queries The "Is" statements return True or False to a wide range of queries. For instance, the user may want to know which entities in his/her model are random emitters and set the number of rays to 10,000. First declare a T_SOURCEPOSSURFACE structure to hold the appropriate data. Next, loop through all entities asking first if the entity is a source and then if it is a random surface emitter. If both "Is" statements return True, then make the change. Remember that the structure pos is not loaded with default values. Therefore, be sure to "Get" the current parameters for each structure element before making changes.
Dim pos As T_SOURCEPOSSURFACE
"Read" source definitions FRED can read numerous types of ray files. These include binary files from FRED, TracePro, OSLO, Zemax, OptiCAD, ASAP and LucidShape as well as text files from FRED, TracePro, OSLO and LightTools. The example below reads a previously saved FRED ray text file after confirming that "Source 3" is of the proper type, that is "SRCPOSGeneral".
id=FindName("Source 3")
"Set" source properties
The "Set" commands convey a wide range of source properties in much the same way the "Get" commands access source information. In fact, "Get" and "Set" are often used in tandem especially when selected source parameters are to be changed while others are to remain the same.
In the following example, the weights of all wavelength of source "lamp" are set to 1 without changing the individual wavelengths or their RGB values:
Dim wavespec As T_WAVELENGTHSPEC This example resets several parameters of a sine/cosine directional apodization while preserving the others:
Dim apod As T_SOURCEDIRAPODSINCOS
As a final example in this section, a bitmap source is created. Note that this source creation requires 3 FRED structures; T_ENTITY, T_SOURCEPOSBITMAP, and T_SOURCEDIRRANGE. The scr structure supplies a name and makes the source traceable. The bpod structure provides dimensions, centering, rays per pixel and the bitmap filename. The dirR structure assigns a 25deg x 25deg elliptic directional property to the rays.
Dim src As T_ENTITY 'set source parameters SetSourcePosBitmap bid, bpod See Also….
|