Exemplo n.º 1
0
        public static string[] GetListofRayDataFieldsPresent(KnownDataFlagBlock dataFlagBlock, FileHeaderBlock fileHeaderBlock, AdditionalRayDataColumnLabelsBlock additionalRayDataColumn = null)
        {
            Type type = typeof(KnownDataFlagBlock);

            string[] rayitems = new string[FindNumberOfRayDataFields(dataFlagBlock, fileHeaderBlock)];
            var      position = 0;

            foreach (FieldInfo fi in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                if (fi.Name == "PositionFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[0] = "X Position";
                    rayitems[1] = "Y Position";
                    rayitems[2] = "Z Position";
                    position   += 3;
                }
                if (fi.Name == "PositionFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[3] = "X Direction Cosine";
                    rayitems[4] = "Y Direction Cosine";
                    rayitems[5] = "Z Direction Cosine";
                    position   += 3;
                }
                if (fi.Name == "RadiantFlux_StokesS0Flag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position] = "Radiant Flux/Stokes S0";
                    position          += 1;
                }

                if (fi.Name == "WavelengthFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position] = "Wavelength";
                    position          += 1;
                }

                if (fi.Name == "LuminousFlux_TristimulusYFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position] = "LuminousFlux / Tristimulus Y";
                    position          += 1;
                }

                if (fi.Name == "StokesFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position]     = "Stokes S1";
                    rayitems[position + 1] = "Stokes S2";
                    rayitems[position + 2] = "Stokes S3";
                    position += 3;
                }

                if (fi.Name == "TristimulusFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position]     = "X Tristimulus";
                    rayitems[position + 1] = "Y Tristimulus";
                    position += 2;
                }

                if (fi.Name == "SpectrumIndexFlag" && (int)fi.GetValue(dataFlagBlock) == 1)
                {
                    rayitems[position] = "Spectrum Index";
                    position          += 1;
                }

                if (fileHeaderBlock.NumberOfAdditionalRayDataItemsPerRay > 0)
                {
                    for (int i = 0; i < fileHeaderBlock.NumberOfAdditionalRayDataItemsPerRay; i++)
                    {
                        rayitems[position] = additionalRayDataColumn.ColumnNames[i];
                    }
                }
            }
            return(rayitems);
        }
Exemplo n.º 2
0
        public IESTM25File(string fileName, ulong numrays)
        {
            using (BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open)))
            {
                FileHeaderBlock fileHeader = new FileHeaderBlock();
                ReadHeaderBlock(reader, ref fileHeader);
                if (!fileHeader.CheckHeaderBlockisValid())
                {
                    throw new InvalidTM25Exception("Header Block Not Correct Size", "");
                }
                FileHeader = fileHeader;

                KnownDataFlagBlock knownDataFlag = new KnownDataFlagBlock();
                ReadDataFlagBlock(reader, ref knownDataFlag);
                if (!knownDataFlag.CheckKnownDataFlagBlockisValid())
                {
                    throw new InvalidTM25Exception("Data Flag Block Not Correct Size", "");
                }
                DataFlags = knownDataFlag;

                DescriptionHeaderBlock descriptionHeader = new DescriptionHeaderBlock();
                ReadDescriptionHeaderBlock(reader, ref descriptionHeader);
                if (!descriptionHeader.CheckDescriptionBlockisValid())
                {
                    throw new InvalidTM25Exception("Description Header Block is Not Correct Size", "");
                }
                DescriptionHeader = descriptionHeader;

                if (FileHeader.NumberOfSpectralTables > 0)
                {
                    SpectralTableBlock spectralTables = new SpectralTableBlock();
                    spectralTables.SpectralTables = new List <SpectralTable>();
                    ReadSpectralTableBlock(reader, ref spectralTables);
                    if (!spectralTables.CheckSpectralTableisValid())
                    {
                        throw new InvalidTM25Exception("Spectral Table Block is Not Correct Size", "");
                    }
                    SpectralTables = spectralTables;
                }

                if (FileHeader.NumberOfAdditionalRayDataItemsPerRay > 0)
                {
                    AdditionalRayDataColumnLabelsBlock columnLabelsBlock = new AdditionalRayDataColumnLabelsBlock();
                    ReadColumnsLabelsBlock(reader, ref columnLabelsBlock);
                    if (!columnLabelsBlock.CheckAdditionalRayDataColumnisValid())
                    {
                        throw new InvalidTM25Exception("Additional Ray Data Columns Block is incorrect");
                    }
                    AdditionalRayDataColumnLabels = columnLabelsBlock;
                }

                if (FileHeader.SizeOfAdditionalTextBlock > 0)
                {
                    AdditionalTextBlock additionalTextBlock = new AdditionalTextBlock();
                    ReadAdditionalTextBlock(reader, ref additionalTextBlock);
                    AdditionalText = additionalTextBlock;
                }

                RayDataLinesBlock rayDataLines = new RayDataLinesBlock();
                rayDataLines.Rays = new float[FileHeader.NumberOfRays][];
                ReadPartialRayDataBlock(reader, ref rayDataLines, numrays);
                rayDataLines.RayDataMembers = TM25HelperFunctions.GetListofRayDataFieldsPresent(DataFlags, FileHeader, AdditionalRayDataColumnLabels);
                RayData = rayDataLines;
            }
        }
