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

#include <Viewer.hpp>

Inheritance diagram for dart::gui::osg::Viewer:
dart::common::Subject dart::gui::osg::ImGuiViewer

Public Member Functions

 Viewer (const ::osg::Vec4 &clearColor=::osg::Vec4(0.9, 0.9, 0.9, 1.0))
 Constructor for dart::gui::osg::Viewer. More...
 
virtual ~Viewer ()
 Destructor. More...
 
void captureScreen (const std::string &filename)
 Capture the current screen in a png file. More...
 
void record (const std::string &directory, const std::string &prefix="image", bool restart=false, std::size_t digits=6)
 As the screen refreshes, save screen capture images to the specified directory. More...
 
void pauseRecording ()
 If the Viewer is recording, then pause the recording. More...
 
bool isRecording () const
 Returns true if the Viewer is currently recording. More...
 
virtual void switchDefaultEventHandler (bool _on)
 Creates the default event handler for this dart::gui::osg::Viewer. More...
 
DefaultEventHandlergetDefaultEventHandler () const
 Return a pointer to the default event handler. More...
 
virtual void switchHeadlights (bool _on)
 Pass in true to turn headlights on, false to turn headlights off. More...
 
bool checkHeadlights () const
 True iff headlights are currently set to true. More...
 
void addWorldNode (WorldNode *_newWorldNode, bool _active=true)
 Add a WorldNode to this Viewer. More...
 
void removeWorldNode (WorldNode *_oldWorldNode)
 Remove a WorldNode from this Viewer. More...
 
void removeWorldNode (std::shared_ptr< dart::simulation::World > _oldWorld)
 Remove the WorldNode associated with _oldWorld from this Viewer. More...
 
WorldNodegetWorldNode (std::shared_ptr< dart::simulation::World > _world) const
 Get the WorldNode associated with the given _world. More...
 
void addAttachment (ViewerAttachment *_attachment)
 Add an attachment to this Viewer. More...
 
void removeAttachment (ViewerAttachment *_attachment)
 Remove the attachment from this Viewer. More...
 
const std::unordered_set< ViewerAttachment * > & getAttachments () const
 Get the set of attachments in this Viewer. More...
 
::osg::Group * getLightGroup ()
 Get the Group node that contains the LightSources for this Viewer. More...
 
const ::osg::Group * getLightGroup () const
 Get the Group node that contains the LightSources for this Viewer. More...
 
const ::osg::ref_ptr<::osg::LightSource > & getLightSource (std::size_t index=0) const
 Get one of the LightSources of this Viewer index either 0 or 1 Useful for shadowing techniques. More...
 
void setupDefaultLights ()
 Set up the default lighting scheme. More...
 
void setUpwardsDirection (const ::osg::Vec3 &_up)
 Set the direction that this Viewer should consider to be upwards (default is <0,0,1>) More...
 
void setUpwardsDirection (const Eigen::Vector3d &_up)
 Set the direction that this Viewer should consider to be upwards (default is <0,0,1>) More...
 
void setWorldNodeActive (WorldNode *_node, bool _active=true)
 Set the given WorldNode to active. More...
 
void setWorldNodeActive (std::shared_ptr< dart::simulation::World > _world, bool _active=true)
 Set the given World to active. More...
 
void simulate (bool _on)
 Set all currently active WorldNodes to simulate _on. More...
 
bool isSimulating () const
 Return true iff this Viewer is currently set to simulate. More...
 
void allowSimulation (bool _allow)
 Prevent simulation from starting, even if simulate(true) is called. More...
 
bool isAllowingSimulation () const
 Return true iff this Viewer is currently allowing simulation to happen. More...
 
DragAndDropenableDragAndDrop (dart::dynamics::Entity *_entity)
 Returns a nullptr if _entity is not a type that can support the built-in drag and drop features, otherwise it returns a pointer to the DragAndDrop interface object that has been created (allowing you to configure it). More...
 
SimpleFrameDnDenableDragAndDrop (dart::dynamics::SimpleFrame *_frame)
 A version of enableDragAndDrop specifically for SimpleFrame objects. More...
 
