예제 #1
0
        static void ElevationBias()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";
            const string OutDir = @"E:\Desktop\out";

            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");
                    string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        for (int i = 0; i < d1.Height; i++)
                        {
                            for (int j = 0; j < d1.Width; j++)
                            {
                                int idx = i * d1.Height + j;
                                d1.Data[idx] += 45;;
                            }
                        }
                        Stream sout = File.Open(file2, FileMode.OpenOrCreate);
                        d1.Save(sout);
                    }
                }
            }
        }
예제 #2
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");
           
        }
예제 #3
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");
        }
예제 #4
0
        static void DoubleSize()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";
            const string OutDir = @"E:\Desktop\out";

            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") + "_3.tdmp");
                    string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_3.tdmp");
                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new FileLocation(file));

                        d1.XSpan *= 2;
                        d1.YSpan *= 2;

                        Stream sout = File.Open(file2, FileMode.OpenOrCreate);
                        d1.Save(sout);
                    }
                }
            }
        }
예제 #5
0
        static void Scan2(string srcDir)
        {
            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") + "_3" + ".tdmp");

                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        Point coord;
                        coord.X = (int)Math.Truncate(d1.Xllcorner);
                        coord.Y = (int)Math.Truncate(d1.Yllcorner);

                        int col = x * 5 - 185;
                        int lat = 95 - y * 5;

                        if (col != coord.X || lat != coord.Y)
                        {
                            Console.WriteLine("Err: " + Path.GetFileNameWithoutExtension(file));
                            d1.Xllcorner = col;
                            d1.Yllcorner = lat;

                            Stream stm = File.Open(file, FileMode.Open);
                            stm.SetLength(0);
                            d1.Save(stm);
                        }
                    }
                }
            }
        }
예제 #6
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            TDMPIO srcData = new TDMPIO();
            srcData.Load(source);

            srcData.Bits = 12;
            srcData.Save(dest.GetStream);
        }
예제 #7
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            TDMPIO srcData = new TDMPIO();

            srcData.Load(source);

            srcData.Bits = 12;
            srcData.Save(dest.GetStream);
        }
예제 #8
0
        public QueryHeight(float longtitude, float lattiude)
        {
            //int x = 0;
            //int y = 0;
            //if (longtitude / 10 != 0)
            //    longtitude = (int)(longtitude / 10) * 10;
            //if (lattiude / 10 != 0)
            //    lattiude = (int)(lattiude / 10) * 10;
            
            //x = (int)((longtitude + 185) / 5);
            //y = (int)((95 - lattiude) / 5);

            double x = 0;
            double y = 0;
            x = (longtitude + 185) / 5;
            y = (95 - lattiude) / 5;

            int x1 = (int)(Math.Truncate(x));
            if (x1 / 2 == 0)
                x1--;
            int y1 = (int)(Math.Truncate(y));
            if (y1 / 2 == 0)
                y1--;
            string dir = "C:\\Users\\penser\\Documents\\Visual Studio 2008\\Projects\\lrvbsvnicg\\Source\\Code2015\\bin\\x86\\Debug\\terrain.lpk\\";

            file = dir + "tile_" + x1.ToString("D2") + "_" + y1.ToString("D2").ToString() + "_0.tdmp";
            FileLocation fl = new FileLocation(file);

            td = new TDMPIO();
            td.Load(new FileLocation(fl));

            int width = td.Width;
            int height = td.Height;
            data = td.Data;

            float detaX = td.XSpan / width;
            float detaY = td.YSpan / height;

            //td.Xllcorner表示经度,角度制。

            if (longtitude <= 0)
                longtitude = -longtitude;
            int posX = (int)(Math.Abs(longtitude - td.Xllcorner) / detaX);

            if (lattiude <= 0)
                lattiude = -lattiude;
            int posY = (int)(Math.Abs(lattiude - td.Yllcorner) / detaY);

            this.Height = data[posY * 513 + posX];
           
        }
예제 #9
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            FileLocation fl = source as FileLocation;

            if (fl != null)
            {
                string path = fl.Path;

                string dir = Path.GetDirectoryName(path);
                string fn  = Path.GetFileNameWithoutExtension(path);


                TDMPIO srcData = new TDMPIO();
                srcData.Load(source);

                float[] demData = srcData.Data;

                int tw = srcData.Width;
                int th = srcData.Height;

                int level = 0;

                FileStream fs = new FileStream(Path.Combine(dir, fn + "_" + level++.ToString() + ".tdmp"), FileMode.OpenOrCreate, FileAccess.Write);
                srcData.Save(fs);


                do
                {
                    tw = tw / 4 + 1;
                    th = th / 4 + 1;

                    float[] levelData = Resize(demData, srcData.Width, srcData.Height, tw, th);


                    TDMPIO result = new TDMPIO();
                    result.Width     = tw;
                    result.Height    = th;
                    result.XSpan     = srcData.XSpan;
                    result.YSpan     = srcData.YSpan;
                    result.Xllcorner = srcData.Xllcorner;
                    result.Yllcorner = srcData.Yllcorner;
                    result.Bits      = srcData.Bits;

                    result.Data = levelData;

                    fs = new FileStream(Path.Combine(dir, fn + "_" + level++.ToString() + ".tdmp"), FileMode.OpenOrCreate, FileAccess.Write);
                    result.Save(fs);
                }while (tw > 32 && th > 32);
            }
        }
예제 #10
0
        static void Scan(string srcDir)
        {
            Dictionary <Point, List <string> > table = new Dictionary <Point, List <string> >(500);

            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))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        Point coord;
                        coord.X = (int)Math.Truncate(d1.Xllcorner);
                        coord.Y = (int)Math.Truncate(d1.Yllcorner);

                        List <string> list;
                        if (!table.TryGetValue(coord, out list))
                        {
                            list = new List <string>();
                            table.Add(coord, list);
                        }
                        list.Add(file);
                    }
                }
            }

            Dictionary <Point, List <string> > .ValueCollection vals = table.Values;
            foreach (List <string> lst in vals)
            {
                if (lst.Count > 1)
                {
                    Console.Write("Collision: ");
                    for (int i = 0; i < lst.Count; i++)
                    {
                        Console.Write(Path.GetFileNameWithoutExtension(lst[i]));
                        if (i < lst.Count - 1)
                        {
                            Console.Write(", ");
                        }
                    }
                    Console.WriteLine();
                }
            }
            Console.ReadKey();
        }
