private static void DrawSOMTile_Gray(SelfOrganizingMapsWPF.DrawTileArgs e, double[] source) { //NOTE: Copied from UtilityWPF.GetBitmap for (int y = 0; y < e.TileHeight; y++) { int offsetImageY = (e.ImageY + y) * e.Stride; int offsetSourceY = y * e.TileWidth; for (int x = 0; x < e.TileWidth; x++) { int indexImage = offsetImageY + ((e.ImageX + x) * e.PixelWidth); byte gray = (source[offsetSourceY + x] * 255).ToByte_Round(); e.BitmapPixelBytes[indexImage + 3] = 255; e.BitmapPixelBytes[indexImage + 2] = gray; e.BitmapPixelBytes[indexImage + 1] = gray; e.BitmapPixelBytes[indexImage + 0] = gray; } } }
private static void DrawSOMTile(SelfOrganizingMapsWPF.DrawTileArgs e) { SOMInput<SOMList.SOMItem> cast = e.Tile as SOMInput<SOMList.SOMItem>; if (cast == null) { throw new InvalidCastException("Expected SOMInput<SOMList.SOMItem>: " + e.Tile == null ? "<null>" : e.Tile.GetType().ToString()); } else if (cast.Source == null) { throw new ApplicationException("cast.Source is null"); } else if (cast.Source.Original == null) { throw new ApplicationException("The original image shouldn't be null"); } if (cast.Source.Original.Length == e.TileWidth * e.TileHeight) { DrawSOMTile_Gray(e, cast.Source.Original); } else if (cast.Source.Original.Length == e.TileWidth * e.TileHeight * 3) { DrawSOMTile_Color(e, cast.Source.Original); } else { throw new ApplicationException("The original image isn't the expected size"); } }