public NoiseAccess(INoise source, enuDimUsage noiseDimUsage, bool withCaching = false) { if (withCaching) { source = new Cache <INoise>(source); } switch (noiseDimUsage) { case enuDimUsage.Noise2D: _noise2D = source as INoise2; break; case enuDimUsage.Noise3D: _noise3D = source as INoise3; break; case enuDimUsage.Noise4D: _noise4D = source as INoise4; break; default: break; } noiseDimUsage = _noiseDimUsage; _source = source; }
public static string Analyse(INoise2 noiseFct, int iteration) { FastRandom rnd = new FastRandom(); //Generate randomIteration number in array int[,] inputNumber = new int[iteration, 2]; for (int i = 0; i < iteration; i++) { inputNumber[i, 0] = rnd.Next(); inputNumber[i, 1] = rnd.Next(); } long from = Stopwatch.GetTimestamp(); double min = double.MaxValue; double max = double.MinValue; for (int i = 0; i < iteration; i++) { double val = noiseFct.Get(inputNumber[i, 0], inputNumber[i, 1]); if (val < min) { min = val; } if (val > max) { max = val; } } long to = Stopwatch.GetTimestamp(); return("INoise2 analysed for " + iteration + " iteration. Time needed : " + ((to - from) / (double)Stopwatch.Frequency * 1000.0) + " ms; Min : " + min + " max : " + max); }
private void InitNoise(INoise2 noise, Range outPutRange) { if (noise != null) { workingNoise = noise; } var bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height); float xl, yl; int w = pictureBox1.Width; int h = pictureBox1.Height; long from = Stopwatch.GetTimestamp(); double[,] noiseData = NoiseSampler.NoiseSampling(new Vector2I(w, h), 0 + OffsetX, 3 + OffsetX, w, 0, 1, h, workingNoise); lblGenerationTime.Text = ((Stopwatch.GetTimestamp() - from) / (double)Stopwatch.Frequency * 1000.0).ToString(); double min = double.MaxValue; double max = double.MinValue; int i = 0; double thresholdFrom = double.Parse(thresholdValue.Text.Replace('.', ',')); double thresholdTo = double.Parse(txtBelow.Text.Replace('.', ',')); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { xl = MathHelper.FullLerp(0, 3, 0, w, x + OffsetX); yl = MathHelper.FullLerp(0, 1, 0, h, y); var val = noiseData[i, 0]; if (val < min) { min = val; } if (val > max) { max = val; } if (withThresHold.Checked) { if (withBelow.CheckState == CheckState.Checked) { if (val > thresholdFrom && val < thresholdTo) { val = 1.0; } else { val = 0.0; } } else { if (val > thresholdFrom) { val = 1.0; } else { val = 0.0; } } } var col = MathHelper.FullLerp(0, 255, outPutRange.Min, outPutRange.Max, val, true); bmp.SetPixel(x, h - y - 1, Color.FromArgb((byte)col, (byte)col, (byte)col)); i++; } } Console.WriteLine("Min : " + min + " max : " + max); pictureBox1.Image = bmp; }