Programming Reference for VirtualLab Fusion  2022.1
Static Public Member Functions | List of all members
VL_Files Class Reference

This class provides methods for the import and export of fields to bitmaps, text files, or bitmap animations and access to the Microsoft Windows file system. More...

Static Public Member Functions

static Bitmap CalculateBitmapFromChromaticFieldsSet2D (ChromaticFieldsSet cfs, double brightnessFactor, out bool noVisibleWavelength, bool interpolated=true, Size? numberOfPixels=null, PhysicalValueRange xRange=null, PhysicalValueRange yRange=null)
 Static conversion method for creating a bitmap from a 2D Chromatic Fields Set. More...
 
static Bitmap CalculateBitmapFromDataArray2D (DataArray2D dataArray, int subsetIndex, FieldQuantity fieldQuantity, bool interpolated=true, Size? numberOfPixels=null, PhysicalValueRange xRange=null, PhysicalValueRange yRange=null, double minValue=double.NaN, double maxValue=double.NaN, ColorLookUpTableForDataView2D colorTable=null, Color? colorForUndefined=null)
 Static public conversion method for creating a bitmap from a 2D Data Array. More...
 
static ComplexAmplitude ImportGrayScaleBitmap (string fileName, double minimumValue=0, double maximumValue=1, FieldQuantity fieldQuantity=FieldQuantity.RealPart, PrecisionMode precision=PrecisionMode.Float, double? wavelength=null)
 Imports the values of a grayscale bitmap (24 bit RGB or 16 bit gray scale) into a ComplexAmplitude. The sampling distance is calculated from the dpi values of the bitmap. More...
 
static ComplexAmplitude LoadField (string fileName)
 Loads a field from a file. More...
 
static HarmonicFieldsSet LoadFieldsSet (string fileName)
 Loads a fields set from a file. More...
 
static int NumberOfLines (string fileName)
 Returns the number of lines in the text file specified by fileName. More...
 
static void ProcessOpticalSetup (string fileNameOpticalSetup, string outputFolder, string fileNameParameters="", PropagationEngine? simulationEngine=null, int? analyzerIndex=null, bool useSubfolder=false)
 Loads and simulates the given Optical Setup file. More...
 
static string ReadLine (string fileName, int lineNumber)
 Returns the nth line of the text file specified by fileName, where \(n\) equals the lineNumber. The first line of the file is line number 1. If the file does not exist or the specified line number is beyond the end of the file, the program using this method will be stopped unless the thrown exception is handled outside of this method. More...
 
static void SaveDocument (IDocument document, string fileName)
 Saves a document (e. g. a ComplexAmplitude or a HarmonicFieldsSet object) to the hard disc. More...
 
static void WriteLineToLogFile (string fileName, string message)
 Writes a string as a separate line to the end of the specified log file. More...
 
static void WriteToLogFile (string fileName, string message)
 Writes a string to the end of the specified log file. In contrast to the WriteLineToLogFile method, this method does not introduce a line break. More...
 

Detailed Description

This class provides methods for the import and export of fields to bitmaps, text files, or bitmap animations and access to the Microsoft Windows file system.

Member Function Documentation

◆ CalculateBitmapFromChromaticFieldsSet2D()

static Bitmap CalculateBitmapFromChromaticFieldsSet2D ( ChromaticFieldsSet  cfs,
double  brightnessFactor,
out bool  noVisibleWavelength,
bool  interpolated = true,
Size?  numberOfPixels = null,
PhysicalValueRange  xRange = null,
PhysicalValueRange  yRange = null 
)
static

Static conversion method for creating a bitmap from a 2D Chromatic Fields Set.

Parameters
cfsChromatic fields set to create the bitmap from
brightnessFactorFactor to increase or decrease the brightness in the bitmap to be calculated. Too high brightness can lead to oversaturation.
noVisibleWavelengthOut parameter that indicates whether none of the wavelengths is in the range of visible wavelengths.
interpolatedIf this optional parameter is set to false, you see the original sampling points in the bitmap. Else an interpolation between neighbored sampling points is done.
numberOfPixelsNumber of pixels in the resulting bitmap. If this optional parameter is not specified, one pixel per sampling point is created.
xRangeOptional x-coordinate range of the Chromatic Fields Set to be displayed in the bitmap. Can be used to show only a part of the Chromatic Fields Set.
yRangeOptional y-coordinate range of the Chromatic Fields Set to be displayed in the bitmap. Can be used to show only a part of the Chromatic Fields Set.
Returns
The bitmap created from the Chromatic Fields Set.

◆ CalculateBitmapFromDataArray2D()

static Bitmap CalculateBitmapFromDataArray2D ( DataArray2D  dataArray,
int  subsetIndex,
FieldQuantity  fieldQuantity,
bool  interpolated = true,
Size?  numberOfPixels = null,
PhysicalValueRange  xRange = null,
PhysicalValueRange  yRange = null,
double  minValue = double.NaN,
double  maxValue = double.NaN,
ColorLookUpTableForDataView2D  colorTable = null,
Color?  colorForUndefined = null 
)
static

Static public conversion method for creating a bitmap from a 2D Data Array.

