Navigation: Scripting Reference Manual > Script Examples > Examples - Surfaces

 

Examples - Surfaces

 

Contact Us: fredsupport@photonengr.com

 

These examples cover the basic FRED scripting commands involving Surfaces:

"Add" - add a Surface or surface attribute,

"AuxData" - auxiliary data management,

"Delete" - remove a Surface attribute,

"Get" - retrieve Surface attributes,

"Init" - initialize a Surface structure,

"Set" - set Surface attributes.

 

The following structures are required for specifying Surfaces and their spatial extent:

T_ENTITY

T_CONICFOCI

T_REVOLVESURF

T_RULEDSURF

T_SURFVISUALIZE

T_TABULATEDCYLINDER

T_TOROIDALASPHERE

T_TUBE

T_TRIMVOLUME


- A wide range of Surface types are available in FRED. Each surface has Aperture, Location/Orientation, Material, Coating, Raytrace control, Scatter, Glue, Grating, Trimming volume, Visualization and Auxiliary data components.

 

- Surfaces MUST be added in the Tree under a Custom Element.  Failure to do so could lead to erroneous behavior.

 

- All surfaces require a T_ENTITY structure as part of their definition in order to specify a minimum amount of information such as parentage, name, trace status and basic visualization attributes. An un-initialized T_ENTITY structure will often lead to undesirable surface attributes. Initializing the T_ENTITY structure and providing a unique name is always recommended.

 

- Upon creation, all surfaces acquire default Trimming, Location/Orientation, Visualization, Material, Coating, and Raytrace control attributes shown below.  Unless specified, FRED will also give the new surface the name "Surf n" where n is an automatically incremented integer. The user is responsible for supplying explicit values for these attributes to achieve the desired result.

 

Attribute

Default

Trimming

XYZ semi-apertures = 1, cylindrical

Location/Orientation

entity's local coordinate system

Visualization

Flat shading, shine=28, opacity=1, local coordinate axes lengths +/- 1.2

Material

material 1=Air, material 2=Air

Coating

Absorb (100%)

Raytrace Control

Halt All

Name

Surf n (n is an auto-incremented integer)

 

- There need not be a separate T_ENTITY structure for each new surface. Once declared, a T_ENTITY structure can be reused as often as necessary as long as the desired attributes are updated for each instance of its use.

 


 

"Add" a Surface or Surface attribute

As a minimum, a T_ENTITY structure must be declared when creating new surfaces. Always initialize this structure to insure predictable results. In the following example, a single T_ENTITY structure is used to create a series of different surfaces. Note that the same structure can be utilized in the creation of the Custom Elements under which these surface reside.

 

Please make sure that your script is followed by an Update command so that your geometry is properly created on the object tree.  Failure to do so will leave the document in an invalid state and may need to be re-loaded.

 

Adding a Plane or Conic

 Dim ent As T_ENTITY
 InitEntity ent

 ent.parent=2
 ent.name="First element"
 c1id = AddCustomElement ( ent )


 ent.parent=c1id
 ent.name="Plane 1.1"
 p1id = AddPlane ( ent )
 

 ent.name="conic 1.1"
 con1id = AddConic ( ent, 0.2, -1 )
'*******************************
 

Adding a Tube

 ent.parent=2
 ent.name="Second element"
 c2id = AddCustomElement ( ent )

 Dim et As T_TUBE
 InitTube tb

 ent.parent=c2id
 ent.name="Tube 1.1"
 'T_TUBE data goes here
 t1id=AddTube ( ent, tb )
'*******************************
 

Adding a Conic Foci

 ent.parent=2
 ent.name="Third element"
 c3id = AddCustomElement ( ent )

 Dim cf As T_CONICFOCI
 InitConicFoci cf

 ent.parent=c3id
 ent.name="confoc 1.1"
 'T_CONICFOCI data goes here
 cfid=AddConicFoci( ent, cf )
'*******************************
 

Adding an Asphere

 ent.parent=2
 ent.name="Fourth element"
 c4id = AddCustomElement ( ent )

 ent.parent=c4id
 ent.name="asphere 1.1"

 'user defined aspheric coefficients

 Dim evena(2) As Double
 Dim odda(2) As Double

 evena(0)=1.32e-2:  evena(1)=-4.923e-4:  evena(2)=7.662e-7  
 odda(0)=-3.77e-3:  odda(1)=4.88e-5:     odda(2)=0
 

 asp1id = AddAsphere( ent, 0.4, -2.038, evena, odda )
'*******************************

 

Adding a Polynomial Asphere

 ent.parent=2
 ent.name="Fifth element"
 c5id = AddCustomElement ( ent )

 

 ent.parent=c5id
 ent.name="poly asphere 1.1"
 

 'user defined aspheric coefficients

 Dim coefp(4) As Double

 coefp(0)=-1.2e-4:  coefp(1)=2.89e-4:  coefp(2)=0.4e-5:  coefp(3)=6.6e-7:  coefp(4)=9.3e-8

 

 pa1id = AddPolynomialAsphere ( ent, -0.25, 1.6, coefp )

