BRDFSlices.DisplayForm.SaveAllSlices_BUGGED C# (CSharp) Method

SaveAllSlices_BUGGED() protected method

protected SaveAllSlices_BUGGED ( ) : void
return void
        protected void SaveAllSlices_BUGGED()
        {
            FileInfo[]	BRDFFiles = new DirectoryInfo( @"D:\Docs\Computer Graphics\Rendering, Radiosity, Photon Maps\BRDFs & Reflection Models\MERL\MERL Database of BRDF\people.csail.mit.edu\wojciech\BRDFDatabase\brdfs" ).GetFiles( "*.binary" );

            int	PitchThetaD = BRDF_SAMPLING_RES_PHI_D/2;
            int	PitchThetaH = PitchThetaD*BRDF_SAMPLING_RES_THETA_D;

            float[,,]	Values = new float[BRDF_SAMPLING_RES_THETA_D,BRDF_SAMPLING_RES_THETA_H,3];
            foreach ( FileInfo BRDFFile in BRDFFiles )
            {
                using ( FileStream S = BRDFFile.OpenRead() )
                    using ( BinaryReader Reader = new BinaryReader( S ) )
                    {
                        // Check coefficients count is the expected value
                        int	DimX = Reader.ReadInt32();
                        int	DimY = Reader.ReadInt32();
                        int	DimZ = Reader.ReadInt32();
                        int	CoeffsCount = DimX*DimY*DimZ;
            // 						if ( CoeffsCount != BRDF_SAMPLING_RES_THETA_H*BRDF_SAMPLING_RES_THETA_D*BRDF_SAMPLING_RES_PHI_D/2 )
            // 							throw new Exception( "The amount of coefficients stored in the file is not the expected value (i.e. " + CoeffsCount + "! (is it a BRDF file?)" );

                        long	BaseOffset = S.Position;
                        for ( int ComponentIndex=0; ComponentIndex < 3; ComponentIndex++ )
                        {
                            double	Factor = 1.0;
                            if ( ComponentIndex == 0 )
                                Factor = BRDF_SCALE_RED;
                            else if ( ComponentIndex == 0 )
                                Factor = BRDF_SCALE_GREEN;
                            else
                                Factor = BRDF_SCALE_BLUE;

                            // Read the PhiD=90° slice
                            //
                            double	Temp;
                            for ( int ThetaH=0; ThetaH < 90; ThetaH++ )
                            {
                                for ( int ThetaD=0; ThetaD < 90; ThetaD++ )
                                {
                                    long	Offset = 90 + 90*(ThetaD + 90*ThetaH);
                                            Offset *= sizeof(double);

                                    S.Position = BaseOffset + Offset;
                                    Temp = Reader.ReadDouble();
                                    Temp *= Factor;

                                    Values[ThetaH,ThetaD,ComponentIndex] = (float) Temp;
                                }
                            }

                            // Go to next component
                            BaseOffset += CoeffsCount * sizeof(double);
                        }
                    }

                string	TargetName = Path.GetDirectoryName( BRDFFile.FullName ) + "\\Slices\\" + Path.GetFileNameWithoutExtension( BRDFFile.FullName ) + ".slice";
                using ( FileStream S = new FileInfo( TargetName ).Create() )
                    using ( BinaryWriter Writer = new BinaryWriter( S ) )
                    {
                        for ( int ThetaH=0; ThetaH < 90; ThetaH++ )
                            for ( int ThetaD=0; ThetaD < 90; ThetaD++ )
                            {
                                Writer.Write( Values[ThetaH,ThetaD,0] );
                                Writer.Write( Values[ThetaH,ThetaD,1] );
                                Writer.Write( Values[ThetaH,ThetaD,2] );
                            }
                    }
            }
        }