コード例 #1
0
        static void Main(string[] args)
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";

            const string DstDir = @"E:\Desktop\out";

            string fileName;

            do
            {
                fileName = Console.ReadLine();
                string pngPath = Path.Combine(DstDir, Path.GetFileNameWithoutExtension(fileName) + ".png");

                fileName = Path.Combine(SrcDir, fileName);

                if (File.Exists(fileName))
                {
                    TDMPIO d1 = new TDMPIO();
                    d1.Load(new DevFileLocation(fileName));
                    TDmpBlur.OutPng(d1.Data, d1.Width, d1.Height, pngPath);

                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("* File not exist.");
                }
            }while (fileName != "exit");
        }
コード例 #2
0
        static void SrtmBath(string srcDir, string bathy)
        {
            const string tmpDir = @"E:\Desktop\tmp\";

            const int bathWidth  = 18433;
            const int bathHeight = 9217;

            byte[] bathyData;

            BinaryReader br = new BinaryReader(File.Open(bathy, FileMode.Open));

            bathyData = br.ReadBytes(bathWidth * bathHeight);
            br.Close();

            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0" + ".tdmp");
                    if (File.Exists(file))
                    {
                        string file2 = Path.Combine(tmpDir, "tile_" + x.ToString("D2") + "_" + (y + 6).ToString("D2") + "_0" + ".tdmp");
                        File.Copy(file, file2);
                    }
                }
            }


            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file = Path.Combine(tmpDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0" + ".tdmp");

                    int startX = (x - 1) * 256;
                    int startY = (y - 1) * 256;// +1536;

                    if (y > 3 && y < 33)
                    {
                        if (File.Exists(file))
                        {
                            TDMPIO d1 = new TDMPIO();
                            d1.Load(new DevFileLocation(file));
                            d1.XSpan *= 2;
                            d1.YSpan *= 2;
                            PlanetEarth.TileCoord2CoordNew(x, y, out d1.Xllcorner, out d1.Yllcorner);

                            float[] data = d1.Data;

                            for (int i = 0; i < d1.Height; i++)
                            {
                                for (int j = 0; j < d1.Width; j++)
                                {
                                    int idx = i * d1.Height + j;
                                    data[idx] *= 5000;

                                    data[idx] += 1500;
                                    data[idx] -= (0xff - bathyData[(startY + i) * bathWidth + startX + j]) * (1500f / 256f);

                                    //data[idx] /= 7000;
                                }
                            }

                            Stream sout = File.Open(Path.Combine(@"E:\Desktop\out\", Path.GetFileNameWithoutExtension(file) + ".tdmp"), FileMode.OpenOrCreate);
                            d1.Save(sout);



                            for (int i = 0; i < d1.Height; i++)
                            {
                                for (int j = 0; j < d1.Width; j++)
                                {
                                    int idx = i * d1.Height + j;
                                    data[idx] /= 7000;
                                }
                            }
                            TDmpBlur.OutPng(data, d1.Width, d1.Height, Path.Combine(@"E:\Desktop\out\",
                                                                                    Path.GetFileNameWithoutExtension(file) + ".png"));
                        }
                        else
                        {
                            TDMPIO d2 = new TDMPIO();
                            d2.Width  = 513;
                            d2.Height = 513;
                            d2.XSpan  = 10;
                            d2.YSpan  = 10;
                            d2.Bits   = 16;

                            PlanetEarth.TileCoord2CoordNew(x, y, out d2.Xllcorner, out d2.Yllcorner);

                            d2.Data = new float[513 * 513];

                            for (int i = 0; i < d2.Height; i++)
                            {
                                for (int j = 0; j < d2.Width; j++)
                                {
                                    int idx = i * d2.Height + j;

                                    d2.Data[idx]  = 1600;
                                    d2.Data[idx] -= (0xff - bathyData[(startY + i) * bathWidth + startX + j]) * (1500f / 256f);
                                }
                            }

                            Stream sout = File.Open(Path.Combine(@"E:\Desktop\out\", Path.GetFileNameWithoutExtension(file) + ".tdmp"), FileMode.OpenOrCreate);
                            d2.Save(sout);



                            for (int i = 0; i < d2.Height; i++)
                            {
                                for (int j = 0; j < d2.Width; j++)
                                {
                                    int idx = i * d2.Height + j;
                                    d2.Data[idx] /= 7000;
                                }
                            }
                            TDmpBlur.OutPng(d2.Data, d2.Width, d2.Height, Path.Combine(@"E:\Desktop\out\",
                                                                                       Path.GetFileNameWithoutExtension(file) + ".png"));
                        }
                    }
                }
            }
        }