OSG::DrawActionBase Class Reference

#include <OSGDrawActionBase.h>

Inheritance diagram for OSG::DrawActionBase:

OSG::Action OSG::ActionBase OSG::RenderAction 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 ~DrawActionBase (void)
 Destructor.
ViewportgetViewport (void) const
void setViewport (Viewport *viewport)
CameragetCamera (void) const
void setCamera (Camera *cam)
const MatrixrgetCameraToWorld (void)
BackgroundgetBackground (void) const
void setBackground (Background *background)
WindowgetWindow (void) const
void setWindow (Window *window)
StatCollectorgetStatCollector (void)
void setStatCollector (StatCollector *stat)
bool getFrustumCulling (void) const
void setFrustumCulling (bool val=true)
bool getVolumeDrawing (void) const
void setVolumeDrawing (bool val=false)
bool getAutoFrustum (void) const
void setAutoFrustum (bool val=true)
const FrustumVolumegetFrustum (void) const
void setFrustum (FrustumVolume &frust)
DrawEnvgetDrawEnv (void) const
virtual bool isVisible (Node *node)=0
UInt32 selectVisibles (void)
MaterialgetMaterial (void) const
NodePtr getMaterialNode (void) const
void setMaterial (Material *pMaterial, NodePtr node)
virtual ActionBase::ResultE start (void)
virtual ActionBase::ResultE stop (ActionBase::ResultE res)
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)

Static Public Attributes

static StatElemDesc< StatTimeElemstatTravTime
static StatElemDesc< StatIntElemstatCullTestedNodes
static StatElemDesc< StatIntElemstatCulledNodes

Protected Member Functions

 DrawActionBase (void)
 Constructor.
 DrawActionBase (const DrawActionBase &source)
void operator= (const DrawActionBase &source)
virtual std::vector< Functor > * getDefaultEnterFunctors (void)=0
virtual std::vector< Functor > * getDefaultLeaveFunctors (void)=0
ResultE callEnter (NodeCorePtrConstArg core)
ResultE callLeave (NodeCorePtrConstArg core)
ResultE recurse (NodePtrConstArg node)
ResultE callNewList (void)

Static Protected Member Functions

static ResultE _defaultEnterFunction (NodeCorePtrConstArg node, Action *action)
static ResultE _defaultLeaveFunction (NodeCorePtrConstArg node, Action *action)

Protected Attributes

Camera_camera
Background_background
Window_window
Viewport_viewport
StatCollector_statistics
bool _frustumCulling
bool _volumeDrawing
bool _autoFrustum
FrustumVolume _frustum
Material_pMaterial
NodePtr _pMaterialNode
Matrixr _mCameraToWorld
DrawEnv_pDrawEnv
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

Detailed Description

The base class for all rendering-related actions.

Definition at line 77 of file OSGDrawActionBase.h.


Member Typedef Documentation

Reimplemented in OSG::RenderAction.

Definition at line 234 of file OSGDrawActionBase.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

DrawActionBase::~DrawActionBase ( void   )  [virtual]

Definition at line 164 of file OSGDrawActionBase.cpp.

References _pDrawEnv, _statistics, and OSG::subRef().

00165 {
00166     delete _pDrawEnv;
00167 
00168     OSG::subRef(_statistics);
00169 }

DrawActionBase::DrawActionBase ( void   )  [protected]

Definition at line 121 of file OSGDrawActionBase.cpp.

References _pDrawEnv.

00121                                    :
00122      Inherited     (      ),
00123     _camera        (NULL  ),
00124     _background    (NULL  ),
00125     _window        (NULL  ),
00126     _viewport      (NULL  ),
00127     _statistics    (NULL  ),
00128     _frustumCulling(true  ),
00129     _volumeDrawing (false ),
00130     _autoFrustum   (true  ),
00131     _frustum       (      ),
00132     _pMaterial     (NULL  ),
00133     _pMaterialNode (NullFC),
00134     _mCameraToWorld(      ),
00135     _pDrawEnv      (NULL  )
00136 {
00137     _pDrawEnv = new DrawEnv;
00138 }

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

Definition at line 141 of file OSGDrawActionBase.cpp.

