/// <summary> /// Converts a given point to RA-Dec coordinate space. /// </summary> /// <param name="point"> /// Point between 1 and 0 inclusive. /// </param> /// <returns> /// Point in RA-Dec coordinates. /// </returns> public Vector2d PointToRaDec(Vector2d point) { int indexX = (int)(point.X / this.subDivSize); int indexY = (int)(point.Y / this.subDivSize); if (indexX > ((int)Math.Pow(2, this.subDivisions) - 1)) { indexX = ((int)Math.Pow(2, this.subDivisions) - 1); } if (indexY > ((int)Math.Pow(2, this.subDivisions) - 1)) { indexY = ((int)Math.Pow(2, this.subDivisions) - 1); } double distX = (point.X - ((double)indexX * this.subDivSize)) / this.subDivSize; double distY = (point.Y - ((double)indexY * this.subDivSize)) / this.subDivSize; Vector2d interpolatedTop = Vector2d.Lerp(this.mapRaDec[indexX, indexY], this.mapRaDec[indexX + 1, indexY], distX); Vector2d interpolatedBottom = Vector2d.Lerp(this.mapRaDec[indexX, indexY + 1], this.mapRaDec[indexX + 1, indexY + 1], distX); Vector2d result = Vector2d.Lerp(interpolatedTop, interpolatedBottom, distY); return result; }
/// <summary> /// Maps image pixels to lat-long values. /// </summary> /// <param name="tileMap">Tile mapper.</param> /// <param name="hasData">Boolean indicates whether the coordinates maps to valid color.</param> /// <returns>List of color values.</returns> private List<Color> MapToColors(OctTileMap tileMap, out bool hasData) { List<Color> colors = new List<Color>(Constants.TileSize * Constants.TileSize); Vector2d point = new Vector2d(); hasData = false; for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++) { point.Y = ((double)pixelY + 0.5) / Constants.TileSize; for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++) { point.X = ((double)pixelX + 0.5) / Constants.TileSize; var v = tileMap.PointToRaDec(point); Color color = (this.colorMap.GetColor(v.X, v.Y)); if (color != Color.Transparent) { hasData = true; } colors.Add(color); } } return colors; }
/// <summary> /// Interpolates the two vectors. /// </summary> /// <param name="left"> /// First vector. /// </param> /// <param name="right"> /// Second vector. /// </param> /// <param name="interpolater"> /// Interpolater factor. /// </param> /// <returns> /// Lerp-ed vector. /// </returns> public static Vector2d Lerp(Vector2d left, Vector2d right, double interpolater) { if (Math.Abs(left.X - right.X) > 180) { if (left.X > right.X) { right.X += 360; } else { left.X += 360; } } return new Vector2d(left.X * (1 - interpolater) + right.X * interpolater, left.Y * (1 - interpolater) + right.Y * interpolater); }
/// <summary> /// Creates the tile specified by level. /// </summary> /// <param name="level"> /// Zoom level. /// </param> /// <param name="tileX"> /// X tile coordinate. /// </param> /// <param name="tileY"> /// Y tile coordinate. /// </param> public void Create(int level, int tileX, int tileY) { // Pick the set of vertices where elevation will be computed. int[] verticesX = backslashVerticesX; int[] verticesY = backslashVerticesY; if (IsSlashQuadrant(level, tileX, tileY)) { verticesX = slashVerticesX; verticesY = slashVerticesY; } // Compute required elevations. short[] h = new short[verticesX.Length]; Vector2d pt = new Vector2d(); OctTileMap tileMap = new OctTileMap(level, tileX, tileY); for (int i = 0; i < verticesX.Length; i++) { pt.X = ((double)verticesX[i]) / VertexInterval; pt.Y = ((double)verticesY[i]) / VertexInterval; Vector2d v = tileMap.PointToRaDec(pt); h[i] = this.elevationMap.GetElevation(v.X - 180.0, v.Y); } // Save elevations. this.tileSerializer.Serialize(h, level, tileX, tileY); }