Ejemplo n.º 1
0
        public void Create()
        {
            Stopwatch sw;

            sw = Stopwatch.StartNew();
            _elevationTexture = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif");
            Console.WriteLine($"Loading texture used {sw.Elapsed}");

            int width  = 11520;
            int height = 5760;

            // string elevationTextureSmallFilename = $@"Generated\Planets\MarsSector\Mars{width}x{height}.raw";
            // if (!File.Exists(elevationTextureSmallFilename))
            // {
            //     sw = Stopwatch.StartNew();
            //     var elevationTextureLarge = TextureHelper.LoadTiff16(@"Datasets\Planets\Mars\Mars_MGS_MOLA_DEM_mosaic_global_463m.tif");
            //     Console.WriteLine($"Loading texture used {sw.Elapsed}");

            //     sw = Stopwatch.StartNew();
            //     _elevationTexture = Resampler.Resample(elevationTextureLarge, width, height);
            //     Console.WriteLine($"Resampling used {sw.Elapsed}");

            //     TextureHelper.SaveRaw16($@"Generated\Planets\MarsSector\Mars{_elevationTexture.Width}x{_elevationTexture.Height}.raw", _elevationTexture);
            //     TextureHelper.SavePng8($@"Generated\Planets\MarsSector\Mars{_elevationTexture.Width}x{_elevationTexture.Height}.png", _elevationTexture);
            // }
            // else
            // {
            //     _elevationTexture = TextureHelper.LoadRaw16(elevationTextureSmallFilename, width, height);
            // }

            width  = 2880;
            height = 1440;
            string elevationTextureBlurFilename = $@"Generated\Planets\MarsSector\MarsBlur{width}x{height}.raw";

            if (!File.Exists(elevationTextureBlurFilename))
            {
                var elevationTextureSmall = Resampler.Resample(_elevationTexture, width, height);

                sw = Stopwatch.StartNew();
                var blurFilter = new BlurFilter(PlanetProjection);
                _elevationTextureBlur = blurFilter.Blur3(elevationTextureSmall, MathHelper.ToRadians(10));
                Console.WriteLine($"Blur used {sw.Elapsed}");

                TextureHelper.SaveRaw16($@"Generated\Planets\MarsSector\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.raw", _elevationTextureBlur);
                TextureHelper.SavePng8($@"Generated\Planets\MarsSector\MarsBlur{_elevationTextureBlur.Width}x{_elevationTextureBlur.Height}.png", _elevationTextureBlur);
            }
            else
            {
                _elevationTextureBlur = TextureHelper.LoadRaw16(elevationTextureBlurFilename, width, height);
            }


            sw = Stopwatch.StartNew();

            var sphericalSector = new SphericalSector();

            sphericalSector.ComputeRadiusTop    = ComputeModelElevationTop;
            sphericalSector.ComputeRadiusBottom = ComputeModelElevationBottom;

            sphericalSector.Create(MathHelper.ToRadians(-10), MathHelper.ToRadians(133), MathHelper.ToRadians(0), MathHelper.ToRadians(142), NumSegments, NumSegments);

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

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

            SaveSTL($@"Generated\Planets\MarsSector\MarsSector{NumSegments}.stl");
        }
Ejemplo n.º 2
0
        public void Create()
        {
            double dLat = Lat0 - Lat1;
            double dLon = Lon1 - Lon0;

            // Calculate sector transform
            _sx  = Math.PI * 2 / dLon;
            _sy  = Math.PI / dLat;
            _sx0 = (Math.PI + Lon0) / (Math.PI * 2) * _sx;
            _sy0 = (Math.PI / 2 - Lat0) / Math.PI * _sy;

            Stopwatch sw;

            sw = Stopwatch.StartNew();
            using (var tiffReader = new TiffReader(File.OpenRead(@"Datasets\Planets\Mars\Mars_HRSC_MOLA_BlendDEM_Global_200mp.tif")))
            {
                var ifd = tiffReader.ImageFileDirectories[0];

                _elevationWidth  = ifd.ImageWidth;
                _elevationHeight = ifd.ImageHeight;

                _sectorOffsetY = (int)(_elevationHeight * (Math.PI / 2 - Lat0) / Math.PI);
                _sectorOffsetX = (int)(_elevationWidth * (Math.PI + Lon0) / (Math.PI * 2));

                _sectorHeight = (int)Math.Ceiling(_elevationHeight * dLat / Math.PI);
                _sectorWidth  = (int)Math.Ceiling(_elevationWidth * dLon / (Math.PI * 2));

                _elevationSectorBitmap = tiffReader.ReadImageFile <short>(ifd, _sectorOffsetX, _sectorOffsetY, _sectorWidth, _sectorHeight).ToBitmap();
                Console.WriteLine($"Loading image sector used {sw.Elapsed}");

                // _elevationSectorBitmap = Resampler.Resample(elevationBitmap, width, height).ToBitmap();
                // Console.WriteLine($"Resampling used {sw.Elapsed}");

                using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsSector\Mars{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif")))
                {
                    var bitmap = _elevationSectorBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                    tiffWriter.WriteImageFile(bitmap);
                }

                BitmapHelper.SaveTiff8($@"Generated\Planets\MarsSector\Mars{_elevationSectorBitmap.Width}x{_elevationSectorBitmap.Height}.tif", _elevationSectorBitmap);

                int    width  = 2880;
                int    height = 1440;
                string elevationTextureBlurFilename = $@"Generated\Planets\MarsSector\MarsBlur{width}x{height}.raw";
                if (!File.Exists(elevationTextureBlurFilename))
                {
                    var elevationTextureSmall = Resampler.Resample(_elevationSectorBitmap, width, height).ToBitmap();

                    sw = Stopwatch.StartNew();
                    var blurFilter = new BlurFilter(PlanetProjection);
                    _elevationBitmapBlur = blurFilter.Blur3(elevationTextureSmall, MathHelper.ToRadians(10));
                    Console.WriteLine($"Blur used {sw.Elapsed}");

                    BitmapHelper.SaveRaw16($@"Generated\Planets\MarsSector\MarsBlur{_elevationBitmapBlur.Width}x{_elevationBitmapBlur.Height}.raw", _elevationBitmapBlur);
                    BitmapHelper.SaveTiff8($@"Generated\Planets\MarsSector\MarsBlur{_elevationBitmapBlur.Width}x{_elevationBitmapBlur.Height}.tif", _elevationBitmapBlur);
                }
                else
                {
                    _elevationBitmapBlur = BitmapHelper.LoadRaw16(elevationTextureBlurFilename, width, height);
                }
            }

            sw = Stopwatch.StartNew();

            var sphericalSector = new SphericalSector();

            sphericalSector.ComputeRadiusTop = ComputeModelElevationTop;

            sphericalSector.Create(Lat0, Lon0, Lat1, Lon1, NumSegments, NumSegments, PlanetRadius - 50000);

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

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

            SaveStl($@"Generated\Planets\MarsSector\MarsSector{NumSegments}.stl");
        }
Ejemplo n.º 3
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"));
        }