References _pDrawEnv, _statistics, and OSG::setRefd().

00141                                                            :
00142      Inherited     (source                 ),
00143     _camera        (source._camera         ),
00144     _background    (source._background     ),
00145     _window        (source._window         ),
00146     _viewport      (source._viewport       ),
00147     _frustumCulling(source._frustumCulling ),
00148     _volumeDrawing (source._volumeDrawing  ),
00149     _autoFrustum   (source._autoFrustum    ),
00150     _frustum       (source._frustum        ),
00151     _pMaterial     (source._pMaterial      ),
00152     _pMaterialNode (source._pMaterialNode  ),
00153     _mCameraToWorld(source._mCameraToWorld ),
00154     _pDrawEnv      (NULL                   )
00155 {
00156     _pDrawEnv = new DrawEnv;
00157 
00158     OSG::setRefd(_statistics, source._statistics);
00159 }


Member Function Documentation

Viewport * OSG::DrawActionBase::getViewport ( void   )  const [inline]

Definition at line 112 of file OSGDrawActionBase.inl.

References _viewport.

Referenced by OSG::RenderAction::deleteOcclusionQueriesPool(), and start().

00113 {
00114     return _viewport;
00115 }

void DrawActionBase::setViewport ( Viewport viewport  ) 

Definition at line 258 of file OSGDrawActionBase.cpp.

References _viewport.

00259 {
00260     _viewport = viewport;
00261 }

Camera * OSG::DrawActionBase::getCamera ( void   )  const [inline]

Definition at line 88 of file OSGDrawActionBase.inl.

References _camera.

Referenced by start().

00089 {
00090     return _camera;
00091 }

void DrawActionBase::setCamera ( Camera cam  ) 

Definition at line 263 of file OSGDrawActionBase.cpp.

References _camera.

00264 {
00265     _camera = cam;
00266 }

const Matrixr & OSG::DrawActionBase::getCameraToWorld ( void   )  [inline]

Background * OSG::DrawActionBase::getBackground ( void   )  const [inline]

Definition at line 100 of file OSGDrawActionBase.inl.

References _background.

00101 {
00102     return _background;
00103 }

void DrawActionBase::setBackground ( Background background  ) 

Definition at line 268 of file OSGDrawActionBase.cpp.

References _background.

00269 {
00270     _background = background;
00271 }

Window * OSG::DrawActionBase::getWindow ( void   )  const [inline]

Definition at line 106 of file OSGDrawActionBase.inl.

References _window.

Referenced by OSG::FBOViewport::render().

00107 {
00108     return _window;
00109 }

void DrawActionBase::setWindow ( Window window  ) 

StatCollector * OSG::DrawActionBase::getStatCollector ( void   )  [inline]

Definition at line 142 of file OSGDrawActionBase.inl.

References _statistics.

Referenced by OSG::SpotLight::renderEnter(), OSG::PointLight::renderEnter(), and OSG::DirectionalLight::renderEnter().

00143 {
00144     return _statistics;
00145 }

void DrawActionBase::setStatCollector ( StatCollector stat  ) 

Definition at line 278 of file OSGDrawActionBase.cpp.

References _statistics, and OSG::setRefd().

Referenced by OSG::SimpleSceneManager::setStatistics().

00279 {
00280 #if 0 // Altered for last frame time
00281     OSG::setRefd(_statistics, statistics);
00282     _ownStat    = false;
00283 #else
00284     OSG::setRefd(_statistics, statistics);
00285 #endif
00286 }

bool OSG::DrawActionBase::getFrustumCulling ( void   )  const [inline]

void DrawActionBase::setFrustumCulling ( bool  val = true  ) 

Definition at line 292 of file OSGDrawActionBase.cpp.

References _frustumCulling.

Referenced by OSG::RenderOptions::activateOptions(), and OSG::BalancedMultiWindow::renderViewport().

00293 {
00294     _frustumCulling = frustumCulling;
00295 }

bool OSG::DrawActionBase::getVolumeDrawing ( void   )  const [inline]

Definition at line 124 of file OSGDrawActionBase.inl.

References _volumeDrawing.

Referenced by OSG::RenderAction::pushVisibility(), selectVisibles(), and OSG::RenderAction::stop().

