示例#1
0
        /// <summary>
        /// This event is raised when the create pyramid function is called.
        /// </summary>
        /// <param name="sender">
        /// create ImageWorker.
        /// </param>
        /// <param name="e">
        /// DoWork EventArgs.
        /// </param>
        private void OnCreateImageWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            ImagePyramidDetails inputDetails = e.Argument as ImagePyramidDetails;
            if (inputDetails != null)
            {
                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.LoadingImage, PyramidGenerationStatus.Started);

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.PyramidGeneration, PyramidGenerationStatus.Started);

                // Define ITileCreator instance for creating image tiles.
                // If the input projection type and output projection type is same then we need to tile the image.
                Core.ITileCreator tileCreator = null;

                // Calculates the estimated thumbnail generation time
                Stopwatch thumbnailGenerationStopwatch = new Stopwatch();
                thumbnailGenerationStopwatch.Start();
                if (inputDetails.InputProjection == InputProjections.EquiRectangular)
                {
                    // Read and initialize the image as an IGrid.
                    var imageGrid = new Core.ImageGrid(inputDetails.InputImagePath, true);
                    var equirectangularGridMap = new Core.EquirectangularGridMap(imageGrid, inputDetails.InputBoundary);
                    var imageColorMap = new Core.ImageColorMap(equirectangularGridMap);

                    tileCreator = Core.TileCreatorFactory.CreateImageTileCreator(
                        imageColorMap,
                        inputDetails.OutputProjection,
                        inputDetails.OutputDirectory);
                }
                else
                {
                    Core.IImageTileSerializer serializer = new Core.ImageTileSerializer(
                        Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory),
                        ImageFormat.Png);
                    tileCreator = new Core.TileChopper(inputDetails.InputImagePath, serializer, inputDetails.OutputProjection, inputDetails.InputBoundary);
                }

                thumbnailGenerationStopwatch.Stop();

                // Thumbnail estimated time is time required to load the image and then create the thumbnail with graphics
                this.ThumbnailEstimatedTime = thumbnailGenerationStopwatch.ElapsedMilliseconds * Constants.ThumbnailMultiplier;

                // Define plumbing for looping through all the tiles to be created for base image and pyramid.
                tileGenerator = new Core.TileGenerator(tileCreator);

                this.cancellationToken = new CancellationTokenSource();
                tileGenerator.ParallelOptions.CancellationToken = this.cancellationToken.Token;

                this.CheckCancel(e);

                // Define bounds of the image. Image is assumed to cover the entire world.
                // If not, change the coordinates accordingly.
                // For Mercator projection, longitude spans from -180 to +180 and latitude from 90 to -90.
                Core.Boundary gridBoundary = new Core.Boundary(
                    inputDetails.InputBoundary.Left,
                    inputDetails.InputBoundary.Top,
                    inputDetails.InputBoundary.Right,
                    inputDetails.InputBoundary.Bottom);
                if (inputDetails.OutputProjection == ProjectionTypes.Toast)
                {
                    // For Toast projection, longitude spans from 0 to +360 and latitude from 90 to -90.
                    gridBoundary.Left += 180;
                    gridBoundary.Right += 180;
                }

                // Start building base image and the pyramid.
                tileGenerator.Generate(inputDetails.Level, gridBoundary);

                if (inputDetails.IsGeneratePlate)
                {
                    NotifyMessage(PyramidGenerationSteps.PlateFileGeneration, PyramidGenerationStatus.Started);
                    this.CheckCancel(e);

                    // Generate Plate file.
                    Core.ImageTileSerializer pyramid = new Core.ImageTileSerializer(
                        Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory),
                        ImageFormat.Png);

                    plateGenerator = new Core.PlateFileGenerator(
                        System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".plate"),
                        inputDetails.Level,
                        ImageFormat.Png);

                    plateGenerator.CreateFromImageTile(pyramid);
                }

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.ThumbnailGeneration, PyramidGenerationStatus.Started);

                // Generate Thumbnail Images.
                string thumbnailFile = System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".jpeg");
                Core.TileHelper.GenerateThumbnail(inputDetails.InputImagePath, 96, 45, thumbnailFile, ImageFormat.Jpeg);

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.WTMLGeneration, PyramidGenerationStatus.Started);

                // Get the path of image tiles created and save it in WTML file.
                string pyramidPath = Core.WtmlCollection.GetWtmlTextureTilePath(Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory), ImageFormat.Png.ToString());

                Core.Boundary inputBoundary = new Core.Boundary(
                    inputDetails.InputBoundary.Left,
                    inputDetails.InputBoundary.Top,
                    inputDetails.InputBoundary.Right,
                    inputDetails.InputBoundary.Bottom);

                // Create and save WTML collection file.
                Core.WtmlCollection wtmlCollection = new Core.WtmlCollection(inputDetails.OutputFilename, thumbnailFile, pyramidPath, inputDetails.Level, inputDetails.OutputProjection, inputBoundary);
                wtmlCollection.Credit = inputDetails.Credits;
                wtmlCollection.CreditUrl = inputDetails.CreditsURL;
                string path = System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".wtml");
                wtmlCollection.Save(path);
            }
        }
