DART  6.7.3
dart::gui::osg::RealTimeWorldNode Class Reference

#include <RealTimeWorldNode.hpp>

Inheritance diagram for dart::gui::osg::RealTimeWorldNode:
dart::gui::osg::WorldNode

Public Member Functions

 RealTimeWorldNode (const std::shared_ptr< dart::simulation::World > &world=nullptr, const ::osg::ref_ptr< osgShadow::ShadowTechnique > &shadower=nullptr, double targetFrequency=60.0, double targetRealTimeFactor=1.0)
 Construct a world node that will attempt to run a simulation with close to real-time playback. More...
 
void setTargetFrequency (double targetFrequency)
 Set the target refresh rate frequency. More...
 
double getTargetFrequency () const
 Get the target refresh rate frequency. More...
 
void setTargetRealTimeFactor (double targetRTF)
 Set the target real time factor. More...
 
double getTargetRealTimeFactor () const
 Get the target real time factor. More...
 
double getLastRealTimeFactor () const
 Get the real time factor that was achieved in the last refresh cycle. More...
 
double getLowestRealTimeFactor () const
 Get the lowest real time factor that has been hit during the simulation. More...
 
double getHighestRealTimeFactor () const
 Get the highest real time factor that has been hit during the simulation. More...
 
void setRealTimeFactorDisplay (bool on)
 Turn the text displaying the real time factor on or off. More...
 
void refresh () override
 This function is called at the beginning of each rendering cycle. More...
 
void setWorld (std::shared_ptr< dart::simulation::World > newWorld)
 Set the World that this WorldNode is associated with. More...
 
std::shared_ptr< dart::simulation::WorldgetWorld () const
 Get the World that this WorldNode is associated with. More...
 
virtual void customPreRefresh ()
 If update() is not overloaded, this function will be called at the beginning of each rendering cycle. More...
 
virtual void customPostRefresh ()
 If update() is not overloaded, this function will be called at the end of each rendering cycle. More...
 
virtual void customPreStep ()
 If update() is not overloaded, this function will be called at the beginning of each simulation step. More...
 
virtual void customPostStep ()
 If update() is not overloaded, this function will be called at the end of each simulation step. More...
 
bool isSimulating () const
 Returns true iff the WorldNode is stepping between render cycles. More...
 
void simulate (bool on)
 Pass in true to take steps between render cycles; pass in false to turn off steps between render cycles. More...
 
void setNumStepsPerCycle (std::size_t steps)
 Set the number of steps to take between each render cycle (only if the simulation is not paused) More...
 
std::size_t getNumStepsPerCycle () const
 Get the number of steps that will be taken between each render cycle (only if the simulation is not paused) More...
 
bool isShadowed () const
 Get whether the WorldNode is casting shadows. More...
 
void setShadowTechnique (::osg::ref_ptr< osgShadow::ShadowTechnique > shadowTechnique=nullptr)
 Set the ShadowTechnique If you wish to disable shadows, pass a nullptr. More...
 
::osg::ref_ptr< osgShadow::ShadowTechnique > getShadowTechnique () const
 Get the current ShadowTechnique nullptr is there are no shadows. More...
 
static ::osg::ref_ptr< osgShadow::ShadowTechnique > createDefaultShadowTechnique (const Viewer *viewer)
 Helper function to create a default ShadowTechnique given a Viewer the default ShadowTechnique is ShadowMap. More...
 

Protected Types

using NodeMap = std::unordered_map< dart::dynamics::Frame *, ShapeFrameNode * >
 

Protected Member Functions

virtual void setupViewer ()
 Called when this world gets added to an dart::gui::osg::Viewer. More...
 
void clearChildUtilizationFlags ()
 Clear the utilization flags of each child node. More...
 
void clearUnusedNodes ()
 Clear any nodes whose utilization flags were not triggered on this render cycle. More...
 
void refreshSkeletons ()
 Refresh all the Skeleton rendering data. More...
 
void refreshSimpleFrames ()
 Refresh all the custom Frame rendering data. More...
 
