osgEarth 2.1.1
Public Types | Public Member Functions | Private Attributes

osgEarth::Util::ObjectLocator Class Reference

Inheritance diagram for osgEarth::Util::ObjectLocator:
Collaboration diagram for osgEarth::Util::ObjectLocator:

List of all members.

Public Types

enum  Components {
  COMP_NONE = 0x00, COMP_POSITION = 0x01, COMP_HEADING = 0x02, COMP_PITCH = 0x04,
  COMP_ROLL = 0x08, COMP_ORIENTATION = COMP_HEADING | COMP_PITCH | COMP_ROLL, COMP_ALL = COMP_POSITION | COMP_ORIENTATION
}
enum  RotationOrder { HPR, RPH }

Public Member Functions

 ObjectLocator (const osgEarth::Map *map)
 ObjectLocator (ObjectLocator *parent, unsigned int compsToInherit=COMP_ALL)
void setPosition (const osg::Vec3d &pos)
const osg::Vec3d & getPosition () const
void setOrientation (const osg::Vec3d &hpr_deg)
const osg::Vec3d & getOrientation () const
void setTime (double t)
double getTime () const
void setRotationOrder (RotationOrder value)
RotationOrder getRotationOrder () const
void setParentLocator (ObjectLocator *parent, unsigned int componentsToInherit=COMP_ALL)
ObjectLocatorgetParentLocator ()
const ObjectLocatorgetParentLocator () const
void setComponentsToInherit (unsigned int compMask)
unsigned int getComponentsToInherit () const
const MapgetMap () const
bool isEmpty () const
bool isValid () const
bool getLocatorPosition (osg::Vec3d &output) const
bool getPositionMatrix (osg::Matrixd &output) const
bool getLocatorOrientation (osg::Vec3d &output) const
bool getOrientationMatrix (osg::Matrixd &output, unsigned inherit=COMP_ALL) const
bool getLocatorMatrix (osg::Matrixd &output, unsigned components=COMP_ALL) const
virtual bool inSyncWith (int exRev) const

Private Attributes

osg::observer_ptr< const
osgEarth::Map
_map
osg::ref_ptr< ObjectLocator_parentLoc
unsigned int _componentsToInherit
RotationOrder _rotOrder
osg::Vec3d _pos
osg::Vec3d _hpr
double _timestamp
bool _isEmpty

Detailed Description

ObjectLocator - a revisioned object that generates a positional matrix for a node.

Definition at line 16 of file ObjectLocator.


Member Enumeration Documentation

Flags that represent separable location components.

Enumerator:
COMP_NONE 
COMP_POSITION 
COMP_HEADING 
COMP_PITCH 
COMP_ROLL 
COMP_ORIENTATION 
COMP_ALL 

Definition at line 21 of file ObjectLocator.

The order in which rotation are calculated

Enumerator:
HPR 
RPH 

Definition at line 32 of file ObjectLocator.

                           {
            HPR,
            RPH
        };

Constructor & Destructor Documentation

ObjectLocator::ObjectLocator ( const osgEarth::Map map)

Constructs a new locator that will generate positional matricies based on the specified SRS and rotation order.

Definition at line 34 of file ObjectLocator.cpp.

                                                   :
_map                ( map ),
_componentsToInherit( COMP_ALL ),
_timestamp          ( 0.0 ),
_isEmpty            ( true ),
_rotOrder           ( HPR )
{
    if ( !_map.valid() )
        OE_WARN << LC << "Illegal: cannot create an ObjectLocator with a NULL Map." << std::endl;
}
ObjectLocator::ObjectLocator ( ObjectLocator parent,
unsigned int  compsToInherit = COMP_ALL 
)

Constucts a new relative locator that inherits the mask of specified components from a parent locator.

Definition at line 45 of file ObjectLocator.cpp.

                                                                                :
_timestamp( 0.0 ),
_isEmpty  ( false ),
_rotOrder ( HPR )
{
    setParentLocator( parentLoc, inheritMask );
    _map = parentLoc->_map.get();
}

Here is the call graph for this function:


Member Function Documentation

unsigned int osgEarth::Util::ObjectLocator::getComponentsToInherit ( ) const [inline]

Definition at line 89 of file ObjectLocator.

bool ObjectLocator::getLocatorMatrix ( osg::Matrixd &  output,
unsigned  components = COMP_ALL 
) const

Gets a matrix that can be used to position and orient an object corresponding to this locator, returning true upon success.