SimpleFrameShapeDnDenableDragAndDrop (dart::dynamics::SimpleFrame *_frame, dart::dynamics::Shape *_shape)
 A version of enableDragAndDrop specifically for a single shape within a SimpleFrame object. More...
 
InteractiveFrameDnDenableDragAndDrop (InteractiveFrame *_frame)
 A version of enableDragAndDrop specifically for InteractiveFrames. More...
 
BodyNodeDnDenableDragAndDrop (dart::dynamics::BodyNode *_bn, bool _useExternalIK=true, bool _useWholeBody=false)
 A version of enableDragAndDrop specifically for BodyNodes. More...
 
bool disableDragAndDrop (DragAndDrop *_dnd)
 Delete a DragAndDrop object. More...
 
bool disableDragAndDrop (SimpleFrameDnD *_dnd)
 Delete a SimpleFrameDnD object. More...
 
bool disableDragAndDrop (SimpleFrameShapeDnD *_dnd)
 Delete a SimpleFrameShapeDnD object. More...
 
bool disableDragAndDrop (InteractiveFrameDnD *_dnd)
 Delete an InteractiveFrameDnD object. More...
 
bool disableDragAndDrop (BodyNodeDnD *_dnd)
 Delete a BodyNodeDnD object. More...
 
const std::string & getInstructions () const
 Get a string containing the user interface constructions for this Viewer. More...
 
void addInstructionText (const std::string &_instruction)
 Add something to the instructions for this Viewer. More...
 
virtual void updateViewer ()
 Called automatically at the beginning of each render cycle. More...
 
void updateDragAndDrops ()
 Called automatically by updateViewer() More...
 
const ::osg::ref_ptr<::osg::Group > & getRootGroup () const
 Get the root ::osg::Group of this Viewer. More...
 
void setVerticalFieldOfView (double fov)
 Sets the vertical field of view of the master camera of the view. More...
 
double getVerticalFieldOfView () const
 Returns the vertical field of view of the master camera of the view. More...
 

Protected Member Functions

void sendDestructionNotification () const
 Send a destruction notification to all Observers. More...
 
void addObserver (Observer *_observer) const
 Add an Observer to the list of Observers. More...
 
void removeObserver (Observer *_observer) const
 Remove an Observer from the list of Observers. More...
 

Protected Attributes

std::size_t mImageSequenceNum
 Current number of the image sequence for screen recording. More...
 
std::size_t mImageDigits
 Number of digits to use when saving an image sequence. More...
 
bool mRecording
 Whether or not the Viewer is currently recording. More...
 
bool mScreenCapture
 Whether or not the Viewer is staged for a screen capture. More...
 
std::string mImageDirectory
 Directory for saving images. More...
 
std::string mImagePrefix
 Prefix to apply to images. More...
 
std::string mScreenCapName
 Name for the next screen capture. More...
 
::osg::ref_ptr< DefaultEventHandlermDefaultEventHandler
 Default WorldNodeEventHandler for this dart::gui::osg::Viewer. More...
 
::osg::ref_ptr<::osg::Group > mRootGroup
 The root node of this Viewer. More...
 
::osg::ref_ptr<::osg::Group > mLightGroup
 The Group Node containing light sources. More...
 
::osg::ref_ptr<::osg::Light > mLight1
 Non-headlights Light #1. More...
 
::osg::ref_ptr<::osg::LightSource > mLightSource1
 Non-headlights LightSource #1. More...
 
::osg::ref_ptr<::osg::Light > mLight2
 Non-headlights Light #2. More...
 
::osg::ref_ptr<::osg::LightSource > mLightSource2
 Non-headlights LightSource #2. More...
 
::osg::Vec3 mUpwards
 Vector pointing upwards. More...
 
::osg::Vec3 mOver
 Vector pointing to the side. More...
 
bool mSimulating
 True iff this Viewer is currently simulating. More...
 
bool mAllowSimulation
 True iff this Viewer is allowing simulation. More...
 
bool mHeadlights
 True iff headlights were last set to be on. More...
 
std::map< WorldNode *, bool > mWorldNodes
 Map of WorldNodes in this dart::gui::osg::Viewer. More...
 
