Beispiel #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!");
        }
Beispiel #2
0
 public static void SaveTiff8(string outputFilename, IBitmap <byte> bitmap)
 {
     using (var tiffWriter = new TiffWriter(File.Create(outputFilename)))
     {
         tiffWriter.WriteImageFile(bitmap);
     }
 }
Beispiel #3
0
 public static void SaveTiff8(string outputFilename, IBitmap <short> bitmap)
 {
     using (var tiffWriter = new TiffWriter(File.Create(outputFilename)))
     {
         var bitmap2 = bitmap.Convert((p) => (byte)((p >> 8) + 128));
         tiffWriter.WriteImageFile(bitmap2);
     }
 }
Beispiel #4
0
        public void Create()
        {
            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];

                _topSectorOffsetY = (int)(ifd.ImageHeight * (Math.PI / 2 - LatT0) / Math.PI);
                _topSectorOffsetX = (int)(ifd.ImageWidth * (Math.PI + LonT0) / (Math.PI * 2));

                _topSectorWidth  = (int)Math.Ceiling(ifd.ImageHeight * (LatT0 - LatT1) / Math.PI);
                _topSectorHeight = (int)Math.Ceiling(ifd.ImageWidth * (LonT1 - LonT0) / (Math.PI * 2));

                var topElevationBitmap = tiffReader.ReadImageFile <short>(ifd, _topSectorOffsetX, _topSectorOffsetY, _topSectorWidth, _topSectorHeight);
                _topElevationBitmap = topElevationBitmap /*Resampler.Resample(topElevationBitmap, 1024, 1024)*/.ToBitmap();
                Console.WriteLine($"Loading image top {_topElevationBitmap.Width}x{_topElevationBitmap.Height} sector used {sw.Elapsed}");

                using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsDouble2\MarsTop.tif")))
                {
                    var bitmap = _topElevationBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                    tiffWriter.WriteImageFile(bitmap);
                }

                //--
                _bottomSectorOffsetY = (int)(ifd.ImageHeight * (Math.PI / 2 - LatB0) / Math.PI);
                _bottomSectorOffsetX = (int)(ifd.ImageWidth * (Math.PI + LonB0) / (Math.PI * 2));

                _bottomSectorWidth  = (int)Math.Ceiling(ifd.ImageHeight * (LatB0 - LatB1) / Math.PI);
                _bottomSectorHeight = (int)Math.Ceiling(ifd.ImageWidth * (LonB1 - LonB0) / (Math.PI * 2));

                var bottomElevationBitmap = tiffReader.ReadImageFile <short>(ifd, _bottomSectorOffsetX, _bottomSectorOffsetY, _bottomSectorWidth, _bottomSectorHeight);
                _bottomElevationBitmap = bottomElevationBitmap /*Resampler.Resample(bottomElevationBitmap, 1024, 1024)*/.ToBitmap();
                Console.WriteLine($"Loading image bottom {_bottomElevationBitmap.Width}x{_bottomElevationBitmap.Height} sector used {sw.Elapsed}");

                using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsDouble2\MarsBottom.tif")))
                {
                    var bitmap = _bottomElevationBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                    tiffWriter.WriteImageFile(bitmap);
                }
            }

            Init();

            sw = Stopwatch.StartNew();
            Split();
            Console.WriteLine($"Time used to split planet geometry: {sw.Elapsed}");
            PrintSummary();

            sw = Stopwatch.StartNew();
            Merge();
            Console.WriteLine($"Time used to merge planet geometry: {sw.Elapsed}");
            PrintSummary();

            SaveStl("Generated/Planets/MarsDouble2/MarsDouble2.stl");
        }
Beispiel #5
0
        public void Join(int lat0, int lon0, int lat1, int lon1)
        {
            int dlat = lat0 - lat1;
            int dlon = lon1 - lon0;

            var readers = new List <RawReader>();

            var concatBitmaps = new List <EnumerableBitmap <short> >();

            for (int lat = lat0; lat >= lat1; lat--)
            {
                var bitmapPaths = new List <string>();
                for (int lon = lon0; lon <= lon1; lon++)
                {
                    string bitmapPath = string.Format(_inputPath, MapPosition(lat, lon));
                    bitmapPaths.Add(bitmapPath);
                }
                var rawReaders = bitmapPaths.Select(p => File.Exists(p) ? new RawReader(File.OpenRead(p)) : null).ToArray();
                readers.AddRange(rawReaders);

                var rowBitmaps = rawReaders.Select(r => r != null ? r.ReadBitmap <short>(1201, 1201) : (IBitmap <short>)_oceanBitmap).ToArray();
                var rowBitmap  = BitmapTools.Concatenate(rowBitmaps);

                concatBitmaps.Add(rowBitmap);
            }

            var theBitmap = BitmapTools.Append(concatBitmaps.ToArray());

            using (var tiffWriter = new TiffWriter(File.Create($@"Datasets\Planets\Earth\ViewFinderPanoramas\dem3_{MapPosition(lat0, lon0)}_{MapPosition(lat1, lon1)}.tif")))
            {
                tiffWriter.BigTiff = true;
                theBitmap          = theBitmap.Convert((p) =>
                {
                    return((short)(((p >> 8) & 0xff) | ((p << 8) & 0xff00)));
                });
                tiffWriter.WriteImageFile(theBitmap);
            }

            foreach (var reader in readers)
            {
                reader?.Dispose();
            }
        }
