Exemple #1
0
        //////////////////////////////////////////////////////////////////////////
        // ZH Mapping
        private void buttonMap_Click( object sender, EventArgs e )
        {
            buttonMap.Enabled = false;

            // Initialize arrays
            for ( int LobeIndex=0; LobeIndex < ZH_LOBES_COUNT; LobeIndex++ )
            {
                m_MappedCoeffsZH[LobeIndex] = new double[SH_ORDER];
                m_MappedAxesZH[LobeIndex] = new Vector2D( 0, 0 );
            }

            // Perform mapping
            double[]	RMS = new double[ZH_LOBES_COUNT];
            SphericalHarmonics.SHFunctions.MapSHIntoZH( m_CoeffsSH, SH_ORDER, m_MappedAxesZH, m_MappedCoeffsZH, INITIAL_DIRECTIONS_HEMISPHERE_SUBDIVISIONS_COUNT, FUNCTION_EVALUATION_SPHERE_SUBDIVISIONS_COUNT, BFGS_CONVERGENCE_TOLERANCE, out RMS, new SphericalHarmonics.SHFunctions.ZHMappingFeedback( MappingFeedback ) );
            progressBar.Value = progressBar.Minimum;

            // Recombine into an SH
            for ( int CoefficientIndex=0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++ )
                m_MappedCoeffsSH[CoefficientIndex] = 0.0;
            for ( int LobeIndex=0; LobeIndex < ZH_LOBES_COUNT; LobeIndex++ )
            {
                // Rotate the lobe to its axis
                double[]	RotatedLobeSHCoefficients = new double[SH_ORDER*SH_ORDER];
                SphericalHarmonics.SHFunctions.ComputeRotatedZHCoefficients( m_MappedCoeffsZH[LobeIndex], SphericalHarmonics.SHFunctions.SphericalToCartesian( m_MappedAxesZH[LobeIndex].x, m_MappedAxesZH[LobeIndex].y ), RotatedLobeSHCoefficients );

                // Accumulate into final SH
                for ( int CoefficientIndex=0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++ )
                    m_MappedCoeffsSH[CoefficientIndex] += RotatedLobeSHCoefficients[CoefficientIndex];
            }

            // Rebuild the sphere
            sphereViewZHEncodedFunction.RebuildSpheres( new SphereView.GetValue( GetValueEvaluatedMappedZHEncoding ) );
            sphereViewZHEncodedFunction.Refresh();

            //////////////////////////////////////////////////////////////////////////
            // Compute RMS
            SphericalHarmonics.SHSamplesCollection	Samples = new SphericalHarmonics.SHSamplesCollection();
                                                    Samples.Initialize( SH_ORDER, 200 );
            double	SumError = 0.0;
            foreach ( SphericalHarmonics.SHSamplesCollection.SHSample Sample in Samples )
            {
                double	GoalValue = 0.0;
                double	EstimateValue = 0.0;
                for ( int CoefficientIndex=0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++ )
                {
                    GoalValue += Sample.m_SHFactors[CoefficientIndex] * m_CoeffsSH[CoefficientIndex];
                    EstimateValue += Sample.m_SHFactors[CoefficientIndex] * m_MappedCoeffsSH[CoefficientIndex];
                }

                SumError += (EstimateValue - GoalValue) * (EstimateValue - GoalValue);
            }

            SumError /= Samples.SamplesCount;

            // Compute error between coefficients
            double	SumCoeffsError = 0.0;
            for ( int CoefficientIndex=0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++ )
                SumCoeffsError += (m_CoeffsSH[CoefficientIndex] - m_MappedCoeffsSH[CoefficientIndex]) * (m_CoeffsSH[CoefficientIndex] - m_MappedCoeffsSH[CoefficientIndex]);
            SumCoeffsError /= SH_ORDER * SH_ORDER;

            //			labelRMSError.Text = SumError.ToString( "G8" );
            labelRMSError.Text = Math.Sqrt( SumCoeffsError ).ToString( "G8" ) + " - Square Difference = " + SumError.ToString( "G4" );
            //////////////////////////////////////////////////////////////////////////

            sphereViewRotatedZHEncodedFunction_MouseUp( null, new MouseEventArgs( MouseButtons.Left, 1, sphereViewRotatedZHEncodedFunction.Width / 2 - sphereViewRotatedZHEncodedFunction.Height / 3, sphereViewRotatedZHEncodedFunction.Height / 3, 0 ) );

            buttonMap.Enabled = true;
        }
