Navigation: Scripting Reference Manual > Script Examples > Examples - Linear Transformation Primitives

 

Examples - Linear Transformation Primitives

 

Contact Us: fredsupport@photonengr.com

 

These examples cover the FRED Linear Transform Primitives scripting commands:

"Add" - add an operation to be defined,

"Delete" - deletes an operation,

"Get" - gets operation or coordinate system info,

"Lock" - allows/prevents update of linear transforms,

"(Re)Start" - sets coordinate system for all operations,

"Place" - appends a PlaceAt operation,

"Rotate" - appends a Rotate operation

"Shift" - appends a Shift operation

"Transform" - transforms vectors from one coordinate system to another.

 

The structures listed below contain parameters required for linear transform primitive commands:

T_COORDSYS

T_OPERATION

 


 

"Add" an operation

The command AddOperation is one method of appending a linear transform operation to a specific entity. In the following example, a "ShiftZ" operation is appended to the entity "Mirror1":

 

Dim tp As T_OPERATION
tp.type="ShiftZ"
tp.val1=2

id=FindName("Mirror1")
AddOperation id, tp
Update


 

"Delete" an operation

Use this command to delete an existing operation from a specific entity. For instance, to delete the last operation associated with "Mirror1", use the following script lines. Remember that the operations are zero-indexed. As a result, it is necessary to subtract 1 from the entity count to get the index of the last operation.

 

id=FindName("Mirror1")
count=GetOperationCount (id)
DeleteOperation id, count-1
Update

 


 

"Get" an operation

The information associated with a specific operation can be retrieved using GetOperation. The GetOperationCount command returns the number of operations associated with a specific entity. In the following example, these commands are used together with DeleteOperation to determine if "Mirror1" has a "ShiftY" operation and, if so, to delete it:

 

Dim op As T_OPERATION
id=FindName("Mirror1")

cnt=0
While (GetOperationCount(id)-1)>cnt
 GetOperation id, cnt, op
 Print cnt, op.type
  If op.type="ShiftY" Then
   DeleteOperation id,cnt
   cnt=cnt-1
  End If
 cnt=cnt+1
Wend


 

"Lock" an operation

When an operation is changed or added, FRED immediately performs an internal update of a general matrix describing entire collection of linear transforms. For large models, this immediate updating can have an adverse effect on processing speed. The LockOperationUpdates command disables immediate updating. Once all operation changes are complete, updating can be enabled and a single Update performed.

 

For i=22 To 3200
 LockOperationUpdates id, True
Next i

 :
 :

'change some parameter values for these 3178 nodes

 :

 :

For i=22 To 3200
 LockOperationUpdates id, False
Next i

Update


 

"(Re)Start" coordinate system

Use the StartCoordSys command to change the reference coordinate system for an entity. Here, the reference coordinate system for "Mirror1" is changed to the be Global coordinate system (-1).

 

id=FindName("Mirror1")
StartCoordSys id,-1

 

The RestartCoordSys command changes the entity reference coordinate system AND deletes all operations on that entity. In this example, the GetCoordSys command is used to determine the desired coordinate system identifier before proceeding with the change.

 

pid=FindName("Prism")

n=GetCoordSys(pid)

mid=FindName("Mirror1")

RestartCoordSys(mid,n)


 

"Place/Rotate/Shift" operations

The Place/Rotate/Shift commands provide a convenient alternative to AddOperation for the purpose of repositioning/reorienting entities. Note, however, that these commands require a coordinate system as one of their arguments.

 

As an example, these lines of code add a "ShiftZ" operation to lens element Edmund 31859. This shift is done with respect to the back surface of the Edmund 43399 element. To complete this task, first determine the identifiers of the Edmund 43399 back surface entity and the Edmund 31859 element. Next, issue the ShiftZ command and Update the FRED document.

 

l1id=FindFullName("Geometry.Edmund 43399 # 1.Surface 2")
l2id=FindFullName("Geometry.Edmund 31859 # 1")
 

ShiftZ l2id, l1id, 1.208
Update


 

 

"Transform" a vector

Use the "Transform" commands to compute the direction of a vector in one coordinate system as expressed in another coordinate system.

 

In this example, "Mirror1" local z-direction faces in the global y-direction while "Mirror2" local z-direction faces in the global z-direction. Given a vector (0,0,1) expressed in the local coordinate system of "Mirror1", that same vector expressed in the local coordinate system of "Mirror2" is (0,1,0).
 

id1=FindFullName("Mirror1")
id2=FindFullName("Mirror2")

x=0:y=0:z=1
Print "vector direction in Mirror1 coordinate system",x,y,z
TransformDirection id1, id2, x, y, z
Print "vector direction in Mirror2 coordinate system",x,y,z

 

Output Window says:

0 0 1

0 1 0


 

See Also….

Advanced Raytrace

Basic Raytrace

Coatings

Curves

Elements

Entity Info

General Ray Data

Gratings

Importance Sampling

Materials

Ray Buffer Handling

Ray Data Get/Set

Ray Path

Raytrace Control

Scatter

Sources

Surfaces

 

 

 

 

 

Copyright © Photon Engineering, LLC