OSG::IntersectAction Class Reference

IntersectAction class. More...

#include <OSGIntersectAction.h>

Inheritance diagram for OSG::IntersectAction:

OSG::Action OSG::ActionBase List of all members.

Public Types

typedef boost::function< ResultE(NodeCorePtrConstArg, Action *)> Functor
typedef ActionBase::ResultE(NodeCore::*) Callback (Action *)
enum  ResultE { Continue, Skip, Quit }

Public Member Functions

IntersectActionoperator= (const IntersectAction &source)
virtual ~IntersectAction (void)
 Destructor.
void setLine (const Line &line, const Real32 maxdist=Inf)
const LinegetLine (void) const
 Constructor Destructor.
Real32 getMaxDist (void) const
bool didHit (void) const
Real32 getHitT (void) const
Pnt3f getHitPoint (void) const
Vec3f getHitNormal (void) const
NodePtr getHitObject (void) const
Int32 getHitTriangle (void) const
Action::ResultE setEnterLeave (Real32 enter, Real32 leave)
void setHit (Real32 t, NodePtr obj, Int32 triIndex, Vec3f &normal)
void scale (Real32 s)
bool operator< (const IntersectAction &other) const
 assignment
bool operator== (const IntersectAction &other) const
bool operator!= (const IntersectAction &other) const
 unequal
void registerEnterFunction (const FieldContainerType &type, const Functor &func)
void registerLeaveFunction (const FieldContainerType &type, const Functor &func)
virtual ResultE apply (std::vector< NodePtr >::iterator begin, std::vector< NodePtr >::iterator end)
virtual ResultE apply (NodePtrConstArg node)
NodePtr getActNode (void)
void setActNode (NodePtrConstArg node)
UInt32 getNNodes (void) const
NodePtr getNode (int index)
void addNode (NodePtrConstArg node)
void useNodeList (void)
UInt32 getTravMask (void) const
void setTravMask (UInt32 val)
bool operator< (const Action &other)
 assignment
bool operator== (const Action &other)
bool operator!= (const Action &other)
 unequal

Static Public Member Functions

static IntersectActioncreate (void)
 create a new action
static IntersectActioncreate (const Line &line, const Real32 maxdist=Inf)
 create a new action
static void setPrototype (IntersectAction *proto)
static IntersectActiongetPrototype (void)
static void registerEnterDefault (const FieldContainerType &type, const Action::Functor &func)
static void registerLeaveDefault (const FieldContainerType &type, const Action::Functor &func)
static void setPrototype (Action *proto)

Protected Member Functions

 IntersectAction (void)
 Constructor.
 IntersectAction (const IntersectAction &source)
virtual Action::ResultE start (void)
virtual std::vector< Functor > * getDefaultEnterFunctors (void)
virtual std::vector< Functor > * getDefaultLeaveFunctors (void)
ResultE callEnter (NodeCorePtrConstArg core)
ResultE callLeave (NodeCorePtrConstArg core)
virtual ResultE stop (ResultE res)
ResultE recurse (NodePtrConstArg node)
ResultE callNewList (void)

Static Protected Member Functions

static bool terminateEnter (void)
static bool terminateLeave (void)
static ResultE _defaultEnterFunction (NodeCorePtrConstArg node, Action *action)
static ResultE _defaultLeaveFunction (NodeCorePtrConstArg node, Action *action)

Protected Attributes

std::vector< Functor_enterFunctors
std::vector< Functor_leaveFunctors
NodePtr _actNode
std::vector< NodePtr > * _actList
bool _useNewList
std::vector< NodePtr > _newList
UInt32 _travMask

Private Types

typedef Action Inherited

Private Attributes

Line _line
Real32 _maxdist
bool _hit
Real32 _enterT
Real32 _leaveT
Real32 _hitT
NodePtr _hitObject
Int32 _hitTriangle
Vec3f _hitNormal

Static Private Attributes

static IntersectAction_prototype = NULL
static std::vector< Functor > * _defaultEnterFunctors = NULL
static std::vector< Functor > * _defaultLeaveFunctors = NULL

