Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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);
            }
        }