Beispiel #6
0
        public void TestWriteRGB8()
        {
            var bitmap = new Bitmap <byte>(32, 32, 3);

            CreateGradient(bitmap);

            var tempFile = Path.Combine(Path.GetTempPath(), "TestWriteRGB8.tif");

            using (var tiffWriter = new TiffWriter(File.Create(tempFile)))
            {
                var ifd = tiffWriter.WriteImageFile(bitmap);

                Assert.Equal(32, ifd.ImageWidth);
                Assert.Equal(32, ifd.ImageHeight);
                Assert.Equal(8, ifd.BitsPerSample);
                Assert.Equal(3, ifd.SamplesPerPixel);
                Assert.Equal(Compression.NoCompression, ifd.Compression);
            }

            var bitmap2 = TiffReader.LoadBitmap <short>(File.OpenRead(tempFile));
        }
        public void Join()
        {
            var tiffReaders  = _inputFiles.Select(p => new TiffReader(File.OpenRead(p))).ToArray();
            var inputBitmaps = tiffReaders.Select(r => r.ReadImageFile <short>()).ToArray();

            var b1 = BitmapTools.Concatenate(inputBitmaps[0], inputBitmaps[1], inputBitmaps[2], inputBitmaps[3], inputBitmaps[4], inputBitmaps[5]);
            var b2 = BitmapTools.Concatenate(inputBitmaps[6], inputBitmaps[7], inputBitmaps[8], inputBitmaps[9], inputBitmaps[10], inputBitmaps[11]);
            var b3 = BitmapTools.Concatenate(inputBitmaps[12], inputBitmaps[13], inputBitmaps[14], inputBitmaps[15], inputBitmaps[16], inputBitmaps[17]);
            var b4 = BitmapTools.Concatenate(inputBitmaps[18], inputBitmaps[19], inputBitmaps[20], inputBitmaps[21], inputBitmaps[22], inputBitmaps[23]);

            var b = BitmapTools.Append(b1, b2, b3, b4);

            using (var tiffWriter = new TiffWriter(File.Create($@"Datasets\Planets\Earth\ViewFinderPanoramas\dem15.tif")))
            {
                tiffWriter.BigTiff = true;
//                var bitmap = _topElevationBitmap.Convert((p) => { return (ushort)(p - short.MinValue); });
                tiffWriter.WriteImageFile(b);
            }

            foreach (var reader in tiffReaders)
            {
                reader.Dispose();
            }
        }
Beispiel #8
0
        public void Create()
        {
            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];

                _topSectorOffsetY = (int)(ifd.ImageHeight * (Math.PI / 2 - LatT0) / Math.PI);
                _topSectorOffsetX = (int)(ifd.ImageWidth * (Math.PI + LonT0) / (Math.PI * 2));

                _topSectorWidth  = (int)Math.Ceiling(ifd.ImageHeight * (LatT0 - LatT1) / Math.PI);
                _topSectorHeight = (int)Math.Ceiling(ifd.ImageWidth * (LonT1 - LonT0) / (Math.PI * 2));

                var topElevationBitmap = tiffReader.ReadImageFile <short>(ifd, _topSectorOffsetX, _topSectorOffsetY, _topSectorWidth, _topSectorHeight);
                // _topElevationBitmap = Resampler.Resample(topElevationBitmap, 899, 899).ToBitmap();
                _topElevationBitmap = topElevationBitmap.ToBitmap();
                Console.WriteLine($"Loading image top {_topElevationBitmap.Width}x{_topElevationBitmap.Height} sector used {sw.Elapsed}");

                using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsDouble\MarsTop.tif")))
                {
                    var bitmap = _topElevationBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                    tiffWriter.WriteImageFile(bitmap);
                }

                //--
                _bottomSectorOffsetY = (int)(ifd.ImageHeight * (Math.PI / 2 - LatB0) / Math.PI);
                _bottomSectorOffsetX = (int)(ifd.ImageWidth * (Math.PI + LonB0) / (Math.PI * 2));

                _bottomSectorWidth  = (int)Math.Ceiling(ifd.ImageHeight * (LatB0 - LatB1) / Math.PI);
                _bottomSectorHeight = (int)Math.Ceiling(ifd.ImageWidth * (LonB1 - LonB0) / (Math.PI * 2));

                var bottomElevationBitmap = tiffReader.ReadImageFile <short>(ifd, _bottomSectorOffsetX, _bottomSectorOffsetY, _bottomSectorWidth, _bottomSectorHeight);
                // _bottomElevationBitmap = Resampler.Resample(bottomElevationBitmap, 899, 899).ToBitmap();
                _bottomElevationBitmap = bottomElevationBitmap.ToBitmap();
                Console.WriteLine($"Loading image bottom {_bottomElevationBitmap.Width}x{_bottomElevationBitmap.Height} sector used {sw.Elapsed}");

                using (var tiffWriter = new TiffWriter(File.Create($@"Generated\Planets\MarsDouble\MarsBottom.tif")))
                {
                    var bitmap = _bottomElevationBitmap.Convert((p) => { return((ushort)(p - short.MinValue)); });
                    tiffWriter.WriteImageFile(bitmap);
                }
            }

            sw = Stopwatch.StartNew();

            var sphericalSector = new Box();

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

            sphericalSector.Create(NumSegments, NumSegments);

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

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

            Console.WriteLine($"NumVertexes: {PlanetVertexes.Count()}");
            Console.WriteLine($"NumTriangles: {PlanetTriangles.Count()}");

            SaveStl($@"Generated\Planets\MarsDouble\MarsDouble{NumSegments}.stl");
        }
Beispiel #9
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");
        }
Beispiel #10
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"));
        }