00125 {
00126     return _volumeDrawing;
00127 }

void DrawActionBase::setVolumeDrawing ( bool  val = false  ) 

Definition at line 308 of file OSGDrawActionBase.cpp.

References _volumeDrawing.

00309 {
00310     _volumeDrawing = volumeDrawing;
00311 }

bool OSG::DrawActionBase::getAutoFrustum ( void   )  const [inline]

Definition at line 130 of file OSGDrawActionBase.inl.

References _autoFrustum.

Referenced by start().

00131 {
00132     return _autoFrustum;
00133 }

void DrawActionBase::setAutoFrustum ( bool  val = true  ) 

Definition at line 300 of file OSGDrawActionBase.cpp.

References _autoFrustum.

00301 {
00302     _autoFrustum = autoFrustum;
00303 }

const FrustumVolume & OSG::DrawActionBase::getFrustum ( void   )  const [inline]

Definition at line 136 of file OSGDrawActionBase.inl.

References _frustum.

Referenced by OSG::TiledQuadTreeTerrain::renderEnter(), and OSG::QuadTreeTerrain::renderEnter().

00137 {
00138     return _frustum;
00139 }

void DrawActionBase::setFrustum ( FrustumVolume frust  ) 

Definition at line 315 of file OSGDrawActionBase.cpp.

References _frustum.

00316 {
00317     _frustum = frustum;
00318 }

DrawEnv * OSG::DrawActionBase::getDrawEnv ( void   )  const [inline]

Definition at line 160 of file OSGDrawActionBase.inl.

References _pDrawEnv.

Referenced by OSG::ScreenLOD::renderEnter().

00161 {
00162     return _pDrawEnv;
00163 }

virtual bool OSG::DrawActionBase::isVisible ( Node node  )  [pure virtual]

UInt32 DrawActionBase::selectVisibles ( void   ) 

Definition at line 321 of file OSGDrawActionBase.cpp.

References OSG::Action::addNode(), OSG::dropVolume(), OSG::getCPtr(), getFrustumCulling(), OSG::Action::getNNodes(), OSG::Action::getNode(), getVolumeDrawing(), isVisible(), OSG::Color3< ValueTypeT >::setValuesRGB(), and OSG::Action::useNodeList().

Referenced by OSG::Switch::render().

00322 {
00323     if(getFrustumCulling() == false)
00324         return getNNodes();
00325 
00326     useNodeList();
00327 
00328     Color3r col;
00329     
00330     UInt32 count = 0;
00331 
00332     for(UInt32 i = 0; i < getNNodes(); i++)
00333     {
00334         if(isVisible(getCPtr(getNode(i))))
00335         {
00336             col.setValuesRGB(0.f,1.f,0.f);
00337 
00338             addNode(getNode(i));
00339 
00340             ++count;
00341         }
00342         else
00343         {
00344             col.setValuesRGB(1.f,0.f,0.f);
00345         }
00346 
00347         if(getVolumeDrawing())
00348         {
00349             dropVolume(this, getNode(i), col);
00350         }
00351     }
00352 
00353     return count;
00354 }

Material * OSG::DrawActionBase::getMaterial ( void   )  const [inline]

NodePtr OSG::DrawActionBase::getMaterialNode ( void   )  const [inline]

Definition at line 154 of file OSGDrawActionBase.inl.

References _pMaterialNode.

Referenced by OSG::MaterialGroup::renderLeave().

00155 {
00156     return _pMaterialNode;
00157 }

void DrawActionBase::setMaterial ( Material pMaterial,
NodePtr  node 
)

Definition at line 173 of file OSGDrawActionBase.cpp.

References _pMaterial, and _pMaterialNode.

Referenced by OSG::MaterialGroup::renderEnter(), and OSG::MaterialGroup::renderLeave().

00174 {
00175     _pMaterial     = pMaterial;
00176     _pMaterialNode = node;
00177 }

ActionBase::ResultE DrawActionBase::start ( void   )  [virtual]

Reimplemented from OSG::Action.

Reimplemented in OSG::RenderAction.

Definition at line 180 of file OSGDrawActionBase.cpp.