Definition at line 203 of file ObjectLocator.cpp.

{
    bool ok = true;
    osg::Matrixd pos, rot;

    if ( comps & COMP_POSITION )
        if ( !getPositionMatrix(pos) )
            ok = false;

    if ( comps & COMP_ORIENTATION )
        if ( !getOrientationMatrix(rot, comps) )
            ok = false;

    output = rot * pos;
    return ok;
}

Here is the call graph for this function:

bool ObjectLocator::getLocatorOrientation ( osg::Vec3d &  output) const

Gets the aggregate orientation (HPR degrees) represented by this locator, returning true upon success.

Definition at line 143 of file ObjectLocator.cpp.

{
    if ( !isValid() )
        return false;

    output = _hpr;

    if ( _parentLoc.valid() && (_componentsToInherit & COMP_ORIENTATION) != 0 )
    {
        osg::Vec3d parentHPR;
        _parentLoc->getLocatorOrientation( parentHPR );
        output += parentHPR;
    }

    return true;
}

Here is the call graph for this function:

bool ObjectLocator::getLocatorPosition ( osg::Vec3d &  output) const

Gets the aggregate position represented by this locator, returning true upon success.

Definition at line 102 of file ObjectLocator.cpp.

{
    if ( !isValid() )
        return false;

    output = _pos;

    if ( _parentLoc.valid() && (_componentsToInherit & COMP_POSITION) != 0 )
    {
        osg::Vec3d parentPos;
        _parentLoc->getLocatorPosition( parentPos );
        output += parentPos;
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const Map* osgEarth::Util::ObjectLocator::getMap ( ) const [inline]

Gets the map associated with this locator.

Definition at line 92 of file ObjectLocator.

{ return _map.get(); }
const osg::Vec3d& osgEarth::Util::ObjectLocator::getOrientation ( ) const [inline]

Definition at line 63 of file ObjectLocator.

{ return _hpr; }
bool ObjectLocator::getOrientationMatrix ( osg::Matrixd &  output,
unsigned  inherit = COMP_ALL 
) const

Gets the aggregate orientation matrix for this locator, returning true upon success.

Definition at line 161 of file ObjectLocator.cpp.

{
    if ( !isValid() )
        return false;

    if ( (inherit & COMP_ORIENTATION) == 0 )
        return true;

    if ( _hpr[0] != 0.0 || _hpr[1] != 0.0 || _hpr[2] != 0.0 )
    {
        // first figure out the orientation
        osg::Quat azim_q;
        if ( inherit & COMP_HEADING )
            azim_q = osg::Quat( osg::DegreesToRadians(_hpr[0]), osg::Vec3d(0,0,1) );

        osg::Quat pitch_q;
        if ( inherit & COMP_PITCH )
            pitch_q = osg::Quat( -osg::DegreesToRadians(_hpr[1]), osg::Vec3d(1,0,0) );

        osg::Quat roll_q;
        if ( inherit & COMP_ROLL )
            roll_q = osg::Quat( osg::DegreesToRadians(_hpr[2]), osg::Vec3d(0,1,0) );

        // these look backwards, but it's actually a fast way to avoid inverting a matrix
        if ( _rotOrder == HPR )
            output.set( roll_q.conj() * pitch_q.conj() * azim_q.conj() );
        else if ( _rotOrder == RPH )
            output.set( azim_q.conj() * pitch_q.conj() * roll_q.conj() );

    }

    if ( _parentLoc.valid() && (_componentsToInherit * COMP_ORIENTATION) != 0 )
    {
        osg::Matrixd parentRot;
        if ( _parentLoc->getOrientationMatrix(parentRot, _componentsToInherit) )
            output = output * parentRot;
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ObjectLocator* osgEarth::Util::ObjectLocator::getParentLocator ( ) [inline]

Definition at line 84 of file ObjectLocator.

{ return _parentLoc.get(); }
const ObjectLocator* osgEarth::Util::ObjectLocator::getParentLocator ( ) const [inline]

Definition at line 85 of file ObjectLocator.

{ return _parentLoc.get(); }
const osg::Vec3d& osgEarth::Util::ObjectLocator::getPosition ( ) const [inline]

Definition at line 56 of file ObjectLocator.

{ return _pos; }
bool ObjectLocator::getPositionMatrix ( osg::Matrixd &  output) const

Gets the aggregate positioning matrix for this locator, returning true upon success.

Definition at line 120 of file ObjectLocator.cpp.

{
    osg::Vec3d pos;
    if ( !getLocatorPosition(pos) )
        return false;

    if ( _map->isGeocentric() )
    {
        _map->getProfile()->getSRS()->getEllipsoid()->computeLocalToWorldTransformFromLatLongHeight(
            osg::DegreesToRadians(pos.y()),
            osg::DegreesToRadians(pos.x()),
            pos.z(),
            output );
    }
    else
    {
        output.makeTranslate(pos);
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

RotationOrder osgEarth::Util::ObjectLocator::getRotationOrder ( ) const [inline]

Definition at line 76 of file ObjectLocator.

{ return _rotOrder; }
double osgEarth::Util::ObjectLocator::getTime ( ) const [inline]

Definition at line 70 of file ObjectLocator.

{ return _timestamp; }
bool ObjectLocator::inSyncWith ( int  exRev) const [virtual]

Override Revisioned::inSync to track with the parent locator's revision.

Definition at line 221 of file ObjectLocator.cpp.

{
    return _parentLoc.valid() ? _parentLoc->inSyncWith( exRev ) :
        osgEarth::Revisioned<osg::Referenced>::inSyncWith( exRev );
}
bool ObjectLocator::isEmpty ( ) const

Whether the locator contains a valid position/orientation.

Definition at line 55 of file ObjectLocator.cpp.

{
    return _parentLoc.valid() ? _parentLoc->isEmpty() : _isEmpty;
}
bool osgEarth::Util::ObjectLocator::isValid ( ) const [inline]

Whether this location contains valid data

Definition at line 98 of file ObjectLocator.

{ return !_isEmpty && _map.valid(); }

Here is the caller graph for this function:

void osgEarth::Util::ObjectLocator::setComponentsToInherit ( unsigned int  compMask)

Policy for inheriting parent locator's components

void ObjectLocator::setOrientation ( const osg::Vec3d &  hpr_deg)

Sets the absolute OR relative orientation of this locator (depending on whether this locator has a parent). Units are Euler angle degrees.

Definition at line 94 of file ObjectLocator.cpp.

{
    _hpr = hpr;
    _isEmpty = false;
    dirty();
}

Here is the call graph for this function:

void ObjectLocator::setParentLocator ( ObjectLocator parent,
unsigned int  componentsToInherit = COMP_ALL 
)

The optional parent locator. If a Locator has a parent, it inherits position and orientation from that parent as prescribed by the Components flags. Otherwise, the Locator is absolute.

Definition at line 61 of file ObjectLocator.cpp.

{
    if ( newParent == this )
    {
        OE_WARN << LC << "Illegal state, locator cannot be its own parent." << std::endl;
        return;
    }

    _parentLoc = newParent;
    _componentsToInherit = inheritMask;

    if ( newParent )
    {
        _map = newParent->_map.get();
    }

    if ( !_map.valid() )
    {
        OE_WARN << "Illegal state, cannot create a Locator with a NULL srs" << std::endl;
    }

    dirty();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ObjectLocator::setPosition ( const osg::Vec3d &  pos)

Sets the absolute OR relative positioning of this locator (depending on whether this locator has a parent). Units conform to this Locator's SRS.

Definition at line 86 of file ObjectLocator.cpp.

{
    _pos = pos;
    _isEmpty = false;
    dirty();
}

Here is the call graph for this function:

void osgEarth::Util::ObjectLocator::setRotationOrder ( RotationOrder  value) [inline]

The order in which to calculate heading, pitch, and roll rotations

Definition at line 75 of file ObjectLocator.

{ _rotOrder = value; }
void osgEarth::Util::ObjectLocator::setTime ( double  t) [inline]

The timestamp associated with this locator's position information. (Note: setting the time does not "dirty" the locator)

Definition at line 69 of file ObjectLocator.

{ _timestamp = t; }

Member Data Documentation

Definition at line 140 of file ObjectLocator.

Definition at line 143 of file ObjectLocator.

Definition at line 145 of file ObjectLocator.

osg::observer_ptr<const osgEarth::Map> osgEarth::Util::ObjectLocator::_map [private]

Definition at line 138 of file ObjectLocator.

Definition at line 139 of file ObjectLocator.

Definition at line 142 of file ObjectLocator.

Definition at line 141 of file ObjectLocator.

Definition at line 144 of file ObjectLocator.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines