Ejemplo n.º 1
0
        private void panelImageSpectrum_Click(object sender, EventArgs e)
        {
                        #if COMPUTE_RADIAL_SLICE
            m_displayHandMadeSpectrum = !m_displayHandMadeSpectrum;
            UpdatePanels();
                        #else
            if (openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try {
                ImageFile noiseImage = new ImageFile(new System.IO.FileInfo(openFileDialog.FileName));
                panelImage.Bitmap         = noiseImage.AsTiledBitmap((uint)panelImage.Width, (uint)panelImage.Height);
                panelImageSpectrum.Bitmap = ComputeSpectrum(noiseImage, 2.0f * noiseImage.Width).AsBitmap;
            } catch (Exception) {
            }
                        #endif
        }
Ejemplo n.º 2
0
        private void buttonVoidAndCluster_Click(object sender, EventArgs e)
        {
            uint textureSize = 1U << integerTrackbarControlTexturePOT.Value;
            uint randomSeed  = (uint)integerTrackbarControlRandomSeed.Value;

            if (m_blueNoiseVoidAndCluster != null)
            {
                m_blueNoiseVoidAndCluster.Dispose();
            }
//			m_blueNoiseVoidAndCluster = new ImageFile( textureSize, textureSize, PIXEL_FORMAT.R8, new ColorProfile( ColorProfile.STANDARD_PROFILE.sRGB ) );
            m_blueNoiseVoidAndCluster = new ImageFile(textureSize, textureSize, PIXEL_FORMAT.R16, new ColorProfile(ColorProfile.STANDARD_PROFILE.LINEAR));

            float4[] scanline = new float4[textureSize];

            ImageFile graphStatistics = new ImageFile((uint)panelImageSpectrum.Width, (uint)panelImageSpectrum.Height, PIXEL_FORMAT.RGBA8, new ColorProfile(ColorProfile.STANDARD_PROFILE.sRGB));
            float4    black           = new float4(0, 0, 0, 1);
            float2    rangeX          = new float2(0, 10000);
//			float2		rangeY = new float2( -10, 10 );
//			float2		rangeY = new float2( -1, 2 );
            float2 rangeY = new float2(0, 1);

            float sigma_i = floatTrackbarControlVariance.Value;                 // Default, recommended value by Ulichney is 1.5

            DateTime startTime = DateTime.Now;

            this.Enabled = false;

            GeneratorVoidAndClusterGPU generator = new GeneratorVoidAndClusterGPU(m_device, (uint)(Math.Log(m_blueNoiseVoidAndCluster.Width) / Math.Log(2.0)));

            generator.Generate(randomSeed, sigma_i, 0.025f, (float _progress, float[,] _texture, List <float> _statistics) => {
                m_blueNoiseVoidAndCluster.WritePixels((uint X, uint Y, ref float4 _color) => {
                    float V = _texture[X, Y];
                    _color.Set(V, V, V, 1.0f);
                });

                if (m_blueNoiseVoidAndCluster.Width < panelImage.Width)
                {
                    panelImage.Bitmap = m_blueNoiseVoidAndCluster.AsTiledBitmap((uint)panelImage.Width, (uint)panelImage.Height);
                }
                else
                {
                    panelImage.Bitmap = m_blueNoiseVoidAndCluster.AsBitmap;
                }

                TimeSpan deltaTime = DateTime.Now - startTime;

                labelAnnealingScore.Text = "Time: " + deltaTime.ToString(@"hh\:mm\:ss") + " ► Progress: " + (100.0f * _progress).ToString("G3") + "%";
                labelAnnealingScore.Refresh();

                Application.DoEvents();

/*				// Plot statistics
 *                              int	lastX = 0;
 *                              graphStatistics.Clear( float4.One );
 * //				graphStatistics.PlotGraphAutoRangeY( black, rangeX, ref rangeY, ( float _X ) => {
 *                              graphStatistics.PlotGraph( black, rangeX, rangeY, ( float _X ) => {
 *                                      int	X = Math.Max( 0, Math.Min( _statistics.Count-1, (int) (_statistics.Count * _X / rangeX.y) ) );
 * //					return _statistics[X];
 *
 *                                      // Integrate...
 *                                      float	sum = 0.0f;
 *                                      for ( int x=lastX; x <= X; x++ )
 *                                              sum += _statistics[x];
 *                                      sum *= X != lastX ? 1.0f / (X - lastX) : 0.0f;
 *                                      lastX = X;
 *
 *                                      return sum;
 *                              } );
 *                              graphStatistics.PlotAxes( black, rangeX, rangeY, 1000.0f, 100.0f );
 *                              panelImageSpectrum.Bitmap = graphStatistics.AsBitmap;
 * //*/
//              if ( _progress == 1.0f ) {
//                  using ( System.IO.FileStream S = new System.IO.FileInfo( "indices.txt" ).Create() ) {
//                      using ( System.IO.StreamWriter W = new System.IO.StreamWriter( S ) ) {
//                          for ( int i=0; i < _statistics.Count; i++ ) {
//                              W.WriteLine( (int) Math.Floor( m_blueNoiseVoidAndCluster.Width*m_blueNoiseVoidAndCluster.Height* _statistics[i] ) );
//                          }
//                      }
//                  }
//              }
            });

            this.Enabled = true;

            m_blueNoiseVoidAndCluster.Save(new System.IO.FileInfo("BlueNoise" + m_blueNoiseVoidAndCluster.Width + "x" + m_blueNoiseVoidAndCluster.Height + "_VoidAndCluster.png"));

            // Quick FFT
            panelImageSpectrum.Bitmap = ComputeSpectrum(m_blueNoiseVoidAndCluster, 2.0f * textureSize).AsBitmap;
        }
Ejemplo n.º 3
0
        private void buttonSolidAngleAlgorithm_Click(object sender, EventArgs e)
        {
            uint textureSize = 1U << integerTrackbarControlTexturePOT.Value;
            uint dimensions  = (uint)integerTrackbarControlVectorDimension.Value;
            uint randomSeed  = (uint)integerTrackbarControlRandomSeed.Value;
            uint iterations  = (uint)integerTrackbarControlAnnealingIterations.Value;

            if (m_blueNoiseAnnealing != null)
            {
                m_blueNoiseAnnealing.Dispose();
            }
            m_blueNoiseAnnealing = new ImageFile(textureSize, textureSize, PIXEL_FORMAT.RGBA8, new ColorProfile(ColorProfile.STANDARD_PROFILE.sRGB));

            float4[] scanline = new float4[textureSize];

            ImageFile graphStatistics = new ImageFile((uint)panelImageSpectrum.Width, (uint)panelImageSpectrum.Height, PIXEL_FORMAT.RGBA8, new ColorProfile(ColorProfile.STANDARD_PROFILE.sRGB));
            float4    black           = new float4(0, 0, 0, 1);
            float2    rangeX          = new float2(0, 10000);
//			float2		rangeY = new float2( -10, 10 );
//			float2		rangeY = new float2( -1, 2 );
            float2 rangeY = new float2(0, 100);

            float sigma_i = floatTrackbarControlVariance.Value; // Default, recommended value is 2.1
            float sigma_s = 1.0f;                               // Default, recommended value

//			uint		notificationIterationsCount = Math.Max( 1U, (uint) (0.025f * iterations) );
            uint notificationIterationsCount = 1000;

            DateTime startTime = DateTime.Now;

            this.Enabled = false;

            GeneratorSolidAngleGPU generator = new GeneratorSolidAngleGPU(m_device, (uint)(Math.Log(m_blueNoiseAnnealing.Width) / Math.Log(2.0)), dimensions);

            generator.Generate(randomSeed, iterations, sigma_i, sigma_s, radioButtonNeighborMutations.Checked, notificationIterationsCount, (uint _iterationIndex, uint _mutationsRate, float _energyScore, Array _texture, List <float> _statistics) => {
                switch (dimensions)
                {
                case 1: {
                    float[,]        texture = _texture as float[, ];
                    m_blueNoiseAnnealing.WritePixels((uint X, uint Y, ref float4 _color) => {
                            float V = texture[X, Y];
                            _color.Set(V, V, V, 1.0f);
                        });
                    break;
                }

                case 2: {
                    float2[,]       texture = _texture as float2[, ];
                    m_blueNoiseAnnealing.WritePixels((uint X, uint Y, ref float4 _color) => {
                            float2 V = texture[X, Y];
                            _color.Set(V.x, V.y, 0, 1.0f);
                        });
                    break;
                }
                }

                if (m_blueNoiseAnnealing.Width < panelImage.Width)
                {
                    panelImage.Bitmap = m_blueNoiseAnnealing.AsTiledBitmap((uint)panelImage.Width, (uint)panelImage.Height);
                }
                else
                {
                    panelImage.Bitmap = m_blueNoiseAnnealing.AsBitmap;
                }

                TimeSpan deltaTime = DateTime.Now - startTime;

                labelAnnealingScore.Text = "Time: " + deltaTime.ToString(@"hh\:mm\:ss") + " ► Score: " + _energyScore + " - Iterations = " + _iterationIndex + " - Mutations Rate: " + _mutationsRate;
                labelAnnealingScore.Refresh();

                Application.DoEvents();

/*				// Plot statistics
 *                              int	lastX = 0;
 *                              graphStatistics.Clear( float4.One );
 * //				graphStatistics.PlotGraphAutoRangeY( black, rangeX, ref rangeY, ( float _X ) => {
 *                              graphStatistics.PlotGraph( black, rangeX, rangeY, ( float _X ) => {
 *                                      int	X = Math.Max( 0, Math.Min( _statistics.Count-1, (int) (_statistics.Count - 10000.0f + _X) ) );
 * //					return _statistics[X];
 *
 *                                      // Integrate...
 *                                      float	sum = 0.0f;
 *                                      for ( int x=lastX; x <= X; x++ )
 *                                              sum += _statistics[x];
 *                                      sum *= X != lastX ? 1.0f / (X - lastX) : 0.0f;
 *                                      lastX = X;
 *
 *                                      return sum;
 *                              } );
 *                              graphStatistics.PlotAxes( black, rangeX, rangeY, 1000.0f, 100.0f );
 *                              panelImageSpectrum.Bitmap = graphStatistics.AsBitmap;
 * //*/
            });

            this.Enabled = true;

            m_blueNoiseAnnealing.Save(new System.IO.FileInfo("BlueNoise" + m_blueNoiseAnnealing.Width + "x" + m_blueNoiseAnnealing.Height + "_SimulatedAnnealing" + dimensions + "D.png"));

            // Quick FFT
            panelImageSpectrum.Bitmap = ComputeSpectrum(m_blueNoiseAnnealing, 2.0f * textureSize).AsBitmap;
        }