std::unordered_set< ViewerAttachment * > mAttachments
 
std::string mInstructions
 string of instructions for this Viewer More...
 
std::map< dart::dynamics::SimpleFrame *, SimpleFrameDnD * > mSimpleFrameDnDMap
 Map from SimpleFrame ptrs to SimpleFrameDnD ptrs. More...
 
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * > mSimpleFrameShapeDnDMap
 Multimap from Shape ptrs to SimpleFrameShapeDnD ptrs. More...
 
std::map< InteractiveFrame *, InteractiveFrameDnD * > mInteractiveFrameDnDMap
 Map from InteractiveFrame ptrs to InteractiveFrameDnD ptrs. More...
 
std::map< dart::dynamics::BodyNode *, BodyNodeDnD * > mBodyNodeDnDMap
 Map from BodyNode ptrs to BodyNodeDnD ptrs. More...
 
std::set< Observer * > mObservers
 List of current Observers. More...
 

Friends

class SaveScreen
 

Constructor & Destructor Documentation

◆ Viewer()

dart::gui::osg::Viewer::Viewer ( const ::osg::Vec4 &  clearColor = ::osg::Vec4(0.9,0.9,0.9,1.0))

Constructor for dart::gui::osg::Viewer.

This will automatically create the default event handler.

◆ ~Viewer()

dart::gui::osg::Viewer::~Viewer ( )
virtual

Destructor.

Member Function Documentation

◆ addAttachment()

void dart::gui::osg::Viewer::addAttachment ( ViewerAttachment _attachment)

Add an attachment to this Viewer.

Note that an attachment can only be attached to one Viewer at a time.

◆ addInstructionText()

void dart::gui::osg::Viewer::addInstructionText ( const std::string &  _instruction)

Add something to the instructions for this Viewer.

You are strongly recommended to end your string with an end-of-line character. An end-of-line character will NOT be added automatically.

◆ addObserver()

void dart::common::Subject::addObserver ( Observer _observer) const
protectedinherited

Add an Observer to the list of Observers.

◆ addWorldNode()

void dart::gui::osg::Viewer::addWorldNode ( WorldNode _newWorldNode,
bool  _active = true 
)

Add a WorldNode to this Viewer.

If active is true, the WorldNode will respond to user input (but it will not begin simulating unless its simulation is currently turned on).

◆ allowSimulation()

void dart::gui::osg::Viewer::allowSimulation ( bool  _allow)

Prevent simulation from starting, even if simulate(true) is called.

◆ captureScreen()

void dart::gui::osg::Viewer::captureScreen ( const std::string &  filename)

Capture the current screen in a png file.

The filename argument should include the full path for the file.

It is recommended that you end the filename with ".png". That is the type of file that will be produced, but the extension will not be added on automatically.

◆ checkHeadlights()

bool dart::gui::osg::Viewer::checkHeadlights ( ) const

True iff headlights are currently set to true.

◆ disableDragAndDrop() [1/5]

bool dart::gui::osg::Viewer::disableDragAndDrop ( BodyNodeDnD _dnd)

Delete a BodyNodeDnD object.

Returns true if a DnD existed and could be deleted

◆ disableDragAndDrop() [2/5]

bool dart::gui::osg::Viewer::disableDragAndDrop ( DragAndDrop _dnd)

Delete a DragAndDrop object.

Returns true if the DnD was active and has now been deleted

◆ disableDragAndDrop() [3/5]

bool dart::gui::osg::Viewer::disableDragAndDrop ( InteractiveFrameDnD _dnd)

Delete an InteractiveFrameDnD object.

Returns true if a DnD existed and could be deleted

◆ disableDragAndDrop() [4/5]

bool dart::gui::osg::Viewer::disableDragAndDrop ( SimpleFrameDnD _dnd)

Delete a SimpleFrameDnD object.

Returns true if the DnD was active and has now been deleted

◆ disableDragAndDrop() [5/5]

bool dart::gui::osg::Viewer::disableDragAndDrop ( SimpleFrameShapeDnD _dnd)

Delete a SimpleFrameShapeDnD object.

