public void GetColorTest() { string colorMapFile = Path.Combine(TestDataPath, "ColorMap.png"); IProjectionGridMap projectionGridMap = new MockClasses.MockProjectionGridMap(); ColorMapOrientation orientation = ColorMapOrientation.Vertical; double minimumValue = double.MinValue; double maximumValue = double.MaxValue; DataColorMap target = new DataColorMap(colorMapFile, projectionGridMap, orientation, minimumValue, maximumValue); Color expectedColor = Color.FromArgb(255, 164, 169, 230); Color actual = target.GetColor(200, 400); Assert.AreEqual(expectedColor, actual); }
/// <summary> /// Initializes a new instance of the DataColorMap class. /// </summary> /// <param name="colorMapFile"> /// Color map file path. This file will be used as Index of colors. /// </param> /// <param name="projectionGridMap"> /// Input image grid map for specified projection. /// </param> /// <param name="orientation"> /// Represents the orientation of the color map. /// For example : Vertical or Horizontal. /// </param> /// <param name="minimumValue"> /// Represents minimum threshold value for color. /// </param> /// <param name="maximumValue"> /// Represents maximum threshold value for color. /// </param> public DataColorMap(string colorMapFile, IProjectionGridMap projectionGridMap, ColorMapOrientation orientation, double minimumValue, double maximumValue) { if (string.IsNullOrEmpty(colorMapFile)) { throw new ArgumentNullException("colorMapFile"); } if (projectionGridMap == null) { throw new ArgumentNullException("projectionGridMap"); } this.projectionGridMap = projectionGridMap; this.minimumThreshold = minimumValue; this.maximumThreshold = maximumValue; try { using (Bitmap bitmap = new Bitmap(Bitmap.FromFile(colorMapFile))) { int samplingPoint = bitmap.Width / 2; int numberOfColors = bitmap.Height; if (orientation == ColorMapOrientation.Horizontal) { samplingPoint = bitmap.Height / 2; numberOfColors = bitmap.Width; } this.colors = new List<Color>(numberOfColors); if (orientation == ColorMapOrientation.Vertical) { for (int i = 0; i < numberOfColors; i++) { this.colors.Add(bitmap.GetPixel(samplingPoint, numberOfColors - i - 1)); } } else if (orientation == ColorMapOrientation.Horizontal) { for (int i = 0; i < numberOfColors; i++) { this.colors.Add(bitmap.GetPixel(numberOfColors - i - 1, samplingPoint)); } } } } catch { throw new InvalidOperationException("Error reading the color map file. Check the color map and orientation."); } }
public void GetNaNColorTest() { try { string colorMapFile = Path.Combine(TestDataPath, "ColorMap.png"); IProjectionGridMap projectionGridMap = new MockClasses.MockProjectionGridMap(); ColorMapOrientation orientation = ColorMapOrientation.Vertical; double minimumValue = double.MinValue; double maximumValue = double.MaxValue; DataColorMap target = new DataColorMap(colorMapFile, projectionGridMap, orientation, minimumValue, maximumValue); Color color = target.GetColor(double.NaN, double.NaN); Assert.AreEqual(color, Color.Transparent); } catch (Exception ex) { Assert.Fail(ex.Message); } }
/// <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)); }
/// <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")); }
/// <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")); }
/// <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)); }
/// <summary> /// Initializes a new instance of the DataColorMap class. /// </summary> /// <param name="colorMapFile"> /// Color map file path. This file will be used as Index of colors. /// </param> /// <param name="projectionGridMap"> /// Input image grid map for specified projection. /// </param> /// <param name="orientation"> /// Represents the orientation of the color map. /// For example : Vertical or Horizontal. /// </param> /// <param name="minimumValue"> /// Represents minimum threshold value for color. /// </param> /// <param name="maximumValue"> /// Represents maximum threshold value for color. /// </param> public DataColorMap(string colorMapFile, IProjectionGridMap projectionGridMap, ColorMapOrientation orientation, double minimumValue, double maximumValue) { if (string.IsNullOrEmpty(colorMapFile)) { throw new ArgumentNullException("colorMapFile"); } if (projectionGridMap == null) { throw new ArgumentNullException("projectionGridMap"); } this.projectionGridMap = projectionGridMap; this.minimumThreshold = minimumValue; this.maximumThreshold = maximumValue; try { using (Bitmap bitmap = new Bitmap(Bitmap.FromFile(colorMapFile))) { int samplingPoint = bitmap.Width / 2; int numberOfColors = bitmap.Height; if (orientation == ColorMapOrientation.Horizontal) { samplingPoint = bitmap.Height / 2; numberOfColors = bitmap.Width; } this.colors = new List <Color>(numberOfColors); if (orientation == ColorMapOrientation.Vertical) { for (int i = 0; i < numberOfColors; i++) { this.colors.Add(bitmap.GetPixel(samplingPoint, numberOfColors - i - 1)); } } else if (orientation == ColorMapOrientation.Horizontal) { for (int i = 0; i < numberOfColors; i++) { this.colors.Add(bitmap.GetPixel(numberOfColors - i - 1, samplingPoint)); } } } } catch { throw new InvalidOperationException("Error reading the color map file. Check the color map and orientation."); } }