OSG::Action Class Reference

Action base class. More...

#include <OSGAction.h>

Inheritance diagram for OSG::Action:

OSG::ActionBase OSG::DrawActionBase OSG::IntersectAction OSG::MixinHead< RenderTravDataSlotDesc > OSG::VRMLWriteAction OSG::RenderAction OSG::DataSlotMixin< MixinHead< RenderTravDataSlotDesc > > OSG::RenderTraversalActionBase OSG::RenderTraversalAction 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

virtual ~Action (void)
 Destructor.
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 Actioncreate (void)
 create a new action
static void setPrototype (Action *proto)
static ActiongetPrototype (void)
static void registerEnterDefault (const FieldContainerType &type, const Functor &func)
static void registerLeaveDefault (const FieldContainerType &type, const Functor &func)

Protected Member Functions

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

Static Protected Member Functions

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 Member Functions

ResultE callStart (void)
ResultE callStop (ResultE res)
Actionoperator= (const Action &source)
 assignment

Static Private Attributes

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

Friends

ActionBase::ResultE MultiCoreRenderEnter (const NodeCorePtr &pCore, Action *action)
ActionBase::ResultE MultiCoreRenderLeave (const NodeCorePtr &pCore, Action *action)

Detailed Description

The action base class.

Definition at line 85 of file OSGAction.h.


Member Typedef Documentation

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

Definition at line 101 of file OSGAction.h.

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

Action::~Action ( void   )  [virtual]

Definition at line 202 of file OSGAction.cpp.

00203 {
00204 }

Action::Action ( void   )  [protected]

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

Definition at line 172 of file OSGAction.cpp.

00172                                     :
00173     _enterFunctors(source._enterFunctors),
00174     _leaveFunctors(source._leaveFunctors),
00175     _travMask     (source._travMask     )
00176 {
00177 }


Member Function Documentation

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

Reimplemented in OSG::RenderTraversalAction, OSG::VRMLWriteAction, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 183 of file OSGAction.cpp.

References _prototype, and Action().

00184 {
00185     Action *act;
00186     
00187     if(_prototype)
00188     {
00189         act = new Action(*_prototype);
00190     }
00191     else
00192     {
00193         act = new Action();
00194     }
00195 
00196     return act;
00197 }

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

Definition at line 125 of file OSGAction.cpp.

References _prototype.

00126 {
00127     _prototype = proto;
00128 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::VRMLWriteAction, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 130 of file OSGAction.cpp.

References _prototype.

00131 {
00132     return _prototype;
00133 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 83 of file OSGAction.cpp.

References _defaultEnterFunction(), _defaultEnterFunctors, and OSG::TypeBase::getId().

00085 {
00086     if(_defaultEnterFunctors == NULL)
00087         _defaultEnterFunctors = new std::vector<Action::Functor>;
00088 
00089 #ifndef OSG_WINCE
00090     while(type.getId() >= _defaultEnterFunctors->size())
00091     {
00092         _defaultEnterFunctors->push_back(&Action::_defaultEnterFunction);
00093     }
00094 #else
00095     while(type.getId() >= _defaultEnterFunctors->size())
00096     {
00097         _defaultEnterFunctors->push_back(&NodeCore::defaultEnter);
00098     }
00099 #endif
00100     
00101     (*_defaultEnterFunctors)[type.getId()] = func;
00102 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 104 of file OSGAction.cpp.

References _defaultLeaveFunction(), _defaultLeaveFunctors, and OSG::TypeBase::getId().

00106 {
00107     if(_defaultLeaveFunctors == NULL)
00108         _defaultLeaveFunctors = new std::vector<Action::Functor>;
00109 
00110 #ifndef OSG_WINCE
00111     while(type.getId() >= _defaultLeaveFunctors->size())
00112     {
00113         _defaultLeaveFunctors->push_back(&Action::_defaultLeaveFunction);
00114     }
00115 #else
00116     while(type.getId() >= _defaultLeaveFunctors->size())
00117     {
00118         _defaultLeaveFunctors->push_back(&NodeCore::defaultLeave);
00119     }
00120 #endif
00121     
00122     (*_defaultLeaveFunctors)[type.getId()] = func;
00123 }

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

Definition at line 212 of file OSGAction.cpp.

References _defaultEnterFunction(), _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 
)

Definition at line 230 of file OSGAction.cpp.

References _defaultLeaveFunction(), _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]

Reimplemented in OSG::VRMLWriteAction.

Definition at line 252 of file OSGAction.cpp.

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

Referenced by OSG::VRMLWriteAction::apply(), 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]

Definition at line 286 of file OSGAction.cpp.

References 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]

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

Definition at line 53 of file OSGAction.inl.

References _actNode.

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

00054 {
00055     _actNode = node;
00056 }

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

Definition at line 84 of file OSGAction.inl.

References _actList, and _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]

Definition at line 59 of file OSGAction.inl.

References _actList, and _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]

void OSG::Action::useNodeList ( void   )  [inline]

UInt32 OSG::Action::getTravMask ( void   )  const [inline]

Definition at line 98 of file OSGAction.inl.

References _travMask.

Referenced by recurse().

00099 {
00100     return _travMask;
00101 }

void OSG::Action::setTravMask ( UInt32  val  )  [inline]

Definition at line 104 of file OSGAction.inl.

References _travMask.

00105 {
00106     _travMask = val;
00107 }

bool Action::operator< ( const Action other  ) 

Definition at line 480 of file OSGAction.cpp.

00481 {
00482     return this < &other;
00483 }

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

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

Definition at line 496 of file OSGAction.cpp.

00497 {
00498     return ! (*this == other);
00499 }

ActionBase::ResultE OSG::Action::callEnter ( NodeCorePtrConstArg  core  )  [inline, protected]

Definition at line 116 of file OSGAction.inl.

References _defaultEnterFunction(), _enterFunctors, getDefaultEnterFunctors(), and size.

Referenced by recurse().

00117 {
00118     ResultE result;
00119 
00120     UInt32 uiFunctorIndex = core->getType().getId();
00121 
00122     if(uiFunctorIndex < _enterFunctors.size())
00123     {
00124         result = _enterFunctors[uiFunctorIndex](core, this);
00125     }
00126     else if(getDefaultEnterFunctors() &&
00127             uiFunctorIndex < getDefaultEnterFunctors()->size())
00128     {
00129         // field container registered method after this action was instantiated
00130         // copy the new functors from default vector
00131 
00132         std::vector<Functor> *defaultEnter = getDefaultEnterFunctors();
00133 
00134         while(defaultEnter->size() > _enterFunctors.size())
00135         {
00136             _enterFunctors.push_back((*defaultEnter)[_enterFunctors.size()]);
00137         }
00138 
00139         result = _enterFunctors[uiFunctorIndex](core, this);
00140     }
00141     else // unknown field container
00142     {
00143         result = _defaultEnterFunction(core, this);
00144     }
00145 
00146     return result;
00147 }

ActionBase::ResultE OSG::Action::callLeave ( NodeCorePtrConstArg  core  )  [inline, protected]

Definition at line 150 of file OSGAction.inl.

References _defaultLeaveFunction(), _leaveFunctors, getDefaultLeaveFunctors(), and size.

Referenced by recurse().

