osgEarth 2.1.1
|
Classes | |
struct | ImageOverlayCallback |
Public Types | |
enum | ControlPoint { CONTROLPOINT_CENTER, CONTROLPOINT_LOWER_LEFT, CONTROLPOINT_LOWER_RIGHT, CONTROLPOINT_UPPER_LEFT, CONTROLPOINT_UPPER_RIGHT } |
typedef std::list < osg::ref_ptr < ImageOverlayCallback > > | CallbackList |
Public Member Functions | |
ImageOverlay (MapNode *mapNode, osg::Image *image=NULL) | |
void | setCorners (const osg::Vec2d &lowerLeft, const osg::Vec2d &lowerRight, const osg::Vec2d &upperLeft, const osg::Vec2d &upperRight) |
void | setLowerLeft (double lon_deg, double lat_deg) |
const osg::Vec2d & | getLowerLeft () const |
void | setLowerRight (double lon_deg, double lat_deg) |
const osg::Vec2d & | getLowerRight () const |
void | setUpperLeft (double lon_deg, double lat_deg) |
const osg::Vec2d & | getUpperLeft () const |
void | setUpperRight (double lon_deg, double lat_deg) |
const osg::Vec2d & | getUpperRight () const |
osg::Vec2d | getCenter () const |
void | setCenter (double lon_deg, double lat_deg) |
osg::Vec2d | getControlPoint (ControlPoint controlPoint) |
void | setControlPoint (ControlPoint controlPoint, double lon_deg, double lat_deg, bool singleVert=false) |
void | addCallback (ImageOverlayCallback *callback) |
void | removeCallback (ImageOverlayCallback *callback) |
osgEarth::Bounds | getBounds () const |
void | setBounds (const osgEarth::Bounds &bounds) |
void | setBoundsAndRotation (const osgEarth::Bounds &bounds, const Angular &rotation) |
osg::Image * | getImage () const |
void | setImage (osg::Image *image) |
void | setNorth (double value_deg) |
void | setSouth (double value_deg) |
void | setEast (double value_deg) |
void | setWest (double value_deg) |
float | getAlpha () const |
void | setAlpha (float alpha) |
virtual void | traverse (osg::NodeVisitor &nv) |
void | dirty () |
Private Member Functions | |
void | fireCallback (ImageOverlay::ControlPoint point, const osg::Vec2d &location) |
void | postCTOR () |
void | init () |
void | clampLatitudes () |
Private Attributes | |
osg::Vec2d | _lowerLeft |
osg::Vec2d | _lowerRight |
osg::Vec2d | _upperRight |
osg::Vec2d | _upperLeft |
osg::ref_ptr< osg::Image > | _image |
bool | _dirty |
OpenThreads::Mutex | _mutex |
osg::Geode * | _geode |
osg::Geometry * | _geometry |
float | _alpha |
CallbackList | _callbacks |
Definition at line 16 of file ImageOverlay.
typedef std::list< osg::ref_ptr<ImageOverlayCallback> > osgEarth::Util::ImageOverlay::CallbackList |
Definition at line 57 of file ImageOverlay.
CONTROLPOINT_CENTER | |
CONTROLPOINT_LOWER_LEFT | |
CONTROLPOINT_LOWER_RIGHT | |
CONTROLPOINT_UPPER_LEFT | |
CONTROLPOINT_UPPER_RIGHT |
Definition at line 20 of file ImageOverlay.
ImageOverlay::ImageOverlay | ( | MapNode * | mapNode, |
osg::Image * | image = NULL |
||
) |
Definition at line 22 of file ImageOverlay.cpp.
: DrapeableNode(mapNode, true), _lowerLeft(10,10), _lowerRight(20, 10), _upperRight(20,20), _upperLeft(10, 20), _image(image), _dirty(false), _alpha(1.0f) { postCTOR(); }
void ImageOverlay::addCallback | ( | ImageOverlayCallback * | callback | ) |
Definition at line 414 of file ImageOverlay.cpp.
{ if ( cb ) this->_callbacks.push_back( cb ); }
void ImageOverlay::clampLatitudes | ( | ) | [private] |
Definition at line 148 of file ImageOverlay.cpp.
{ clampLatitude( _lowerLeft ); clampLatitude( _lowerRight ); clampLatitude( _upperLeft ); clampLatitude( _upperRight ); }
void ImageOverlay::dirty | ( | ) |
Definition at line 400 of file ImageOverlay.cpp.
{ { OpenThreads::ScopedLock< OpenThreads::Mutex > lock(_mutex); _dirty = true; } for( CallbackList::iterator i = _callbacks.begin(); i != _callbacks.end(); i++ ) { i->get()->onOverlayChanged(); } }
void osgEarth::Util::ImageOverlay::fireCallback | ( | ImageOverlay::ControlPoint | point, |
const osg::Vec2d & | location | ||
) | [private] |
float ImageOverlay::getAlpha | ( | ) | const |
Definition at line 132 of file ImageOverlay.cpp.
{ return _alpha; }
osgEarth::Bounds ImageOverlay::getBounds | ( | ) | const |
Definition at line 221 of file ImageOverlay.cpp.
{ osgEarth::Bounds bounds; bounds.expandBy(_lowerLeft.x(), _lowerLeft.y()); bounds.expandBy(_lowerRight.x(), _lowerRight.y()); bounds.expandBy(_upperLeft.x(), _upperLeft.y()); bounds.expandBy(_upperRight.x(), _upperRight.y()); return bounds; }
osg::Vec2d ImageOverlay::getCenter | ( | ) | const |
Definition at line 158 of file ImageOverlay.cpp.
{ return (_lowerLeft + _lowerRight + _upperRight + _upperLeft) / 4.0; }
osg::Vec2d ImageOverlay::getControlPoint | ( | ControlPoint | controlPoint | ) |
Definition at line 316 of file ImageOverlay.cpp.
{ switch (controlPoint) { case CONTROLPOINT_CENTER: return getCenter(); case CONTROLPOINT_UPPER_LEFT: return getUpperLeft(); case CONTROLPOINT_LOWER_LEFT: return getLowerLeft(); case CONTROLPOINT_UPPER_RIGHT: return getUpperRight(); case CONTROLPOINT_LOWER_RIGHT: return getLowerRight(); default: return getCenter(); } }
osg::Image * ImageOverlay::getImage | ( | ) | const |
Definition at line 117 of file ImageOverlay.cpp.
{ return _image.get(); }
const osg::Vec2d& osgEarth::Util::ImageOverlay::getLowerLeft | ( | ) | const [inline] |
Definition at line 35 of file ImageOverlay.
{ return _lowerLeft; }
const osg::Vec2d& osgEarth::Util::ImageOverlay::getLowerRight | ( | ) | const [inline] |
Definition at line 38 of file ImageOverlay.
{ return _lowerRight;}
const osg::Vec2d& osgEarth::Util::ImageOverlay::getUpperLeft | ( | ) | const [inline] |
Definition at line 41 of file ImageOverlay.
{ return _upperLeft; }
const osg::Vec2d& osgEarth::Util::ImageOverlay::getUpperRight | ( | ) | const [inline] |
Definition at line 44 of file ImageOverlay.
{ return _upperRight;}
void ImageOverlay::init | ( | ) | [private] |
Definition at line 48 of file ImageOverlay.cpp.
{ OpenThreads::ScopedLock< OpenThreads::Mutex > lock(_mutex); double height = 0; osg::Geometry* geometry = new osg::Geometry(); osg::Vec3d ll; const osg::EllipsoidModel* ellipsoid = _mapNode->getMap()->getProfile()->getSRS()->getEllipsoid(); ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_lowerLeft.y()), osg::DegreesToRadians(_lowerLeft.x()), height, ll.x(), ll.y(), ll.z()); osg::Vec3d lr; ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_lowerRight.y()), osg::DegreesToRadians(_lowerRight.x()), height, lr.x(), lr.y(), lr.z()); osg::Vec3d ur; ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_upperRight.y()), osg::DegreesToRadians(_upperRight.x()), height, ur.x(), ur.y(), ur.z()); osg::Vec3d ul; ellipsoid->convertLatLongHeightToXYZ(osg::DegreesToRadians(_upperLeft.y()), osg::DegreesToRadians(_upperLeft.x()), height, ul.x(), ul.y(), ul.z()); osg::Vec3Array* verts = new osg::Vec3Array(4); (*verts)[0] = ll; (*verts)[1] = lr; (*verts)[2] = ur; (*verts)[3] = ul; geometry->setVertexArray( verts ); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0] = osg::Vec4(1,1,1,_alpha); geometry->setColorArray( colors ); geometry->setColorBinding( osg::Geometry::BIND_OVERALL ); GLuint tris[6] = { 0, 1, 2, 0, 2, 3 }; geometry->addPrimitiveSet(new osg::DrawElementsUInt( GL_TRIANGLES, 6, tris ) ); bool flip = false; if (_image.valid()) { //Create the texture osg::Texture2D* texture = new osg::Texture2D(_image.get()); texture->setResizeNonPowerOfTwoHint(false); _geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); flip = _image->getOrigin()==osg::Image::TOP_LEFT; } osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,flip ? 1.0 : 0.0f); (*texcoords)[1].set(1.0f,flip ? 1.0 : 0.0f); (*texcoords)[2].set(1.0f,flip ? 0.0 : 1.0f); (*texcoords)[3].set(0.0f,flip ? 0.0 : 1.0f); geometry->setTexCoordArray(0, texcoords); MeshSubdivider ms; ms.run(*geometry, osg::DegreesToRadians(5.0), GEOINTERP_RHUMB_LINE); _geode->removeDrawables(0, _geode->getNumDrawables() ); _geode->addDrawable( geometry ); _geometry = geometry; _dirty = false; }
void ImageOverlay::postCTOR | ( | ) | [private] |
Definition at line 36 of file ImageOverlay.cpp.
{ _geode = new osg::Geode; //addChild( _geode ); setNode( _geode ); init(); ADJUST_UPDATE_TRAV_COUNT( this, 1 ); }
void ImageOverlay::removeCallback | ( | ImageOverlayCallback * | callback | ) |
Definition at line 421 of file ImageOverlay.cpp.
{ CallbackList::iterator i = std::find( _callbacks.begin(), _callbacks.end(), cb); if (i != _callbacks.end()) { _callbacks.erase( i ); } }
void ImageOverlay::setAlpha | ( | float | alpha | ) |
void ImageOverlay::setBounds | ( | const osgEarth::Bounds & | bounds | ) |
Definition at line 231 of file ImageOverlay.cpp.
{ setCorners(osg::Vec2d(extent.xMin(), extent.yMin()), osg::Vec2d(extent.xMax(), extent.yMin()), osg::Vec2d(extent.xMin(), extent.yMax()), osg::Vec2d(extent.xMax(), extent.yMax())); }
void ImageOverlay::setBoundsAndRotation | ( | const osgEarth::Bounds & | bounds, |
const Angular & | rotation | ||
) |
Definition at line 238 of file ImageOverlay.cpp.
{ double rot_rad = rot.as(Units::RADIANS); if ( osg::equivalent( rot_rad, 0.0 ) ) { setBounds( b ); } else { osg::Vec2d ll( b.xMin(), b.yMin() ); osg::Vec2d ul( b.xMin(), b.yMax() ); osg::Vec2d ur( b.xMax(), b.yMax() ); osg::Vec2d lr( b.xMax(), b.yMin() ); double sinR = sin(-rot_rad), cosR = cos(-rot_rad); osg::Vec2d c( 0.5*(b.xMax()+b.xMin()), 0.5*(b.yMax()+b.yMin()) ); // there must be a better way, but my internet is down so i can't look it up with now.. osg::ref_ptr<SpatialReference> srs = SpatialReference::create("wgs84"); osg::ref_ptr<SpatialReference> utm = srs->createUTMFromLongitude( c.x() ); osg::Vec2d ll_utm, ul_utm, ur_utm, lr_utm, c_utm; srs->transform2D( ll.x(), ll.y(), utm.get(), ll_utm.x(), ll_utm.y() ); srs->transform2D( ul.x(), ul.y(), utm.get(), ul_utm.x(), ul_utm.y() ); srs->transform2D( ur.x(), ur.y(), utm.get(), ur_utm.x(), ur_utm.y() ); srs->transform2D( lr.x(), lr.y(), utm.get(), lr_utm.x(), lr_utm.y() ); srs->transform2D( c.x(), c.y(), utm.get(), c_utm.x(), c_utm.y() ); osg::Vec2d llp( cosR*(ll_utm.x()-c_utm.x()) - sinR*(ll_utm.y()-c_utm.y()), sinR*(ll_utm.x()-c_utm.x()) + cosR*(ll_utm.y()-c_utm.y()) ); osg::Vec2d ulp( cosR*(ul_utm.x()-c_utm.x()) - sinR*(ul_utm.y()-c_utm.y()), sinR*(ul_utm.x()-c_utm.x()) + cosR*(ul_utm.y()-c_utm.y()) ); osg::Vec2d urp( cosR*(ur_utm.x()-c_utm.x()) - sinR*(ur_utm.y()-c_utm.y()), sinR*(ur_utm.x()-c_utm.x()) + cosR*(ur_utm.y()-c_utm.y()) ); osg::Vec2d lrp( cosR*(lr_utm.x()-c_utm.x()) - sinR*(lr_utm.y()-c_utm.y()), sinR*(lr_utm.x()-c_utm.x()) + cosR*(lr_utm.y()-c_utm.y()) ); utm->transform2D( (llp+c_utm).x(), (llp+c_utm).y(), srs.get(), ll.x(), ll.y() ); utm->transform2D( (ulp+c_utm).x(), (ulp+c_utm).y(), srs.get(), ul.x(), ul.y() ); utm->transform2D( (urp+c_utm).x(), (urp+c_utm).y(), srs.get(), ur.x(), ur.y() ); utm->transform2D( (lrp+c_utm).x(), (lrp+c_utm).y(), srs.get(), lr.x(), lr.y() ); setCorners( ll, lr, ul, ur ); } }
void ImageOverlay::setCenter | ( | double | lon_deg, |
double | lat_deg | ||
) |
Definition at line 164 of file ImageOverlay.cpp.
{ osg::Vec2d center = getCenter(); osg::Vec2d newCenter(lon_deg, lat_deg); osg::Vec2d offset = newCenter - center; setCorners(_lowerLeft += offset, _lowerRight += offset, _upperLeft += offset, _upperRight += offset); }
void ImageOverlay::setControlPoint | ( | ControlPoint | controlPoint, |
double | lon_deg, | ||
double | lat_deg, | ||
bool | singleVert = false |
||
) |
Definition at line 336 of file ImageOverlay.cpp.
{ switch (controlPoint) { case CONTROLPOINT_CENTER: return setCenter(lon_deg, lat_deg); break; case CONTROLPOINT_UPPER_LEFT: if (singleVert) { setUpperLeft(lon_deg, lat_deg); } else { setNorth(lat_deg); setWest(lon_deg); } break; case CONTROLPOINT_LOWER_LEFT: if (singleVert) { setLowerLeft(lon_deg, lat_deg); } else { setSouth(lat_deg); setWest(lon_deg); } break; case CONTROLPOINT_UPPER_RIGHT: if (singleVert) { setUpperRight(lon_deg, lat_deg); } else { setNorth( lat_deg); setEast( lon_deg ); } break; case CONTROLPOINT_LOWER_RIGHT: if (singleVert) { setLowerRight(lon_deg, lat_deg); } else { setSouth( lat_deg ); setEast( lon_deg ); } break; } }
void ImageOverlay::setCorners | ( | const osg::Vec2d & | lowerLeft, |
const osg::Vec2d & | lowerRight, | ||
const osg::Vec2d & | upperLeft, | ||
const osg::Vec2d & | upperRight | ||
) |
Definition at line 208 of file ImageOverlay.cpp.
{ _lowerLeft = lowerLeft; _lowerRight = lowerRight; _upperLeft = upperLeft; _upperRight = upperRight; clampLatitudes(); dirty(); }
void ImageOverlay::setEast | ( | double | value_deg | ) |
Definition at line 192 of file ImageOverlay.cpp.
{ _upperRight.x() = value_deg; _lowerRight.x() = value_deg; dirty(); }
void ImageOverlay::setImage | ( | osg::Image * | image | ) |
Definition at line 122 of file ImageOverlay.cpp.
void ImageOverlay::setLowerLeft | ( | double | lon_deg, |
double | lat_deg | ||
) |
Definition at line 284 of file ImageOverlay.cpp.
{ _lowerLeft = osg::Vec2d(lon_deg, lat_deg); clampLatitudes(); dirty(); }
void ImageOverlay::setLowerRight | ( | double | lon_deg, |
double | lat_deg | ||
) |
Definition at line 292 of file ImageOverlay.cpp.
{ _lowerRight = osg::Vec2d(lon_deg, lat_deg); clampLatitudes(); dirty(); }
void ImageOverlay::setNorth | ( | double | value_deg | ) |
Definition at line 174 of file ImageOverlay.cpp.
{ _upperRight.y() = value_deg; _upperLeft.y() = value_deg; clampLatitudes(); dirty(); }
void ImageOverlay::setSouth | ( | double | value_deg | ) |
Definition at line 183 of file ImageOverlay.cpp.
{ _lowerRight.y() = value_deg; _lowerLeft.y() = value_deg; clampLatitudes(); dirty(); }
void ImageOverlay::setUpperLeft | ( | double | lon_deg, |
double | lat_deg | ||
) |
Definition at line 308 of file ImageOverlay.cpp.
{ _upperLeft = osg::Vec2d(lon_deg, lat_deg); clampLatitudes(); dirty(); }
void ImageOverlay::setUpperRight | ( | double | lon_deg, |
double | lat_deg | ||
) |
Definition at line 300 of file ImageOverlay.cpp.
{ _upperRight = osg::Vec2d(lon_deg, lat_deg); clampLatitudes(); dirty(); }
void ImageOverlay::setWest | ( | double | value_deg | ) |
Definition at line 200 of file ImageOverlay.cpp.
{ _lowerLeft.x() = value_deg; _upperLeft.x() = value_deg; dirty(); }
void ImageOverlay::traverse | ( | osg::NodeVisitor & | nv | ) | [virtual] |
Reimplemented from osgEarth::DrapeableNode.
Definition at line 391 of file ImageOverlay.cpp.
{ if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && _dirty) { init(); } DrapeableNode::traverse(nv); }
float osgEarth::Util::ImageOverlay::_alpha [private] |
Definition at line 97 of file ImageOverlay.
Definition at line 98 of file ImageOverlay.
bool osgEarth::Util::ImageOverlay::_dirty [private] |
Reimplemented from osgEarth::DrapeableNode.
Definition at line 93 of file ImageOverlay.
osg::Geode* osgEarth::Util::ImageOverlay::_geode [private] |
Definition at line 95 of file ImageOverlay.
osg::Geometry* osgEarth::Util::ImageOverlay::_geometry [private] |
Definition at line 96 of file ImageOverlay.
osg::ref_ptr< osg::Image > osgEarth::Util::ImageOverlay::_image [private] |
Definition at line 92 of file ImageOverlay.
osg::Vec2d osgEarth::Util::ImageOverlay::_lowerLeft [private] |
Definition at line 88 of file ImageOverlay.
osg::Vec2d osgEarth::Util::ImageOverlay::_lowerRight [private] |
Definition at line 89 of file ImageOverlay.
OpenThreads::Mutex osgEarth::Util::ImageOverlay::_mutex [private] |
Definition at line 94 of file ImageOverlay.
osg::Vec2d osgEarth::Util::ImageOverlay::_upperLeft [private] |
Definition at line 91 of file ImageOverlay.
osg::Vec2d osgEarth::Util::ImageOverlay::_upperRight [private] |
Definition at line 90 of file ImageOverlay.