void refreshBaseFrameNode (dart::dynamics::Frame *frame)
 
void refreshShapeFrameNode (dart::dynamics::Frame *frame)
 

Protected Attributes

bool mFirstRefresh
 Reset each time the simulation is paused. More...
 
::osg::Timer mRefreshTimer
 Keeps track of the time between refreshes. More...
 
double mTargetRealTimeLapse
 The target for how much time should elapse between refreshes. More...
 
double mTargetSimTimeLapse
 The target for how much simulation time should elapse between refreshes. More...
 
double mLastRealTimeFactor
 The RTF that was achieved in the last refresh cycle. More...
 
double mLowestRealTimeFactor
 The lowest RTF that has been achieved. More...
 
double mHighestRealTimeFactor
 The highest RTF that has been achieved. More...
 
NodeMap mFrameToNode
 Map from Frame pointers to FrameNode pointers. More...
 
std::shared_ptr< dart::simulation::WorldmWorld
 The World that this WorldNode is associated with. More...
 
bool mSimulating
 True iff simulation is active. More...
 
std::size_t mNumStepsPerCycle
 Number of steps to take between rendering cycles. More...
 
ViewermViewer
 Viewer that this WorldNode is inside of. More...
 
::osg::ref_ptr<::osg::Group > mNormalGroup
 OSG group for non-shadowed objects. More...
 
::osg::ref_ptr<::osg::Group > mShadowedGroup
 OSG group for shadowed objects. More...
 
bool mShadowed
 Whether the shadows are enabled. More...
 

Member Typedef Documentation

◆ NodeMap

using dart::gui::osg::WorldNode::NodeMap = std::unordered_map<dart::dynamics::Frame*, ShapeFrameNode*>
protectedinherited

Constructor & Destructor Documentation

◆ RealTimeWorldNode()

dart::gui::osg::RealTimeWorldNode::RealTimeWorldNode ( const std::shared_ptr< dart::simulation::World > &  world = nullptr,
const ::osg::ref_ptr< osgShadow::ShadowTechnique > &  shadower = nullptr,
double  targetFrequency = 60.0,
double  targetRealTimeFactor = 1.0 
)

Construct a world node that will attempt to run a simulation with close to real-time playback.

If a simulation is too computationally expensive, the simulation might not be able to keep up with real time.

Parameters
[in]worldThe world to simulate
[in]targetFrequencyThe expected refresh rate. The actual refresh rate may depend on your monitor and your computer's display settings.
[in]targetRealTimeFactorThis factor at which the simulation should run. A value of 1.0 (default) means it will try to run at real time. A value 2.0 means the simulation will try to run at double real time speed (fast-forward). A value of 0.5 means the simulation will try to run at half of real-time speed (slowed down).
[in]shadowTechThe shading technique to use when rendering this world.

Member Function Documentation

◆ clearChildUtilizationFlags()

void dart::gui::osg::WorldNode::clearChildUtilizationFlags ( )
protectedinherited

Clear the utilization flags of each child node.

◆ clearUnusedNodes()

void dart::gui::osg::WorldNode::clearUnusedNodes ( )
protectedinherited

Clear any nodes whose utilization flags were not triggered on this render cycle.

◆ createDefaultShadowTechnique()

osg::ref_ptr< osgShadow::ShadowTechnique > dart::gui::osg::WorldNode::createDefaultShadowTechnique ( const Viewer viewer)
inherited

Helper function to create a default ShadowTechnique given a Viewer the default ShadowTechnique is ShadowMap.

◆ customPostRefresh()

void dart::gui::osg::WorldNode::customPostRefresh ( )
virtualinherited

If update() is not overloaded, this function will be called at the end of each rendering cycle.

This function can be overloaded to customize the behavior of each update. The default behavior is to do nothing, so overloading this function will not interfere with the usual update() operation.

◆ customPostStep()

void dart::gui::osg::WorldNode::customPostStep ( )
virtualinherited

If update() is not overloaded, this function will be called at the end of each simulation step.

This function can be overloaded to customize the behavior of each step. The default behavior is to do nothing, so overloading this function will not interfere with the usual update() operation. This will not get called if the simulation is paused.

