public void UpdateImages() { if (_mapData == null) { return; } int width = _mapData.Width; int height = _mapData.Height; if (Bitmap == null || Bitmap.PixelHeight != height || Bitmap.PixelWidth != width) { Bitmap = new WriteableBitmap(width, height); } ZMax = new Thickness(0, height, 0, 0); if (ColorBar == null) { ColorBar = new WriteableBitmap(256, 1); } switch (ScalingTypeOptionVM.SelectedValue) { case ScalingType.Linear: for (int i = 0; i < _mapData.RawData.Length; i++) { Bitmap.Pixels[i] = GetGrayscaleColor(_mapData.RawData[i], _MinValue, _MaxValue); } break; case ScalingType.Log: default: if (_MinValue <= 0.0) { _MinValue = 10E-9; } if (_MaxValue <= 0.0) { _MaxValue = 10E2; } for (int i = 0; i < _mapData.RawData.Length; i++) { if (_mapData.RawData[i] >= 0) { Bitmap.Pixels[i] = GetGrayscaleColor(Math.Log10(_mapData.RawData[i]), Math.Log10(_MinValue), Math.Log10(_MaxValue)); } else // clamp to Log10(min) if the value goes negative { Bitmap.Pixels[i] = GetGrayscaleColor(Math.Log10(_MinValue), Math.Log10(_MinValue), Math.Log10(_MaxValue)); } } break; } Bitmap.Invalidate(); //refreshes the image for (int i = 0; i < ColorBar.PixelWidth; i++) { ColorBar.Pixels[i] = GetGrayscaleColor(i, 0, ColorBar.PixelWidth - 1); } ColorBar.Invalidate(); YExpectationValue = _mapData.YExpectationValue; this.OnPropertyChanged("Bitmap"); this.OnPropertyChanged("ColorBar"); this.OnPropertyChanged("YExpectationValue"); }