示例#1
0
        private static void DrawSOMTile_Color(SelfOrganizingMapsWPF.DrawTileArgs e, VectorND source)
        {
            //NOTE: Copied from UtilityWPF.GetBitmap_RGB

            for (int y = 0; y < e.TileHeight; y++)
            {
                int offsetImageY  = (e.ImageY + y) * e.Stride;
                int offsetSourceY = y * e.TileWidth * 3;

                for (int x = 0; x < e.TileWidth; x++)
                {
                    int indexImage  = offsetImageY + ((e.ImageX + x) * e.PixelWidth);
                    int indexSource = offsetSourceY + (x * 3);

                    byte r = (source[indexSource + 0] * 255).ToByte_Round();
                    byte g = (source[indexSource + 1] * 255).ToByte_Round();
                    byte b = (source[indexSource + 2] * 255).ToByte_Round();

                    e.BitmapPixelBytes[indexImage + 3] = 255;
                    e.BitmapPixelBytes[indexImage + 2] = r;
                    e.BitmapPixelBytes[indexImage + 1] = g;
                    e.BitmapPixelBytes[indexImage + 0] = b;
                }
            }
        }
示例#2
0
        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.Size == e.TileWidth * e.TileHeight)
            {
                DrawSOMTile_Gray(e, cast.Source.Original);
            }
            else if (cast.Source.Original.Size == e.TileWidth * e.TileHeight * 3)
            {
                DrawSOMTile_Color(e, cast.Source.Original);
            }
            else
            {
                throw new ApplicationException("The original image isn't the expected size");
            }
        }