예제 #1
0
        private static Bitmap ReadTile(int lon, int lat)
        {
            DTEDFile dted = new DTEDFile();
            using (FileStream fs = File.OpenRead(string.Format(@"Data\dted\e0{0}\n{1}.dt0", lon, lat)))
                dted.Read(fs);

            UserHeaderLabel uhl = dted.UHL;

            Bitmap bmp = new Bitmap(tileWidth, tileHeight);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, tileWidth, tileHeight), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            byte[] data = new byte[bmpData.Stride * bmpData.Height];

            for (int y = 0; y < tileHeight; ++y)
            {
                for (int x = 0; x < tileWidth; ++x)
                {
                    int value = dted.GetElevation(x, y);
                    Color col = s_terrainPalette[value + 500];
                    int pixelOffset = (tileHeight - y - 1) * bmpData.Stride + x * 4;
                    data[pixelOffset + 0] = col.B;
                    data[pixelOffset + 1] = col.G;
                    data[pixelOffset + 2] = col.R;
                    data[pixelOffset + 3] = 255;
                }
            }
            Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
            bmp.UnlockBits(bmpData);
            return bmp;
        }
예제 #2
0
        private void ScanDTED(int lon, int lat)
        {
            DTEDFile dted = new DTEDFile();
            using (FileStream fs = File.OpenRead(string.Format(@"Data\dted\e0{0}\n{1}.dt0", lon, lat)))
                dted.Read(fs);

            int[,] data = new int[tileHeight + 2, tileWidth + 2];
            bool[,] visitMask = new bool[tileHeight + 2, tileWidth + 2];

            for (int y = 0; y < tileHeight + 2; ++y)
            {
                data[y, 0] = int.MinValue;
                data[y, tileWidth + 1] = int.MinValue;
            }
            for (int x = 0; x < tileWidth + 2; ++x)
            {
                data[0, x] = int.MinValue;
                data[tileHeight + 1, x] = int.MinValue;
            }

            int min = int.MaxValue;
            int max = int.MinValue;
            for (int y = 0; y < tileHeight; ++y)
            {
                for (int x = 0; x < tileWidth; ++x)
                {
                    int value = dted.GetElevation(x, y);
                    data[y + 1, x + 1] = value;
                    min = Math.Min(value, min);
                    max = Math.Max(value, max);
                }
            }

            Bitmap bmp = new Bitmap((tileWidth + 2) * PixelSize, (tileHeight + 2) * PixelSize, PixelFormat.Format32bppArgb);

            PictureBox pb = new PictureBox();
            pb.Image = bmp;
            pb.Width = (tileWidth + 2) * PixelSize;
            pb.Height = (tileHeight + 2) * PixelSize;
            pb.Top = 0;
            pb.Left = 500;
            Controls.Add(pb);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                int counter = 0;
                //for (int h = max; h >= min; --h)
                int h = 600;
                {
                    //if (h % 300 != 0) continue;

                    for (int y = 0; y < tileHeight + 2; ++y)
                        for (int x = 0; x < tileWidth + 2; ++x)
                            visitMask[y, x] = false;

                    for (int y = 1; y <= tileHeight; ++y)
                    {
                        for (int x = 1; x <= tileWidth; ++x)
                        {
                            Rectangle pixelRect = new Rectangle(x * PixelSize, (tileHeight - y) * PixelSize, PixelSize, PixelSize);
                            int value = data[y, x];
                            if (value < h)
                                g.FillRectangle(Brushes.Black, pixelRect);
                            else
                                g.FillRectangle(Brushes.Gray, pixelRect);
                        }
                    }

                    bool inside = false;
                    for (int y = 1; y <= tileHeight; ++y)
                    {
                        for (int x = 1; x <= tileWidth; ++x)
                        {
                            if (visitMask[y, x])
                            {
                                inside = true;
                                continue;
                            }

                            int value = data[y, x];
                            if (value < h)
                                inside = false;
                            else if (!inside)
                            {
                                counter++;
                                if (counter == 7)
                                    return;
                                List<Point> vector = TryTrace(data, visitMask, g, x, y, h);
                                if (vector.Count == 1)
                                {
                                    g.DrawEllipse(Pens.Blue, vector[0].X, vector[0].Y, PixelSize, PixelSize);
                                }
                                if (vector.Count > 2)
                                    g.DrawPolygon(Pens.Blue, vector.ToArray());

                                inside = true;
                            }
                        }
                    }
                }
            }
        }