Ejemplo n.º 1
0
        public void CreateAltitudeMap(double minToleranceValue, double maxToleranceValue, COLORCODE colorcode)
        {
            try
            {
                BuildHeightArray();
                // Calculate the function's value over the area.
                int    xwidth = heightArr.GetUpperBound(0) + 1;
                int    zwidth = heightArr.GetUpperBound(1) + 1;
                double dx     = (XIndexMax - XIndexMin) / xwidth;
                double dz     = (ZIndexMax - ZIndexMin) / zwidth;

                // Get the upper and lower bounds on the values.
                SetColors();

                // Make the BitmapPixelMaker.
                BitmapPixelMaker bm_texture_maker = new BitmapPixelMaker(xwidth, zwidth);
                var bm_solid_maker = new BitmapPixelMaker(xwidth, zwidth);

                // Set the pixel colors.
                for (int ix = 0; ix < xwidth; ix++)
                {
                    for (int iz = 0; iz < zwidth; iz++)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(100, 100, 100);
                        var cc = new ColorCoder(colorcode);

                        switch (colorcode)
                        {
                        case COLORCODE.GREEN_RED:
                            cc.SetValues(minToleranceValue, maxToleranceValue);
                            break;

                        case COLORCODE.MONO:

                            break;

                        case COLORCODE.RAINBOW:
                        default:
                            cc.SetValues(ScaledMinValue, ScaledMaxValue);
                            break;
                        }
                        color = cc.MapColor(heightArr[ix, iz]);
                        bm_texture_maker.SetPixel(ix, iz, color);
                    }
                }

                // Convert the BitmapPixelMaker into a WriteableBitmap.
                AltitudeMap = bm_texture_maker.MakeBitmap(96, 96);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        // Create the altitude map texture bitmap.
        private void CreateAltitudeMap(double[,] values, double maxToleranceValue, COLORCODE colorcode)
        {
            try
            {
                // Calculate the function's value over the area.
                int    xwidth = values.GetUpperBound(0) + 1;
                int    zwidth = values.GetUpperBound(1) + 1;
                double dx     = (xIndexMax - xIndexMin) / xwidth;
                double dz     = (zIndexMax - zIndexMin) / zwidth;

                // Get the upper and lower bounds on the values.
                var get_values =
                    from double value in values
                    select value;
                double ymin = get_values.Min();
                double ymax = get_values.Max();

                // Make the BitmapPixelMaker.
                BitmapPixelMaker bm_maker = new BitmapPixelMaker(xwidth, zwidth);
                double[]         contours = new double[10];
                double           dc       = (ymax - ymin) / contours.Length;
                for (int ci = 0; ci < contours.Length; ci++)
                {
                    contours[ci] = ci * dc + ymin;
                }
                // Set the pixel colors.
                for (int ix = 0; ix < xwidth; ix++)
                {
                    for (int iz = 0; iz < zwidth; iz++)
                    {
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(100, 100, 100);
                        switch (colorcode)
                        {
                        case COLORCODE.GREEN_RED:
                            color = ColorCoder.MapGreenRedColor(values[ix, iz], maxToleranceValue);
                            break;

                        case COLORCODE.MONO:
                            color = ColorCoder.MapMonoColor();
                            break;

                        case COLORCODE.RAINBOW:
                        default:
                            color = ColorCoder.MapRainbowColor(values[ix, iz], ymin, ymax);
                            break;
                        }

                        bm_maker.SetPixel(ix, iz, color);
                    }
                }

                // Convert the BitmapPixelMaker into a WriteableBitmap.
                WriteableBitmap wbitmap  = bm_maker.MakeBitmap(96, 96);
                string          filename = "texture.png";

                // Save the bitmap into a file.
                wbitmap.Save(filename);
            }
            catch (Exception)
            {
                throw;
            }
        }