DART  6.10.1
WorldNode.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2021, The DART development contributors
3  * All rights reserved.
4  *
5  * The list of contributors can be found at:
6  * https://github.com/dartsim/dart/blob/master/LICENSE
7  *
8  * This file is provided under the following "BSD-style" License:
9  * Redistribution and use in source and binary forms, with or
10  * without modification, are permitted provided that the following
11  * conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef DART_GUI_OSG_WORLDNODE_HPP_
34 #define DART_GUI_OSG_WORLDNODE_HPP_
35 
36 #include <memory>
37 #include <unordered_map>
38 #include <osg/Group>
39 #include <osgShadow/ShadowTechnique>
40 
41 #include "dart/gui/osg/Viewer.hpp"
42 
43 namespace dart {
44 
45 namespace simulation {
46 class World;
47 } // namespace simulation
48 
49 namespace dynamics {
50 class Frame;
51 class Entity;
52 class ShapeFrame;
53 } // namespace dynamics
54 
55 namespace gui {
56 namespace osg {
57 
58 class FrameNode;
59 class ShapeFrameNode;
60 class EntityNode;
61 class Viewer;
62 
64 class WorldNode : public ::osg::Group
65 {
66 public:
67  friend class Viewer;
68 
71  explicit WorldNode(
72  std::shared_ptr<dart::simulation::World> world = nullptr,
73  ::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
74 
76  void setWorld(std::shared_ptr<dart::simulation::World> newWorld);
77 
79  std::shared_ptr<dart::simulation::World> getWorld() const;
80 
90  virtual void refresh();
91 
97  virtual void customPreRefresh();
98 
104  virtual void customPostRefresh();
105 
111  virtual void customPreStep();
112 
118  virtual void customPostStep();
119 
121  bool isSimulating() const;
122 
125  void simulate(bool on);
126 
129  void setNumStepsPerCycle(std::size_t steps);
130 
133  std::size_t getNumStepsPerCycle() const;
134 
136  bool isShadowed() const;
137 
140  void setShadowTechnique(
141  ::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
142 
145  ::osg::ref_ptr<osgShadow::ShadowTechnique> getShadowTechnique() const;
146 
149  static ::osg::ref_ptr<osgShadow::ShadowTechnique>
150  createDefaultShadowTechnique(const Viewer* viewer);
151 
153  virtual ~WorldNode();
154 
155 protected:
159  virtual void setupViewer();
160 
163 
166  void clearUnusedNodes();
167 
169  void refreshSkeletons();
170 
172  void refreshSimpleFrames();
173 
175 
177 
178  using NodeMap = std::
179  unordered_map<dart::dynamics::Frame*, ::osg::ref_ptr<ShapeFrameNode>>;
180 
183 
185  std::shared_ptr<dart::simulation::World> mWorld;
186 
189 
191  std::size_t mNumStepsPerCycle;
192 
195 
197  ::osg::ref_ptr<::osg::Group> mNormalGroup;
198 
200  ::osg::ref_ptr<::osgShadow::ShadowedScene> mShadowedGroup;
201 
203  bool mShadowed;
204 };
205 
206 } // namespace osg
207 } // namespace gui
208 } // namespace dart
209 
210 #endif // DART_GUI_OSG_WORLDNODE_HPP_
The Frame class serves as the backbone of DART's kinematic tree structure.
Definition: Frame.hpp:58
Definition: Viewer.hpp:112
WorldNode class encapsulates a World to be displayed in OpenSceneGraph.
Definition: WorldNode.hpp:65
void refreshSkeletons()
Refresh all the Skeleton rendering data.
Definition: WorldNode.cpp:229
void refreshBaseFrameNode(dart::dynamics::Frame *frame)
Definition: WorldNode.cpp:257
Viewer * mViewer
Viewer that this WorldNode is inside of.
Definition: WorldNode.hpp:194
std::size_t getNumStepsPerCycle() const
Get the number of steps that will be taken between each render cycle (only if the simulation is not p...
Definition: WorldNode.cpp:179
bool isSimulating() const
Returns true iff the WorldNode is stepping between render cycles.
Definition: WorldNode.cpp:161
virtual ~WorldNode()
Destructor.
Definition: WorldNode.cpp:185
NodeMap mFrameToNode
Map from Frame pointers to FrameNode pointers.
Definition: WorldNode.hpp:182
bool mSimulating
True iff simulation is active.
Definition: WorldNode.hpp:188
virtual void setupViewer()
Called when this world gets added to an dart::gui::osg::Viewer.
Definition: WorldNode.cpp:191
WorldNode(std::shared_ptr< dart::simulation::World > world=nullptr, ::osg::ref_ptr< osgShadow::ShadowTechnique > shadowTechnique=nullptr)
Default constructor Shadows are disabled by default.
Definition: WorldNode.cpp:66
void setNumStepsPerCycle(std::size_t steps)
Set the number of steps to take between each render cycle (only if the simulation is not paused)
Definition: WorldNode.cpp:173
void setWorld(std::shared_ptr< dart::simulation::World > newWorld)
Set the World that this WorldNode is associated with.
Definition: WorldNode.cpp:100
virtual void refresh()
This function is called at the beginning of each rendering cycle.
Definition: WorldNode.cpp:112
::osg::ref_ptr<::osg::Group > mNormalGroup
OSG group for non-shadowed objects.
Definition: WorldNode.hpp:197
void refreshSimpleFrames()
Refresh all the custom Frame rendering data.
Definition: WorldNode.cpp:247
virtual void customPreStep()
If update() is not overloaded, this function will be called at the beginning of each simulation step.
Definition: WorldNode.cpp:149
std::unordered_map< dart::dynamics::Frame *, ::osg::ref_ptr< ShapeFrameNode > > NodeMap
Definition: WorldNode.hpp:179
void setShadowTechnique(::osg::ref_ptr< osgShadow::ShadowTechnique > shadowTechnique=nullptr)
Set the ShadowTechnique If you wish to disable shadows, pass a nullptr.
Definition: WorldNode.cpp:340
static ::osg::ref_ptr< osgShadow::ShadowTechnique > createDefaultShadowTechnique(const Viewer *viewer)
Helper function to create a default ShadowTechnique given a Viewer the default ShadowTechnique is Sha...
Definition: WorldNode.cpp:365
bool mShadowed
Whether the shadows are enabled.
Definition: WorldNode.hpp:203
void simulate(bool on)
Pass in true to take steps between render cycles; pass in false to turn off steps between render cycl...
Definition: WorldNode.cpp:167
void clearUnusedNodes()
Clear any nodes whose utilization flags were not triggered on this render cycle.
Definition: WorldNode.cpp:204
virtual void customPostStep()
If update() is not overloaded, this function will be called at the end of each simulation step.
Definition: WorldNode.cpp:155
void refreshShapeFrameNode(dart::dynamics::Frame *frame)
Definition: WorldNode.cpp:277
::osg::ref_ptr<::osgShadow::ShadowedScene > mShadowedGroup
OSG group for shadowed objects.
Definition: WorldNode.hpp:200
bool isShadowed() const
Get whether the WorldNode is casting shadows.
Definition: WorldNode.cpp:334
virtual void customPostRefresh()
If update() is not overloaded, this function will be called at the end of each rendering cycle.
Definition: WorldNode.cpp:143
::osg::ref_ptr< osgShadow::ShadowTechnique > getShadowTechnique() const
Get the current ShadowTechnique nullptr is there are no shadows.
Definition: WorldNode.cpp:356
void clearChildUtilizationFlags()
Clear the utilization flags of each child node.
Definition: WorldNode.cpp:197
virtual void customPreRefresh()
If update() is not overloaded, this function will be called at the beginning of each rendering cycle.
Definition: WorldNode.cpp:137
std::shared_ptr< dart::simulation::World > getWorld() const
Get the World that this WorldNode is associated with.
Definition: WorldNode.cpp:106
std::shared_ptr< dart::simulation::World > mWorld
The World that this WorldNode is associated with.
Definition: WorldNode.hpp:185
std::size_t mNumStepsPerCycle
Number of steps to take between rendering cycles.
Definition: WorldNode.hpp:191
Definition: BulletCollisionDetector.cpp:65