示例#1
0
        public DemNetVisualTopoService()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(AppContext.BaseDirectory)
                         .AddJsonFile("appsettings.json", optional: true)
                         .AddJsonFile("secrets.json", optional: true, reloadOnChange: false)
                         .Build();


            this.services = new ServiceCollection()
                            .AddOptions()
                            .AddLogging(loggingBuilder => loggingBuilder
                                        .AddDebug()
                                        .SetMinimumLevel(LogLevel.Debug))
                            .Configure <AppSecrets>(config.GetSection(nameof(AppSecrets)))
                            .Configure <DEMNetOptions>(config.GetSection(nameof(DEMNetOptions)))
                            .AddDemNetCore()
                            .AddDemNetglTF()
                            .AddDemNetVisualTopoExtension()
                            .BuildServiceProvider();



            this.visualTopoService = services.GetService <VisualTopoService>();
            this.elevationService  = services.GetService <ElevationService>();
            this.meshService       = services.GetService <MeshService>();
            this.sharpGltfService  = services.GetService <SharpGltfService>();
            this.imageryService    = services.GetService <ImageryService>();
        }
示例#2
0
        public OsmTests(DemNetFixture fixture)
        {
            _osmProcessor     = fixture.ServiceProvider.GetService <DefaultOsmProcessor>();
            _elevationService = fixture.ServiceProvider.GetService <ElevationService>();

            _imageryService = fixture.ServiceProvider.GetService <ImageryService>();
            _gltfService    = fixture.ServiceProvider.GetService <SharpGltfService>();
        }
示例#3
0
 public ImagerySample(ILogger <glTF3DSamples> logger
                      , IElevationService elevationService
                      , SharpGltfService sharpGltfService
                      , ImageryService imageryService)
 {
     _logger           = logger;
     _elevationService = elevationService;
     _sharpGltfService = sharpGltfService;
     _imageryService   = imageryService;
 }
示例#4
0
 public AerialGpxSample(ILogger <Gpx3DSamples> logger
                        , IRasterService rasterService
                        , IElevationService elevationService
                        , ImageryService imageryService
                        , SharpGltfService sharpGltfService)
 {
     _logger           = logger;
     _rasterService    = rasterService;
     _elevationService = elevationService;
     _imageryService   = imageryService;
     _sharpGltfService = sharpGltfService;
 }
示例#5
0
 public OsmExtensionSample(DefaultOsmProcessor osmProcessor
                           , OverpassAPIDataService osmService
                           , ImageryService imageryService
                           , ElevationService elevationService
                           , SharpGltfService gltfService
                           , ILogger <OsmExtensionSample> logger)
 {
     this._osmProcessor     = osmProcessor;
     this._imageryService   = imageryService;
     this._elevationService = elevationService;
     this._gltfService      = gltfService;
     this._logger           = logger;
     this._osmService       = osmService;
 }
 public CustomRasterElevationSample(ILogger <CustomRasterElevationSample> logger
                                    , RasterService rasterService
                                    , ElevationService elevationService
                                    , MeshService meshService
                                    , SharpGltfService sharpGltfService
                                    , ImageryService imageryService)
 {
     _logger           = logger;
     _rasterService    = rasterService;
     _elevationService = elevationService;
     _sharpGltfService = sharpGltfService;
     _imageryService   = imageryService;
     _meshService      = meshService;
 }
示例#7
0
 public VisualTopoSample(ILogger <VisualTopoSample> logger
                         , SharpGltfService gltfService
                         , MeshService meshService
                         , ElevationService elevationService
                         , ImageryService imageryService
                         , VisualTopoService visualTopoService)
 {
     _logger            = logger;
     _meshService       = meshService;
     _gltfService       = gltfService;
     _elevationService  = elevationService;
     _imageryService    = imageryService;
     _visualTopoService = visualTopoService;
 }
示例#8
0
 public Text3DSample(ILogger <Text3DSample> logger
                     , ElevationService elevationService
                     , MeshService meshService
                     , AdornmentsService adornmentsService
                     , RasterService rasterService
                     , ImageryService imageryService
                     , SharpGltfService sharpGltfService)
 {
     _logger            = logger;
     _elevationService  = elevationService;
     _rasterService     = rasterService;
     _imageryService    = imageryService;
     _sharpGltfService  = sharpGltfService;
     _adornmentsService = adornmentsService;
     _meshService       = meshService;
 }
        public HelladicSample(DefaultOsmProcessor sampleOsmProcessor
                              , ImageryService imageryService
                              , ElevationService elevationService
                              , SharpGltfService gltfService
                              , MeshService meshService
                              , Sketchfab.SketchfabApi sketchFabApi
                              , IOptions <AppSecrets> secrets
                              , ILogger <HelladicSample> logger)
        {
            this._sampleOsmProcessor = sampleOsmProcessor;
            this._imageryService     = imageryService;
            this._elevationService   = elevationService;
            this._gltfService        = gltfService;
            this._meshService        = meshService;
            this._sketchFabApi       = sketchFabApi;
            this._sketchFabToken     = secrets.Value.SketchFabToken;
            this._logger             = logger;

            if (string.IsNullOrEmpty(_sketchFabToken))
            {
                _logger.LogWarning($"SketchfabToken is not set. Ensure you have a secrets.json file with a SketchfabToken entry with your api token (see https://sketchfab.com/settings/password)");
            }
        }
示例#10
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);
        }
        /// <summary>
        /// Get Bing Map Image
        /// </summary>
        protected override void GetMapInternal()
        {
            try
            {
                MapUriOptions mapUriOptions = new MapUriOptions
                {
                    Style = Satellite ? MapStyle.AerialWithLabels : MapStyle.Road,
                    StyleSpecified = true,
                    ZoomLevel = Zoom,
                    ZoomLevelSpecified = true,
                    ImageType = ImageType.Jpeg,
                    ImageTypeSpecified = true,
                    ImageSize = new SizeOfint
                    {
                        Width = Width,
                        WidthSpecified = true,
                        Height = Height,
                        HeightSpecified = true
                    }
                };
                MapUriRequest mapUriRequest = new MapUriRequest
                {
                    Credentials = new Credentials
                    {
                        Token = TokenService.GetToken(Username, Password)
                    },
                    Center = new Location
                    {
                        Latitude = Latitude,
                        LatitudeSpecified = true,
                        Longitude = Longitude,
                        LongitudeSpecified = true
                    },
                    Options = mapUriOptions
                };
                using (ImageryService imageryService = new ImageryService())
                {
                    MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
                    Log.Info("MapService.GetMap", "URL: {0}", mapUriResponse.Uri);

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(mapUriResponse.Uri);
                    request.Credentials = new NetworkCredential(Username, Password);
                    request.AllowAutoRedirect = true;
                    request.ReadWriteTimeout = 5000;
                    request.Method = "GET";
                    request.Timeout = 5000;
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            if (MapDownloaded != null)
                            {
                                MapDownloaded(this, new MapEventArgs(new Bitmap(stream), true));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("MapService.GetMap", "Exception: {0}", ex.Message);
                if (MapDownloaded != null)
                {
                    MapDownloaded(this, new MapEventArgs(null, false));
                }
            }
        }