'*******************************

 

Adding a Toroidal Asphere

 ent.parent=2
 ent.name="Sixth element"
 c6id = AddCustomElement ( ent )

 

 Dim tasp As T_TOROIDALASPHERE
 InitToroidalAsphere tasp
 

 ent.parent=c6id
 ent.name="toroidal asphere 1.1"

 

 'T_TOROIDALASPHERE data goes here

 

 'user defined toroidal asphere coefficients
 Dim ctasp(1,3) As Double
 ctasp(0,0)=0 : ctasp(1,0)=0 'unused placeholders - should be set to zero
 ctasp(0,1)=0 : ctasp(1,1)=0 'unused placeholders - should be set to zero
 'A coef                B coef
 ctasp(0,2)=0.03    : ctasp(1,2)=0.04
 ctasp(0,3)=-0.0005 : ctasp(1,3)=-0.004
 

 id = AddToroidalAsphere ( ent, tasp, ctasp )

'*******************************

 

Adding an XY Toroidal Asphere

 ent.parent=2
 ent.name="Seventh element"
 c7id = AddCustomElement ( ent )

 

 Dim xytasp As T_TOROIDALASPHERE
 InitToroidalAsphere xytasp
 

 ent.parent=c7id
 ent.name="XYtoroidal asphere 1.1"

 

 'T_TOROIDALASPHERE data goes here

 

 'user defined XYtoroidal asphere coefficients
 Dim cxytasp(1) As Double
 cxytasp(0)=0.002 : cxytasp(1)=0.003

 

 id = AddXYToroidalAsphere ( ent, xytasp, cxytasp )

'*******************************

 

Adding a Zernike Aspheric Surface

 ent.parent=2
 ent.name="Eigth element"
 c8id = AddCustomElement ( ent )

 

 ent.parent=c8id
 ent.name="Zernike aspheric 1.1"

 

 'use SetZernikeSurfCoefInterpretation, SetZernikeSurfBaseConic, SetZernikeSurfIthAsphCoef
 'to set base conic, aspheric terms and coefficient interpretation

 

 Dim zrn8(4) As Double
 zrn8(0)=0.2 : zrn8(1)=0.3 : zrn8(2)=0.4 : zrn8(3)=0 :zrn8(4)=0.5  'Zernike coefficients
 

 id = AddZernikeSurf ( ent, 2.5, 2.5, zrn8 )

'*******************************

 

Adding an Implicit Scripted Surface

 ent.parent=2
 ent.name="Ninth element"
 c9id = AddCustomElement ( ent )

 

 ent.parent=c9id
 ent.name="Implicit Script Surface 1.1"

 

 scrptsurfid=AddImplicitScriptSurf ( ent )

 'use SetImplicitScript to specify script name

'*******************************

 

Adding a NURB Surface (using 1-D points array, see the AddNURBSurf topic for discussion)

 ent.parent=2
 ent.name="Tenth element"
 c10id = AddCustomElement ( ent )

 

 ent.parent=c10id
 ent.name="NURBs Surface 1.1"

 

 Dim knotU(3) As Double

 Dim knotV(3) As Double

 Dim Npoints(3*4-1) As Double

 Dim Nweights(3) As Double

 

 knotU(0)=0 : knotU(1)=0 : knotU(2)=1 : knotU(3)=1
 knotV(0)=0 : knotV(1)=0 : knotV(2)=1 : knotV(3)=1
 Npoints(0)=-0.5 : Npoints(1)=-0.5 : Npoints(2)=0  : Nweights(0)=1
 Npoints(3)=0.5  : Npoints(4)=-0.5 : Npoints(5)=0  : Nweights(1)=1
 Npoints(6)=-0.5 : Npoints(7)=0.5  : Npoints(8)=0  : Nweights(2)=1
 Npoints(9)=0.5  : Npoints(10)=0.5 : Npoints(11)=0 : Nweights(3)=1

 

 NURBid = AddNURBSurf ( ent, 1, 1, 2, 2, knotU, knotV, Npoints, Nweights )

'*******************************

 

Adding a Revolved Surface

 ent.parent=2
 ent.name="Eleventh element"
 c11id = AddCustomElement ( ent )

 

 ent.parent=c11id
 ent.name="Revolved Surface 1.1"

 

 Dim rvs As T_REVOLVESURF

 InitRevolveSurf curvid, rvs     'uses existing curve to create surface of revolution

 

 'T_REVOLVESURF data goes here

 

 rsid = AddRevolveSurf ( ent, rvs )

'*******************************

 