예제 #11
0
        static void Simplify()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";

            //const string OutDir = @"E:\Desktop\out";

            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");
                    //string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    if (File.Exists(file))
                    {
                        bool   passed = false;
                        TDMPIO d1     = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        for (int i = 0; i < d1.Height; i++)
                        {
                            for (int j = 0; j < d1.Width; j++)
                            {
                                int idx = i * d1.Height + j;
                                if (d1.Data[idx] > 500)
                                {
                                    passed = true;
                                }
                            }
                        }

                        if (!passed)
                        {
                            Console.WriteLine(file);
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_1" + ".tdmp");
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_2" + ".tdmp");
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_3" + ".tdmp");
                            File.Delete(file);
                        }
                    }
                }
            }
        }
예제 #12
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            TDMPIO src = new TDMPIO();
            src.Load(source);

            float[] rsd = TDmpLodGen.Resize(src.Data, src.Width, src.Height, ResizeSize, ResizeSize);

            TDMPIO dst = new TDMPIO();
            dst.Width = ResizeSize;
            dst.Height = ResizeSize;
            dst.Bits = src.Bits;
            dst.Xllcorner = src.Xllcorner;
            dst.Yllcorner = src.Yllcorner;
            dst.XSpan = src.XSpan;
            dst.YSpan = src.YSpan;

            dst.Data = rsd;
            dst.Save(dest.GetStream);
        }
예제 #13
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            TDMPIO src = new TDMPIO();

            src.Load(source);

            float[] rsd = TDmpLodGen.Resize(src.Data, src.Width, src.Height, ResizeSize, ResizeSize);

            TDMPIO dst = new TDMPIO();

            dst.Width     = ResizeSize;
            dst.Height    = ResizeSize;
            dst.Bits      = src.Bits;
            dst.Xllcorner = src.Xllcorner;
            dst.Yllcorner = src.Yllcorner;
            dst.XSpan     = src.XSpan;
            dst.YSpan     = src.YSpan;

            dst.Data = rsd;
            dst.Save(dest.GetStream);
        }
예제 #14
0
        static void Scan(string srcDir)
        {
            Dictionary<Point, List<string>> table = new Dictionary<Point, List<string>>(500);

            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))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        Point coord;
                        coord.X = (int)Math.Truncate(d1.Xllcorner);
                        coord.Y = (int)Math.Truncate(d1.Yllcorner);

                        List<string> list;
                        if (!table.TryGetValue(coord, out list))
                        {
                            list = new List<string>();
                            table.Add(coord, list);
                        }
                        list.Add(file);
                    }
                }
            }

            Dictionary<Point, List<string>>.ValueCollection vals = table.Values;
            foreach (List<string> lst in vals)
            {
                if (lst.Count > 1)
                {
                    Console.Write("Collision: ");
                    for (int i = 0; i < lst.Count; i++)
                    {
                        Console.Write(Path.GetFileNameWithoutExtension(lst[i]));
                        if (i < lst.Count - 1)
                        {
                            Console.Write(", ");
                        }
                    }
                    Console.WriteLine();
                }
            }
            Console.ReadKey();
        }
예제 #15
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"));
                        }
                    }
                }
            }
        }
예제 #16
0
        static void Convert(string srcDir, string dstDir, string suffix)
        {
            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    int minX = x - 2;
                    int maxX = x + 2;
                    int minY = y - 2;
                    int maxY = y + 2;

                    if (minX < 0)
                    {
                        minX = 71;
                    }
                    if (maxX > 72)
                    {
                        maxX = 1;
                    }

                    //if (minY < 0) minY = 23;
                    //if (maxY > 72) maxY = 1;

                    string[] files = new string[9];
                    files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");
                    files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");
                    files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");

                    files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");
                    files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");
                    files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");

                    files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");
                    files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");
                    files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");

                    bool[] exists = new bool[9];
                    bool   passed = false;
                    for (int i = 0; i < files.Length; i++)
                    {
                        exists[i] = File.Exists(files[i]);
                        passed   |= exists[i];
                    }
                    passed &= exists[4];

                    if (passed)
                    {
                        int width  = 0;
                        int height = 0;

                        int  bits   = 32;
                        bool parsed = false;

                        TDMPIO[] dataBlocks = new TDMPIO[9];
                        for (int i = 0; i < 9; i++)
                        {
                            if (exists[i])
                            {
                                TDMPIO d1 = new TDMPIO();
                                d1.Load(new DevFileLocation(files[i]));
                                if (!parsed)
                                {
                                    width  = d1.Width;
                                    height = d1.Height;

                                    bits   = d1.Bits;
                                    parsed = true;
                                }

                                dataBlocks[i] = d1;
                            }
                        }

                        float[] databy = new float[width * height];

                        DataGetter dg = new DataGetter(
                            dataBlocks[0] == null ? null : dataBlocks[0].Data,
                            dataBlocks[1] == null ? null : dataBlocks[1].Data,
                            dataBlocks[2] == null ? null : dataBlocks[2].Data,
                            dataBlocks[3] == null ? null : dataBlocks[3].Data,
                            dataBlocks[4] == null ? null : dataBlocks[4].Data,
                            dataBlocks[5] == null ? null : dataBlocks[5].Data,
                            dataBlocks[6] == null ? null : dataBlocks[6].Data,
                            dataBlocks[7] == null ? null : dataBlocks[7].Data,
                            dataBlocks[8] == null ? null : dataBlocks[8].Data, width, height);


                        string fileName = Path.Combine(dstDir, Path.GetFileName(files[4]));

                        TDMPIO result = new TDMPIO();
                        result.Bits      = 16;
                        result.Height    = height;
                        result.Width     = width;
                        result.XSpan     = dataBlocks[4].XSpan;
                        result.YSpan     = dataBlocks[4].YSpan;
                        result.Xllcorner = dataBlocks[4].Xllcorner;
                        result.Yllcorner = dataBlocks[4].Yllcorner;
                        result.Data      = new float[width * height];

                        int[] weightMap = new int[width * height];

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                result.Data[i * width + j] = dg[i + height, j + width];
                                weightMap[i * width + j]   = 1;
                            }
                        }

                        for (int i = 0; i < height; i++)
                        {
                            if (dg.HasValue(i + height, width - 1))
                            {
                                result.Data[i * width] += dg[i + height, width - 1];
                                weightMap[i * width]++;
                            }
                            if (dg.HasValue(i + height, 2 * width))
                            {
                                result.Data[i * width + height - 1] += dg[i + height, 2 * width];
                                weightMap[i * width + height - 1]++;
                            }
                        }

                        for (int j = 0; j < width; j++)
                        {
                            if (dg.HasValue(height - 1, j + width))
                            {
                                result.Data[j] += dg[height - 1, j + width];
                                weightMap[j]++;
                            }
                            if (dg.HasValue(2 * height, j + width))
                            {
                                result.Data[width * (height - 1) + j] += dg[2 * height, j + width];
                                weightMap[width * (height - 1) + j]++;
                            }
                        }


                        //result.Data[0] += dg[width - 1, height - 1];
                        //weightMap[0]++;

                        //result.Data[width - 1] += dg[2 * width, height - 1];
                        //weightMap[width - 1]++;

                        //result.Data[width * (height - 1)] += dg[width - 1, 2 * height];
                        //weightMap[width * (height - 1) - 1]++;

                        //result.Data[width * height - 1] += dg[2 * width, 2 * height];
                        //weightMap[width * height - 1]++;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;
                                result.Data[idx] /= (float)weightMap[idx];
                            }
                        }

                        result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write));
                        Console.Write('#');
                    }
                }
            }
        }
