public static BitmapSource ILArrayToBitmapSource(ILArray <double> surface) { // Define parameters used to create the BitmapSource. PixelFormat pf = PixelFormats.Bgr32; int width = surface.Dimensions[0]; int height = surface.Dimensions[1]; int bytes = (pf.BitsPerPixel + 7) / 8; int rawStride = (width * bytes); byte[] rawImage = new byte[rawStride * height]; int index = 0; ColourMap ColourMap = new ColourMap(ColourMapType.Jet, 256); byte[,] cmap = ColourMap.ToByteArray(); double range = surface.MaxValue - surface.MinValue; double min = surface.MinValue; int magnitude = 0; ILArray <int> scaled = (ILArray <int>)ILMath.convert(NumericType.Int32, ILMath.floor((surface - min) * 256.0 / range)); ILIterator <int> iterator = scaled.CreateIterator(); Stopwatch sw = Stopwatch.StartNew(); sw.Reset(); sw.Start(); magnitude = iterator.Value; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { if (magnitude == 256) { magnitude = 255; } rawImage[index] = cmap[magnitude, 3]; rawImage[index + 1] = cmap[magnitude, 2]; rawImage[index + 2] = cmap[magnitude, 1]; rawImage[index + 3] = cmap[magnitude, 0]; index += bytes; magnitude = iterator.Increment(); } } sw.Stop(); string result; result = "Elapsed time: " + sw.ElapsedMilliseconds.ToString() + " ms"; // Create a BitmapSource. BitmapSource bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride); return(bitmap); }
public ColourBar(ColourMap colourMap) { InitializeComponent(); this.colourMap = colourMap; colourBarPanel = new ColourBarPanel(); image = new FalseColourImage(new Rect(0, Min, 1, Max), MathHelper.Counter(1, colourMap.Length), false); colourBarPanel.plotItems.Add(image); image.ColourMap = colourMap; colourBarPanel.Margin = new Thickness(0, 0, 5, 0); this.grid.Children.Add(colourBarPanel); colourMapUpdateTimer = new DispatcherTimer(); colourMapUpdateTimer.Interval = new TimeSpan(1000); // 1/10 s colourMapUpdateTimer.Tick += OnColourMapUpdateTimerElapsed; AddSliders(); AddContextMenu(); FocusVisualStyle = null; }
public static BitmapSource ILArrayToBitmapSource(ILArray<double> surface) { // Define parameters used to create the BitmapSource. PixelFormat pf = PixelFormats.Bgr32; int width = surface.Dimensions[0]; int height = surface.Dimensions[1]; int bytes = (pf.BitsPerPixel + 7) / 8; int rawStride = (width * bytes); byte[] rawImage = new byte[rawStride * height]; int index = 0; ColourMap ColourMap = new ColourMap(ColourMapType.Jet, 256); byte[,] cmap = ColourMap.ToByteArray(); double range = surface.MaxValue - surface.MinValue; double min = surface.MinValue; int magnitude = 0; ILArray<int> scaled = (ILArray<int>)ILMath.convert(NumericType.Int32,ILMath.floor((surface - min) * 256.0 / range)); ILIterator<int> iterator = scaled.CreateIterator(); Stopwatch sw = Stopwatch.StartNew(); sw.Reset(); sw.Start(); magnitude = iterator.Value; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { if (magnitude == 256) { magnitude = 255; } rawImage[index] = cmap[magnitude, 3]; rawImage[index + 1] = cmap[magnitude, 2]; rawImage[index + 2] = cmap[magnitude, 1]; rawImage[index + 3] = cmap[magnitude, 0]; index += bytes; magnitude = iterator.Increment(); } } sw.Stop(); string result; result = "Elapsed time: " + sw.ElapsedMilliseconds.ToString() + " ms"; // Create a BitmapSource. BitmapSource bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride); return bitmap; }
protected void Initialize(bool newColourBar) { colourMapUpdateTimer = new DispatcherTimer(); colourMapUpdateTimer.Interval = TimeSpan.FromSeconds(0.2); colourMap = new ColourMap(ColourMapType.Jet, 256); imageRectangle = new Path(); Geometry geometry = new RectangleGeometry(bounds); imageRectangle.Data = geometry; RenderOptions.SetBitmapScalingMode(imageRectangle, BitmapScalingMode.NearestNeighbor); #if ILNumerics if (useILArray) { indices = UnderlyingILArrayToIndexArray(colourMap.Length); } #endif if (!useILArray) { indices = UnderlyingToIndexArray(colourMap.Length); } writeableBitmap = new WriteableBitmap(IndexArrayToBitmapSource()); imageBrush = new ImageBrush(writeableBitmap); imageRectangle.Fill = imageBrush; Bounds = new Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight); if (newColourBar) { colourBar = new ColourBar(ColourMap); #if ILNumerics if (useILArray) { colourBar.Min = underlyingILArrayData.MinValue; colourBar.Max = underlyingILArrayData.MaxValue; } #endif if (!useILArray) { colourBar.Min = underlyingData.Min(); colourBar.Max = underlyingData.Max(); } } }
public static BitmapSource ILArrayToBitmapSource(ILArray <double> surface, ColourMap colourMap) { // Define parameters used to create the BitmapSource. PixelFormat pf = PixelFormats.Bgr32; int width = surface.Dimensions[0]; int height = surface.Dimensions[1]; int bytes = (pf.BitsPerPixel + 7) / 8; int rawStride = (width * bytes); byte[] rawImage = new byte[rawStride * height]; int index = 0; byte[,] cmap = colourMap.ToByteArray(); int colourMapLength = colourMap.Length; double min = surface.MinValue; double range = surface.MaxValue - min; int magnitude = 0; ILArray <int> scaled = (ILArray <int>)ILMath.convert(NumericType.Int32, ILMath.floor((surface - min) * (double)((colourMapLength - 1) / range))); ILIterator <int> iterator = scaled.CreateIterator(); magnitude = iterator.Value; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { rawImage[index] = cmap[magnitude, 3]; rawImage[index + 1] = cmap[magnitude, 2]; rawImage[index + 2] = cmap[magnitude, 1]; rawImage[index + 3] = cmap[magnitude, 0]; index += bytes; magnitude = iterator.Increment(); } } // Create a BitmapSource. BitmapSource bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride); return(bitmap); }
public static BitmapSource ILArrayToBitmapSourceReversed(ILArray<double> surface, ColourMap colourMap) { // Define parameters used to create the BitmapSource. PixelFormat pf = PixelFormats.Bgr32; int width = surface.Dimensions[0]; int height = surface.Dimensions[1]; int bytes = (pf.BitsPerPixel + 7) / 8; int rawStride = (width * bytes); byte[] rawImage = new byte[rawStride * height]; int index = 0; byte[,] cmap = colourMap.ToByteArray(); int colourMapLength = colourMap.Length; double range = surface.MaxValue - surface.MinValue; double min = surface.MinValue; int magnitude = 0; ILArray<int> scaled = (ILArray<int>)ILMath.convert(NumericType.Int32, ILMath.floor((surface - min) * (double)(colourMapLength - 1) / range)); ILIterator<int> iterator = scaled.CreateIterator(); magnitude = iterator.Value; for (int y = height - 1; y >= 0; --y) { index = y * rawStride; for (int x = 0; x < width; ++x) { rawImage[index] = cmap[magnitude, 3]; rawImage[index + 1] = cmap[magnitude, 2]; rawImage[index + 2] = cmap[magnitude, 1]; rawImage[index + 3] = cmap[magnitude, 0]; index += bytes; magnitude = iterator.Increment(); } } // Create a BitmapSource. BitmapSource bitmap = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, rawStride); return bitmap; }
protected void Initialize(bool newColourBar) { colourMapUpdateTimer = new DispatcherTimer(); colourMapUpdateTimer.Interval = TimeSpan.FromSeconds(0.2); colourMap = new ColourMap(ColourMapType.Jet, 256); imageRectangle = new Path(); Geometry geometry = new RectangleGeometry(Bounds); imageRectangle.Data = geometry; RenderOptions.SetBitmapScalingMode(imageRectangle, BitmapScalingMode.NearestNeighbor); #if ILNumerics if (useILArray) { indices = UnderlyingILArrayToIndexArray(colourMap.Length); } #endif if (!useILArray) indices = UnderlyingToIndexArray(colourMap.Length); writeableBitmap = new WriteableBitmap(IndexArrayToBitmapSource()); imageBrush = new ImageBrush(writeableBitmap); imageRectangle.Fill = imageBrush; Bounds = new Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight); if (newColourBar) { colourBar = new ColourBar(ColourMap); #if ILNumerics if (useILArray) { colourBar.Min = underlyingILArrayData.MinValue; colourBar.Max = underlyingILArrayData.MaxValue; } #endif if (!useILArray) { colourBar.Min = underlyingData.Min(); colourBar.Max = underlyingData.Max(); } } }