Detailed Description

The intersect action class.

Definition at line 75 of file OSGIntersectAction.h.


Member Typedef Documentation

Definition at line 217 of file OSGIntersectAction.h.

typedef boost::function<ResultE (NodeCorePtrConstArg, Action *)> OSG::Action::Functor [inherited]

Definition at line 101 of file OSGAction.h.

typedef ActionBase::ResultE(NodeCore::*) OSG::Action::Callback(Action *) [inherited]

Definition at line 103 of file OSGAction.h.


Member Enumeration Documentation

enum OSG::ActionBase::ResultE [inherited]

Enumerator:
Continue 
Skip 
Quit 

Definition at line 71 of file OSGActionBase.h.

00072     {
00073         Continue,   // continue with my children
00074         Skip,       // skip my children
00075                     // really needed? Cancel, 
00076                     // skip my brothers, go one step up
00077         Quit        // forget it, you're done
00078     };


Constructor & Destructor Documentation

IntersectAction::~IntersectAction ( void   )  [virtual]

Definition at line 254 of file OSGIntersectAction.cpp.

00255 {
00256 }

IntersectAction::IntersectAction ( void   )  [protected]

Definition at line 184 of file OSGIntersectAction.cpp.

References _defaultEnterFunctors, _defaultLeaveFunctors, OSG::Action::_enterFunctors, and OSG::Action::_leaveFunctors.

Referenced by create().

00184                                      :
00185      Inherited  (     ),
00186     _line       (     ), 
00187     _maxdist    (     ), 
00188     _hit        (false), 
00189     _enterT     (   -1), 
00190     _leaveT     (   -1), 
00191     _hitT       (   -1), 
00192     _hitObject  (     ),
00193     _hitTriangle(   -1)
00194 {
00195     if(_defaultEnterFunctors)
00196         _enterFunctors = *_defaultEnterFunctors;
00197 
00198     if(_defaultLeaveFunctors)
00199         _leaveFunctors = *_defaultLeaveFunctors;
00200 }

IntersectAction::IntersectAction ( const IntersectAction source  )  [protected]

Definition at line 203 of file OSGIntersectAction.cpp.

00203                                                               :
00204      Inherited  (source             ),
00205     _line       (source._line       ), 
00206     _maxdist    (source._maxdist    ), 
00207     _hit        (source._hit        ), 
00208     _enterT     (source._enterT     ), 
00209     _leaveT     (source._leaveT     ), 
00210     _hitT       (source._hitT       ), 
00211     _hitObject  (source._hitObject  ),
00212     _hitTriangle(source._hitTriangle)
00213 {
00214 }


Member Function Documentation

IntersectAction * IntersectAction::create ( void   )  [static]

Reimplemented from OSG::Action.

Definition at line 220 of file OSGIntersectAction.cpp.

References _prototype, and IntersectAction().

Referenced by OSG::Navigator::buttonRelease(), OSG::Navigator::getIntersectionPoint(), and OSG::WalkNavigator::WalkNavigator().

00221 {
00222     IntersectAction * act;
00223     
00224     if(_prototype)
00225         act = new IntersectAction(*_prototype);
00226     else
00227         act = new IntersectAction();
00228     
00229     return act;
00230 }

IntersectAction * IntersectAction::create ( const Line line,
const Real32  maxdist = Inf 
) [static]

Definition at line 236 of file OSGIntersectAction.cpp.

References _prototype, IntersectAction(), and setLine().

00238 {
00239     IntersectAction *act;
00240     
00241     if(_prototype)
00242         act = new IntersectAction(*_prototype);
00243     else
00244         act = new IntersectAction();
00245     
00246     act->setLine(line, maxdist);
00247 
00248     return act;
00249 }

void IntersectAction::setPrototype ( IntersectAction proto  )  [static]

Definition at line 150 of file OSGIntersectAction.cpp.

References _prototype.

00151 {
00152     _prototype = proto;
00153 }

IntersectAction * IntersectAction::getPrototype ( void   )  [static]

Reimplemented from OSG::Action.

Definition at line 155 of file OSGIntersectAction.cpp.