예제 #17
0
        static void Convert(string srcDir, string dstDir, string suffix)
        {
            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    int minX = x - 2;
                    int maxX = x + 2;
                    int minY = y - 2;
                    int maxY = y + 2;

                    if (minX < 0) minX = 71;
                    if (maxX > 72) maxX = 1;

                    //if (minY < 0) minY = 23;
                    //if (maxY > 72) maxY = 1;

                    string[] files = new string[9];
                    files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");
                    files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");
                    files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + suffix + ".tdmp");

                    files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");
                    files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");
                    files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + suffix + ".tdmp");

                    files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");
                    files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");
                    files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + suffix + ".tdmp");

                    bool[] exists = new bool[9];
                    bool passed = false;
                    for (int i = 0; i < files.Length; i++)
                    {
                        exists[i] = File.Exists(files[i]);
                        passed |= exists[i];
                    }
                    passed &= exists[4];

                    if (passed)
                    {
                        int width = 0;
                        int height = 0;

                        int bits = 32;
                        bool parsed = false;

                        TDMPIO[] dataBlocks = new TDMPIO[9];
                        for (int i = 0; i < 9; i++)
                        {
                            if (exists[i])
                            {
                                TDMPIO d1 = new TDMPIO();
                                d1.Load(new DevFileLocation(files[i]));
                                if (!parsed)
                                {
                                    width = d1.Width;
                                    height = d1.Height;

                                    bits = d1.Bits;
                                    parsed = true;
                                }

                                dataBlocks[i] = d1;
                            }
                        }

                        float[] databy = new float[width * height];

                        DataGetter dg = new DataGetter(
                            dataBlocks[0] == null ? null : dataBlocks[0].Data,
                            dataBlocks[1] == null ? null : dataBlocks[1].Data,
                            dataBlocks[2] == null ? null : dataBlocks[2].Data,
                            dataBlocks[3] == null ? null : dataBlocks[3].Data,
                            dataBlocks[4] == null ? null : dataBlocks[4].Data,
                            dataBlocks[5] == null ? null : dataBlocks[5].Data,
                            dataBlocks[6] == null ? null : dataBlocks[6].Data,
                            dataBlocks[7] == null ? null : dataBlocks[7].Data,
                            dataBlocks[8] == null ? null : dataBlocks[8].Data, width, height);


                        string fileName = Path.Combine(dstDir, Path.GetFileName(files[4]));
                      
                        TDMPIO result = new TDMPIO();
                        result.Bits = 16;
                        result.Height = height;
                        result.Width = width;
                        result.XSpan = dataBlocks[4].XSpan;
                        result.YSpan = dataBlocks[4].YSpan;
                        result.Xllcorner = dataBlocks[4].Xllcorner;
                        result.Yllcorner = dataBlocks[4].Yllcorner;
                        result.Data = new float[width * height];

                        int[] weightMap = new int[width * height];

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {

                                result.Data[i * width + j] = dg[i + height, j + width];
                                weightMap[i * width + j] = 1;

                            }
                        }

                        for (int i = 0; i < height; i++)
                        {
                            if (dg.HasValue(i + height, width - 1))
                            {
                                result.Data[i * width] += dg[i + height, width - 1];
                                weightMap[i * width]++;
                            }
                            if (dg.HasValue(i + height, 2 * width))
                            {
                                result.Data[i * width + height - 1] += dg[i + height, 2 * width];
                                weightMap[i * width + height - 1]++;
                            }
                        }

                        for (int j = 0; j < width; j++)
                        {
                            if (dg.HasValue(height - 1, j + width))
                            {
                                result.Data[j] += dg[height - 1, j + width];
                                weightMap[j]++;
                            }
                            if (dg.HasValue(2 * height, j + width))
                            {
                                result.Data[width * (height - 1) + j] += dg[2 * height, j + width];
                                weightMap[width * (height - 1) + j]++;
                            }
                        }


                        //result.Data[0] += dg[width - 1, height - 1];
                        //weightMap[0]++;

                        //result.Data[width - 1] += dg[2 * width, height - 1];
                        //weightMap[width - 1]++;

                        //result.Data[width * (height - 1)] += dg[width - 1, 2 * height];
                        //weightMap[width * (height - 1) - 1]++;

                        //result.Data[width * height - 1] += dg[2 * width, 2 * height];
                        //weightMap[width * height - 1]++;

                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;
                                result.Data[idx] /= (float)weightMap[idx];
                            }
                        }

                        result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write));
                        Console.Write('#');
                    }
                }
            }
        }
