Class VL_Files
- Namespace
- VirtualLab.Programming
- Assembly
- VirtualLab.Programming.dll
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.
public static class VL_Files
- Inheritance
-
VL_Files
- Inherited Members
Methods
CalculateBitmapFromChromaticFieldsSet2D(ChromaticFieldsSet, double, out bool, bool, Size?, PhysicalValueRange?, PhysicalValueRange?)
Static conversion method for creating a bitmap from a 2D Chromatic Fields Set.
public static Bitmap CalculateBitmapFromChromaticFieldsSet2D(ChromaticFieldsSet cfs, double brightnessFactor, out bool noVisibleWavelength, bool interpolated = true, Size? numberOfPixels = null, PhysicalValueRange? xRange = null, PhysicalValueRange? yRange = null)
Parameters
cfsChromaticFieldsSetChromatic fields set to create the bitmap from
brightnessFactordoubleFactor to increase or decrease the brightness in the bitmap to be calculated. Too high brightness can lead to oversaturation.
noVisibleWavelengthboolOut parameter that indicates whether none of the wavelengths is in the range of visible wavelengths.
interpolatedboolIf 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.numberOfPixelsSize?Number of pixels in the resulting bitmap. If this optional parameter is not specified, one pixel per sampling point is created.
xRangePhysicalValueRangeOptional 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.
yRangePhysicalValueRangeOptional 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
- Bitmap
The bitmap created from the Chromatic Fields Set.
CalculateBitmapFromDataArray2D(DataArray2D, int, FieldQuantity, bool, Size?, PhysicalValueRange?, PhysicalValueRange?, double, double, ColorLookUpTableForDataView2D?, Color?, double, bool)
Static public conversion method for creating a bitmap from a 2D Data Array.
public static Bitmap CalculateBitmapFromDataArray2D(DataArray2D dataArray, int subsetIndex, FieldQuantity fieldQuantity, bool interpolated = true, Size? numberOfPixels = null, PhysicalValueRange? xRange = null, PhysicalValueRange? yRange = null, double minValue = NaN, double maxValue = NaN, ColorLookUpTableForDataView2D? colorTable = null, Color? colorForUndefined = null, double relativeThresholdForPhaseArtifacts = 0, bool replaceSincFFTbyTruncatedSinc = true)
Parameters
dataArrayDataArray2DData Array to create the bitmap from
subsetIndexintThe index of that data subset of the Data Array to be converted to the bitmap.
fieldQuantityFieldQuantityThe field quantity to be converted to the bitmap.
interpolatedboolIf 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.numberOfPixelsSize?Number of pixels in the resulting bitmap. If this optional parameter is not specified, one pixel per sampling point is created.
xRangePhysicalValueRangeOptional 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.
yRangePhysicalValueRangeOptional 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.
minValuedoubleOptional minimum value to be mapped to a color. All values below will have the same color as this value.
maxValuedoubleOptional maximum value to be mapped to a color. All values above will have the same color as this value.
colorTableColorLookUpTableForDataView2DOptional color table for mapping double values to colors. By default the corresponding Global Option is used.
colorForUndefinedColor?Color to be used for undefined values. By default the corresponding Global Option is used.
relativeThresholdForPhaseArtifactsdoubleThreshold for suppressing phase artifacts. If set to zero or below, no suppression will be done. In case this flag is set to
true, the expensive SincFFT will be replaced by TruncatedSinc. Applies only if parameter fieldQuantity is set to FieldQuantity.Phase.replaceSincFFTbyTruncatedSincbool
Returns
- Bitmap
The bitmap created from the DataArray2D
ImportBitmap(string)
Import of a bitmap file. The document type will be determined automatically: An RGB image will be imported as HarmonicFieldsSet. A gray-scale or indexed image will be imported as DataArray.
public static IDocument? ImportBitmap(string fileName)
Parameters
fileNamestringFull path of image to be imported.
Returns
- IDocument
Either a HarmonicFieldsSet (for RGB image) or a DataArray (for indexed or gray-scale image).
ImportGrayScaleBitmap(string, double, double, FieldQuantity, PrecisionMode, double?)
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.
public static ComplexAmplitude ImportGrayScaleBitmap(string fileName, double minimumValue = 0, double maximumValue = 1, FieldQuantity fieldQuantity = FieldQuantity.RealPart, PrecisionMode precision = PrecisionMode.Double, double? wavelength = null)
Parameters
fileNamestringFile name of the bitmap to be imported.
minimumValuedoubleOptional minimum value, i.e. the value of black pixels. 0 by default.
maximumValuedoubleOptional maximum value, i.e. the value of white pixels. 1 by default.
fieldQuantityFieldQuantityOptional field quantity. If not specified, the data is imported into the real part. If the field quantity is
Imaginary PartorPhase, the resulting ComplexAmplitude will be complex-valued, otherwise it will be real-valued.precisionPrecisionModeOptional precision. No longer used.
wavelengthdouble?Optional wavelength. If you specify this value, a Harmonic Field instead of a Jones Matrix Transmission is generated.
Returns
- ComplexAmplitude
A ComplexAmplitude with the imported data.
ImportTextFileIntoChromaticFieldsSet(string, double, ChromaticFieldsSetType, double, double, string, string, string, string, int, int, int, bool, bool)
Imports a text file into a ChromaticFieldsSet object.
public static ChromaticFieldsSet? ImportTextFileIntoChromaticFieldsSet(string fileName, double wavelength, ChromaticFieldsSetType type = ChromaticFieldsSetType.Unspecified, double samplingDistanceX = 1, double samplingDistanceY = 1, string commentIndicator = "#", string columnSeparator = " ", string decimalSeparator = ".", string groupSeparator = "", int firstRow = -1, int lastRow = -1, int numberOfCharactersToSkip = 0, bool decreasingXCoordinates = false, bool decreasingYCoordinates = false)
Parameters
fileNamestringThe full path of the text file to be imported.
wavelengthdoubleThe wavelength of the chromatic fields set to be created.
typeChromaticFieldsSetTypeThe type of object which is to be represented by the imported chromatic fields set.
samplingDistanceXdoubleThe sampling distance to be used for the x-coordinates if the coordinates are not coded within the data.
samplingDistanceYdoubleThe sampling distance to be used for the y-coordinates if the coordinates are not coded within the data.
commentIndicatorstringThe character to be interpreted as comment indicator, preceding lines which are to be ignored.
columnSeparatorstringCharacter which separates columns in the file. Please note: All 'white-space' characters are interchangeable. This means, for example, providing a blank will work with tabulator-separated columns and vice versa.
decimalSeparatorstringCharacter which separates the integer part from the fractional part of the numbers in the file.
groupSeparatorstringCharacter which 'groups' three digits respectively, so it can be called 'thousands separator' as well. This parameter may be left empty, meaning that no group separator is used in the file.
firstRowintThe first row to read from file. If set to -1, all lines will be processed.
lastRowintThe last row to read from file. If set to -1, all lines will be processed.
numberOfCharactersToSkipintIf greater than zero, this number of characters will be ignored at the beginning of each line.
decreasingXCoordinatesboolAre the actual x-coordinates to be interpreted as decreasing with increasing column-index?
decreasingYCoordinatesboolAre the actual y-coordinates to be interpreted as decreasing with increasing row-index?
Returns
- ChromaticFieldsSet
The imported ChromaticFieldsSet.
ImportTextFileIntoChromaticFieldsSet1D(string, List<double>, ChromaticFieldsSetType, bool, double, string, string, string, string, int, int, int, bool, bool)
Imports a text file into a ChromaticFieldsSet_1D object.
public static ChromaticFieldsSet_1D? ImportTextFileIntoChromaticFieldsSet1D(string fileName, List<double> wavelengths, ChromaticFieldsSetType type = ChromaticFieldsSetType.Unspecified, bool coordinatesAreCodedInData = false, double samplingDistance = 1, string commentIndicator = "#", string columnSeparator = " ", string decimalSeparator = ".", string groupSeparator = "", int firstRow = -1, int lastRow = -1, int numberOfCharactersToSkip = 0, bool expectDataInColumns = true, bool decreasingCoordinates = false)
Parameters
fileNamestringThe full path of the text file to be imported.
wavelengthsList<double>The wavelengths of the chromatic fields set to be created.
typeChromaticFieldsSetTypeThe type of object which is to be represented by the imported chromatic fields set.
coordinatesAreCodedInDataboolAre the coordinates for all of the data points given in the text data (being the first column or row of values) as well?
samplingDistancedoubleThe sampling distance to be used if the coordinates are not coded within the data.
commentIndicatorstringThe character to be interpreted as comment indicator, preceding lines which are to be ignored.
columnSeparatorstringCharacter which separates columns in the file. Please note: All 'white-space' characters are interchangeable. This means, for example, providing a blank will work with tabulator-separated columns and vice versa.
decimalSeparatorstringCharacter which separates the integer part from the fractional part of the numbers in the file.
groupSeparatorstringCharacter which 'groups' three digits respectively, so it can be called 'thousands separator' as well. This parameter may be left empty, meaning that no group separator is used in the file.
firstRowintThe first row to read from file. If set to -1, all lines will be processed.
lastRowintThe last row to read from file. If set to -1, all lines will be processed.
numberOfCharactersToSkipintIf greater than zero, this number of characters will be ignored at the beginning of each line.
expectDataInColumnsboolSeveral data sets (corresponding to different wavelengths) can be in columns or in rows. Which option is preferred (column-wise =
truevs. row-wise =false)?decreasingCoordinatesboolAre the actual coordinates to be interpreted as decreasing with increasing column- (or row-) index?
Returns
- ChromaticFieldsSet_1D
The imported ChromaticFieldsSet_1D.
ImportTextFileIntoComplexField(string, bool, int, int, int, string, string, string, string, out List<(bool is1D, bool? isGridless, bool? isEquidistant, bool? dataInColumns, int noOfSubsets)>)
Imports a text file into a ComplexField object.
public static ComplexField? ImportTextFileIntoComplexField(string fileName, bool expectComplexValues, int firstRow, int lastRow, int numberOfCharactersToSkip, string commentIndicator, string columnSeparator, string decimalSeparator, string groupSeparator, out List<(bool is1D, bool? isGridless, bool? isEquidistant, bool? dataInColumns, int noOfSubsets)> possibleCombinations)
Parameters
fileNamestringFull path of the file to import.
expectComplexValuesboolIf
true, the values in the file are expected to be complex-valued. If the import is successful, the result will be complex-valued as well.firstRowintThe first row to read from file. If set to -1, all lines will be processed.
lastRowintThe last row to read from file. If set to -1, all lines will be processed.
numberOfCharactersToSkipintIf greater than zero, this number of characters will be ignored at the beginning of each line.
commentIndicatorstringThe character to be interpreted as comment indicator, preceding lines which are to be ignored.
columnSeparatorstringCharacter which separates columns in the file. Please note: All 'white-space' characters are interchangeable. This means, for example, providing a blank will work with tabulator-separated columns and vice versa.
decimalSeparatorstringCharacter which separates the integer part from the fractional part of the numbers in the file.
groupSeparatorstringCharacter which 'groups' three digits respectively, so it can be called 'thousands separator' as well. This parameter may be left empty, meaning that no group separator is used in the file.
possibleCombinationsList<(bool is1D, bool? isGridless, bool? isEquidistant, bool? dataInColumns, int noOfSubsets)>List of all possible property combinations a DataArray, constructed from the imported ComplexField, could have.
Returns
- ComplexField
The read ComplexField if the import worked well. Otherwise null will be returned.
ImportTextFileIntoDataArray(string, bool, bool, double, double, string, string, string, string, int, int, int, bool, bool, bool, bool, bool, PhysicalMeaningType)
Imports a text file into a DataArray object.
public static DataArrayBase? ImportTextFileIntoDataArray(string fileName, bool expectComplexValues = false, bool coordinatesAreCodedInData = false, double samplingDistanceX = 1, double samplingDistanceY = 1, string commentIndicator = "#", string columnSeparator = " ", string decimalSeparator = ".", string groupSeparator = "", int firstRow = -1, int lastRow = -1, int numberOfCharactersToSkip = 0, bool prefer2Dover1D = true, bool preferGriddedOverGridless = true, bool expect1DOrGridlessDataInColumns = true, bool decreasingXCoordinates = false, bool decreasingYCoordinates = false, PhysicalMeaningType typeOfDA = PhysicalMeaningType.None)
Parameters
fileNamestringThe full path of the text file to be imported.
expectComplexValuesboolAre the data to be interpreted as being complex-valued?
coordinatesAreCodedInDataboolAre the coordinates for all of the data points given in the text data (being the first column and/or row of values) as well?
samplingDistanceXdoubleIf the coordinates are not coded within the data, this gives the sampling distance to be used in 1D case or the sampling distance for the x-coordinates in 2D case.
samplingDistanceYdoubleIf the coordinates are not coded within the data, this gives the sampling distance to be used for the y-coordinates in 2D case.
commentIndicatorstringThe character to be interpreted as comment indicator, preceding lines which are to be ignored.
columnSeparatorstringCharacter which separates columns in the file. Please note: All 'white-space' characters are interchangeable. This means, for example, providing a blank will work with tabulator-separated columns and vice versa.
decimalSeparatorstringCharacter which separates the integer part from the fractional part of the numbers in the file.
groupSeparatorstringCharacter which 'groups' three digits respectively, so it can be called 'thousands separator' as well. This parameter may be left empty, meaning that no group separator is used in the file.
firstRowintThe first row to read from file. If set to -1, all lines will be processed.
lastRowintThe last row to read from file. If set to -1, all lines will be processed.
numberOfCharactersToSkipintIf greater than zero, this number of characters will be ignored at the beginning of each line.
prefer2Dover1DboolIf the data can be interpreted as 2D or 1D, which one has to be preferred (2D =
truevs. 1D =false)?preferGriddedOverGridlessboolIf the data are 2D and can be interpreted as being on a coordinate grid as well as being 'gridless', which one has to be preferred (gridded =
truevs. gridless =false)?expect1DOrGridlessDataInColumnsboolIf the data are 1D or gridless 2D where each of several data sets can be in columns as well as in rows - which option is preferred (column-wise =
truevs. row-wise =false)?decreasingXCoordinatesboolIf the coordinates are not given in the file, are the actual x-coordinates to be interpreted as decreasing with increasing column- (or row-) index?
decreasingYCoordinatesboolIf the coordinates are not given in the file, are the actual y-coordinates to be interpreted as decreasing with increasing row-index?
typeOfDAPhysicalMeaningTypeThe type of object which is to be represented by the imported data array.
Returns
- DataArrayBase
The imported DataArray. It has to be casted into DataArray2D, DataArray1D, or DataArrayGridless first before it can be processed further.
ImportTextFileIntoHarmonicField(string, double, bool, string, string, string, string, int, int, int)
Imports a text file into a HarmonicField object.
public static ComplexAmplitude? ImportTextFileIntoHarmonicField(string fileName, double wavelength, bool expectComplexValues = false, string commentIndicator = "#", string columnSeparator = " ", string decimalSeparator = ".", string groupSeparator = "", int firstRow = -1, int lastRow = -1, int numberOfCharactersToSkip = 0)
Parameters
fileNamestringFull path of the file to import.
wavelengthdoubleWavelength for the new HarmonicField.
expectComplexValuesboolIf
true, the values in the file are expected to be complex-valued. If the import is successful, the result will be complex-valued as well.commentIndicatorstringThe character to be interpreted as comment indicator, preceding lines which are to be ignored.
columnSeparatorstringCharacter which separates columns in the file. Please note: All 'white-space' characters are interchangeable. This means, for example, providing a blank will work with tabulator-separated columns and vice versa.
decimalSeparatorstringCharacter which separates the integer part from the fractional part of the numbers in the file.
groupSeparatorstringCharacter which 'groups' three digits respectively, so it can be called 'thousands separator' as well. This parameter may be left empty, meaning that no group separator is used in the file.
firstRowintThe first row to read from file. If set to -1, all lines will be processed.
lastRowintThe last row to read from file. If set to -1, all lines will be processed.
numberOfCharactersToSkipintIf greater than zero, this number of characters will be ignored at the beginning of each line.
Returns
- ComplexAmplitude
The read ComplexField if the import worked well. Otherwise null will be returned.
LoadField(string)
Loads a field from a file.
public static ComplexAmplitude LoadField(string fileName)
Parameters
fileNamestringFull path of the file to load. Note that backslashes must be doubled, for example “C:\myField.ca2”.
Returns
- ComplexAmplitude
The loaded field.
LoadFieldsSet(string)
Loads a fields set from a file.
public static HarmonicFieldsSet LoadFieldsSet(string fileName)
Parameters
fileNamestringFull path of the file to load. Note that backslashes must be doubled, for example “C:\myFieldsSet.hfs”
Returns
- HarmonicFieldsSet
The loaded fields set.
NumberOfLines(string)
Returns the number of lines in the text file specified by fileName.
public static int NumberOfLines(string fileName)
Parameters
fileNamestringThe 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
- int
The number of lines in the specified text file.
ProcessOpticalSetup(string, string, string, PropagationEngine?, int?, bool)
Loads and simulates the given Optical Setup file.
public static void ProcessOpticalSetup(string fileNameOpticalSetup, string outputFolder, string fileNameParameters = "", PropagationEngine? simulationEngine = null, int? analyzerIndex = null, bool useSubfolder = false)
Parameters
fileNameOpticalSetupstringThe complete path of the Optical Setup file.
outputFolderstringThe 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.
fileNameParametersstringIf 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.
simulationEnginePropagationEngine?The simulation engine to use. If this optional parameter is not specified, the given analyzer is executed instead.
analyzerIndexint?Index 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.
useSubfolderboolIf set to
truea unique sub-folder for each simulation run is generated.
ReadLine(string, int)
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.
public static string ReadLine(string fileName, int lineNumber)
Parameters
fileNamestringThe full path of the file from which the text is to be read. Note that backslashes must be doubled, for example “C:\log.txt”.
lineNumberintThe line number to be read.
Returns
- string
The read line.
Exceptions
- ArgumentException
Line number must be between 1 and the number of lines in the file.
SaveDocument(IDocument, string)
Saves a document (e. g. a ComplexAmplitude or a HarmonicFieldsSet object) to the hard disc.
public static void SaveDocument(IDocument document, string fileName)
Parameters
documentIDocumentThe document to save.
fileNamestringThe desired file name including the full path. Note that backslashes must be doubled, for example “C:\myField.ca2”
WriteLineToLogFile(string, string)
Writes a string as a separate line to the end of the specified log file.
public static void WriteLineToLogFile(string fileName, string message)
Parameters
fileNamestringThe 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.
messagestringThe string to write into the log file.
WriteToLogFile(string, string)
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.
public static void WriteToLogFile(string fileName, string message)