Exemplo n.º 3
0
        public static int FindNumberOfRayDataFields(KnownDataFlagBlock dataFlagBlock, FileHeaderBlock fileHeaderBlock)
        {
            Type type          = typeof(KnownDataFlagBlock);
            int  numberofitems = 0;

            foreach (FieldInfo fi in type.GetFields(BindingFlags.Instance | BindingFlags.Public))
            {
                if (fi.Name == "PositionFlag" || fi.Name == "DirectionFlag" || fi.Name == "StokesFlag")
                {
                    if ((int)fi.GetValue(dataFlagBlock) == 1)
                    {
                        numberofitems += 3;
                    }
                }
                else if (fi.Name == "TristimulusFlag")
                {
                    if ((int)fi.GetValue(dataFlagBlock) == 1)
                    {
                        numberofitems += 2;
                    }
                }
                else
                {
                    if ((int)fi.GetValue(dataFlagBlock) == 1)
                    {
                        numberofitems++;
                    }
                }
            }

            if (fileHeaderBlock.NumberOfAdditionalRayDataItemsPerRay > 0)
            {
                numberofitems += fileHeaderBlock.NumberOfAdditionalRayDataItemsPerRay;
            }

            return(numberofitems);
        }
Exemplo n.º 4
0
        private void ReadHeaderBlock(BinaryReader reader, ref FileHeaderBlock fileheader)
        {
            var bytebuffer = reader.ReadBytes(4);
            var text       = System.Text.Encoding.ASCII.GetString(bytebuffer);

            if (text != "TM25")
            {
                throw new InvalidTM25Exception("FileType is not TM25", text);
            }
            fileheader.FileType = bytebuffer;

            var intbuffer = reader.ReadInt32();

            if (intbuffer != 2013)
            {
                throw new InvalidTM25Exception("File Version is not 2013", intbuffer.ToString());
            }
            fileheader.FileVersion = intbuffer;

            fileheader.CreationMethod          = reader.ReadInt32();
            fileheader.TotalLuminousFlux       = reader.ReadSingle();
            fileheader.TotalRadiantFlux        = reader.ReadSingle();
            fileheader.NumberOfRays            = reader.ReadUInt64();
            fileheader.FileCreationDateAndTime = reader.ReadBytes(28);
            fileheader.RayStartPosition        = reader.ReadInt32();

            intbuffer = reader.ReadInt32();
            if (intbuffer > 4 || intbuffer < 0)
            {
                throw new InvalidTM25Exception("Spectral Data Identifier Not Valid", intbuffer.ToString());
            }
            fileheader.SpectralDataIdentifier = intbuffer;

            var floatbuffer = reader.ReadSingle();

            if (fileheader.SpectralDataIdentifier == 1 && floatbuffer < 0)
            {
                throw new InvalidTM25Exception("Single Wavelength Not Valid", floatbuffer.ToString());
            }

            fileheader.MinimumWavelength = reader.ReadSingle();
            fileheader.MaximumWavelength = reader.ReadSingle();

            intbuffer = reader.ReadInt32();
            if ((fileheader.SpectralDataIdentifier == 3 || fileheader.SpectralDataIdentifier == 4) && intbuffer < 1)
            {
                throw new InvalidTM25Exception("Number of Spectral Tables Not Valid", intbuffer.ToString());
            }
            fileheader.NumberOfSpectralTables = intbuffer;

            intbuffer = reader.ReadInt32();
            if (intbuffer < 0)
            {
                throw new InvalidTM25Exception("Number of Additional Ray Data Items Not Valid", intbuffer.ToString());
            }

            intbuffer = reader.ReadInt32();
            if (intbuffer % 32 != 0 || intbuffer < 0)
            {
                throw new InvalidTM25Exception("Size of Additional Text Block Not Valid", intbuffer.ToString());
            }

            reader.ReadBytes(168);
        }