예제 #18
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"));
                        }
                    }
                }
            }
        }
예제 #19
0
        void Convert()
        {
            for (int x = 1; x < 80; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file1 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    string file2 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    string file3 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp");
                    string file4 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp");

                    bool ex1 = File.Exists(file1);
                    bool ex2 = File.Exists(file2);
                    bool ex3 = File.Exists(file3);
                    bool ex4 = File.Exists(file4);

                    if (ex1 || ex2 || ex3 || ex4)
                    {
                        int   width  = 0;
                        int   height = 0;
                        float xSpan  = 0;
                        float ySpan  = 0;

                        float xllCorner = 0;
                        float yllCorner = 0;
                        int   bits      = 32;
                        bool  parsed    = false;

                        TDMPIO d1 = new TDMPIO();
                        if (ex1)
                        {
                            d1.Load(new DevFileLocation(file1));

                            if (!parsed)
                            {
                                width     = d1.Width;
                                height    = d1.Height;
                                xSpan     = d1.XSpan;
                                ySpan     = d1.YSpan;
                                xllCorner = d1.Xllcorner;
                                yllCorner = d1.Yllcorner;
                                bits      = d1.Bits;
                            }
                        }

                        TDMPIO d2 = new TDMPIO();
                        if (ex2)
                        {
                            d2.Load(new DevFileLocation(file2));
                            if (!parsed)
                            {
                                width     = d2.Width;
                                height    = d2.Height;
                                xSpan     = d2.XSpan;
                                ySpan     = d2.YSpan;
                                xllCorner = d2.Xllcorner - xSpan;
                                yllCorner = d2.Yllcorner;
                                bits      = d2.Bits;
                            }
                        }

                        TDMPIO d3 = new TDMPIO();
                        if (ex3)
                        {
                            d3.Load(new DevFileLocation(file3));
                            if (!parsed)
                            {
                                width     = d3.Width;
                                height    = d3.Height;
                                xSpan     = d3.XSpan;
                                ySpan     = d3.YSpan;
                                xllCorner = d3.Xllcorner;
                                yllCorner = d3.Yllcorner - ySpan;
                                bits      = d3.Bits;
                            }
                        }

                        TDMPIO d4 = new TDMPIO();
                        if (ex4)
                        {
                            d4.Load(new DevFileLocation(file4));
                            if (!parsed)
                            {
                                width     = d4.Width;
                                height    = d4.Height;
                                xSpan     = d4.XSpan;
                                ySpan     = d4.YSpan;
                                xllCorner = d4.Xllcorner - xSpan;
                                yllCorner = d4.Yllcorner - ySpan;
                                bits      = d4.Bits;
                            }
                        }

                        TDMPIO data = new TDMPIO();
                        data.Data      = new float[width * height * 4];
                        data.Width     = width * 2;
                        data.Height    = height * 2;
                        data.Xllcorner = xllCorner;
                        data.Yllcorner = yllCorner;
                        data.XSpan     = xSpan * 2;
                        data.YSpan     = ySpan * 2;
                        data.Bits      = bits;

                        DataGetter dg = new DataGetter(d1.Data, d2.Data, d3.Data, d4.Data, width, height);
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {
                                data.Data[i * data.Width + j] = dg[i, j];
                            }
                        }

                        string     outPath = Path.Combine(dstDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                        FileStream fs      = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.Write);
                        data.Save(fs);
                    }
                }
            }
        }
예제 #20
0
        public override void Convert(ResourceLocation source, ResourceLocation dest)
        {
            FileLocation fl = source as FileLocation;

            if (fl != null)
            {
                string path = fl.Path;

                string dir = Path.GetDirectoryName(path);
                string fn = Path.GetFileNameWithoutExtension(path);


                TDMPIO srcData = new TDMPIO();
                srcData.Load(source);

                float[] demData = srcData.Data;

                int tw = srcData.Width;
                int th = srcData.Height;

                int level = 0;

                FileStream fs = new FileStream(Path.Combine(dir, fn + "_" + level++.ToString() + ".tdmp"), FileMode.OpenOrCreate, FileAccess.Write);
                srcData.Save(fs);


                do
                {
                    tw = tw / 4 + 1;
                    th = th / 4 + 1;

                    float[] levelData = Resize(demData, srcData.Width, srcData.Height, tw, th);


                    TDMPIO result = new TDMPIO();
                    result.Width = tw;
                    result.Height = th;
                    result.XSpan = srcData.XSpan;
                    result.YSpan = srcData.YSpan;
                    result.Xllcorner = srcData.Xllcorner;
                    result.Yllcorner = srcData.Yllcorner;
                    result.Bits = srcData.Bits;

                    result.Data = levelData;

                    fs = new FileStream(Path.Combine(dir, fn + "_" + level++.ToString() + ".tdmp"), FileMode.OpenOrCreate, FileAccess.Write);
                    result.Save(fs);
                }
                while (tw > 32 && th > 32);
            }
        }
예제 #21
0
        static void ElevationBias()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";
            const string OutDir = @"E:\Desktop\out";
            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");
                    string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        for (int i = 0; i < d1.Height; i++)
                        {
                            for (int j = 0; j < d1.Width; j++)
                            {
                                int idx = i * d1.Height + j;
                                d1.Data[idx] += 45; ;
                            }
                        }
                        Stream sout = File.Open(file2, FileMode.OpenOrCreate);
                        d1.Save(sout);
                    }
                }
            }
        }
