osgEarth 2.1.1
|
Static Public Member Functions | |
static bool | latLonToFaceCoords (double lat_deg, double lon_deg, double &out_x, double &out_y, int &out_face, int faceHint=-1) |
static bool | faceCoordsToLatLon (double x, double y, int face, double &out_lat_deg, double &out_lon_deg) |
static int | getFace (const TileKey &key) |
static bool | cubeToFace (double &in_out_x, double &in_out_y, int &out_face) |
static bool | cubeToFace (double &in_out_xmin, double &in_out_ymin, double &in_out_xmax, double &in_out_ymax, int &out_face) |
static bool | faceToCube (double &in_out_x, double &in_out_y, int face) |
bool CubeUtils::cubeToFace | ( | double & | in_out_x, |
double & | in_out_y, | ||
int & | out_face | ||
) | [static] |
Converts cube coordinates (0,0=>6,1) to face coordinates (0,0=>1,1,F). WARNING. If the cube coordinate lies on a face boundary, this method will always return the lower-numbered face. The "extent" version of this method (below) is better b/c it's unambiguous.
Definition at line 235 of file Cube.cpp.
{ // convert from unicube space (0,0=>6,1) to face space (0,0=>1,1 + face#) // too tired to compute a formula right now out_face = in_out_x <= 1.0 ? 0 : in_out_x <= 2.0 ? 1 : in_out_x <= 3.0 ? 2 : in_out_x <= 4.0 ? 3 : in_out_x <= 5.0 ? 4 : 5; in_out_x = in_out_x - (double)out_face; // y unchanged return true; }
bool CubeUtils::cubeToFace | ( | double & | in_out_xmin, |
double & | in_out_ymin, | ||
double & | in_out_xmax, | ||
double & | in_out_ymax, | ||
int & | out_face | ||
) | [static] |
Converts cube coordinates (0,0=>6,1) to face coordinates (0,0=>1,1,F). This version takes an extent, which is better than the non-extent version since it can resolve face-border ambiguity.
Definition at line 252 of file Cube.cpp.
{ int min_face = in_out_xmin < 1.0 ? 0 : in_out_xmin < 2.0 ? 1 : in_out_xmin < 3.0 ? 2 : in_out_xmin < 4.0 ? 3 : in_out_xmin < 5.0 ? 4 : 5; int max_face = in_out_xmax <= 1.0 ? 0 : in_out_xmax <= 2.0 ? 1 : in_out_xmax <= 3.0 ? 2 : in_out_xmax <= 4.0 ? 3 : in_out_xmax <= 5.0 ? 4 : 5; if ( min_face != max_face ) { OE_WARN << LC << "Min face <> Max face!" << std::endl; return false; } out_face = min_face; in_out_xmin -= (double)out_face; in_out_xmax -= (double)out_face; // y values are unchanged return true; }
bool CubeUtils::faceCoordsToLatLon | ( | double | x, |
double | y, | ||
int | face, | ||
double & | out_lat_deg, | ||
double & | out_lon_deg | ||
) | [static] |
Converts face coordinates into lat/long.
Definition at line 141 of file Cube.cpp.
{ double offset = 0.0; osg::Vec2d s( x, y ); // validate coordinate range: if ( x < 0 || x > 1 || y < 0 || y > 1 ) { OE_WARN << LC << "faceCoordToLatLon: input out of range" << std::endl; return false; } if ( face < 4 ) // equatorial faces { s.x() = (x + face) * 0.25; s.y() = (y + 0.5) * 0.5; } else if( face == 4 ) // north polar face { if ( x < y ) // left or top quadrant { if(x + y < 1.0) // left quadrant { s.x() = 1.0 - y; s.y() = x; offset += 3; } else // top quadrant { s.y() = 1.0 - y; s.x() = 1.0 - x; offset += 2; } } else if( x + y >= 1.0 ) // right quadrant { s.x() = y; s.y() = 1.0 - x; offset += 1.0; } s.x() -= s.y(); if(s.y() != 0.5) s.x() *= 0.5 / (0.5 - s.y()); s.x() = (s.x() + offset) * 0.25; s.y() = (s.y() + 1.5) * 0.5; } else if ( face == 5 ) // south polar face { offset = 1.0; if ( x > y ) // right or bottom quadrant { if( x + y >= 1.0) // right quadrant { s.x() = 1.0 - y; s.y() = x - 0.5; offset += 1.0; } else // bottom quadrant { s.x() = 1.0 - x; s.y() = 0.5 - y; offset += 2; } } else // left or top quadrant { if(x + y < 1.0) // left quadrant { s.x() = y; s.y() = 0.5 - x; offset -= 1.0; } else // top quadrant s.y() = y - 0.5; } if(s.y() != 0) s.x() = (s.x() - 0.5) * 0.5 / s.y() + 0.5; s.x() = (s.x() + offset) * 0.25; s.y() *= 0.5; } else { return false; // invalid face specification } // convert to degrees out_lon_deg = s.x() * 360 - 180; out_lat_deg = s.y() * 180 - 90; return true; }
bool CubeUtils::faceToCube | ( | double & | in_out_x, |
double & | in_out_y, | ||
int | face | ||
) | [static] |
static int osgEarth::CubeUtils::getFace | ( | const TileKey & | key | ) | [static] |
Get the face # containing a TileKey.
bool CubeUtils::latLonToFaceCoords | ( | double | lat_deg, |
double | lon_deg, | ||
double & | out_x, | ||
double & | out_y, | ||
int & | out_face, | ||
int | faceHint = -1 |
||
) | [static] |
Converts lat/long into face coordinates. You can optionally supply a "face hint" if you already know which face the result will be in. This is handy for resolving border ambiguities (i.e. a lat/lon that falls on the border of two faces).
Definition at line 33 of file Cube.cpp.
{ // normalized latitude and longitude double nlat = (lat_deg+90.0)/180.0; double nlon = (lon_deg+180.0)/360.0; // check for out-of-range: if ( nlat < 0 || nlat > 1 || nlon < 0 || nlon > 1 ) return false; int face_x; if ( faceHint >= 0 ) { out_face = faceHint; if ( faceHint < 4 ) { face_x = faceHint; } else { face_x = (int)(4 * nlon); if ( face_x == 4 ) face_x = 3; } } else { face_x = (int)(4 * nlon); if ( face_x == 4 ) face_x = 3; int face_y = (int)(2 * nlat + 0.5); if ( face_y == 1 ) out_face = face_x; else out_face = face_y < 1 ? 5 : 4; //GW: not sure why this was here; but I think this issue is the cause of cracks when // projecting CUBE source imagery onto a WGS84 globe. // //if ( osg::equivalent( lat_deg, -45 ) ) // out_face = 5; } out_x = 4 * nlon - face_x; out_y = 2 * nlat - 0.5; if(out_face < 4) // equatorial calculations done return true; double tmp; if(out_face == 4) // north polar face { out_y = 1.5 - out_y; out_x = 2 * (out_x - 0.5) * out_y + 0.5; switch(face_x) { case 0: // bottom out_y = 0.5 - out_y; break; case 1: // right side, swap and reverse lat tmp = out_x; out_x = 0.5 + out_y; out_y = tmp; break; case 2: // top; reverse lat and lon out_x = 1 - out_x; out_y = 0.5 + out_y; break; case 3: // left side; swap and reverse lon tmp = out_x; out_x = 0.5 - out_y; out_y = 1 - tmp; break; } } else // south polar face { out_y += 0.5; out_x = 2 * (out_x - 0.5) * out_y + 0.5; switch(face_x) { case 0: // left tmp = out_x; out_x = 0.5 - out_y; out_y = tmp; break; case 1: // top out_y = 0.5 + out_y; break; case 2: // right tmp = out_x; out_x = 0.5 + out_y; out_y = 1 - tmp; break; case 3: // bottom out_x = 1 - out_x; out_y = 0.5 - out_y; break; } } return true; }