Returns true if a DnD existed and could be deleted

◆ enableDragAndDrop() [1/5]

BodyNodeDnD * dart::gui::osg::Viewer::enableDragAndDrop ( dart::dynamics::BodyNode _bn,
bool  _useExternalIK = true,
bool  _useWholeBody = false 
)

A version of enableDragAndDrop specifically for BodyNodes.

◆ enableDragAndDrop() [2/5]

DragAndDrop * dart::gui::osg::Viewer::enableDragAndDrop ( dart::dynamics::Entity _entity)

Returns a nullptr if _entity is not a type that can support the built-in drag and drop features, otherwise it returns a pointer to the DragAndDrop interface object that has been created (allowing you to configure it).

If a DragAndDrop interface already existed for this object, the existing one will be returned.

◆ enableDragAndDrop() [3/5]

SimpleFrameDnD * dart::gui::osg::Viewer::enableDragAndDrop ( dart::dynamics::SimpleFrame _frame)

A version of enableDragAndDrop specifically for SimpleFrame objects.

◆ enableDragAndDrop() [4/5]

SimpleFrameShapeDnD * dart::gui::osg::Viewer::enableDragAndDrop ( dart::dynamics::SimpleFrame _frame,
dart::dynamics::Shape _shape 
)

A version of enableDragAndDrop specifically for a single shape within a SimpleFrame object.

Dragging and Dropping the shape will also drag and drop the entire Frame

◆ enableDragAndDrop() [5/5]

InteractiveFrameDnD * dart::gui::osg::Viewer::enableDragAndDrop ( InteractiveFrame _frame)

A version of enableDragAndDrop specifically for InteractiveFrames.

◆ getAttachments()

const std::unordered_set< ViewerAttachment * > & dart::gui::osg::Viewer::getAttachments ( ) const

Get the set of attachments in this Viewer.

◆ getDefaultEventHandler()

DefaultEventHandler * dart::gui::osg::Viewer::getDefaultEventHandler ( ) const

Return a pointer to the default event handler.

◆ getInstructions()

const std::string & dart::gui::osg::Viewer::getInstructions ( ) const

Get a string containing the user interface constructions for this Viewer.

◆ getLightGroup() [1/2]

osg::Group * dart::gui::osg::Viewer::getLightGroup ( )

Get the Group node that contains the LightSources for this Viewer.

◆ getLightGroup() [2/2]

const ::osg::Group * dart::gui::osg::Viewer::getLightGroup ( ) const

Get the Group node that contains the LightSources for this Viewer.

◆ getLightSource()

const ::osg::ref_ptr<::osg::LightSource > & dart::gui::osg::Viewer::getLightSource ( std::size_t  index = 0) const

Get one of the LightSources of this Viewer index either 0 or 1 Useful for shadowing techniques.

◆ getRootGroup()

const ::osg::ref_ptr<::osg::Group > & dart::gui::osg::Viewer::getRootGroup ( ) const

Get the root ::osg::Group of this Viewer.

◆ getVerticalFieldOfView()

double dart::gui::osg::Viewer::getVerticalFieldOfView ( ) const

Returns the vertical field of view of the master camera of the view.

Returns
Vertical field of view in degrees if the camera is perspective view, 0.0 otherwise.

◆ getWorldNode()

WorldNode * dart::gui::osg::Viewer::getWorldNode ( std::shared_ptr< dart::simulation::World _world) const

Get the WorldNode associated with the given _world.

Returns nullptr if this Viewer does not contain a WorldNode associated with _world.

◆ isAllowingSimulation()

bool dart::gui::osg::Viewer::isAllowingSimulation ( ) const

Return true iff this Viewer is currently allowing simulation to happen.

◆ isRecording()

bool dart::gui::osg::Viewer::isRecording ( ) const

Returns true if the Viewer is currently recording.

◆ isSimulating()

bool dart::gui::osg::Viewer::isSimulating ( ) const

Return true iff this Viewer is currently set to simulate.

◆ pauseRecording()

void dart::gui::osg::Viewer::pauseRecording ( )

If the Viewer is recording, then pause the recording.

The next time record() is called, the numbering of the images will resume from where it left off.