예제 #22
0
        static void DoubleSize()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";
            const string OutDir = @"E:\Desktop\out";
            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") + "_3.tdmp");
                    string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_3.tdmp");
                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new FileLocation(file));

                        d1.XSpan *= 2;
                        d1.YSpan *= 2;

                        Stream sout = File.Open(file2, FileMode.OpenOrCreate);
                        d1.Save(sout);
                    }
                }
            }
        }
예제 #23
0
        void Convert()
        {
            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    int minX = x - 2;
                    int maxX = x + 2;
                    int minY = y - 2;
                    int maxY = y + 2;

                    if (minX < 0)
                    {
                        minX = 71;
                    }
                    if (maxX > 72)
                    {
                        maxX = 1;
                    }

                    //if (minY < 0) minY = 23;
                    //if (maxY > 72) maxY = 1;

                    string[] files = new string[9];
                    files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");
                    files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");
                    files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");

                    files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");

                    files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");
                    files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");
                    files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");

                    bool[] exists = new bool[9];

                    bool passed = false;
                    for (int i = 0; i < files.Length; i++)
                    {
                        exists[i] = File.Exists(files[i]);
                        passed   |= exists[i];
                    }
                    passed &= exists[4];

                    if (passed)
                    {
                        int width  = 0;
                        int height = 0;

                        int  bits   = 32;
                        bool parsed = false;

                        TDMPIO[] dataBlocks = new TDMPIO[9];
                        for (int i = 0; i < 9; i++)
                        {
                            if (exists[i])
                            {
                                TDMPIO d1 = new TDMPIO();
                                d1.Load(new DevFileLocation(files[i]));
                                if (!parsed)
                                {
                                    width  = d1.Width;
                                    height = d1.Height;

                                    bits   = d1.Bits;
                                    parsed = true;
                                }

                                dataBlocks[i] = d1;
                            }
                        }


                        float[] original = dataBlocks[4].Data;

                        float[] sampleSrc1 = dataBlocks[0] == null ? null : BathymetrySlopSampleData(dataBlocks[0].Data);
                        float[] sampleSrc2 = dataBlocks[1] == null ? null : BathymetrySlopSampleData(dataBlocks[1].Data);
                        float[] sampleSrc3 = dataBlocks[2] == null ? null : BathymetrySlopSampleData(dataBlocks[2].Data);
                        float[] sampleSrc4 = dataBlocks[3] == null ? null : BathymetrySlopSampleData(dataBlocks[3].Data);
                        float[] sampleSrc5 = dataBlocks[4] == null ? null : BathymetrySlopSampleData(dataBlocks[4].Data);
                        float[] sampleSrc6 = dataBlocks[5] == null ? null : BathymetrySlopSampleData(dataBlocks[5].Data);
                        float[] sampleSrc7 = dataBlocks[6] == null ? null : BathymetrySlopSampleData(dataBlocks[6].Data);
                        float[] sampleSrc8 = dataBlocks[7] == null ? null : BathymetrySlopSampleData(dataBlocks[7].Data);
                        float[] sampleSrc9 = dataBlocks[8] == null ? null : BathymetrySlopSampleData(dataBlocks[8].Data);

                        DataGetter dg = new DataGetter(
                            dataBlocks[0] == null ? null : sampleSrc1,
                            dataBlocks[1] == null ? null : sampleSrc2,
                            dataBlocks[2] == null ? null : sampleSrc3,
                            dataBlocks[3] == null ? null : sampleSrc4,
                            dataBlocks[4] == null ? null : sampleSrc5,
                            dataBlocks[5] == null ? null : sampleSrc6,
                            dataBlocks[6] == null ? null : sampleSrc7,
                            dataBlocks[7] == null ? null : sampleSrc8,
                            dataBlocks[8] == null ? null : sampleSrc9, width, height);


                        #region 高斯模糊
                        int brushSize = 65;

                        float[] databy = new float[width * height];

                        float[] weights = MathEx.ComputeGuassFilter1D((float)Math.Sqrt(1 * brushSize), brushSize);

                        #region Normalize
                        float maxValue = 0;
                        for (int i = 0; i < brushSize; i++)
                        {
                            maxValue += weights[i];
                        }

                        if (maxValue != 0)
                        {
                            float scale = 1.0f / maxValue;

                            for (int i = 0; i < brushSize; i++)
                            {
                                weights[i] *= scale;
                            }
                        }

                        #endregion

                        int mid = brushSize / 2;

                        #region Y方向模糊
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;

                                if (original[idx] < 1600)
                                {
                                    float val = 0;
                                    for (int ii = 0; ii < brushSize; ii++)
                                    {
                                        val += weights[ii] * dg[i + ii - mid + width, j + height];
                                    }
                                    databy[idx] = MathEx.Clamp(0, 1600, val);
                                }
                                else
                                {
                                    databy[idx] = original[idx];
                                }
                            }
                        }
                        #endregion


                        float[] databx = new float[width * height];
                        dg.MainData = databy;

                        #region X方向模糊
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;

                                if (original[idx] < 1600)
                                {
                                    float val = 0;
                                    for (int ii = 0; ii < brushSize; ii++)
                                    {
                                        val += weights[ii] * dg[i + width, j + ii - mid + height];
                                    }
                                    databx[idx] = MathEx.Clamp(0, 1600, val);
                                }
                                else
                                {
                                    databx[idx] = original[idx];
                                }
                            }
                        }
                        #endregion

                        #endregion

                        string fileName     = Path.Combine(dstDir, Path.GetFileName(files[4]));
                        string fileNameImg  = Path.Combine(dstDir, Path.GetFileName(files[4]) + "s.png");
                        string fileNameImg2 = Path.Combine(dstDir, Path.GetFileName(files[4]) + "d.png");

                        TDMPIO result = new TDMPIO();
                        result.Data      = databx;
                        result.Bits      = 16;
                        result.Height    = height;
                        result.Width     = width;
                        result.XSpan     = dataBlocks[4].XSpan;
                        result.YSpan     = dataBlocks[4].YSpan;
                        result.Xllcorner = dataBlocks[4].Xllcorner;
                        result.Yllcorner = dataBlocks[4].Yllcorner;

                        result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write));

                        #region 预览图
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;
                                original[idx] /= 7000;
                                databx[idx]   /= 7000;
                            }
                        }
                        OutPng(databx, width, height, fileNameImg);
                        OutPng(original, width, height, fileNameImg2);
                        #endregion
                    }
                }
            }
        }