00151 {
00152     ResultE result;
00153 
00154     UInt32 uiFunctorIndex = core->getType().getId();
00155 
00156     if(uiFunctorIndex < _leaveFunctors.size())
00157     {
00158         result = _leaveFunctors[uiFunctorIndex](core, this);
00159     }
00160     else if(getDefaultLeaveFunctors() &&
00161             uiFunctorIndex < getDefaultLeaveFunctors()->size())
00162     {
00163         // field container registered method after this action was instantiated
00164         // copy the new functors from default vector
00165 
00166         std::vector<Functor> *defaultLeave = getDefaultLeaveFunctors();
00167 
00168         while(defaultLeave->size() > _leaveFunctors.size())
00169         {
00170             _leaveFunctors.push_back((*defaultLeave)[_leaveFunctors.size()]);
00171         }
00172 
00173         result = _leaveFunctors[uiFunctorIndex](core, this);
00174     }
00175     else // unknown field container
00176     {
00177         result = _defaultLeaveFunction(core, this);
00178     }
00179 
00180     return result;
00181 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::DrawActionBase, OSG::RenderTraversalActionBase, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 452 of file OSGAction.cpp.

References OSG::ActionBase::Continue.

Referenced by callStart().

00453 {
00454     return Continue;
00455 }

ActionBase::ResultE Action::stop ( ResultE  res  )  [protected, virtual]

Reimplemented in OSG::RenderTraversalAction, OSG::DrawActionBase, OSG::RenderTraversalActionBase, and OSG::RenderAction.

Definition at line 457 of file OSGAction.cpp.

Referenced by callStop(), and OSG::RenderAction::stop().

00458 {
00459     return res;
00460 }

ActionBase::ResultE Action::recurse ( NodePtrConstArg  node  )  [protected]

Definition at line 306 of file OSGAction.cpp.

References _actList, _actNode, _newList, _useNewList, callEnter(), callLeave(), callNewList(), OSG::ActionBase::Continue, getTravMask(), NullFC, OSG::ActionBase::Quit, OSG::ActionBase::Skip, and SWARNING.

Referenced by apply(), and callNewList().

00307 {
00308     if(node == NullFC)
00309         return Continue;
00310 
00311     if((node->getTravMask() & getTravMask()) == 0)
00312         return Continue;
00313 
00314 #if OSG_1_COMPAT
00315     if(node->getOcclusionMask() & 1)
00316         return Continue;
00317 #endif
00318 
00319     NodeCorePtr core = node->getCore();
00320     
00321     if(core == NullFC)
00322     {
00323         SWARNING << "recurse: core is Null,  don't know what to do!" 
00324                  << std::endl;
00325         return Quit;                    
00326     }
00327     
00328     Action::ResultE result;
00329     
00330     _actList = NULL;
00331     _actNode = node;
00332 
00333     _newList.clear();
00334 
00335     _useNewList = false;
00336     
00337     result = callEnter(node->getCore());
00338 
00339     if(result != Continue)
00340     {
00341         if(result == Skip)
00342             return Continue;
00343     
00344         return result;
00345     }
00346     
00347     if(! _newList.empty())
00348     {
00349         result = callNewList();
00350     }
00351     else if(! _useNewList) // new list is empty, but not used?
00352     {
00353         std::vector<NodePtr>::const_iterator it;
00354 
00355         for(  it  = node->getMFChildren()->begin(); 
00356               it != node->getMFChildren()->end(); 
00357             ++it)
00358         {
00359             result = recurse(*it);
00360             
00361             if(result != Continue)
00362                 break;
00363         }
00364     }   
00365     
00366     _actNode = node;
00367 
00368     if(result == Continue)
00369     {
00370         result = callLeave(node->getCore());
00371     }
00372     else
00373     {
00374         callLeave(node->getCore());
00375     }
00376 
00377     if(result == Skip)
00378         return Continue;
00379         
00380     return result;
00381 }

ActionBase::ResultE Action::callNewList ( void   )  [protected]

Definition at line 384 of file OSGAction.cpp.

References _actList, _newList, OSG::ActionBase::Continue, and recurse().

Referenced by callStart(), callStop(), and recurse().

00385 {
00386     ResultE result = Continue;
00387 
00388     // need to make a copy, because the one in the action is cleared
00389 
00390     std::vector<NodePtr> nodeList;
00391 
00392     nodeList.swap(_newList);
00393 
00394     std::vector<NodePtr>::iterator it;
00395 
00396     _actList = &nodeList;
00397 
00398     for(it = nodeList.begin(); it != nodeList.end(); ++it)
00399     {
00400         result = recurse(*it);
00401 
00402         if(result != Continue)
00403             break;
00404     }
00405     
00406     return result;
00407 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::VRMLWriteAction, OSG::DrawActionBase, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 506 of file OSGAction.cpp.

References _defaultEnterFunctors.

Referenced by callEnter().

00507 {
00508     return _defaultEnterFunctors;
00509 }

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

Reimplemented in OSG::RenderTraversalAction, OSG::VRMLWriteAction, OSG::DrawActionBase, OSG::RenderAction, and OSG::IntersectAction.

Definition at line 511 of file OSGAction.cpp.

References _defaultLeaveFunctors.

Referenced by callLeave().

00512 {
00513     return _defaultLeaveFunctors;
00514 }

ActionBase::ResultE Action::_defaultEnterFunction ( NodeCorePtrConstArg  node,
Action action 
) [static, protected]

ActionBase::ResultE Action::_defaultLeaveFunction ( NodeCorePtrConstArg  node,
Action action 
) [static, protected]

ActionBase::ResultE Action::callStart ( void   )  [private]

Definition at line 412 of file OSGAction.cpp.

References _newList, callNewList(), OSG::ActionBase::Continue, and start().

Referenced by apply().

00413 {
00414     ResultE res = Continue;
00415     
00416     // call the start and see if it returns some nodes
00417     
00418     _newList.clear();
00419 
00420     if((res = start()) != Continue)
00421         return res;     
00422     
00423     // got some nodes? call them
00424     
00425     if(! _newList.empty())
00426         res = callNewList();
00427     
00428     // return the result
00429 
00430     return res;
00431 }

ActionBase::ResultE Action::callStop ( ResultE  res  )  [private]

Definition at line 435 of file OSGAction.cpp.

References _newList, callNewList(), OSG::ActionBase::Continue, and stop().

Referenced by apply().

00436 {
00437     // call the start and see if it returns some nodes
00438     
00439     _newList.clear();
00440 
00441     if((res = stop(res)) != Continue)
00442         return res;     
00443             
00444     if(! _newList.empty())
00445         res = callNewList();
00446 
00447     return res;
00448 }

Action & Action::operator= ( const Action source  )  [private]

Definition at line 467 of file OSGAction.cpp.

00468 {
00469     if (this == &source)
00470         return *this;
00471 
00472     return *this;
00473 }


Friends And Related Function Documentation

ActionBase::ResultE MultiCoreRenderEnter ( const NodeCorePtr &  pCore,
Action action 
) [friend]

ActionBase::ResultE MultiCoreRenderLeave ( const NodeCorePtr &  pCore,
Action action 
) [friend]


Member Data Documentation

std::vector<Functor> OSG::Action::_enterFunctors [protected]

std::vector<Functor> OSG::Action::_leaveFunctors [protected]

NodePtr OSG::Action::_actNode [protected]

Definition at line 277 of file OSGAction.h.

Referenced by getActNode(), getNNodes(), getNode(), recurse(), and setActNode().

std::vector<NodePtr>* OSG::Action::_actList [protected]

Definition at line 279 of file OSGAction.h.

Referenced by callNewList(), getNNodes(), getNode(), and recurse().