References _prototype.

00156 {
00157     return _prototype;
00158 }

IntersectAction& OSG::IntersectAction::operator= ( const IntersectAction source  ) 

void IntersectAction::setLine ( const Line line,
const Real32  maxdist = Inf 
)

const Line & OSG::IntersectAction::getLine ( void   )  const [inline]

Real32 OSG::IntersectAction::getMaxDist ( void   )  const [inline]

bool OSG::IntersectAction::didHit ( void   )  const [inline]

Real32 OSG::IntersectAction::getHitT ( void   )  const [inline]

Definition at line 114 of file OSGIntersectAction.inl.

References _hitT, and didHit().

Referenced by OSG::WalkNavigator::forward(), getHitPoint(), and OSG::WalkNavigator::right().

00115 {
00116     if(! didHit())
00117         return -1;
00118 
00119     return _hitT;
00120 }

Pnt3f OSG::IntersectAction::getHitPoint ( void   )  const [inline]

Definition at line 123 of file OSGIntersectAction.inl.

References _line, didHit(), OSG::Line::getDirection(), getHitT(), OSG::Line::getPosition(), and OSG::PointInterface< ValueTypeT, StorageInterfaceT >::Null.

Referenced by OSG::Navigator::buttonRelease(), and OSG::Navigator::getIntersectionPoint().

00124 {
00125     if(! didHit())
00126         return Pnt3f::Null;
00127     
00128     Pnt3f res;
00129 
00130     res = _line.getPosition() + getHitT() * _line.getDirection();
00131 
00132     return res;
00133 }

Vec3f OSG::IntersectAction::getHitNormal ( void   )  const [inline]

Definition at line 136 of file OSGIntersectAction.inl.

References _hitNormal, didHit(), and OSG::VectorInterface< ValueTypeT, StorageInterfaceT >::Null.

00137 {
00138     if(! didHit())
00139         return Vec3f::Null;
00140     
00141     return _hitNormal;
00142 }

NodePtr OSG::IntersectAction::getHitObject ( void   )  const [inline]

Definition at line 145 of file OSGIntersectAction.inl.

References _hitObject, didHit(), and NullFC.

00146 {
00147     if(! didHit())
00148         return NullFC;
00149 
00150     return _hitObject;
00151 }

Int32 OSG::IntersectAction::getHitTriangle ( void   )  const [inline]

Definition at line 154 of file OSGIntersectAction.inl.

References _hitTriangle, and didHit().

00155 {
00156     if(! didHit())
00157         return -1;
00158 
00159     return _hitTriangle;
00160 }

Action::ResultE IntersectAction::setEnterLeave ( Real32  enter,
Real32  leave 
)

Definition at line 268 of file OSGIntersectAction.cpp.

References _hit, _hitT, _maxdist, OSG::ActionBase::Continue, and OSG::ActionBase::Skip.

00269 {
00270     if(leave < 0 || enter > _maxdist ||
00271        ( _hit && enter > _hitT ))
00272     {
00273         return Action::Skip;
00274     }
00275 
00276     return Action::Continue;
00277 }

void IntersectAction::setHit ( Real32  t,
NodePtr  obj,
Int32  triIndex,
Vec3f normal 
)

Definition at line 279 of file OSGIntersectAction.cpp.

References _hit, _hitNormal, _hitObject, _hitT, _hitTriangle, and _maxdist.

Referenced by OSG::Geometry::intersect().

00283 {
00284     if(t < 0 || t > _hitT || t > _maxdist)
00285         return;
00286         
00287     _hitT        = t;
00288     _hitObject   = obj;
00289     _hitTriangle = triIndex;
00290     _hitNormal   = normal;
00291     _hit         = true;
00292 }

void IntersectAction::scale ( Real32  s  ) 

bool IntersectAction::operator< ( const IntersectAction other  )  const

Definition at line 321 of file OSGIntersectAction.cpp.

00322 {
00323     return this < &other;
00324 }

bool OSG::IntersectAction::operator== ( const IntersectAction other  )  const

bool IntersectAction::operator!= ( const IntersectAction other  )  const