예제 #24
0
        static void Simplify()
        {
            const string SrcDir = @"E:\Documents\ic10gd\Source\Code2015\bin\x86\Debug\terrain.lpk";
            //const string OutDir = @"E:\Desktop\out";

            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");
                    //string file2 = Path.Combine(OutDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    if (File.Exists(file))
                    {
                        bool passed = false;
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));

                        for (int i = 0; i < d1.Height; i++)
                        {
                            for (int j = 0; j < d1.Width; j++)
                            {
                                int idx = i * d1.Height + j;
                                if (d1.Data[idx] > 500)
                                {
                                    passed = true;
                                }
                            }
                        }

                        if (!passed) 
                        {
                            Console.WriteLine(file);
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_1" + ".tdmp");
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_2" + ".tdmp");
                            File.Delete(file);
                            file = Path.Combine(SrcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_3" + ".tdmp");
                            File.Delete(file);

                        }
                    }
                }
            }
        }
예제 #25
0
        void Convert()
        {
            for (int x = 1; x < 72; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    int minX = x - 2;
                    int maxX = x + 2;
                    int minY = y - 2;
                    int maxY = y + 2;

                    if (minX < 0) minX = 71;
                    if (maxX > 72) maxX = 1;

                    //if (minY < 0) minY = 23;
                    //if (maxY > 72) maxY = 1;

                    string[] files = new string[9];
                    files[0] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");
                    files[1] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");
                    files[2] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + minY.ToString("D2") + ".tdmp");

                    files[3] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    files[4] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    files[5] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");

                    files[6] = Path.Combine(srcDir, "tile_" + minX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");
                    files[7] = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");
                    files[8] = Path.Combine(srcDir, "tile_" + maxX.ToString("D2") + "_" + maxY.ToString("D2") + ".tdmp");

                    bool[] exists = new bool[9];

                    bool passed = false;
                    for (int i = 0; i < files.Length; i++)
                    {
                        exists[i] = File.Exists(files[i]);
                        passed |= exists[i];
                    }
                    passed &= exists[4];

                    if (passed)
                    {
                        int width = 0;
                        int height = 0;

                        int bits = 32;
                        bool parsed = false;

                        TDMPIO[] dataBlocks = new TDMPIO[9];
                        for (int i = 0; i < 9; i++)
                        {
                            if (exists[i])
                            {
                                TDMPIO d1 = new TDMPIO();
                                d1.Load(new DevFileLocation(files[i]));
                                if (!parsed)
                                {
                                    width = d1.Width;
                                    height = d1.Height;

                                    bits = d1.Bits;
                                    parsed = true;
                                }

                                dataBlocks[i] = d1;
                            }
                        }


                        float[] original = dataBlocks[4].Data;

                        float[] sampleSrc1 = dataBlocks[0] == null ? null : BathymetrySlopSampleData(dataBlocks[0].Data);
                        float[] sampleSrc2 = dataBlocks[1] == null ? null : BathymetrySlopSampleData(dataBlocks[1].Data);
                        float[] sampleSrc3 = dataBlocks[2] == null ? null : BathymetrySlopSampleData(dataBlocks[2].Data);
                        float[] sampleSrc4 = dataBlocks[3] == null ? null : BathymetrySlopSampleData(dataBlocks[3].Data);
                        float[] sampleSrc5 = dataBlocks[4] == null ? null : BathymetrySlopSampleData(dataBlocks[4].Data);
                        float[] sampleSrc6 = dataBlocks[5] == null ? null : BathymetrySlopSampleData(dataBlocks[5].Data);
                        float[] sampleSrc7 = dataBlocks[6] == null ? null : BathymetrySlopSampleData(dataBlocks[6].Data);
                        float[] sampleSrc8 = dataBlocks[7] == null ? null : BathymetrySlopSampleData(dataBlocks[7].Data);
                        float[] sampleSrc9 = dataBlocks[8] == null ? null : BathymetrySlopSampleData(dataBlocks[8].Data);

                        DataGetter dg = new DataGetter(
                            dataBlocks[0] == null ? null : sampleSrc1,
                            dataBlocks[1] == null ? null : sampleSrc2,
                            dataBlocks[2] == null ? null : sampleSrc3,
                            dataBlocks[3] == null ? null : sampleSrc4,
                            dataBlocks[4] == null ? null : sampleSrc5,
                            dataBlocks[5] == null ? null : sampleSrc6,
                            dataBlocks[6] == null ? null : sampleSrc7,
                            dataBlocks[7] == null ? null : sampleSrc8,
                            dataBlocks[8] == null ? null : sampleSrc9, width, height);


                        #region 高斯模糊
                        int brushSize = 65;

                        float[] databy = new float[width * height];

                        float[] weights = MathEx.ComputeGuassFilter1D((float)Math.Sqrt(1 * brushSize), brushSize);

                        #region Normalize
                        float maxValue = 0;
                        for (int i = 0; i < brushSize; i++)
                        {
                            maxValue += weights[i];
                        }

                        if (maxValue != 0)
                        {
                            float scale = 1.0f / maxValue;

                            for (int i = 0; i < brushSize; i++)
                            {
                                weights[i] *= scale;
                            }
                        }

                        #endregion

                        int mid = brushSize / 2;

                        #region Y方向模糊
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;

                                if (original[idx] < 1600)
                                {
                                    float val = 0;
                                    for (int ii = 0; ii < brushSize; ii++)
                                    {
                                        val += weights[ii] * dg[i + ii - mid + width, j + height];
                                    }
                                    databy[idx] = MathEx.Clamp(0, 1600, val);
                                }
                                else databy[idx] = original[idx];
                            }
                        }
                        #endregion


                        float[] databx = new float[width * height];
                        dg.MainData = databy;

                        #region X方向模糊
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;

                                if (original[idx] < 1600)
                                {
                                    float val = 0;
                                    for (int ii = 0; ii < brushSize; ii++)
                                    {
                                        val += weights[ii] * dg[i + width, j + ii - mid + height];
                                    }
                                    databx[idx] = MathEx.Clamp(0, 1600, val);
                                }
                                else databx[idx] = original[idx];
                            }
                        }
                        #endregion

                        #endregion

                        string fileName = Path.Combine(dstDir, Path.GetFileName(files[4]) );
                        string fileNameImg = Path.Combine(dstDir, Path.GetFileName(files[4]) + "s.png");
                        string fileNameImg2 = Path.Combine(dstDir, Path.GetFileName(files[4]) + "d.png");

                        TDMPIO result = new TDMPIO();
                        result.Data = databx;
                        result.Bits = 16;
                        result.Height = height;
                        result.Width = width;
                        result.XSpan = dataBlocks[4].XSpan;
                        result.YSpan = dataBlocks[4].YSpan;
                        result.Xllcorner = dataBlocks[4].Xllcorner;
                        result.Yllcorner = dataBlocks[4].Yllcorner;

                        result.Save(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write));

                        #region 预览图
                        for (int i = 0; i < height; i++)
                        {
                            for (int j = 0; j < width; j++)
                            {
                                int idx = i * width + j;
                                original[idx] /= 7000;
                                databx[idx] /= 7000;
                            }
                        }
                        OutPng(databx, width, height, fileNameImg);
                        OutPng(original, width, height, fileNameImg2);
                        #endregion
                    }
                }
            }
        }