◆ customPreRefresh()

void dart::gui::osg::WorldNode::customPreRefresh ( )
virtualinherited

If update() is not overloaded, this function will be called at the beginning of each rendering cycle.

This function can be overloaded to customize the behavior of each update. The default behavior is to do nothing, so overloading this function will not interfere with the usual update() operation.

◆ customPreStep()

void dart::gui::osg::WorldNode::customPreStep ( )
virtualinherited

If update() is not overloaded, this function will be called at the beginning of each simulation step.

This function can be overloaded to customize the behavior of each step. The default behavior is to do nothing, so overloading this function will not interfere with the usual update() operation. This will not get called if the simulation is paused.

◆ getHighestRealTimeFactor()

double dart::gui::osg::RealTimeWorldNode::getHighestRealTimeFactor ( ) const

Get the highest real time factor that has been hit during the simulation.

◆ getLastRealTimeFactor()

double dart::gui::osg::RealTimeWorldNode::getLastRealTimeFactor ( ) const

Get the real time factor that was achieved in the last refresh cycle.

This may be smaller than target real time factor, because the simulation may not have had time to reach it.

◆ getLowestRealTimeFactor()

double dart::gui::osg::RealTimeWorldNode::getLowestRealTimeFactor ( ) const

Get the lowest real time factor that has been hit during the simulation.

◆ getNumStepsPerCycle()

std::size_t dart::gui::osg::WorldNode::getNumStepsPerCycle ( ) const
inherited

Get the number of steps that will be taken between each render cycle (only if the simulation is not paused)

◆ getShadowTechnique()

osg::ref_ptr< osgShadow::ShadowTechnique > dart::gui::osg::WorldNode::getShadowTechnique ( ) const
inherited

Get the current ShadowTechnique nullptr is there are no shadows.

◆ getTargetFrequency()

double dart::gui::osg::RealTimeWorldNode::getTargetFrequency ( ) const

Get the target refresh rate frequency.

◆ getTargetRealTimeFactor()

double dart::gui::osg::RealTimeWorldNode::getTargetRealTimeFactor ( ) const

Get the target real time factor.

◆ getWorld()

std::shared_ptr< dart::simulation::World > dart::gui::osg::WorldNode::getWorld ( ) const
inherited

Get the World that this WorldNode is associated with.

◆ isShadowed()

bool dart::gui::osg::WorldNode::isShadowed ( ) const
inherited

Get whether the WorldNode is casting shadows.

◆ isSimulating()

bool dart::gui::osg::WorldNode::isSimulating ( ) const
inherited

Returns true iff the WorldNode is stepping between render cycles.

◆ refresh()

void dart::gui::osg::RealTimeWorldNode::refresh ( )
overridevirtual

This function is called at the beginning of each rendering cycle.

It updates the tree of Frames and Entities that need to be rendered. It may also take a simulation step if the simulation is not paused.

If you want to customize what happens at the beginning of each rendering cycle, you can either overload this function, or you can overload customUpdate(). This update() function will automatically call customUpdate() at the beginning of each rendering cycle. By default, customUpdate() does nothing.

Reimplemented from dart::gui::osg::WorldNode.

◆ refreshBaseFrameNode()

void dart::gui::osg::WorldNode::refreshBaseFrameNode ( dart::dynamics::Frame frame)
protectedinherited

◆ refreshShapeFrameNode()

void dart::gui::osg::WorldNode::refreshShapeFrameNode ( dart::dynamics::Frame frame)
protectedinherited

◆ refreshSimpleFrames()

void dart::gui::osg::WorldNode::refreshSimpleFrames ( )
protectedinherited

Refresh all the custom Frame rendering data.

◆ refreshSkeletons()

void dart::gui::osg::WorldNode::refreshSkeletons ( )
protectedinherited

Refresh all the Skeleton rendering data.

◆ setNumStepsPerCycle()

void dart::gui::osg::WorldNode::setNumStepsPerCycle ( std::size_t  steps)
inherited