References _camera, _frustum, _mCameraToWorld, _statistics, OSG::addRef(), OSG::ActionBase::Continue, OSG::StatCollector::create(), getAutoFrustum(), getCamera(), OSG::StatCollector::getElem(), OSG::Camera::getFrustum(), getFrustumCulling(), OSG::Camera::getViewing(), getViewport(), OSG::StatElem::reset(), statCulledNodes, statCullTestedNodes, OSG::Drawable::statNLines, OSG::Drawable::statNPoints, OSG::Drawable::statNPrimitives, OSG::Drawable::statNTriangles, OSG::Drawable::statNVertices, and statTravTime.

00181 {
00182     if(getFrustumCulling() == true &&
00183        getAutoFrustum   () == true &&
00184        getCamera        () != NULL &&
00185        getViewport      () != NULL)
00186     {
00187         getCamera()->getFrustum( _frustum, *getViewport() );
00188     }
00189 
00190     if(_camera != NULL && getViewport() != NULL)
00191     {
00192         _camera->getViewing( _mCameraToWorld,
00193                              getViewport()->getPixelWidth(),
00194                              getViewport()->getPixelHeight() );
00195         _mCameraToWorld.invert();
00196     }
00197 
00198 #if 0 // Altered for last frame time
00199     if(_statistics == NULL)
00200     {
00201         _statistics = StatCollector::create();
00202 
00203         OSG::addRef(_statistics);
00204 
00205         _ownStat = true;
00206     }
00207     else
00208     {
00209         _ownStat = false;        
00210     }
00211 #endif
00212 
00213     if(_statistics != NULL)
00214     {
00215         _statistics->getElem(statTravTime)->start();
00216         _statistics->getElem(statCullTestedNodes)->reset();
00217         _statistics->getElem(statCulledNodes)->reset();
00218         
00219         // this really doesn't belong here, but don't know a better place to put it
00220         if(_statistics->getElem(Drawable::statNTriangles,false))
00221         {
00222             _statistics->getElem(Drawable::statNTriangles )->set(0);
00223             _statistics->getElem(Drawable::statNLines     )->set(0);
00224             _statistics->getElem(Drawable::statNPoints    )->set(0);
00225             _statistics->getElem(Drawable::statNVertices  )->set(0);
00226             _statistics->getElem(Drawable::statNPrimitives)->set(0);
00227         }
00228     }
00229 
00230     return Action::Continue;
00231 }

ActionBase::ResultE DrawActionBase::stop ( ActionBase::ResultE  res  )  [virtual]

Reimplemented from OSG::Action.

Reimplemented in OSG::RenderAction.

Definition at line 233 of file OSGDrawActionBase.cpp.

References _statistics, OSG::StatCollector::getElem(), statTravTime, and OSG::subRef().

00234 {
00235     if(_statistics != NULL)
00236     {
00237         _statistics->getElem(statTravTime)->stop();
00238     }
00239 
00240 #if 0 // Altered for last frame time
00241     if(_ownStat)
00242     {
00243         OSG::subRef(_statistics);
00244 
00245         _statistics = NULL;
00246     }
00247     else
00248     {
00249         _ownStat = false;        
00250     }
00251 #endif
00252         
00253     return res; 
00254 }

void OSG::DrawActionBase::operator= ( const DrawActionBase source  )  [protected]

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

Reimplemented from OSG::Action.

Implemented in OSG::RenderAction.

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

Reimplemented from OSG::Action.

Implemented in OSG::RenderAction.

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

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

Definition at line 183 of file OSGAction.cpp.

References OSG::Action::_prototype, and OSG::Action::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, inherited]

Definition at line 125 of file OSGAction.cpp.

References OSG::Action::_prototype.

00126 {
00127     _prototype = proto;
00128 }

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

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

Definition at line 130 of file OSGAction.cpp.

References OSG::Action::_prototype.

00131 {
00132     return _prototype;
00133 }

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

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

Definition at line 83 of file OSGAction.cpp.

References OSG::Action::_defaultEnterFunction(), OSG::Action::_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, inherited]

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

Definition at line 104 of file OSGAction.cpp.

References OSG::Action::_defaultLeaveFunction(), OSG::Action::_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 
) [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 <