예제 #26
0
        public QueryHeight(float longtitude, float lattiude)
        {
            //int x = 0;
            //int y = 0;
            //if (longtitude / 10 != 0)
            //    longtitude = (int)(longtitude / 10) * 10;
            //if (lattiude / 10 != 0)
            //    lattiude = (int)(lattiude / 10) * 10;

            //x = (int)((longtitude + 185) / 5);
            //y = (int)((95 - lattiude) / 5);

            double x = 0;
            double y = 0;

            x = (longtitude + 185) / 5;
            y = (95 - lattiude) / 5;

            int x1 = (int)(Math.Truncate(x));

            if (x1 / 2 == 0)
            {
                x1--;
            }
            int y1 = (int)(Math.Truncate(y));

            if (y1 / 2 == 0)
            {
                y1--;
            }
            string dir = "C:\\Users\\penser\\Documents\\Visual Studio 2008\\Projects\\lrvbsvnicg\\Source\\Code2015\\bin\\x86\\Debug\\terrain.lpk\\";

            file = dir + "tile_" + x1.ToString("D2") + "_" + y1.ToString("D2").ToString() + "_0.tdmp";
            FileLocation fl = new FileLocation(file);

            td = new TDMPIO();
            td.Load(new FileLocation(fl));

            int width  = td.Width;
            int height = td.Height;

            data = td.Data;

            float detaX = td.XSpan / width;
            float detaY = td.YSpan / height;

            //td.Xllcorner表示经度,角度制。

            if (longtitude <= 0)
            {
                longtitude = -longtitude;
            }
            int posX = (int)(Math.Abs(longtitude - td.Xllcorner) / detaX);

            if (lattiude <= 0)
            {
                lattiude = -lattiude;
            }
            int posY = (int)(Math.Abs(lattiude - td.Yllcorner) / detaY);

            this.Height = data[posY * 513 + posX];
        }
예제 #27
0
        public float[,] totalMapData;//用于存储所有图片的高度信息的数组

        public ConnectMap()
        {
            totalsub = new float[36,14][];
            totalMapData = new float[Height, Width];

            string dir = "C:\\Users\\penser\\Documents\\Visual Studio 2008\\Projects\\lrvbsvnicg\\Source\\Code2015\\bin\\x86\\Debug\\terrain.lpk\\";
            //int sub = 0;
            for (int i = 0; i < 36; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    int x = i * 2 + 1;
                    int y = j * 2 + 5;

                    file = dir + "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0.tdmp";
                    TDMPIO td = new TDMPIO();
                    if (File.Exists(file))
                    {
                        td.Load(new FileLocation(file));
                        Console.WriteLine(i.ToString() + "_" + j.ToString());


                        totalsub[i, j] = td.Data;
                    }
                }
            }

            Console.WriteLine("down");
            for (int i = 0; i < 36; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    int x = i * 2 + 1;
                    int y = j * 2 + 5;

                    float[] temp = totalsub[i, j];
                    if (temp != null)
                    {
                        for (int iPerMap = 0; iPerMap < temp.Length; iPerMap++)
                        {
                            int xx = iPerMap % 513;
                            int yy = iPerMap / 513;
                            totalMapData[j * 513 + yy, i * 513 + xx] = temp[iPerMap];
                        }
                    }
                }
            }


            //for (int i = 0; i < Amount; i++)
            //{
            //    float[] temp = totalsub[i];
            //    for (int width = 0; width < 36; width++)
            //    {
            //        for (int height = 0; height < 12; height++)
            //        {
            //            for (int iPerMap = 0; iPerMap < temp.Length; iPerMap++)
            //                totalMapData[width * 513, height * 513] = temp[iPerMap];
            //        }
            //    }
            //}


        }
예제 #28
0
        static void Scan2(string srcDir)
        {
           
            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") + "_3" + ".tdmp");

                    if (File.Exists(file))
                    {
                        TDMPIO d1 = new TDMPIO();
                        d1.Load(new DevFileLocation(file));
                        
                        Point coord;
                        coord.X = (int)Math.Truncate(d1.Xllcorner);
                        coord.Y = (int)Math.Truncate(d1.Yllcorner);

                        int col = x * 5 - 185;
                        int lat = 95 - y * 5;

                        if (col != coord.X || lat != coord.Y)
                        {
                            Console.WriteLine("Err: " + Path.GetFileNameWithoutExtension(file));
                            d1.Xllcorner = col;
                            d1.Yllcorner = lat;

                            Stream stm = File.Open(file, FileMode.Open);
                            stm.SetLength(0);
                            d1.Save(stm);
                        }

                        
                    }
                }
            }


        }