◆ record()

void dart::gui::osg::Viewer::record ( const std::string &  directory,
const std::string &  prefix = "image",
bool  restart = false,
std::size_t  digits = 6 
)

As the screen refreshes, save screen capture images to the specified directory.

The prefix argument will be the first part of the name of each image. The second part of the image will contain an integer with "digits" number of digits; any unused leading digits will be filled with 0. The integer corresponds to its number in the sequence of frames.

Set the restart argument to true if you want the sequence counter to restart from 0.

◆ removeAttachment()

void dart::gui::osg::Viewer::removeAttachment ( ViewerAttachment _attachment)

Remove the attachment from this Viewer.

◆ removeObserver()

void dart::common::Subject::removeObserver ( Observer _observer) const
protectedinherited

Remove an Observer from the list of Observers.

◆ removeWorldNode() [1/2]

void dart::gui::osg::Viewer::removeWorldNode ( std::shared_ptr< dart::simulation::World _oldWorld)

Remove the WorldNode associated with _oldWorld from this Viewer.

◆ removeWorldNode() [2/2]

void dart::gui::osg::Viewer::removeWorldNode ( WorldNode _oldWorldNode)

Remove a WorldNode from this Viewer.

◆ sendDestructionNotification()

void dart::common::Subject::sendDestructionNotification ( ) const
protectedinherited

Send a destruction notification to all Observers.

This will cause all Observers to behave as if this Subject has been permanently deleted, so it should only be called when that behavior is desired.

◆ setupDefaultLights()

void dart::gui::osg::Viewer::setupDefaultLights ( )

Set up the default lighting scheme.

◆ setUpwardsDirection() [1/2]

void dart::gui::osg::Viewer::setUpwardsDirection ( const ::osg::Vec3 &  _up)

Set the direction that this Viewer should consider to be upwards (default is <0,0,1>)

◆ setUpwardsDirection() [2/2]

void dart::gui::osg::Viewer::setUpwardsDirection ( const Eigen::Vector3d &  _up)

Set the direction that this Viewer should consider to be upwards (default is <0,0,1>)

◆ setVerticalFieldOfView()

void dart::gui::osg::Viewer::setVerticalFieldOfView ( double  fov)

Sets the vertical field of view of the master camera of the view.

Parameters
[in]fovVertical field of view in degrees.

◆ setWorldNodeActive() [1/2]

void dart::gui::osg::Viewer::setWorldNodeActive ( std::shared_ptr< dart::simulation::World _world,
bool  _active = true 
)

Set the given World to active.

◆ setWorldNodeActive() [2/2]

void dart::gui::osg::Viewer::setWorldNodeActive ( WorldNode _node,
bool  _active = true 
)

Set the given WorldNode to active.

◆ simulate()

void dart::gui::osg::Viewer::simulate ( bool  _on)

Set all currently active WorldNodes to simulate _on.

◆ switchDefaultEventHandler()

void dart::gui::osg::Viewer::switchDefaultEventHandler ( bool  _on)
virtual

Creates the default event handler for this dart::gui::osg::Viewer.

◆ switchHeadlights()

void dart::gui::osg::Viewer::switchHeadlights ( bool  _on)
virtual

Pass in true to turn headlights on, false to turn headlights off.

◆ updateDragAndDrops()

void dart::gui::osg::Viewer::updateDragAndDrops ( )

Called automatically by updateViewer()

◆ updateViewer()

void dart::gui::osg::Viewer::updateViewer ( )
virtual

Called automatically at the beginning of each render cycle.

Friends And Related Function Documentation

◆ SaveScreen

friend class SaveScreen
friend

Member Data Documentation

◆ mAllowSimulation

bool dart::gui::osg::Viewer::mAllowSimulation
protected

True iff this Viewer is allowing simulation.

◆ mAttachments

std::unordered_set<ViewerAttachment*> dart::gui::osg::Viewer::mAttachments
protected

◆ mBodyNodeDnDMap

std::map<dart::dynamics::BodyNode*,BodyNodeDnD*> dart::gui::osg::Viewer::mBodyNodeDnDMap
protected

