コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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;
            }
        }
コード例 #4
0
        private void ReadDataFlagBlock(BinaryReader reader, ref KnownDataFlagBlock knownDataFlag)
        {
            var intbuffer = reader.ReadInt32();

            if (intbuffer != 1)
            {
                throw new InvalidTM25Exception("Position Flag Must be 1", intbuffer.ToString());
            }
            knownDataFlag.PositionFlag = intbuffer;

            intbuffer = reader.ReadInt32();
            if (intbuffer != 1)
            {
                throw new InvalidTM25Exception("Direction Flag Must be 1", intbuffer.ToString());
            }
            knownDataFlag.DirectionFlag = intbuffer;

            var radiantFluxFlag = reader.ReadInt32();

            intbuffer = reader.ReadInt32();
            if (intbuffer > 1)
            {
                throw new InvalidTM25Exception("Wavelength Flag not 0 or 1", intbuffer.ToString());
            }
            if (FileHeader.SpectralDataIdentifier == 2 && intbuffer == 0)
            {
                throw new InvalidTM25Exception("Wavelength Flag not Present", intbuffer.ToString());
            }
            knownDataFlag.WavelengthFlag = intbuffer;

            var luminousFluxFlag = reader.ReadInt32();
            var stokesFlag       = reader.ReadInt32();
            var tristimulusFlag  = reader.ReadInt32();

            intbuffer = reader.ReadInt32();
            if (intbuffer > 1)
            {
                throw new InvalidTM25Exception("Spectrum Index Flag not 0 or 1", intbuffer.ToString());
            }
            if (FileHeader.SpectralDataIdentifier == 4 && intbuffer == 0)
            {
                throw new InvalidTM25Exception("Spectrum Index Flag Not Correct", intbuffer.ToString());
            }
            if (FileHeader.SpectralDataIdentifier != 4 && intbuffer == 1)
            {
                throw new InvalidTM25Exception("Spectrum Index Flag Not Correct", intbuffer.ToString());
            }
            knownDataFlag.SpetrumIndexFlag = intbuffer;

            if (radiantFluxFlag == 0 && luminousFluxFlag == 0)
            {
                throw new InvalidTM25Exception("Radiant Flux Flag Not Correct", radiantFluxFlag.ToString());
            }
            if (stokesFlag == 1 && radiantFluxFlag == 0)
            {
                throw new InvalidTM25Exception("Radiant Flux Flag Not Correct", radiantFluxFlag.ToString());
            }
            if ((FileHeader.SpectralDataIdentifier == 2 || FileHeader.SpectralDataIdentifier == 4) && radiantFluxFlag == 0)
            {
                throw new InvalidTM25Exception("Radiant Flux Flag Not Correct", radiantFluxFlag.ToString());
            }
            if (radiantFluxFlag > 1)
            {
                throw new InvalidTM25Exception(@"Radiant Flux/Stokes So  Flag not 0 or 1", intbuffer.ToString());
            }
            knownDataFlag.RadiantFlux_StokesS0Flag = radiantFluxFlag;
            knownDataFlag.StokesFlag = stokesFlag;

            if (tristimulusFlag == 1 && luminousFluxFlag == 0)
            {
                throw new InvalidTM25Exception("Luminous Flux Flag Not Correct", luminousFluxFlag.ToString());
            }
            if ((FileHeader.SpectralDataIdentifier == 2) || (FileHeader.SpectralDataIdentifier == 4))
            {
                luminousFluxFlag = 0;
            }
            knownDataFlag.LuminousFlux_TristimulusYFlag = luminousFluxFlag;

            if (tristimulusFlag == 1 && FileHeader.SpectralDataIdentifier != 0)
            {
                throw new InvalidTM25Exception("Tristimulus Data is only allowed if Spectral Data Identifier = 0", tristimulusFlag.ToString());
            }
            knownDataFlag.TristimulusFlag = tristimulusFlag;
        }