예제 #29
0
        void Convert()
        {
            for (int x = 1; x < 80; x += 2)
            {
                for (int y = 1; y < 36; y += 2)
                {
                    string file1 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    string file2 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                    string file3 = Path.Combine(srcDir, "tile_" + x.ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp");
                    string file4 = Path.Combine(srcDir, "tile_" + (x + 1).ToString("D2") + "_" + (y + 1).ToString("D2") + ".tdmp");

                    bool ex1 = File.Exists(file1);
                    bool ex2 = File.Exists(file2);
                    bool ex3 = File.Exists(file3);
                    bool ex4 = File.Exists(file4);

                    if (ex1 || ex2 || ex3 || ex4)
                    {
                        int width = 0;
                        int height = 0;
                        float xSpan = 0;
                        float ySpan = 0;

                        float xllCorner = 0;
                        float yllCorner = 0;
                        int bits = 32;
                        bool parsed = false;

                        TDMPIO d1 = new TDMPIO();
                        if (ex1)
                        {
                            d1.Load(new DevFileLocation(file1));

                            if (!parsed)
                            {
                                width = d1.Width;
                                height = d1.Height;
                                xSpan = d1.XSpan;
                                ySpan = d1.YSpan;
                                xllCorner = d1.Xllcorner;
                                yllCorner = d1.Yllcorner;
                                bits = d1.Bits;
                            }
                        }

                        TDMPIO d2 = new TDMPIO();
                        if (ex2)
                        {
                            d2.Load(new DevFileLocation(file2));
                            if (!parsed)
                            {
                                width = d2.Width;
                                height = d2.Height;
                                xSpan = d2.XSpan;
                                ySpan = d2.YSpan;
                                xllCorner = d2.Xllcorner - xSpan;
                                yllCorner = d2.Yllcorner;
                                bits = d2.Bits;
                            }
                        }

                        TDMPIO d3 = new TDMPIO();
                        if (ex3)
                        {
                            d3.Load(new DevFileLocation(file3));
                            if (!parsed)
                            {
                                width = d3.Width;
                                height = d3.Height;
                                xSpan = d3.XSpan;
                                ySpan = d3.YSpan;
                                xllCorner = d3.Xllcorner;
                                yllCorner = d3.Yllcorner - ySpan;
                                bits = d3.Bits;
                            }
                        }

                        TDMPIO d4 = new TDMPIO();
                        if (ex4)
                        {
                            d4.Load(new DevFileLocation(file4));
                            if (!parsed)
                            {
                                width = d4.Width;
                                height = d4.Height;
                                xSpan = d4.XSpan;
                                ySpan = d4.YSpan;
                                xllCorner = d4.Xllcorner - xSpan;
                                yllCorner = d4.Yllcorner - ySpan;
                                bits = d4.Bits;
                            }
                        }

                        TDMPIO data = new TDMPIO();
                        data.Data = new float[width * height * 4];
                        data.Width = width * 2;
                        data.Height = height * 2;
                        data.Xllcorner = xllCorner;
                        data.Yllcorner = yllCorner;
                        data.XSpan = xSpan * 2;
                        data.YSpan = ySpan * 2;
                        data.Bits = bits;

                        DataGetter dg = new DataGetter(d1.Data, d2.Data, d3.Data, d4.Data, width, height);
                        for (int i = 0; i < data.Height; i++)
                        {
                            for (int j = 0; j < data.Width; j++)
                            {
                                data.Data[i * data.Width + j] = dg[i, j];
                            }
                        }

                        string outPath = Path.Combine(dstDir, "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + ".tdmp");
                        FileStream fs = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.Write);
                        data.Save(fs);
                    }
                }
            }
        }
예제 #30
0
        public float[,] totalMapData;  //用于存储所有图片的高度信息的数组

        public ConnectMap()
        {
            totalsub     = new float[36, 14][];
            totalMapData = new float[Height, Width];

            string dir = "C:\\Users\\penser\\Documents\\Visual Studio 2008\\Projects\\lrvbsvnicg\\Source\\Code2015\\bin\\x86\\Debug\\terrain.lpk\\";

            //int sub = 0;
            for (int i = 0; i < 36; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    int x = i * 2 + 1;
                    int y = j * 2 + 5;

                    file = dir + "tile_" + x.ToString("D2") + "_" + y.ToString("D2") + "_0.tdmp";
                    TDMPIO td = new TDMPIO();
                    if (File.Exists(file))
                    {
                        td.Load(new FileLocation(file));
                        Console.WriteLine(i.ToString() + "_" + j.ToString());


                        totalsub[i, j] = td.Data;
                    }
                }
            }

            Console.WriteLine("down");
            for (int i = 0; i < 36; i++)
            {
                for (int j = 0; j < 14; j++)
                {
                    int x = i * 2 + 1;
                    int y = j * 2 + 5;

                    float[] temp = totalsub[i, j];
                    if (temp != null)
                    {
                        for (int iPerMap = 0; iPerMap < temp.Length; iPerMap++)
                        {
                            int xx = iPerMap % 513;
                            int yy = iPerMap / 513;
                            totalMapData[j * 513 + yy, i * 513 + xx] = temp[iPerMap];
                        }
                    }
                }
            }


            //for (int i = 0; i < Amount; i++)
            //{
            //    float[] temp = totalsub[i];
            //    for (int width = 0; width < 36; width++)
            //    {
            //        for (int height = 0; height < 12; height++)
            //        {
            //            for (int iPerMap = 0; iPerMap < temp.Length; iPerMap++)
            //                totalMapData[width * 513, height * 513] = temp[iPerMap];
            //        }
            //    }
            //}
        }