Set the number of steps to take between each render cycle (only if the simulation is not paused)

◆ setRealTimeFactorDisplay()

void dart::gui::osg::RealTimeWorldNode::setRealTimeFactorDisplay ( bool  on)

Turn the text displaying the real time factor on or off.

◆ setShadowTechnique()

void dart::gui::osg::WorldNode::setShadowTechnique ( ::osg::ref_ptr< osgShadow::ShadowTechnique >  shadowTechnique = nullptr)
inherited

Set the ShadowTechnique If you wish to disable shadows, pass a nullptr.

◆ setTargetFrequency()

void dart::gui::osg::RealTimeWorldNode::setTargetFrequency ( double  targetFrequency)

Set the target refresh rate frequency.

◆ setTargetRealTimeFactor()

void dart::gui::osg::RealTimeWorldNode::setTargetRealTimeFactor ( double  targetRTF)

Set the target real time factor.

◆ setupViewer()

void dart::gui::osg::WorldNode::setupViewer ( )
protectedvirtualinherited

Called when this world gets added to an dart::gui::osg::Viewer.

Override this function to customize the way your WorldNode starts up in an dart::gui::osg::Viewer. Default behavior does nothing.

◆ setWorld()

void dart::gui::osg::WorldNode::setWorld ( std::shared_ptr< dart::simulation::World newWorld)
inherited

Set the World that this WorldNode is associated with.

◆ simulate()

void dart::gui::osg::WorldNode::simulate ( bool  on)
inherited

Pass in true to take steps between render cycles; pass in false to turn off steps between render cycles.

Member Data Documentation

◆ mFirstRefresh

bool dart::gui::osg::RealTimeWorldNode::mFirstRefresh
protected

Reset each time the simulation is paused.

◆ mFrameToNode

NodeMap dart::gui::osg::WorldNode::mFrameToNode
protectedinherited

Map from Frame pointers to FrameNode pointers.

◆ mHighestRealTimeFactor

double dart::gui::osg::RealTimeWorldNode::mHighestRealTimeFactor
protected

The highest RTF that has been achieved.

◆ mLastRealTimeFactor

double dart::gui::osg::RealTimeWorldNode::mLastRealTimeFactor
protected

The RTF that was achieved in the last refresh cycle.

◆ mLowestRealTimeFactor

double dart::gui::osg::RealTimeWorldNode::mLowestRealTimeFactor
protected

The lowest RTF that has been achieved.

◆ mNormalGroup

::osg::ref_ptr<::osg::Group> dart::gui::osg::WorldNode::mNormalGroup
protectedinherited

OSG group for non-shadowed objects.

◆ mNumStepsPerCycle

std::size_t dart::gui::osg::WorldNode::mNumStepsPerCycle
protectedinherited

Number of steps to take between rendering cycles.

◆ mRefreshTimer

::osg::Timer dart::gui::osg::RealTimeWorldNode::mRefreshTimer
protected

Keeps track of the time between refreshes.

◆ mShadowed

bool dart::gui::osg::WorldNode::mShadowed
protectedinherited

Whether the shadows are enabled.

◆ mShadowedGroup

::osg::ref_ptr<::osg::Group> dart::gui::osg::WorldNode::mShadowedGroup
protectedinherited

OSG group for shadowed objects.

◆ mSimulating

bool dart::gui::osg::WorldNode::mSimulating
protectedinherited

True iff simulation is active.

◆ mTargetRealTimeLapse

double dart::gui::osg::RealTimeWorldNode::mTargetRealTimeLapse
protected

The target for how much time should elapse between refreshes.

◆ mTargetSimTimeLapse

double dart::gui::osg::RealTimeWorldNode::mTargetSimTimeLapse
protected

The target for how much simulation time should elapse between refreshes.

◆ mViewer

Viewer* dart::gui::osg::WorldNode::mViewer
protectedinherited

Viewer that this WorldNode is inside of.

◆ mWorld

std::shared_ptr<dart::simulation::World> dart::gui::osg::WorldNode::mWorld
protectedinherited

The World that this WorldNode is associated with.