osgEarth 2.1.1
|
Public Member Functions | |
CubeSpatialReference (void *handle) | |
virtual GeoLocator * | createLocator (double xmin, double ymin, double xmax, double ymax, bool plate_carre=false) const |
virtual bool | isGeographic () const |
virtual bool | isProjected () const |
virtual bool | preTransform (double &x, double &y, double &z, void *context) const |
virtual bool | postTransform (double &x, double &y, double &z, void *context) const |
virtual bool | transformExtent (const SpatialReference *to_srs, double &in_out_xmin, double &in_out_ymin, double &in_out_xmax, double &in_out_ymax, void *context) const |
Protected Member Functions | |
void | _init () |
The "Cube" SRS represents a 6-face cube, each face being in unit coordinates (0,0=>1,1). the cube as whole lays out all six faces side by side, resulting in a space measuring (0,0=>6,1). The face number corresponds to the x-axis ordinal.
CubeSpatialReference::CubeSpatialReference | ( | void * | handle | ) |
Definition at line 390 of file Cube.cpp.
: SpatialReference( handle, "OSGEARTH", "unified-cube", "Unified Cube" ) { //nop }
void CubeSpatialReference::_init | ( | ) | [protected, virtual] |
Reimplemented from osgEarth::SpatialReference.
Definition at line 397 of file Cube.cpp.
{ SpatialReference::_init(); _is_user_defined = true; _is_cube = true; _is_contiguous = false; _is_geographic = false; _name = "Unified Cube"; }
GeoLocator * CubeSpatialReference::createLocator | ( | double | xmin, |
double | ymin, | ||
double | xmax, | ||
double | ymax, | ||
bool | plate_carre = false |
||
) | const [virtual] |
Creates a new Locator object based on this spatial reference.
xmin,ymin,xmax,ymax | Extents of the tile for which to create a locator. These should be in degrees for a geographic/geocentric scene. |
plate_carre | Set this to true for the special case in which you are using a geographic SRS with a PROJECTED map (like flat-earth lat/long). |
Reimplemented from osgEarth::SpatialReference.
Definition at line 409 of file Cube.cpp.
{ int face; CubeUtils::cubeToFace( xmin, ymin, xmax, ymax, face ); GeoLocator* result = new CubeFaceLocator( face ); osg::Matrixd transform; transform.set( xmax-xmin, 0.0, 0.0, 0.0, 0.0, ymax-ymin, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, xmin, ymin, 0.0, 1.0); result->setTransform( transform ); return result; }
virtual bool osgEarth::CubeSpatialReference::isGeographic | ( | ) | const [inline, virtual] |
True is this is a geographic SRS (i.e. unprojected lat/long)
Reimplemented from osgEarth::SpatialReference.
Definition at line 123 of file Cube.
{ return false; }
virtual bool osgEarth::CubeSpatialReference::isProjected | ( | ) | const [inline, virtual] |
True if this is a projected SRS (i.e. local coordinate system)
Reimplemented from osgEarth::SpatialReference.
Definition at line 124 of file Cube.
{ return true; }
bool CubeSpatialReference::postTransform | ( | double & | x, |
double & | y, | ||
double & | z, | ||
void * | context | ||
) | const [virtual] |
Reimplemented from osgEarth::SpatialReference.
Definition at line 452 of file Cube.cpp.
{ //Convert the incoming points from lat/lon back to face coordinates int face; double out_x, out_y; // convert from lat/long to x/y/face bool success = CubeUtils::latLonToFaceCoords( y, x, out_x, out_y, face ); if (!success) { OE_WARN << LC << "Could not transform face coordinates to lat lon" << std::endl; return false; } //TODO: what to do about boundary points? if ( !CubeUtils::faceToCube( out_x, out_y, face ) ) { OE_WARN << LC << "fromFace(" << out_x << "," << out_y << "," << face << ") failed" << std::endl; return false; } x = out_x; y = out_y; return true; }
bool CubeSpatialReference::preTransform | ( | double & | x, |
double & | y, | ||
double & | z, | ||
void * | context | ||
) | const [virtual] |
Reimplemented from osgEarth::SpatialReference.
Definition at line 429 of file Cube.cpp.
{ // Convert the incoming points from cube => face => lat/long. int face; if ( !CubeUtils::cubeToFace( x, y, face ) ) { OE_WARN << LC << "Failed to convert (" << x << "," << y << ") into face coordinates." << std::endl; return false; } double lat_deg, lon_deg; bool success = CubeUtils::faceCoordsToLatLon( x, y, face, lat_deg, lon_deg ); if (!success) { OE_WARN << LC << "Could not transform face coordinates to lat lon" << std::endl; return false; } x = lon_deg; y = lat_deg; return true; }
bool CubeSpatialReference::transformExtent | ( | const SpatialReference * | to_srs, |
double & | in_out_xmin, | ||
double & | in_out_ymin, | ||
double & | in_out_xmax, | ||
double & | in_out_ymax, | ||
void * | context | ||
) | const [virtual] |
Transforms a spatial extent to another SRS.
TODO: Update this method to work for: a) Geographic extents that cross the date line; and b) Polar extents.
Reimplemented from osgEarth::SpatialReference.
Definition at line 488 of file Cube.cpp.
{ // note: this method only works when the extent is isolated to one face of the cube. If you // want to transform an artibrary extent, you need to break it up into separate extents for // each cube face. bool ok = true; double face_xmin = in_out_xmin, face_ymin = in_out_ymin; double face_xmax = in_out_xmax, face_ymax = in_out_ymax; int face; CubeUtils::cubeToFace( face_xmin, face_ymin, face_xmax, face_ymax, face ); // for equatorial faces, the normal transformation process will suffice (since it will call into // pre/postTransform). if ( face < 4 ) { ok = SpatialReference::transformExtent( to_srs, in_out_xmin, in_out_ymin, in_out_xmax, in_out_ymax ); } else { // otherwise we are on one of the polar faces (4 or 5): // four corners in face space: double fx[4] = { face_xmin, face_xmax, face_xmax, face_xmin }; double fy[4] = { face_ymin, face_ymin, face_ymax, face_ymax }; bool crosses_pole = fx[LL] < 0.5 && fx[UR] > 0.5 && fy[LL] < 0.5 && fy[UR] > 0.5; if ( crosses_pole ) // full x extent. { bool north = face == 4; // else south to_srs->getGeographicSRS()->transform2D( -180.0, north? 45.0 : -90.0, to_srs, in_out_xmin, in_out_ymin ); to_srs->getGeographicSRS()->transform2D( 180.0, north? 90.0 : -45.0, to_srs, in_out_xmax, in_out_ymax ); } else { double lat_deg[4]; double lon_deg[4]; double latmin, latmax, lonmin, lonmax; for( int i=0; i<4; ++i ) { CubeUtils::faceCoordsToLatLon( fx[i], fy[i], face, lat_deg[i], lon_deg[i] ); } latmin = SMALLEST( lat_deg[0], lat_deg[1], lat_deg[2], lat_deg[3] ); latmax = LARGEST( lat_deg[0], lat_deg[1], lat_deg[2], lat_deg[3] ); // check to see whether the extent crosses the date line boundary. If so, // make the UL corner the southwest and the LR corner the east. bool crosses_date_line = fx[UL]+(1-fy[UL]) < 1.0 && (1-fx[LR])+fy[LR] < 1.0 && fx[LL]+fy[LL] < 1.0; if ( crosses_date_line ) { lonmin = lon_deg[UL]; lonmax = lon_deg[LR]; } else { lonmin = SMALLEST( lon_deg[0], lon_deg[1], lon_deg[2], lon_deg[3] ); lonmax = LARGEST( lon_deg[0], lon_deg[1], lon_deg[2], lon_deg[3] ); } if ( to_srs->isGeographic() ) { in_out_xmin = lonmin; in_out_xmax = lonmax; in_out_ymin = latmin; in_out_ymax = latmax; } else { bool ok1 = transform2D( lonmin, latmin, to_srs, in_out_xmin, in_out_ymin, context ); bool ok2 = transform2D( lonmax, latmax, to_srs, in_out_xmax, in_out_ymax, context ); ok = ok1 && ok2; } } } return ok; }