Exemple #1
0
        public void Save(string filename)
        {
            double[,] mesh = SlopeMap.GetInstance().GetSlopeMap();
            int width  = mesh.GetUpperBound(0) + 1;
            int height = mesh.GetUpperBound(1) + 1;

            double maxslopetoexport = Config.GetInstance().SlopemapExportMaxSlope;

            Image image = new Image(width, height);
            //Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            //Graphics g = Graphics.FromImage(bitmap);
            // cache pencolors;
            List <MovementAreaConfig>  movementareas         = Config.GetInstance().movementareas;
            SortedList <double, Color> sortedcolorbymaxslope = new SortedList <double, Color>();

            foreach (MovementAreaConfig movementarea in movementareas)
            {
                if (movementarea.MaxSlope >= 0)
                {
                    sortedcolorbymaxslope.Add(movementarea.MaxSlope, movementarea.color);
                }
                else
                {
                    sortedcolorbymaxslope.Add(double.PositiveInfinity, movementarea.color);
                }
            }
            for (int area = 0; area < sortedcolorbymaxslope.Count; area++)
            {
                LogFile.GetInstance().WriteLine(sortedcolorbymaxslope.Keys[area] + " " + sortedcolorbymaxslope.Values[area].ToString());
            }
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Color colortouse = new Color(1, 1, 1);
                    for (int area = 0; area < sortedcolorbymaxslope.Count; area++)
                    {
                        if (mesh[i, j] < sortedcolorbymaxslope.Keys[area])
                        {
                            colortouse = sortedcolorbymaxslope.Values[area];
                            break;
                        }
                    }
                    int valuetowrite = (int)(mesh[i, j] * 255 / maxslopetoexport);
                    valuetowrite = Math.Max(0, valuetowrite);
                    valuetowrite = Math.Min(255, valuetowrite);
                    image.SetPixel(i, j, (byte)(colortouse.r * 255 * valuetowrite),
                                   (byte)(colortouse.g * 255 * valuetowrite),
                                   (byte)(colortouse.b * 255 * valuetowrite),
                                   255
                                   );
                }
            }
            image.Save(filename);
            exportheightmapfilename = filename;
            MainUI.GetInstance().uiwindow.InfoMessage("Slopemap exported");
        }
Exemple #2
0
        void Save(string filename)
        {
            double[,] mesh = SlopeMap.GetInstance().GetSlopeMap();
            int width  = mesh.GetUpperBound(0) + 1;
            int height = mesh.GetUpperBound(1) + 1;

            double maxslopetoexport = Config.GetInstance().SlopemapExportMaxSlope;

            Bitmap   bitmap = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            Graphics g      = Graphics.FromImage(bitmap);
            // cache pencolors;
            List <MovementAreaConfig>  movementareas         = Config.GetInstance().movementareas;
            Dictionary <Color, Pen[]>  penarraybycolor       = new Dictionary <Color, Pen[]>();
            SortedList <double, Color> sortedcolorbymaxslope = new SortedList <double, Color>();

            foreach (MovementAreaConfig movementarea in movementareas)
            {
                if (movementarea.MaxSlope >= 0)
                {
                    sortedcolorbymaxslope.Add(movementarea.MaxSlope, movementarea.color);
                }
                else
                {
                    sortedcolorbymaxslope.Add(double.PositiveInfinity, movementarea.color);
                }
                if (!penarraybycolor.ContainsKey(movementarea.color))
                {
                    Vector3 colorvector = new Vector3(movementarea.color.r, movementarea.color.g, movementarea.color.b);
                    penarraybycolor.Add(movementarea.color, new Pen[256]);
                    for (int i = 0; i < 256; i++)
                    {
                        Vector3 thiscolorvector = colorvector * i;
                        penarraybycolor[movementarea.color][i] =
                            new Pen(System.Drawing.Color.FromArgb(
                                        (int)thiscolorvector.x, (int)thiscolorvector.y, (int)thiscolorvector.z));
                    }
                }
            }
            for (int area = 0; area < sortedcolorbymaxslope.Count; area++)
            {
                Console.WriteLine(sortedcolorbymaxslope.Keys[area] + " " + sortedcolorbymaxslope.Values[area].ToString());
            }
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Color colortouse = new Color(1, 1, 1);
                    for (int area = 0; area < sortedcolorbymaxslope.Count; area++)
                    {
                        if (mesh[i, j] < sortedcolorbymaxslope.Keys[area])
                        {
                            colortouse = sortedcolorbymaxslope.Values[area];
                            break;
                        }
                    }
                    int valuetowrite = (int)(mesh[i, j] * 255 / maxslopetoexport);
                    valuetowrite = Math.Max(0, valuetowrite);
                    valuetowrite = Math.Min(255, valuetowrite);
                    g.DrawRectangle(penarraybycolor[colortouse][valuetowrite], i, j, 1, 1);
                }
            }
            bitmap.Save(filename, ImageFormat.Bmp);
        }