Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Directory.SetCurrentDirectory(@"c:\Ludde\FractalWorlds");

            var sw = Stopwatch.StartNew();

//            var demReader = new DemZipRawReader(@"\\luddepc\Earth2\SRTM.zip", "{0}.hgt", 3601, 3601);
            var demReader = new DemZipTiffReader(@"\\luddepc\Earth2\ASTER.zip", "ASTGTM2_{0}_dem.tif", 3601, 3601);
            //var demReader = new DemTiffReader(@"\\luddepc\Earth\ASTERunzip\ASTGTM2_{0}_dem.tif", 3601, 3601);

            //t.Join(78, -83, 68, -73);
            // t.Join(64, 5, 54, 15);

            // Kazbek 42°41′57″N 44°31′06″ECoordinates: 42°41′57″N 44°31′06″E [1]
            int lat0      = 48;
            int lon0      = 40;
            int lat1      = 40;
            int lon1      = 48;
            var theBitmap = demReader.LoadBitmap(lat0, lon0, lat1, lon1);

            using (var tiffWriter = new TiffWriter(File.Create(string.Format(@"Datasets\Planets\Earth\ASTER_{0}_{1}.tif", demReader.MapGranulateName(lat0, lon0), demReader.MapGranulateName(lat1, lon1)))))
            {
                tiffWriter.BigTiff = true;
                tiffWriter.WriteImageFile(theBitmap);
            }

            Console.WriteLine($"Saving bitmap in {sw.Elapsed}");

            Console.WriteLine("Done!");
        }
Example #2
0
        public void Create()
        {
            var targetPath = $@"Generated\Planets\Earth\{Name}";

            Directory.CreateDirectory(targetPath);

            int lat0deg = (int)Math.Floor(MathHelper.ToDegrees(Lat0));
            int lat1deg = (int)Math.Floor(MathHelper.ToDegrees(Lat1));
            int lon0deg = (int)Math.Floor(MathHelper.ToDegrees(Lon0));
            int lon1deg = (int)Math.Floor(MathHelper.ToDegrees(Lon1));

            double lat0 = MathHelper.ToRadians(lat0deg + 1);
            double lat1 = MathHelper.ToRadians(lat1deg);
            double lon0 = MathHelper.ToRadians(lon0deg);
            double lon1 = MathHelper.ToRadians(lon1deg + 1);

            // Calculate sector transform
            _sx  = Math.PI * 2 / (lon1 - lon0);
            _sy  = Math.PI / (lat0 - lat1);
            _sx0 = (Math.PI + lon0) / (Math.PI * 2) * _sx;
            _sy0 = (Math.PI / 2 - lat0) / Math.PI * _sy;

            // --

            int totalWidth  = 3601 * 360;
            int totalHeight = 3601 * 180;

            int sectorHeight = (int)Math.Round(totalHeight * (Lat0 - Lat1) / Math.PI);
            int sectorWidth  = (int)Math.Round(totalWidth * (Lon1 - Lon0) / (Math.PI * 2));

            Console.WriteLine($"Using image sector {sectorWidth}x{sectorHeight}");

            var sw = Stopwatch.StartNew();

            if (UseAster)
            {
                using (var demReader = new DemZipTiffReader(@"Datasets\Planets\Earth\ASTER.zip", "ASTGTM2_{0}_dem.tif", 3601, 3601))
                {
                    var elevationSectorBitmap = demReader.LoadBitmap(lat0deg, lon0deg, lat1deg, lon1deg);

                    Console.WriteLine($"Loading ASTER image {elevationSectorBitmap.Width}x{elevationSectorBitmap.Height}");

                    int w = Math.Min(elevationSectorBitmap.Width, (elevationSectorBitmap.Width * NumSegmentsLon) / sectorWidth);
                    int h = Math.Min(elevationSectorBitmap.Height, (elevationSectorBitmap.Height * NumSegmentsLat) / sectorHeight);

                    _elevationSectorBitmap = Resampler.Resample(elevationSectorBitmap, w, h).ToBitmap();
                }
            }
            else
            {
                using (var demReader = new DemZipRawReader(@"Datasets\Planets\Earth\SRTM.zip", "{0}.hgt", 3601, 3601))
                {
                    var elevationSectorBitmap = demReader.LoadBitmap(lat0deg, lon0deg, lat1deg, lon1deg);

                    Console.WriteLine($"Loading SRTM image {elevationSectorBitmap.Width}x{elevationSectorBitmap.Height}");

                    int w = Math.Min(elevationSectorBitmap.Width, (elevationSectorBitmap.Width * NumSegmentsLon) / sectorWidth);
                    int h = Math.Min(elevationSectorBitmap.Height, (elevationSectorBitmap.Height * NumSegmentsLat) / sectorHeight);

//                    _elevationSectorBitmap = Resampler.Resample(elevationSectorBitmap, w, h).ToBitmap();
                    _elevationSectorBitmap = elevationSectorBitmap.ToBitmap();
                }
            }
            Console.WriteLine($"Loading image sector {_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height} used {sw.Elapsed}");

            using (var tiffWriter = new TiffWriter(File.Create(Path.Combine(targetPath, $"Earth{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif"))))
            {
                var bitmap = _elevationSectorBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                tiffWriter.WriteImageFile(bitmap);
            }

            sw = Stopwatch.StartNew();

            var sphericalSector = new SphericalSector();

            sphericalSector.ComputeRadiusTop = ComputeModelElevationTop;

            sphericalSector.Create(Lat0, Lon0, Lat1, Lon1, NumSegmentsLat, NumSegmentsLon, ModelScale * (PlanetRadius + ElevationBottom * ElevationScale));

            CenterVertexes(sphericalSector.Vertexes);

            PlanetVertexes  = sphericalSector.Vertexes;
            PlanetTriangles = sphericalSector.Triangles;

            Console.WriteLine($"Time used to create planet vertexes: {sw.Elapsed}");

            SaveStl(Path.Combine(targetPath, $"{Name}{NumSegmentsLon}_{ElevationScale}x.stl"));
        }