private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (Contour == null) { return; } double mux = ConvertToDouble(textBox17) / pictureBox1.Width; double muy = ConvertToDouble(textBox18) / pictureBox1.Height; double x = e.X * mux; double y = (pictureBox1.Height - e.Y) * muy; if (e.Location != OldPosition) { OldPosition = e.Location; Hint.Active = true; Hint.SetToolTip( pictureBox1, String.Format( "X = {0 : 0.##} м; Y = {1 : 0.##} м; L = {2 : 0.##} дБ", x - ConvertToDouble(textBox19), y - ConvertToDouble(textBox18) / 2, Contour.Interpolate(x, y))); } }
public void ModifyEngineSoundContour( double MinSoundLevel, double MaxSoundLevel, ref EngineSoundContour EngineSoundContour) // см. метод с аналогичной сигнатурой в IModel { int ImageWidth = EngineSoundContour.Contour.Width; int ImageHeight = EngineSoundContour.Contour.Height; double[] X = EngineSoundContour.X; double[] Y = EngineSoundContour.Y; double[,] SoundLevels = EngineSoundContour.SoundLevels; var Contour = new Bitmap(ImageWidth, ImageHeight); using (var g = Graphics.FromImage(Contour)) { int gNx = 300, gNy = 300; double mux = X.Max() / ImageWidth; double muy = Y.Max() / ImageHeight; int dx = ImageWidth / gNx; int dy = ImageHeight / gNy; double Max = SoundLevels[0, 0]; double Min = Max; var Interpolator = new DoubleInterpolation(X, Y, SoundLevels); for (int i = 0; i < SoundLevels.GetLength(0); i++) { for (int j = 0; j < SoundLevels.GetLength(1); j++) { if (SoundLevels[i, j] > Max) { Max = SoundLevels[i, j]; } else if (SoundLevels[i, j] < Min) { Min = SoundLevels[i, j]; } } } var Intervals = new double[] { 0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0 }; var R = new Interpolation(Intervals, new double[] { 0, 0, 0, 0, 0, 0, 124, 203, 255, 255, 255, 255 }); var G = new Interpolation(Intervals, new double[] { 0, 124, 203, 255, 255, 255, 255, 255, 255, 203, 124, 0 }); var B = new Interpolation(Intervals, new double[] { 255, 255, 255, 255, 203, 124, 0, 0, 0, 0, 0, 0 }); Func <double, Color> GetColor = x => { x = (x - MinSoundLevel) / (MaxSoundLevel - MinSoundLevel); return(Color.FromArgb( (int)R.Interpolate(x * 11), (int)G.Interpolate(x * 11), (int)B.Interpolate(x * 11))); }; for (int i = 0; i < gNx; i++) { ProgressChanged((int)(i * 100.0 / gNx)); int x = i * ImageWidth / gNx; for (int j = 0; j < gNy; j++) { int y = j * ImageHeight / gNy; var color = GetColor(Interpolator.Interpolate(x * mux, y * muy)); using (var Brush = new SolidBrush(color)) { g.FillRectangle(Brush, x, y, i * dx, i * dy); } } } } ProgressChanged(100); EngineSoundContour = new EngineSoundContour(X, Y, SoundLevels, Contour); }