Exemple #1
0
        public static float[,,] Create3DNoise(int smoothness,
                                              int nodesWidthCount,
                                              int nodesHeightCount,
                                              int nodesDepthCount,
                                              int segmentSize,
                                              int seed = 0)
        {
            List <float[, , ]> nodesLayers = new List <float[, , ]>();

            for (int i = 0; i < smoothness; i++)
            {
                float[,,] layer = new float[nodesWidthCount, nodesHeightCount, nodesDepthCount];
                for (int j = 0; j < nodesWidthCount; j++)
                {
                    for (int k = 0; k < nodesHeightCount; k++)
                    {
                        for (int l = 0; l < nodesDepthCount; l++)
                        {
                            layer[j, k, l] = (float)RandomContainer.GetDouble(BottomNoiseBound(i), TopNoiseBound(i), seed);
                        }
                    }
                }
                nodesLayers.Add(layer);
            }
            return(VolumeInterpolation.MultiDerpByNodes(nodesLayers, segmentSize));
        }
        /// <summary>
        /// Draw the interpolation results.
        /// </summary>
        public void Draw()
        {
            VolumeInterpolation volumeInterpolation = workerThread.GetVolumeInterpolation();
            int scale = volumeInterpolation.GetScale();

            double[] minMax = GetMinMax();

            // draw result for all coordinates
            for (int x = 0; x < volumeInterpolation.Values.GetLength(0); x++)
            {
                for (int y = 0; y < volumeInterpolation.Values.GetLength(1); y++)
                {
                    Rectangle rect = new Rectangle();
                    rect.Width  = scale;
                    rect.Height = scale;
                    byte intensity = (byte)(255 - (255 / (minMax[1] - minMax[0])) * (volumeInterpolation.Values[x, y, speakerIndex, 0] - minMax[0]));
                    rect.Fill = new SolidColorBrush(Color.FromRgb(intensity, intensity, 255));

                    canvas.Children.Add(rect);
                    Canvas.SetLeft(rect, x * scale);
                    Canvas.SetTop(rect, (volumeInterpolation.Values.GetLength(1) - y) * scale);
                }
            }

            // add the current position
            currentPosition        = new Rectangle();
            currentPosition.Width  = scale;
            currentPosition.Height = scale;
            currentPosition.Fill   = Brushes.Orange;
            canvas.Children.Add(currentPosition);
            Canvas.SetLeft(currentPosition, -10);
            Canvas.SetTop(currentPosition, -10);

            workerThread.ResultReady += ResultReady;
        }
        /// <summary>
        /// Gets the global minimum and maximum of the interpolation.
        /// </summary>
        /// <returns>Array where minimum is stored at index 0 and maximum at index 1.</returns>
        private double[] GetMinMax()
        {
            VolumeInterpolation volumeInterpolation = workerThread.GetVolumeInterpolation();

            double[] minMax = new double[2] {
                1000, -1000
            };

            for (int x = 0; x < volumeInterpolation.Values.GetLength(0); x++)
            {
                for (int y = 0; y < volumeInterpolation.Values.GetLength(1); y++)
                {
                    double value = volumeInterpolation.Values[x, y, speakerIndex, 0];

                    if (value < minMax[0])
                    {
                        minMax[0] = value;
                    }

                    if (value > minMax[1])
                    {
                        minMax[1] = value;
                    }
                }
            }

            return(minMax);
        }
 /// <summary>
 /// Update the current position when it changes.
 /// </summary>
 /// <param name="sender">Worker thread.</param>
 /// <param name="e">Event arguments.</param>
 private void ResultReady(object sender, ResultReadyEventArgs e)
 {
     if (e.Result.GetCoordinates().HasValue)
     {
         VolumeInterpolation volumeInterpolation = workerThread.GetVolumeInterpolation();
         int scale = volumeInterpolation.GetScale();
         Canvas.SetLeft(currentPosition, volumeInterpolation.MapCoordinate(e.Result.GetCoordinates().Value.X) * scale);
         Canvas.SetTop(currentPosition, (volumeInterpolation.Values.GetLength(1) - volumeInterpolation.MapCoordinate(e.Result.GetCoordinates().Value.Y)) * scale);
     }
 }
Exemple #5
0
 /// <summary>
 /// Set the volume interpolation instance.
 /// </summary>
 /// <param name="volumeInterpolation"></param>
 public void SetVolumeInterpolation(VolumeInterpolation volumeInterpolation)
 {
     this.volumeInterpolation = volumeInterpolation;
 }