FRED can import a variety of rayset formats, including its own FCR and FRBS as well as those provided by other distributors. This flexibility is further extended by offering imported or User-defined source types which allow raysets to be dynamically imported from an external file or stored within the FRED document, respectively. If possible, a binary ray file format is recommended for both speed and compactness. The following rayfile formats are used by FRED:
FCR (FRED Compact Rayset) A compact and efficient binary file format written by FRED and ProSource (ProSource Binary Format for FRED). These files contain only ray position (x,y,z), ray direction (a,b,c) and flux. Read these files with the Imported Source dialog, script commands SetSourcePosImported & ReadBasicRayDataFromFile, the Ray Manipulation Utility and User-defined Source Position type. The FCR file format is float (single) precision, so any calculations made by reloading FCR data into FRED will not be exactly the same as an equivalent calculation run entirely in FRED without the use of rayfile data.
TM25 The TM25 Ray File Format is a standard developed by the Illuminating Engineering Society (IES) to describe detailed ray data used in optical simulations and lighting design. These files contain ray position (x,y,z), ray direction (a, b, c), flux (radiant power of the ray) and wavelength (optional, if multi-spectral data is included).
ASAP Distribution File (*.dis) This is a compact and efficient binary format written by ASAP. These files contain only ray position (x,y,z), ray direction (a,b,c), flux plus two other fields (OPL, shape) which FRED ignores.
ProSource Binary Format This format is identical to the FCR format except for header information. Supports files from Zemax, OPTICAD & TracePro.
ASCII/Text This is a text file format containing ray position (x,y,z), ray direction (a,b,c), flux and optionally OPL. Supports LightTools, & TracePro text file formats.
CSV This is a comma separated values list with each row corresponding to a single ray and having nine associated values. The nine values are the ray's x,y,z position vector, a,b,c direction vector, power, wavelength (microns), and optical path length.
LucidShape This is a binary format containing ray position (x,y,z), ray direction (a,b,c), flux. No units specification is included.
LightTools This is a text file format containing ray position (x,y,z), ray direction (a,b,c), flux and optionally OPL. No units specification is included.
TracePro This is a text file format containing ray position (x,y,z), ray direction (a,b,c), flux and optionally OPL.
FRBS This binary file format saves ray buffer data directly. As such, this file type is required in order to save coherent and/or polarized ray data. Only two methods can be used to load this file type; the Ray Manipulation Utility or the script command ReadRaysFromFRBSFileToRayBuffer. Note also that this rayset is not added to the Source Folder.
Ray file data can be accessed from the following locations. •From a Detailed Source dialog Positions / Directions tab, select "Read rays from file and generate dynamically" as the Ray Positions type. •From a Detailed Source dialog Positions / Directions tab, select "User defined rays (manually defined)" as the Ray Positions type. Right mouse click in the spreadsheet area and select "Replace With Rays From a File" from the list menu. •Through the use of a Rayfile Source type Source Primitive.
The *.fcr file format includes only the basic incoherent ray information and its structure consists of a binary header followed by one packet of binary information per ray.
The *.fcr header structure has the following format in C++: struct { int Identifier; int NbrRays; //!< The number of rays in the file char Description[100] //!< A text description of the source. Always 100 bytes long. float SourceFlux; //!< The total flux of this source float RaySetFlux; //!< The flux represented by this rayset float Wavelength; //!< The wavelength in microns, 0 if a composite float AzimuthBeg, AzimuthEnd; //!< Angular range for ray set (Degrees) float PolarBeg, PolarEnd; //!< Angular range for ray set (Degrees) long DimensionUnits; //!< METERS=0, INCHES=1, CENTIMETERS=2, FEET=3, MILLIMETERS=4 float LocX, LocY, LocZ; //!< Coordinate Translation of the source float RotX,RotY, RotZ; //!< Source Rotation (Radians) float ScaleX, Scale Y, ScaleZ; //!< Scale factor to expand/contract source float unused1, unused2, unused3, unused4; //!< not used int RayFormatType; //!<FluxOnly(=TriStimY?)=0, TriStimAll=1, Spectral=2, TriStimX=3, TriStimZ=4 int FluxType; //!<Watts=0, Lumens=1 int BytesPerRay; //!<28 for FluxOnly,TriStimX,TriStimZ; 32 for Spectral; 36 for TriStimAll int reserved4; //!< reserved }
The *.fcr ray packet structure has the following format. the wavelength may or may not be present depending on whether the user has selected that option on export.: struct { float x, y, z; //!< position data for the ray float l, m, n; //!< orientation data for the ray float intensity; //!< power data for the ray float wavelength; //!< wavelength in microns }
FRED Script for Reading FCR Files The FRED script code below demonstrates how to read a binary FCR file and manually add rays to the ray buffer. Note that this script is simply a demonstration of how to read the binary file format. Reading FCR files can be accomplished in the GUI using the Ray Manipulation Utilities dialog or in the scripting language using the ReadBasicRayDataFromFile() function.
Sub Main
DeleteRays()
Dim infile As String infile = "C:\temp\fred\support\fcr_wavlTest.fcr"
Print "Reading FCR file..." Print "Entry" & Chr(9) & "Read Value"
Open infile For Binary Access Read As #1
'Process the header and get the number of rays and the bytes per ray Dim nRays As Long, nBytes As Long, srcWavl As Single ReadHeader( nRays, nBytes, srcWavl )
'Process the ray data Print "Generating " & nRays & " rays from file and adding to ray buffer." Dim curRay As Long For curRay = 1 To nRays ReadRay( srcWavl ) Next
Print "Finished adding rays to buffer."
Close #1
End Sub
Function ReadRay( ByVal in_srcWavl As Single ) As Huge_
'Process the next ray
'Ray position Dim xPos As Single, yPos As Single, zPos As Single Get #1, , xPos Get #1, , yPos Get #1, , zPos
'Ray direction Dim xDir As Single, yDir As Single, zDir As Single Get #1, , xDir Get #1, , yDir Get #1, , zDir
'Ray flux Dim rPwr As Single Get #1, , rPwr
'Build the T_RAY Dim tRay As T_RAY tRay.active = True tRay.entity = 1 'optical sources node tRay.x = xPos tRay.y = yPos tRay.z = zPos tRay.a = xDir tRay.b = yDir tRay.c = zDir tRay.power = rPwr
'If wavelength data is present, get it, otherwise set the source wavelength from file header data If in_srcWavl = 0 Then Dim wavl As Single Get #1, , wavl tRay.wavelength = wavl Else tRay.wavelength = in_srcWavl End If
'Add the ray to the buffer Dim ridx As Huge_ ridx = AddRay( tRay )
Return ridx
End Function
Function ReadHeader( ByRef in_rcount As Long, _ ByRef in_rbytes As Long, _ ByRef in_srcWavl As Single ) As Boolean
'Reads the file header structure and returns the number of rays in the file
Print "" Print "Header information:"
'Identifier Dim id As Long Get #1, , id Print "Vendor ID" & Chr(9) & id
'Number of rays Get #1, , in_rcount Print "Number of rays" & Chr(9) & in_rcount
'Description string (always 100 characters long) Dim desc As String*100 Get #1, , desc Print "Description" & Chr(9) & desc
'Source flux Dim srcflux As Single Get #1, , srcflux Print "Source flux" & Chr(9) & srcflux
'Flux in rayset Dim rsetflux As Single Get #1, , rsetflux Print "Rayset flux" & Chr(9) & rsetflux
'Wavelength in microns, zero if multiple wavelengths Get #1, , in_srcwavl Print "Wavelength" & Chr(9) & in_srcwavl
'Azimuth start and end Dim aziStart As Single, aziEnd As Single Get #1, , aziStart Get #1, , aziEnd Print "Azimuth range" & Chr(9) & aziStart & Chr(9) & aziEnd
'Polar start and end Dim polStart As Single, polEnd As Single Get #1, , polStart Get #1, , polEnd Print "Polar range" & Chr(9) & polStart & Chr(9) & polEnd
'Units, 0=meters, 1=inches, 2=cm, 3=feet, 4=mm Dim runits As Long Get #1, , runits Print "Rayfile units" & Chr(9) & runits
'Source position translation Dim xPos As Single, yPos As Single, zPos As Single Get #1, , xPos Get #1, , yPos Get #1, , zPos Print "Origin position" & Chr(9) & xPos & Chr(9) & yPos & Chr(9) & zPos
'Source rotation (radians) Dim xRot As Single, yRot As Single, zRot As Single Get #1, , xRot Get #1, , yRot Get #1, , zRot Print "Source rotation (rad)" & Chr(9) & xRot & Chr(9) & yRot & Chr(9) & zRot
'Source scale factors Dim xScale As Single, yScale As Single, zScale As Single Get #1, , xScale Get #1, , yScale Get #1, , zScale Print "Source scale factors" & Chr(9) & xScale & Chr(9) & yScale & Chr(9) & zScale
'Empty unused slots Dim u1 As Single, u2 As Single, u3 As Single, u4 As Single Get #1, , u1 Get #1, , u2 Get #1, , u3 Get #1, , u4
'Ray format type; 0=FluxOnly (TriStimY), 1=TriStimAll, 2=Spectral, 3=TriStimX, 4=TriStimZ Dim rtype As Long Get #1, , rtype Print "Ray format type" & Chr(9) & rtype
'Ray flux type; 0=Watts, 1=Lumens Dim rfluxtype As Long Get #1, , rfluxtype Print "Ray flux type" & Chr(9) & rfluxtype
'Bytes per ray; <28 for FluxOnly,TriStimX,TriStimZ; 32 for Spectral; 36 for TriStimAll Get #1, , in_rbytes Print "Bytes per ray" & Chr(9) & in_rbytes
'Final reserved Dim res1 As Long Get #1, , res1
Print ""
Return True
End Function
Matlab Script for Reading FCR Files The Matlab script below defines a function that will read in an FCR file and process the ray data into an array.
function fcrraydata = fcr2matfun(fnfcr)
fid = fopen( fnfcr ); fcrraydata.identifier = fread( fid , 1 , 'long' ); fcrraydata.Nrays = fread( fid , 1 , 'int' ); fcrraydata.description = strip(char( [ fread( fid , 100 , 'char*1' ) ].' )); fcrraydata.sourceflux = fread( fid , 1 , 'float' ); fcrraydata.raysetflux = fread( fid , 1 , 'float' ); fcrraydata.wavelength = fread( fid , 1 , 'float' ); fcrraydata.azistart = fread( fid , 1 , 'float' ); fcrraydata.aziend = fread( fid , 1 , 'float' ); fcrraydata.polstart = fread( fid , 1 , 'float' ); fcrraydata.polend = fread( fid , 1 , 'float' ); fcrraydata.dimunits = fread( fid , 1 , 'long' ); fcrraydata.x0 = fread( fid , 1 , 'float' ); fcrraydata.y0 = fread( fid , 1 , 'float' ); fcrraydata.z0 = fread( fid , 1 , 'float' ); fcrraydata.alpha = fread( fid , 1 , 'float' ); fcrraydata.beta = fread( fid , 1 , 'float' ); fcrraydata.gamma = fread( fid , 1 , 'float' ); fcrraydata.sX = fread( fid , 1 , 'float' ); fcrraydata.sY = fread( fid , 1 , 'float' ); fcrraydata.sZ = fread( fid , 1 , 'float' ); fread( fid , 4 , 'float' ); rayformattype = fread( fid , 1 , 'int' );
% fluxtype = fread( fid , 1 , 'int' ); % bytesperray = fread( fid , 1 , 'int' ); % rayreserved = fread( fid , 1 , 'int' );
fread( fid , 3 , 'int' ); if rayformattype == 0
% [ x y z xdir ydir zdir flux ] fcrraydata.raydata = fread( fid , [ 7 fcrraydata.Nrays ] , 'float' ).'; elseif rayformattype == 2
% [ x y z xdir ydir zdir flux wavelength ] fcrraydata.raydata = fread( fid , [ 8 fcrraydata.Nrays ] , 'float' ).'; else warning('!!! Format not supported !!!') end fclose( fid ); end
ReadRaysFromFRBSFileToRayBuffer
|