Exemple #2
0
        //////////////////////////////////////////////////////////////////////////
        // ZH Mapping

        private void buttonMap_Click(object sender, EventArgs e)
        {
            buttonMap.Enabled = false;

            // Initialize arrays
            for (int LobeIndex = 0; LobeIndex < ZH_LOBES_COUNT; LobeIndex++)
            {
                m_MappedCoeffsZH[LobeIndex] = new double[SH_ORDER];
                m_MappedAxesZH[LobeIndex]   = new Vector2D(0, 0);
            }

            // Perform mapping
            double[] RMS = new double[ZH_LOBES_COUNT];
            SphericalHarmonics.SHFunctions.MapSHIntoZH(m_CoeffsSH, SH_ORDER, m_MappedAxesZH, m_MappedCoeffsZH, INITIAL_DIRECTIONS_HEMISPHERE_SUBDIVISIONS_COUNT, FUNCTION_EVALUATION_SPHERE_SUBDIVISIONS_COUNT, BFGS_CONVERGENCE_TOLERANCE, out RMS, new SphericalHarmonics.SHFunctions.ZHMappingFeedback(MappingFeedback));
            progressBar.Value = progressBar.Minimum;

            // Recombine into an SH
            for (int CoefficientIndex = 0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++)
            {
                m_MappedCoeffsSH[CoefficientIndex] = 0.0;
            }
            for (int LobeIndex = 0; LobeIndex < ZH_LOBES_COUNT; LobeIndex++)
            {
                // Rotate the lobe to its axis
                double[] RotatedLobeSHCoefficients = new double[SH_ORDER * SH_ORDER];
                SphericalHarmonics.SHFunctions.ComputeRotatedZHCoefficients(m_MappedCoeffsZH[LobeIndex], SphericalHarmonics.SHFunctions.SphericalToCartesian(m_MappedAxesZH[LobeIndex].x, m_MappedAxesZH[LobeIndex].y), RotatedLobeSHCoefficients);

                // Accumulate into final SH
                for (int CoefficientIndex = 0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++)
                {
                    m_MappedCoeffsSH[CoefficientIndex] += RotatedLobeSHCoefficients[CoefficientIndex];
                }
            }

            // Rebuild the sphere
            sphereViewZHEncodedFunction.RebuildSpheres(new SphereView.GetValue(GetValueEvaluatedMappedZHEncoding));
            sphereViewZHEncodedFunction.Refresh();


            //////////////////////////////////////////////////////////////////////////
            // Compute RMS
            SphericalHarmonics.SHSamplesCollection Samples = new SphericalHarmonics.SHSamplesCollection();
            Samples.Initialize(SH_ORDER, 200);
            double SumError = 0.0;

            foreach (SphericalHarmonics.SHSamplesCollection.SHSample Sample in Samples)
            {
                double GoalValue     = 0.0;
                double EstimateValue = 0.0;
                for (int CoefficientIndex = 0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++)
                {
                    GoalValue     += Sample.m_SHFactors[CoefficientIndex] * m_CoeffsSH[CoefficientIndex];
                    EstimateValue += Sample.m_SHFactors[CoefficientIndex] * m_MappedCoeffsSH[CoefficientIndex];
                }

                SumError += (EstimateValue - GoalValue) * (EstimateValue - GoalValue);
            }

            SumError /= Samples.SamplesCount;

            // Compute error between coefficients
            double SumCoeffsError = 0.0;

            for (int CoefficientIndex = 0; CoefficientIndex < SH_ORDER * SH_ORDER; CoefficientIndex++)
            {
                SumCoeffsError += (m_CoeffsSH[CoefficientIndex] - m_MappedCoeffsSH[CoefficientIndex]) * (m_CoeffsSH[CoefficientIndex] - m_MappedCoeffsSH[CoefficientIndex]);
            }
            SumCoeffsError /= SH_ORDER * SH_ORDER;


//			labelRMSError.Text = SumError.ToString( "G8" );
            labelRMSError.Text = Math.Sqrt(SumCoeffsError).ToString("G8") + " - Square Difference = " + SumError.ToString("G4");
            //////////////////////////////////////////////////////////////////////////


            sphereViewRotatedZHEncodedFunction_MouseUp(null, new MouseEventArgs(MouseButtons.Left, 1, sphereViewRotatedZHEncodedFunction.Width / 2 - sphereViewRotatedZHEncodedFunction.Height / 3, sphereViewRotatedZHEncodedFunction.Height / 3, 0));

            buttonMap.Enabled = true;
        }