Parameters
dataArrayData Array to create the bitmap from
subsetIndexThe index of that data subset of the Data Array to be converted to the bitmap.
fieldQuantityThe field quantity to be converted to the bitmap.
interpolatedIf this optional parameter is set to false, you see the original sampling points in the bitmap. Else an interpolation between neighbored sampling points is done, using the interpolation methods (X and Y) of the data array.
numberOfPixelsNumber of pixels in the resulting bitmap. If this optional parameter is not specified, one pixel per sampling point is created.
xRangeOptional x-coordinate range of the Data Array to be displayed in the bitmap. Can be used to show only a part of the Chromatic Fields Set.
yRangeOptional y-coordinate range of the Data Array to be displayed in the bitmap. Can be used to show only a part of the Chromatic Fields Set.
minValueOptional minimum value to be mapped to a color. All values below will have the same color as this value.
maxValueOptional maximum value to be mapped to a color. All values above will have the same color as this value.
colorTableOptional color table for mapping double values to colors. By default the corresponding Global Option is used.
colorForUndefinedColor to be used for undefined values. By default the corresponding Global Option is used.
Returns
The bitmap created from the DataArray2D

◆ ImportGrayScaleBitmap()

static ComplexAmplitude ImportGrayScaleBitmap ( string  fileName,
double  minimumValue = 0,
double  maximumValue = 1,
FieldQuantity  fieldQuantity = FieldQuantity.RealPart,
PrecisionMode  precision = PrecisionMode.Float,
double?  wavelength = null 
)
static

Imports the values of a grayscale bitmap (24 bit RGB or 16 bit gray scale) into a ComplexAmplitude. The sampling distance is calculated from the dpi values of the bitmap.

Parameters
fileNameFile name of the bitmap to be imported.
minimumValueOptional minimum value, i.e. the value of black pixels. 0 by default.
maximumValueOptional maximum value, i.e. the value of white pixels. 1 by default.
fieldQuantityOptional field quantity. If not specified, the data is imported into the real part. If the field quantity is Imaginary Part or Phase, the resulting ComplexAmplitude will be complex-valued, otherwise it will be real-valued.
precisionOptional precision (float or double) of the resulting field. Float by default.
wavelengthOptional wavelength. If you specify this value, a Harmonic Field instead of a Jones Matrix Transmission is generated.
Returns
A ComplexAmplitude with the imported data.

◆ LoadField()

static ComplexAmplitude LoadField ( string  fileName)
static

Loads a field from a file.

Parameters
fileNameFull path of the file to load. Note that backslashes must be doubled, for example “C:\myField.ca2”.
Returns
The loaded field.

◆ LoadFieldsSet()

static HarmonicFieldsSet LoadFieldsSet ( string  fileName)
static

Loads a fields set from a file.

Parameters
fileNameFull path of the file to load. Note that backslashes must be doubled, for example “C:\myFieldsSet.hfs”
Returns
The loaded fields set.

◆ NumberOfLines()

static int NumberOfLines ( string  fileName)
static

Returns the number of lines in the text file specified by fileName.

Parameters
fileNameThe full path of the file from which the text is to be read. Note that backslashes must be doubled, for example “C:\log.txt”.
Returns
The number of lines in the specified text file.

◆ ProcessOpticalSetup()

static void ProcessOpticalSetup ( string  fileNameOpticalSetup,
string  outputFolder,
string  fileNameParameters = "",
PropagationEngine?  simulationEngine = null,
int?  analyzerIndex = null,
bool  useSubfolder = false 
)
static

Loads and simulates the given Optical Setup file.

Parameters
fileNameOpticalSetupThe complete path of the Optical Setup file.
outputFolderThe folder to which all results are written. Note that messages, warnings, and errors are still written to the Messages tab of the main window of VirtualLab Fusion.
fileNameParametersIf you specify this optional parameter, the parameters of the Optical Setup are overwritten with the parameters of that given file. The file must be in a specific XML format which can be generated by exporting an Optical Setup to batch mode files within VirtualLab Fusion.
simulationEngineThe simulation engine to use. If this optional parameter is not specified, the given analyzer is executed instead.
analyzerIndexIndex of the analyzer to be executed. If this optional parameter is not specified and also no simulation engine, then the default simulation engine as defined in the Global Options is used.
useSubfolderIf set to true a unique sub-folder for each simulation run is generated.

◆ ReadLine()

static string ReadLine ( string  fileName,
int  lineNumber 
)
static

Returns the nth line of the text file specified by fileName, where \(n\) equals the lineNumber. The first line of the file is line number 1. If the file does not exist or the specified line number is beyond the end of the file, the program using this method will be stopped unless the thrown exception is handled outside of this method.

Parameters
fileNameThe full path of the file from which the text is to be read. Note that backslashes must be doubled, for example “C:\log.txt”.
lineNumberThe line number to be read.
Returns
The read line.
Exceptions
System.ArgumentExceptionLine number must be between 1 and the number of lines in the file.

◆ SaveDocument()

static void SaveDocument ( IDocument  document,
string  fileName 
)
static

Saves a document (e. g. a ComplexAmplitude or a HarmonicFieldsSet object) to the hard disc.

Parameters
documentThe document to save.
fileNameThe desired file name including the full path. Note that backslashes must be doubled, for example “C:\myField.ca2”

◆ WriteLineToLogFile()

static void WriteLineToLogFile ( string  fileName,
string  message 
)
static

Writes a string as a separate line to the end of the specified log file.

Parameters
fileNameThe full path of the file into which the text is to be written. Note that backslashes must be doubled, for example “C:\log.txt”. If the file does not exist, it is created.
messageThe string to write into the log file.

◆ WriteToLogFile()

static void WriteToLogFile ( string  fileName,
string  message 
)
static

Writes a string to the end of the specified log file. In contrast to the WriteLineToLogFile method, this method does not introduce a line break.

Parameters
fileNameThe full path of the file into which the text is to be written. Note that backslashes must be doubled, for example “C:\log.txt”. If the file does not exist, it is created.
messageThe string to write into the log file.