Ejemplo n.º 1
0
        public void BoudingBoxConservationTest(string datasetName)
        {
            var dataset = DEMDataSet.RegisteredDatasets.First(d => d.Name == datasetName);

            string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))";


            BoundingBox bbox = GeometryService.GetBoundingBox(bboxWKT);

            Assert.NotNull(bbox);
            Assert.Equal(bboxWKT, bbox.WKT);

            HeightMap heightMap = _elevationService.GetHeightMap(ref bbox, dataset);

            heightMap = heightMap.ReprojectGeodeticToCartesian().BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.ZScale(2.5f).BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.CenterOnOrigin().BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.FitInto(30f).BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());
        }
Ejemplo n.º 2
0
        public void BoudingBoxConservationTest()
        {
            string bboxWKT = "POLYGON((5.54888 43.519525, 5.61209 43.519525, 5.61209 43.565225, 5.54888 43.565225, 5.54888 43.519525))";


            BoundingBox bbox = GeometryService.GetBoundingBox(bboxWKT);

            Assert.NotNull(bbox);
            Assert.Equal(bboxWKT, bbox.WKT);

            HeightMap heightMap = _elevationService.GetHeightMap(bbox, DEMDataSet.SRTM_GL1);

            heightMap = heightMap.ReprojectGeodeticToCartesian().BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.ZScale(2.5f).BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.CenterOnOrigin().BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());

            heightMap = heightMap.FitInto(30f).BakeCoordinates();
            Assert.True(heightMap.BoundingBox == heightMap.Coordinates.GetBoundingBox());
        }
Ejemplo n.º 3
0
        internal void Run(ServiceProvider serviceProvider)
        {
            bool              useTIN           = false; // still buggy with SRID 3857
            int               v_outSrid        = Reprojection.SRID_PROJECTED_MERCATOR;
            IglTFService      glTF             = serviceProvider.GetService <IglTFService>();
            IElevationService elevationService = serviceProvider.GetService <IElevationService>();

            string outputDir = Path.GetFullPath(Path.Combine(_outputDirectory, "glTF"));

            Logger.Info("============================");
            Logger.Info($"= {nameof(TextureSamples)}");
            Logger.Info("============================");
            Logger.Info($"= {nameof(TextureSamples)} : Datadirectory report");


            // Get GPX points
            var bbox = GeometryService.GetBoundingBox(_bboxWkt);

            //=======================
            // Textures
            //
            TextureInfo texInfo = null;


            ImageryService imageryService = new ImageryService();

            Console.WriteLine("Download image tiles...");
            TileRange tiles = imageryService.DownloadTiles(bbox, ImageryProvider.StamenToner, 1);

            Console.WriteLine("Construct texture...");
            string fileName = Path.Combine(outputDir, "Texture.jpg");

            texInfo = imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg);

            //
            //=======================

            //=======================
            // Normal map
            Console.WriteLine("Height map...");
            float     Z_FACTOR   = 2f;
            HeightMap hMapNormal = elevationService.GetHeightMap(bbox, _normalsDataSet);

            //HeightMap hMapNormal = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1", "ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF);

            hMapNormal = hMapNormal.ReprojectTo(4326, v_outSrid);
            //hMapNormal = hMapNormal.ReprojectGeodeticToCartesian();

            Console.WriteLine("Generate normal map...");
            TextureInfo normal = imageryService.GenerateNormalMap(hMapNormal, outputDir);
            //
            //=======================

            //=======================
            // Get height map
            HeightMap hMap = elevationService.GetHeightMap(bbox, _meshDataSet);
            //HeightMap hMap = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1","ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF);

            //=======================
            // UV mapping (before projection)
            PBRTexture pBRTexture = PBRTexture.Create(texInfo, normal, imageryService.ComputeUVMap(hMap, texInfo));

            hMap = hMap.ReprojectTo(4326, v_outSrid);
            hMap = hMap.CenterOnOrigin().ZScale(Z_FACTOR);


            //=======================


            //=======================
            // MESH 3D terrain

            List <MeshPrimitive> meshes = new List <MeshPrimitive>();
            // generate mesh with texture
            MeshPrimitive triangleMesh;

            if (useTIN)
            {
                Console.WriteLine("Create TIN...");
                //triangleMesh = GenerateTIN(hMapTIN, glTF, pBRTexture);
                triangleMesh = TINGeneration.GenerateTIN(hMap, 10d, glTF, pBRTexture, v_outSrid);
            }
            else
            {
                Console.WriteLine("GenerateTriangleMesh...");
                triangleMesh = glTF.GenerateTriangleMesh_Boxed(hMap);
            }
            meshes.Add(triangleMesh);

            // model export
            Console.WriteLine("GenerateModel...");
            Model model = glTF.GenerateModel(meshes, this.GetType().Name);

            glTF.Export(model, outputDir, $"{GetType().Name} NONormal", false, true);
        }