Definition at line 338 of file OSGIntersectAction.cpp.

00339 {
00340     return ! (*this == other);
00341 }

void IntersectAction::registerEnterDefault ( const FieldContainerType type,
const Action::Functor func 
) [static]

void IntersectAction::registerLeaveDefault ( const FieldContainerType type,
const Action::Functor func 
) [static]

bool IntersectAction::terminateEnter ( void   )  [static, protected]

Definition at line 86 of file OSGIntersectAction.cpp.

References _defaultEnterFunctors, and FDEBUG_GV.

Referenced by registerEnterDefault().

00087 {
00088     FDEBUG_GV(("Terminate IntersectAction Enter\n"));
00089 
00090     delete _defaultEnterFunctors;
00091 
00092     _defaultEnterFunctors = NULL;
00093 
00094     return true;
00095 }

bool IntersectAction::terminateLeave ( void   )  [static, protected]

Definition at line 97 of file OSGIntersectAction.cpp.

References _defaultLeaveFunctors, and FDEBUG_GV.

Referenced by registerLeaveDefault().

00098 {
00099     FDEBUG_GV(("Terminate IntersectAction Leave\n"));
00100 
00101     delete _defaultLeaveFunctors;
00102 
00103     _defaultLeaveFunctors = NULL;
00104 
00105     return true;
00106 }

Action::ResultE IntersectAction::start ( void   )  [protected, virtual]

Reimplemented from OSG::Action.

Definition at line 303 of file OSGIntersectAction.cpp.

References _hit, _hitObject, _hitT, _hitTriangle, OSG::ActionBase::Continue, OSG::Inf, and NullFC.

00304 {
00305     _hitT        = Inf;
00306     _hitObject   = NullFC;
00307     _hitTriangle = -1;
00308     _hit         = false;
00309 
00310     return Continue;
00311 }

std::vector< IntersectAction::Functor > * IntersectAction::getDefaultEnterFunctors ( void   )  [protected, virtual]

Reimplemented from OSG::Action.

Definition at line 350 of file OSGIntersectAction.cpp.

References _defaultEnterFunctors.

00351 {
00352     return _defaultEnterFunctors;
00353 }

std::vector< IntersectAction::Functor > * IntersectAction::getDefaultLeaveFunctors ( void   )  [protected, virtual]

Reimplemented from OSG::Action.

Definition at line 356 of file OSGIntersectAction.cpp.

References _defaultLeaveFunctors.

00357 {
00358     return _defaultLeaveFunctors;
00359 }

void Action::setPrototype ( Action proto  )  [static, inherited]

Definition at line 125 of file OSGAction.cpp.

References OSG::Action::_prototype.

00126 {
00127     _prototype = proto;
00128 }

void Action::registerEnterFunction ( const FieldContainerType type,
const Functor func 
) [inherited]

Definition at line 212 of file OSGAction.cpp.

References OSG::Action::_defaultEnterFunction(), OSG::Action::_enterFunctors, and OSG::TypeBase::getId().

00214 {
00215 #ifndef OSG_WINCE
00216     while(type.getId() >= _enterFunctors.size())
00217     {
00218         _enterFunctors.push_back(&Action::_defaultEnterFunction);
00219     }
00220 #else
00221     while(type.getId() >= _enterFunctors.size())
00222     {
00223         _enterFunctors.push_back(&NodeCore::defaultEnter);
00224     }
00225 #endif
00226     
00227     _enterFunctors[type.getId()] = func;
00228 }

void Action::registerLeaveFunction ( const FieldContainerType type,
const Functor func 
) [inherited]

Definition at line 230 of file OSGAction.cpp.

References OSG::Action::_defaultLeaveFunction(), OSG::Action::_leaveFunctors, and OSG::TypeBase::getId().

00232 {
00233 #ifndef OSG_WINCE
00234     while(type.getId() >= _leaveFunctors.size())
00235     {
00236         _leaveFunctors.push_back(&Action::_defaultLeaveFunction);
00237     }
00238 #else
00239     while(type.getId() >= _leaveFunctors.size())
00240     {
00241         _leaveFunctors.push_back(&NodeCore::defaultLeave);
00242     }
00243 #endif
00244     
00245     _leaveFunctors[type.getId()] = func;
00246 }