Adding a Ruled Surface

 ent.parent=2
 ent.name="Twelveth element"
 c12id = AddCustomElement ( ent )

 

 ent.parent=c12id
 ent.name="Ruled Surface 1.1"

 

 Dim rlds As T_RULEDSURF      'no Init command exists for Ruled Surface so attributes MUST be assigned

 rlds.curve1=curv1id

 rlds.curve2=curv2id

 rlds.crossConnect=True

 

 rld1id = AddRuledSurf ( ent, rlds )

'*******************************

 

Adding a Spline Surface

 ent.parent=2
 ent.name="Thirteenth element"
 c13id = AddCustomElement ( ent )

 

 ent.parent=c13id
 ent.name="Spline Surface 1.1"

 

 Dim uBp(1) As Double
 Dim vBp(1) As Double
 Dim Spcoef(2,2,2,0,0) As Double
 

 uBp(0)=0 : uBp5(1)=1
 vBp(0)=0 : vBp(1)=1
 Spcoef(0,0,0,0,0)=0 : Spcoef(1,0,0,0,0)=0 : Spcoef(2,0,0,0,0)=0
 Spcoef(0,1,0,0,0)=0 : Spcoef(1,1,0,0,0)=1 : Spcoef(2,1,0,0,0)=0
 Spcoef(0,2,0,0,0)=0 : Spcoef(1,2,0,0,0)=0 : Spcoef(2,2,0,0,0)=0
 Spcoef(0,0,1,0,0)=1 : Spcoef(1,0,1,0,0)=0 : Spcoef(2,0,1,0,0)=0
 Spcoef(0,1,1,0,0)=0 : Spcoef(1,1,1,0,0)=0 : Spcoef(2,1,1,0,0)=0
 Spcoef(0,2,1,0,0)=0 : Spcoef(1,2,1,0,0)=0 : Spcoef(2,2,1,0,0)=0
 Spcoef(0,0,2,0,0)=0 : Spcoef(1,0,2,0,0)=0 : Spcoef(2,0,2,0,0)=0
 Spcoef(0,1,2,0,0)=0 : Spcoef(1,1,2,0,0)=0 : Spcoef(2,1,2,0,0)=0
 Spcoef(0,2,2,0,0)=0 : Spcoef(1,2,2,0,0)=0 : Spcoef(2,2,2,0,0)=0
 

 splnid = AddSplineSurf ( ent, 2, 2, uBp, vBp, Spcoef )

'*******************************

 

Adding a Tabulated Cylinder

 ent.parent=2
 ent.name="Fourteenth element"
 c14id = AddCustomElement ( ent )

 

 ent.parent=c14id
 ent.name="Tabulated Cylinder 1.1"

 

 Dim tc As T_TABULATEDCYLINDER      'no Init command exists for Tabulated Cylinder so attributes MUST be assigned

 tc.x=0 : tc.y=0 : tc.z=1           'extrusion direction vector

 tc.curve=crv8id                    'identifier of curve to be extruded

 

 tcylid = AddTabulatedCylinder ( ent, tc )

'*******************************

 

Adding a Trimmed Parametric Surface

 ent.parent=2
 ent.name="Fifteenth element"
 c15id = AddCustomElement ( ent )

 

 ent.parent=c15id
 ent.name="Trimmed Parametric 1.1"

 

 id = AddTrimmedParametric ( ent, 38, 26, 27 )

'*******************************

Update


 

"AuxData" management

 


 

"Delete" a Surface attribute

Delete a scatter model from a surface as shown in this example:

 

id=FindName("Diffuser")

scid=FindScatter("White Lambertian")

DeleteSurfIthScatter id, scid


 

"Init" a Surface structure

(see "Add" section above)


 

"Get/Set" Surface attributes

Use the "Get" and "Set" commands to retrieve and change Surface parameters. In this example, the 2nd to the last XYToroidal Aspheric coefficient is reduced by 10%:

 

id=FindName("potato chip optic")

n = GetXYToroidalAsphereCoefCount ( id )

cval = GetXYToroidalAsphereIthCoef ( id, n-3 )

cval=cval*0.9

SetXYToroidalAsphereIthCoef id, n-3, cval

 

In this example, the trimming hole location in a primary mirror is shifted in the +x-direction by 0.2 mm:

 

Dim tv As T_TRIMVOLUME

 

id=FindName("Primary")

GetTrimVolume id, tv

tv.xCenterHole=tv.xCenterHole+0.2

SetTrimVolume id, tv

 

Material, Scatter model, Coatings and Raytrace controls for a specific surface can be retrieved and changed. Here, all surfaces using a specific Raytrace control have that attribute changed:

 

For i=0 To GetEntityCount()-1
 If IsSurface(i) Then
  If GetSurfRaytraceCtrl(i)=FindRaytraceCtrl("Transmit Specular") Then
   SetSurfRaytraceCtrl i, FindRaytraceCtrl("Allow All")
  End If
 End If
Next i


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

Ray Path

Raytrace Control

Scatter

Sources

 

 

 

 

 

Copyright © Photon Engineering, LLC