示例#2
0
        /// <summary>
        /// Processes a list of input image tiles and generates pyramid for level N.
        /// </summary>
        /// <param name="inputFilePath">Xml file with list of image tile information.</param>
        /// <param name="outputDir">Output directory where the image tiles of pyramid has to be stored.</param>
        /// <param name="projection">Projection to be used.</param>
        /// <param name="inputBoundary">Input image boundary.</param>
        private static void ProcessMultipartEquirectangularImage(string inputFilePath, string outputDir, ProjectionTypes projection, Boundary inputBoundary)
        {
            ImageFormat imageFormat = ImageFormat.Png;

            Trace.TraceInformation("{0}: Reading image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));

            // Get the list of equirectangular images input.
            string[,] imageTiles = Program.GetInputImageList(inputFilePath);

            // Check if the image is circular.
            double longitudeDelta = inputBoundary.Right - inputBoundary.Left;
            bool circular = (360.0 - longitudeDelta) < 0.000001;

            // Build an image grid using the input images
            var imageGrid = new ImageGrid(imageTiles, circular);

            // Build the grid map for equirectangular projection using the image grid and boundary co-ordinates
            var equirectangularGridMap = new EquirectangularGridMap(imageGrid, inputBoundary);

            // Build the color map using equirectangular projection grid map
            var imageColorMap = new ImageColorMap(equirectangularGridMap);

            var maximumLevelsOfDetail = TileHelper.CalculateMaximumLevel(imageGrid.Height, imageGrid.Width, inputBoundary);

            // Define ITileCreator instance for creating image tiles.
            ITileCreator tileCreator = TileCreatorFactory.CreateImageTileCreator(imageColorMap, projection, outputDir);

            // Define bounds of the image. Image is assumed to cover the entire world.
            // If not, change the coordinates accordingly.
            // For Mercator projection, longitude spans from -180 to +180 and latitude from 90 to -90.
            Boundary gridBoundary = new Boundary(inputBoundary.Left, inputBoundary.Top, inputBoundary.Right, inputBoundary.Bottom);
            if (projection == ProjectionTypes.Toast)
            {
                // For Toast projection, longitude spans from 0 to +360 and latitude from 90 to -90.
                gridBoundary.Left += 180;
                gridBoundary.Right += 180;
            }

            // Define plumbing for looping through all the tiles to be created for base image and pyramid.
            var tileGenerator = new TileGenerator(tileCreator);

            // Start building base image and the pyramid.
            Trace.TraceInformation("{0}: Building base and parent levels...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            tileGenerator.Generate(maximumLevelsOfDetail, gridBoundary);

            string fileName = Path.GetFileNameWithoutExtension(inputFilePath);

            // Generate Plate file.
            Trace.TraceInformation("{0}: Building Plate file...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            ImageTileSerializer pyramid = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png);
            PlateFileGenerator plateGenerator = new PlateFileGenerator(
                Path.Combine(outputDir, fileName + ".plate"),
                maximumLevelsOfDetail,
                ImageFormat.Png);
            plateGenerator.CreateFromImageTile(pyramid);

            // Generate Thumbnail Images.
            Trace.TraceInformation("{0}: Building Thumbnail image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            string thumbnailFile = Path.Combine(outputDir, fileName + ".jpeg");
            TileHelper.GenerateThumbnail(pyramid.GetFileName(0, 0, 0), 96, 45, thumbnailFile, ImageFormat.Jpeg);

            // Get the path of image tiles created and save it in WTML file.
            Trace.TraceInformation("{0}: Building WTML file..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            string pyramidPath = WtmlCollection.GetWtmlTextureTilePath(TileHelper.GetDefaultImageTilePathTemplate(outputDir), imageFormat.ToString());

            // Create and save WTML collection file.
            WtmlCollection wtmlCollection = new WtmlCollection(fileName, thumbnailFile, pyramidPath, maximumLevelsOfDetail, projection, inputBoundary);
            string path = Path.Combine(outputDir, fileName + ".wtml");
            wtmlCollection.Save(path);
            Trace.TraceInformation("{0}: Collection successfully generated.", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
        }
示例#3
0
        /// <summary>
        /// Perform delineation for the specified region.
        /// </summary>
        /// <param name="inputGrid">Input data set.</param>
        /// <param name="outputDir">Output directory where the delineationated image tiles have to be persisted.</param>
        /// <param name="referenceImagePath">Reference image tiles folder path.</param>
        /// <param name="colorMapPath">Color map file path.</param>
        /// <param name="orientation">Color orientation.</param>
        /// <param name="maxLevel">Maximum level of the pyramid.</param>
        private static void DelineateImage(string inputGrid, string outputDir, string referenceImagePath, string colorMapPath, ColorMapOrientation orientation, int maxLevel)
        {
            Trace.TraceInformation("{0}: Starting delineation..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss"));
            Trace.TraceInformation("{0}: Reading dataset..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss"));
            ImageFormat imageFormat = ImageFormat.Png;

            // Read and parse the input dataset.
            var equirectangularGrid = new EquirectangularGrid(inputGrid);
            equirectangularGrid.MaximumLevelsOfDetail = maxLevel;

            // Define a color map to lookup color pixel for double values.
            var colorMap = new EquirectangularColorMap(colorMapPath, equirectangularGrid, orientation);

            // Define serialization mechanism for storing/retrieving reference tiles.
            var referenceTileSerializer = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(referenceImagePath), ImageFormat.Png);

            // Define an instance of ITielCreator to create the tiles.
            var tileSerializer = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png);
            var imageTileCreator = new MaskedTileCreator(colorMap, tileSerializer, true);

            // Start building the image tiles.
            var tileGenerator = new TileGenerator(imageTileCreator);
            imageTileCreator.ReferenceTileSerializer = referenceTileSerializer;
            tileGenerator.Generate(maxLevel);

            string fileName = Path.GetFileNameWithoutExtension(inputGrid);

            // Generate Thumbnail Images.
            string thumbnailFile = Path.Combine(outputDir, fileName + ".jpeg");
            TileHelper.GenerateThumbnail(tileSerializer.GetFileName(0, 0, 0), 96, 45, thumbnailFile);

            // Create and save WTML file.
            string textureTilePath = WtmlCollection.GetWtmlTextureTilePath(TileHelper.GetDefaultImageTilePathTemplate(outputDir), imageFormat.ToString());
            WtmlCollection wtmlCollection = new WtmlCollection(fileName, thumbnailFile, textureTilePath, equirectangularGrid.MaximumLevelsOfDetail, ProjectionTypes.Toast);
            string path = Path.Combine(outputDir, fileName + ".wtml");
            wtmlCollection.Save(path);
            Trace.TraceInformation("{0}: Collection successfully generated.", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss"));
        }
示例#4
0
        /// <summary>
        /// Processes a list of input image tiles and generates pyramid for level N.
        /// </summary>
        /// <param name="inputFilePath">Xml file with list of image tile information.</param>
        /// <param name="outputDir">Output directory where the image tiles of pyramid has to be stored.</param>
        /// <param name="projection">Projection to be used.</param>
        private static void ProcessMultipartEquirectangularImage(string inputFilePath, string outputDir, ProjectionTypes projection)
        {
            ImageFormat imageFormat = ImageFormat.Png;

            Trace.TraceInformation("{0}: Reading image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));

            // Get the list of equirectangular images input.
            string[,] imageTiles = Program.GetInputImageList(inputFilePath);

            // Set the grid boundaries
            var imageBoundary = new Boundary(-180, -90, 180, 90);

            // Build an image grid using the input images
            var imageGrid = new ImageGrid(imageTiles, true);

            // Build the grid map for equirectangular projection using the image grid and boundary co-ordinates
            var equirectangularGridMap = new EquirectangularGridMap(imageGrid, imageBoundary);

            // Build the color map using equirectangular projection grid map
            var imageColorMap = new ImageColorMap(equirectangularGridMap);

            var maximumLevelsOfDetail = TileHelper.CalculateMaximumLevel(imageGrid.Height, imageGrid.Width, imageBoundary);

            // Define ITileCreator instance for creating image tiles.
            ITileCreator tileCreator = TileCreatorFactory.CreateImageTileCreator(imageColorMap, projection, outputDir);

            // Define plumbing for looping through all the tiles to be created for base image and pyramid.
            var tileGenerator = new TileGenerator(tileCreator);

            // Start building base image and the pyramid.
            Trace.TraceInformation("{0}: Building base and parent levels...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            tileGenerator.Generate(maximumLevelsOfDetail);

            string fileName = Path.GetFileNameWithoutExtension(inputFilePath);

            // Generate Plate file.
            Trace.TraceInformation("{0}: Building Plate file...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            ImageTileSerializer pyramid = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png);
            PlateFileGenerator plateGenerator = new PlateFileGenerator(
                Path.Combine(outputDir, fileName + ".plate"),
                maximumLevelsOfDetail,
                ImageFormat.Png);
            plateGenerator.CreateFromImageTile(pyramid);

            // Generate Thumbnail Images.
            Trace.TraceInformation("{0}: Building Thumbnail image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            string thumbnailFile = Path.Combine(outputDir, fileName + ".jpeg");
            TileHelper.GenerateThumbnail(pyramid.GetFileName(0, 0, 0), 96, 45, thumbnailFile, ImageFormat.Jpeg);

            // Get the path of image tiles created and save it in WTML file.
            Trace.TraceInformation("{0}: Building WTML file..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            string pyramidPath = WtmlCollection.GetWtmlTextureTilePath(TileHelper.GetDefaultImageTilePathTemplate(outputDir), imageFormat.ToString());

            // Create and save WTML collection file.
            WtmlCollection wtmlCollection = new WtmlCollection(fileName, thumbnailFile, pyramidPath, maximumLevelsOfDetail, projection);
            string path = Path.Combine(outputDir, fileName + ".wtml");
            wtmlCollection.Save(path);
            Trace.TraceInformation("{0}: Collection successfully generated.", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
        }
示例#5
0
        /// <summary>
        /// Processes the input equirectangular dataset.
        /// </summary>
        /// <param name="inputGrid">
        /// Input image path.
        /// </param>
        /// <param name="outputDir">
        /// Output directory where pyramid is generated.
        /// </param>
        /// <param name="projection">
        /// Projection type.
        /// </param>
        private static void ProcessEquirectangularGrid(string inputGrid, string outputDir, ProjectionTypes projection)
        {
            Trace.TraceInformation("{0}: Reading dataset..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            ImageFormat imageFormat = ImageFormat.Png;

            // Read and parse glacier bay dataset.
            // Define a color map with relief shading implemented.
            var datagridDetails = DataGridHelper.LoadFromFile(inputGrid);

            // Build a data grid using the input data set
            var dataGrid = new DataGrid(datagridDetails.Data, false);

            // Build the grid map for equirectangular projection using the data grid and boundary co-ordinates
            var equirectangularGridMap = new EquirectangularGridMap(dataGrid, datagridDetails.Boundary);

            // Build the color map using equirectangular projection grid map
            var dataColorMap = new ShadedReliefColorMap(equirectangularGridMap);

            var maximumLevelsOfDetail = 15;

            // Define an instance of ITileCreator to create image tiles.
            ITileCreator imageTileCreator = TileCreatorFactory.CreateImageTileCreator(dataColorMap, projection, outputDir);

            // Define an instance of ITileCreator to create DEM tiles.
            // Define serialization mechanism for storing and retrieving DEM tiles.
            ITileCreator demTileCreator = TileCreatorFactory.CreateDemTileCreator(dataColorMap, projection, outputDir);

            // MultiTile creator encapsulates image and DEM tile creators.
            var multiTileCreator = new MultiTileCreator(new Collection<ITileCreator>() { imageTileCreator, demTileCreator }, projection);

            // Define boundary for the region.
            var boundary = new Boundary(datagridDetails.Boundary.Left, datagridDetails.Boundary.Top, datagridDetails.Boundary.Right, datagridDetails.Boundary.Bottom);
            if (projection == ProjectionTypes.Toast)
            {
                boundary.Left += 180.0;
                boundary.Right += 180.0;
            }

            // Generate base tiles and fill up the pyramid.
            var tileGenerator = new TileGenerator(multiTileCreator);
            tileGenerator.Generate(maximumLevelsOfDetail, boundary);

            // Path of Mercator and Toast DEM tile server.
            const string MercatorDemTilePath = @"http://(web server address)?Q={0},{1},{2},Mercator,dem2178";
            const string ToastDemTilePath = @"http://(web server address)?Q={0},{1},{2},Toast,dem1033";

            string fileName = Path.GetFileNameWithoutExtension(inputGrid);

            // Generate Thumbnail Images.
            Trace.TraceInformation("{0}: Building Thumbnail image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            ImageTileSerializer tileSerializer = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png);
            string thumbnailFile = Path.Combine(outputDir, fileName + ".jpeg");
            TileHelper.GenerateThumbnail(tileSerializer.GetFileName(0, 0, 0), 96, 45, thumbnailFile, ImageFormat.Jpeg);

            // Create and save WTML file.
            string textureTilePath = WtmlCollection.GetWtmlTextureTilePath(TileHelper.GetDefaultImageTilePathTemplate(outputDir), imageFormat.ToString());
            var inputBoundary = new Boundary(datagridDetails.Boundary.Left, datagridDetails.Boundary.Top, datagridDetails.Boundary.Right, datagridDetails.Boundary.Bottom);
            WtmlCollection wtmlCollection = new WtmlCollection(fileName, thumbnailFile, textureTilePath, maximumLevelsOfDetail, projection, inputBoundary);
            wtmlCollection.ZoomLevel = 0.2;
            wtmlCollection.IsElevationModel = true;
            wtmlCollection.DemTilePath = projection == ProjectionTypes.Mercator ? MercatorDemTilePath : ToastDemTilePath;
            string path = Path.Combine(outputDir, fileName + ".wtml");
            wtmlCollection.Save(path);
            Trace.TraceInformation("{0}: Collection successfully generated.", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
        }
示例#6
0
        /// <summary>
        /// Processes the input equirectangular dataset.
        /// </summary>
        /// <param name="inputFile">
        /// Input File path.
        /// </param>
        /// <param name="outputDir">
        /// Output directory where pyramid is generated.
        /// </param>
        /// <param name="colorMapPath">
        /// Map of color map file.
        /// </param>
        /// <param name="orientation">
        /// Orientation of color map file.
        /// </param>
        /// <param name="projection">
        /// Projection type.
        /// </param>
        public static void ProcessEquirectangularGrid(string inputFile, string outputDir, string colorMapPath, ColorMapOrientation orientation, ProjectionTypes projection)
        {
            Trace.TraceInformation("{0}: Reading input dataset...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));

            // Get grid details from the input file
            var dataGridDetails = DataGridHelper.LoadFromFile(inputFile);

            // Populate the data grid using grid details
            var dataGrid = new DataGrid(dataGridDetails.Data, true);

            // Build a equirectangular projection grid map using the data grid and boundary details
            var equirectangularGridMap = new EquirectangularGridMap(dataGrid, dataGridDetails.Boundary);

            // Build a color map using equirectangular projection grid map
            var dataColorMap = new DataColorMap(colorMapPath, equirectangularGridMap, orientation, dataGridDetails.MinimumThreshold, dataGridDetails.MaximumThreshold);

            // Define an instance of ITileCreator to create image tiles.
            ITileCreator imageTileCreator = TileCreatorFactory.CreateImageTileCreator(dataColorMap, projection, outputDir);

            Trace.TraceInformation("{0}: Building base and parent levels...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            TileGenerator tileGenerator = new TileGenerator(imageTileCreator);
            int zoomLevels = 5;
            tileGenerator.Generate(zoomLevels);

            string fileName = Path.GetFileNameWithoutExtension(inputFile);

            // Generate Thumbnail Images.
            Trace.TraceInformation("{0}: Building Thumbnail image..", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            ImageTileSerializer tileSerializer = new ImageTileSerializer(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png);
            string thumbnailFile = Path.Combine(outputDir, fileName + ".jpeg");
            TileHelper.GenerateThumbnail(tileSerializer.GetFileName(0, 0, 0), 96, 45, thumbnailFile, ImageFormat.Jpeg);

            // Create and save WTML file.
            Trace.TraceInformation("{0}: Generating WTML file...", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
            string textureTilePath = WtmlCollection.GetWtmlTextureTilePath(TileHelper.GetDefaultImageTilePathTemplate(outputDir), ImageFormat.Png.ToString());
            WtmlCollection wtmlCollection = new WtmlCollection(fileName, thumbnailFile, textureTilePath, zoomLevels, projection);
            wtmlCollection.IsElevationModel = false;
            string path = Path.Combine(outputDir, fileName + ".wtml");
            wtmlCollection.Save(path);
            Trace.TraceInformation("{0}: Collection successfully generated.", DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss", CultureInfo.InvariantCulture));
        }
        public void ValidateWtmlToastCollectionSet()
        {
            WtmlCollection wtmlCollecn = new WtmlCollection("Temp", "tempName.jpeg", Environment.CurrentDirectory, 7, ProjectionTypes.Toast);
            Assert.IsNotNull(wtmlCollecn);

            // Save WTMl file
            string filePath = @"ValidTemp.wtml";
            wtmlCollecn.Save(filePath);
            Assert.IsTrue(File.Exists(filePath));
        }
示例#8
0
        /// <summary>
        /// This event is raised when the create pyramid function is called.
        /// </summary>
        /// <param name="sender">
        /// create ImageWorker.
        /// </param>
        /// <param name="e">
        /// DoWork EventArgs.
        /// </param>
        private void OnCreateImageWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            ImagePyramidDetails inputDetails = e.Argument as ImagePyramidDetails;

            if (inputDetails != null)
            {
                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.LoadingImage, PyramidGenerationStatus.Started);

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.PyramidGeneration, PyramidGenerationStatus.Started);

                // Define ITileCreator instance for creating image tiles.
                // If the input projection type and output projection type is same then we need to tile the image.
                Core.ITileCreator tileCreator = null;

                // Calculates the estimated thumbnail generation time
                Stopwatch thumbnailGenerationStopwatch = new Stopwatch();
                thumbnailGenerationStopwatch.Start();
                if (inputDetails.InputProjection == InputProjections.EquiRectangular)
                {
                    // Read and initialize the image as an IGrid.
                    var imageGrid = new Core.ImageGrid(inputDetails.InputImagePath, true);
                    var equirectangularGridMap = new Core.EquirectangularGridMap(imageGrid, inputDetails.InputBoundary);
                    var imageColorMap          = new Core.ImageColorMap(equirectangularGridMap);

                    tileCreator = Core.TileCreatorFactory.CreateImageTileCreator(
                        imageColorMap,
                        inputDetails.OutputProjection,
                        inputDetails.OutputDirectory);
                }
                else
                {
                    Core.IImageTileSerializer serializer = new Core.ImageTileSerializer(
                        Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory),
                        ImageFormat.Png);
                    tileCreator = new Core.TileChopper(inputDetails.InputImagePath, serializer, inputDetails.OutputProjection, inputDetails.InputBoundary);
                }

                thumbnailGenerationStopwatch.Stop();

                // Thumbnail estimated time is time required to load the image and then create the thumbnail with graphics
                this.ThumbnailEstimatedTime = thumbnailGenerationStopwatch.ElapsedMilliseconds * Constants.ThumbnailMultiplier;

                // Define plumbing for looping through all the tiles to be created for base image and pyramid.
                tileGenerator = new Core.TileGenerator(tileCreator);

                this.cancellationToken = new CancellationTokenSource();
                tileGenerator.ParallelOptions.CancellationToken = this.cancellationToken.Token;

                this.CheckCancel(e);

                // Define bounds of the image. Image is assumed to cover the entire world.
                // If not, change the coordinates accordingly.
                // For Mercator projection, longitude spans from -180 to +180 and latitude from 90 to -90.
                Core.Boundary gridBoundary = new Core.Boundary(
                    inputDetails.InputBoundary.Left,
                    inputDetails.InputBoundary.Top,
                    inputDetails.InputBoundary.Right,
                    inputDetails.InputBoundary.Bottom);
                if (inputDetails.OutputProjection == ProjectionTypes.Toast)
                {
                    // For Toast projection, longitude spans from 0 to +360 and latitude from 90 to -90.
                    gridBoundary.Left  += 180;
                    gridBoundary.Right += 180;
                }

                // Start building base image and the pyramid.
                tileGenerator.Generate(inputDetails.Level, gridBoundary);

                if (inputDetails.IsGeneratePlate)
                {
                    NotifyMessage(PyramidGenerationSteps.PlateFileGeneration, PyramidGenerationStatus.Started);
                    this.CheckCancel(e);

                    // Generate Plate file.
                    Core.ImageTileSerializer pyramid = new Core.ImageTileSerializer(
                        Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory),
                        ImageFormat.Png);

                    plateGenerator = new Core.PlateFileGenerator(
                        System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".plate"),
                        inputDetails.Level,
                        ImageFormat.Png);

                    plateGenerator.CreateFromImageTile(pyramid);
                }

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.ThumbnailGeneration, PyramidGenerationStatus.Started);

                // Generate Thumbnail Images.
                string thumbnailFile = System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".jpeg");
                Core.TileHelper.GenerateThumbnail(inputDetails.InputImagePath, 96, 45, thumbnailFile, ImageFormat.Jpeg);

                this.CheckCancel(e);

                NotifyMessage(PyramidGenerationSteps.WTMLGeneration, PyramidGenerationStatus.Started);

                // Get the path of image tiles created and save it in WTML file.
                string pyramidPath = Core.WtmlCollection.GetWtmlTextureTilePath(Core.TileHelper.GetDefaultImageTilePathTemplate(inputDetails.OutputDirectory), ImageFormat.Png.ToString());

                Core.Boundary inputBoundary = new Core.Boundary(
                    inputDetails.InputBoundary.Left,
                    inputDetails.InputBoundary.Top,
                    inputDetails.InputBoundary.Right,
                    inputDetails.InputBoundary.Bottom);

                // Create and save WTML collection file.
                Core.WtmlCollection wtmlCollection = new Core.WtmlCollection(inputDetails.OutputFilename, thumbnailFile, pyramidPath, inputDetails.Level, inputDetails.OutputProjection, inputBoundary);
                wtmlCollection.Credit    = inputDetails.Credits;
                wtmlCollection.CreditUrl = inputDetails.CreditsURL;
                string path = System.IO.Path.Combine(inputDetails.OutputDirectory, inputDetails.OutputFilename + ".wtml");
                wtmlCollection.Save(path);
            }
        }