ActionBase::ResultE Action::apply ( std::vector< NodePtr >::iterator  begin,
std::vector< NodePtr >::iterator  end 
) [virtual, inherited]

Reimplemented in OSG::VRMLWriteAction.

Definition at line 252 of file OSGAction.cpp.

References OSG::Action::callStart(), OSG::Action::callStop(), OSG::ActionBase::Continue, NullFC, OSG::ActionBase::Quit, OSG::Action::recurse(), and SWARNING.

Referenced by OSG::VRMLWriteAction::apply(), OSG::Action::apply(), OSG::Navigator::buttonRelease(), OSG::WalkNavigator::forward(), OSG::Navigator::getIntersectionPoint(), OSG::WalkNavigator::right(), and OSG::VRMLWriteAction::write().

00254 {
00255     Action::ResultE res = Continue;
00256     
00257     // call the start function and its' returns
00258 
00259     if((res = callStart()) != Continue)
00260         return res;     
00261     
00262     // call the given nodes
00263     
00264     for(; begin != end; ++begin)
00265     {
00266         if(*begin == NullFC)
00267         {
00268             SWARNING << "apply: encountered NullNode!" << std::endl;
00269             return Quit;            
00270         }
00271         else
00272         {
00273             res = recurse(*begin);
00274             
00275             if(res != Continue)
00276                 break;
00277         }
00278     }
00279         
00280     // call the stop function and its' returns
00281     res = callStop(res);  
00282     
00283     return res;
00284 }

ActionBase::ResultE Action::apply ( NodePtrConstArg  node  )  [virtual, inherited]

Definition at line 286 of file OSGAction.cpp.

References OSG::Action::apply(), NullFC, OSG::ActionBase::Quit, and SWARNING.

00287 {
00288     if(node == NullFC)
00289     {
00290         SWARNING << "apply: node is Null!" << std::endl;
00291         return Quit;            
00292     }
00293 
00294     std::vector<NodePtr> nodeList;
00295 
00296     nodeList.push_back(node);
00297 
00298     return apply(nodeList.begin(), nodeList.end());
00299 }

NodePtr OSG::Action::getActNode ( void   )  [inline, inherited]

void OSG::Action::setActNode ( NodePtrConstArg  node  )  [inline, inherited]

Definition at line 53 of file OSGAction.inl.

References OSG::Action::_actNode.

Referenced by OSG::RenderAction::draw().

00054 {
00055     _actNode = node;
00056 }

UInt32 OSG::Action::getNNodes ( void   )  const [inline, inherited]

Definition at line 84 of file OSGAction.inl.

References OSG::Action::_actList, and OSG::Action::_actNode.

Referenced by OSG::Switch::intersect(), OSG::Switch::render(), OSG::DistanceLOD::render(), OSG::ScreenLOD::renderEnter(), and OSG::DrawActionBase::selectVisibles().

00085 {
00086     if(_actList == NULL)
00087     {
00088         return _actNode->getNChildren();
00089     }
00090     else
00091     {
00092         return (*_actList).size();
00093     }
00094 }

NodePtr OSG::Action::getNode ( int  index  )  [inline, inherited]

Definition at line 59 of file OSGAction.inl.

References OSG::Action::_actList, and OSG::Action::_actNode.

Referenced by OSG::Switch::intersect(), OSG::Switch::render(), OSG::DistanceLOD::render(), OSG::ScreenLOD::renderEnter(), and OSG::DrawActionBase::selectVisibles().

00060 {
00061     if(_actList == NULL)
00062     {
00063         return _actNode->getChild(index);
00064     }
00065     else
00066     {
00067         return (*_actList)[index];
00068     }
00069 }

void OSG::Action::addNode ( NodePtrConstArg  node  )  [inline, inherited]

Definition at line 72 of file OSGAction.inl.

References OSG::Action::_newList.

Referenced by OSG::Switch::intersect(),