Navigation: Scripting Reference Manual > Script Examples > Examples - Raytrace Ray Path

 

Examples - Raytrace Ray Path

 

Contact Us: fredsupport@photonengr.com

 

These examples cover the basic FRED scripting commands involving ray paths:

"RayPathMode" - user defined mode settings,

"Path" - general path information,

"PathEvent" - specific event information,

"PathEventIs" - query specific events

Copying Raypaths to User-defined Paths

 

No structures are required for Ray Path commands.

 

A ray path is defined as a unique sequence of surface intersections. In FRED, the user is able to construct specific paths of interest prior to raytracing or determine paths resulting from a non-sequential raytrace. Ray path construction is facilitated by the "User-defined Ray Paths" dialog found on the Raytrace dropdown menu. In this dialog, the user creates and names a sequential list of surface intersections to be followed by each ray. If any ray fails to follow the designated path, that ray terminates at the last allowed intersection.  In addition, FRED automatically recognizes and defines what is termed the DefaultSequential ray path (the "primary" or "imaging" path) whenever a CodeV, Zemax or OSLO lens is imported. Sequential paths offer the advantages of 1) ignoring all but the path  of interest, and 2) decreasing raytrace time.

 

Determination of ray paths is an important aspect of stray light applications. In FRED, the determination of ray paths is accomplished by means of an "Advanced Raytrace". To activate this feature, select "Determine raypaths" in the "Advanced Raytrace" dialog box or set the "Determine ray paths" flag rayPaths in T_ADVANCEDRAYTRACE.  Note that these ray paths are identified not by a name but by an zero-indexed integer value.


 

"RayPathMode" information

Since there are two types of raytrace paths in FRED, the user must be able to determine/set the operational mode. Use the SetUserDefinedRayPathMode command to place FRED in the desired mode.

 

SetUserDefinedRayPathMode True   'set FRED to the ray path construction mode

 

Use IsUserDefinedRayPathMode to query FRED as to its current mode. In this example, if FRED is in the path construction mode then set the mode to path determination, otherwise do nothing.

 

If IsUserDefinedRayPathMode() Then

SetUserDefinedRayPathMode False

End If


 

"Path" information

The basic attributes of ray paths can be accessed using the "Path" commands. Commands such as PathPower and PathRayCount logically apply to the path determination mode only. This example finds the number of paths whose power exceeds a threshold value of 1e-4:

 

thresh=1e-4

pcount=0

For i=0 To PathCount()-1

 If PathPower(i)>thresh Then

  pcount=pcount+1

 End If

Next i

Print "There are " & pcount " paths with power greater than " & thresh

 

Other commands such as PathName, PathDescription, & PathFind logically apply only to paths the user has constructed (user defined paths):

 

pid=PathFind("ghost path between S4 and S6")

desc = PathDescription ( pid )

Print desc

 

Both path modes respond to the commands PathCount and PathDelete. In this example, FRED deletes all the determined paths whose power is less than 1e-5:

 

thresh=1e-5
i=0
Do While PathCount()>i
 If PathPower(i)<thresh Then
  PathDelete i
 Else
  i=i+1
 End If
Loop

 

while, in this example, FRED deletes the constructed path named "Trace Path 6":

 

pid=PathFind("Trace Path 6")
PathDelete pid

 

Note that paths from the determined path list which are copied to the user-defined path list are named "Trace Path #" where # is the path number.


 

"PathEvent" information

The "PathEvent" commands allow the user to examine specific path-related information. In this example, FRED is asked to print the ordered list of node intersections associated with path identifier 6. This list only provides node numbers. It does not provide any specifics concerning the intersection:

 

For i=0 To PathEventCount ( 6 )-1
id = PathEventItemID ( 6, i )
Print id
Next i
 

The PathEvent command returns all event information for a specified path. With this command, the user can find out whether an intersection is transmission/reflection/absorption, whether it is specular or scatter, the ancestary, etc. In the example below, PathEvent is used to interrogate path 6:

 

Dim id&, typ&, order&
Dim spec As Boolean
Dim nonSeq As Boolean
Dim child As Boolean
Dim pause As Boolean

For i=0 To PathEventCount(6)-1
PathEvent 6,i, id, typ, spec, child, nonSeq, pause, order
Print i,id,typ,spec,child,nonSeq,pause,order
Next i

 

To add a new user-defined path and load it with events, use PathAdd and PathAddEvent.

 

pathid=PathAdd("mypath","a new user path")
Print pathid
 

sid1=FindName("Lens surface")

sid2=FindName("Mirror 1")
event = PathAddEvent( pathid, sid1, +1, True, False, True, False, 0 )
event = PathAddEvent( pathid, sid2, -1, True, False, True, False, 0 )


 

"PathEventIs" queries

The individual events can be queried using the "PathEventIs" commands. There is an "Is" command corresponding to each entry in the PathEvent command. For example, FRED is asked to count the number of Transmit events in path 6:

 

transcount=0
For i=0 To PathEventCount(6)-1
 If PathEventIsTransmit(6,i) Then
  transcount=transcount+1
 End If
Next i
Print transcount


Copying Raypaths

Raypaths exist in two forms; "Determined raypaths" & User-defined raypaths. "Determined raypaths" are obtained during an Advanced Raytrace and are deleted when the next raytrace is executed. User-defined raypaths are saved in your FRED document and can be edited/added/deleted. The command SetUserDefinedRayPathMode is used in scripting to switch between the raypath modes. This example copies raypaths determined from an Advanced Raytrace to User-defined raypaths.

 

For i=0 To PathCount()-1

 

 pathnam="path " & i
  SetUserDefinedRayPathMode True
   idd=PathAdd(pathnam, pathdesc)
  SetUserDefinedRayPathMode False
    For j=1 To PathEventCount(i)-1
      PathEvent i,j,id,typ,spec,child,nonSeq,pause,order
     SetUserDefinedRayPathMode True
      event=PathAddEvent(idd,id,typ,spec,child,False,pause,order)
     SetUserDefinedRayPathMode False
    Next j

Next i 'end loop over paths
Update

 


See Also….

Advanced Raytrace

Basic Raytrace

Coatings

Curves

Elements

Entity Info

General Ray Data

Gratings

Importance Sampling

Linear Transforms

Materials

Ray Buffer Handling

Ray Data Get/Set

Raytrace Control

Scatter

Sources

Surfaces

 

 

 

 

 

Copyright © Photon Engineering, LLC