Map from BodyNode ptrs to BodyNodeDnD ptrs.

◆ mDefaultEventHandler

::osg::ref_ptr<DefaultEventHandler> dart::gui::osg::Viewer::mDefaultEventHandler
protected

Default WorldNodeEventHandler for this dart::gui::osg::Viewer.

◆ mHeadlights

bool dart::gui::osg::Viewer::mHeadlights
protected

True iff headlights were last set to be on.

◆ mImageDigits

std::size_t dart::gui::osg::Viewer::mImageDigits
protected

Number of digits to use when saving an image sequence.

◆ mImageDirectory

std::string dart::gui::osg::Viewer::mImageDirectory
protected

Directory for saving images.

◆ mImagePrefix

std::string dart::gui::osg::Viewer::mImagePrefix
protected

Prefix to apply to images.

◆ mImageSequenceNum

std::size_t dart::gui::osg::Viewer::mImageSequenceNum
protected

Current number of the image sequence for screen recording.

◆ mInstructions

std::string dart::gui::osg::Viewer::mInstructions
protected

string of instructions for this Viewer

◆ mInteractiveFrameDnDMap

std::map<InteractiveFrame*,InteractiveFrameDnD*> dart::gui::osg::Viewer::mInteractiveFrameDnDMap
protected

Map from InteractiveFrame ptrs to InteractiveFrameDnD ptrs.

◆ mLight1

::osg::ref_ptr<::osg::Light> dart::gui::osg::Viewer::mLight1
protected

Non-headlights Light #1.

◆ mLight2

::osg::ref_ptr<::osg::Light> dart::gui::osg::Viewer::mLight2
protected

Non-headlights Light #2.

◆ mLightGroup

::osg::ref_ptr<::osg::Group> dart::gui::osg::Viewer::mLightGroup
protected

The Group Node containing light sources.

◆ mLightSource1

::osg::ref_ptr<::osg::LightSource> dart::gui::osg::Viewer::mLightSource1
protected

Non-headlights LightSource #1.

◆ mLightSource2

::osg::ref_ptr<::osg::LightSource> dart::gui::osg::Viewer::mLightSource2
protected

Non-headlights LightSource #2.

◆ mObservers

std::set<Observer*> dart::common::Subject::mObservers
mutableprotectedinherited

List of current Observers.

◆ mOver

::osg::Vec3 dart::gui::osg::Viewer::mOver
protected

Vector pointing to the side.

◆ mRecording

bool dart::gui::osg::Viewer::mRecording
protected

Whether or not the Viewer is currently recording.

◆ mRootGroup

::osg::ref_ptr<::osg::Group> dart::gui::osg::Viewer::mRootGroup
protected

The root node of this Viewer.

◆ mScreenCapName

std::string dart::gui::osg::Viewer::mScreenCapName
protected

Name for the next screen capture.

◆ mScreenCapture

bool dart::gui::osg::Viewer::mScreenCapture
protected

Whether or not the Viewer is staged for a screen capture.

◆ mSimpleFrameDnDMap

std::map<dart::dynamics::SimpleFrame*,SimpleFrameDnD*> dart::gui::osg::Viewer::mSimpleFrameDnDMap
protected

Map from SimpleFrame ptrs to SimpleFrameDnD ptrs.

◆ mSimpleFrameShapeDnDMap

std::multimap<dart::dynamics::Shape*,SimpleFrameShapeDnD*> dart::gui::osg::Viewer::mSimpleFrameShapeDnDMap
protected

Multimap from Shape ptrs to SimpleFrameShapeDnD ptrs.

We use a multimap in order to support the possibility of a single Shape being used by multiple objects

◆ mSimulating

bool dart::gui::osg::Viewer::mSimulating
protected

True iff this Viewer is currently simulating.

◆ mUpwards

::osg::Vec3 dart::gui::osg::Viewer::mUpwards
protected

Vector pointing upwards.

◆ mWorldNodes

std::map<WorldNode*,bool> dart::gui::osg::Viewer::mWorldNodes
protected

Map of WorldNodes in this dart::gui::osg::Viewer.

A WorldNode will map to true iff it is currently active