DART  6.6.2
WorldNode.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2018, 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 <osg/Group>
37 #include <osgShadow/ShadowTechnique>
38 #include <unordered_map>
39 #include <memory>
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 
68  friend class Viewer;
69 
72  explicit WorldNode(std::shared_ptr<dart::simulation::World> world = nullptr, ::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
73 
75  void setWorld(std::shared_ptr<dart::simulation::World> newWorld);
76 
78  std::shared_ptr<dart::simulation::World> getWorld() const;
79 
89  virtual void refresh();
90 
96  virtual void customPreRefresh();
97 
103  virtual void customPostRefresh();
104 
110  virtual void customPreStep();
111 
117  virtual void customPostStep();
118 
120  bool isSimulating() const;
121 
124  void simulate(bool on);
125 
128  void setNumStepsPerCycle(std::size_t steps);
129 
132  std::size_t getNumStepsPerCycle() const;
133 
135  bool isShadowed() const;
136 
139  void setShadowTechnique(::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
140 
143  ::osg::ref_ptr<osgShadow::ShadowTechnique> getShadowTechnique() const;
144 
147  static ::osg::ref_ptr<osgShadow::ShadowTechnique> createDefaultShadowTechnique(const Viewer* viewer);
148 
149 protected:
150 
152  virtual ~WorldNode();
153 
157  virtual void setupViewer();
158 
161 
164  void clearUnusedNodes();
165 
167  void refreshSkeletons();
168 
170  void refreshSimpleFrames();
171 
173 
175 
176  using NodeMap = std::unordered_map<dart::dynamics::Frame*, ShapeFrameNode*>;
177 
180 
182  std::shared_ptr<dart::simulation::World> mWorld;
183 
186 
188  std::size_t mNumStepsPerCycle;
189 
192 
194  ::osg::ref_ptr<::osg::Group> mNormalGroup;
195 
197  ::osg::ref_ptr<::osg::Group> mShadowedGroup;
198 
200  bool mShadowed;
201 
202 };
203 
204 } // namespace osg
205 } // namespace gui
206 } // namespace dart
207 
208 #endif // DART_GUI_OSG_WORLDNODE_HPP_
The Frame class serves as the backbone of DART's kinematic tree structure.
Definition: Frame.hpp:57
Definition: Viewer.hpp:116
WorldNode class encapsulates a World to be displayed in OpenSceneGraph.
Definition: WorldNode.hpp:65
std::unordered_map< dart::dynamics::Frame *, ShapeFrameNode * > NodeMap
Definition: WorldNode.hpp:176
void refreshSkeletons()
Refresh all the Skeleton rendering data.
Definition: WorldNode.cpp:231
void refreshBaseFrameNode(dart::dynamics::Frame *frame)
Definition: WorldNode.cpp:259
Viewer * mViewer
Viewer that this WorldNode is inside of.
Definition: WorldNode.hpp:191
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:178
bool isSimulating() const
Returns true iff the WorldNode is stepping between render cycles.
Definition: WorldNode.cpp:160
virtual ~WorldNode()
Destructor.
Definition: WorldNode.cpp:184
NodeMap mFrameToNode
Map from Frame pointers to FrameNode pointers.
Definition: WorldNode.hpp:179
bool mSimulating
True iff simulation is active.
Definition: WorldNode.hpp:185
virtual void setupViewer()
Called when this world gets added to an dart::gui::osg::Viewer.
Definition: WorldNode.cpp:190
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:68
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:172
void setWorld(std::shared_ptr< dart::simulation::World > newWorld)
Set the World that this WorldNode is associated with.
Definition: WorldNode.cpp:99
virtual void refresh()
This function is called at the beginning of each rendering cycle.
Definition: WorldNode.cpp:111
::osg::ref_ptr<::osg::Group > mNormalGroup
OSG group for non-shadowed objects.
Definition: WorldNode.hpp:194
void refreshSimpleFrames()
Refresh all the custom Frame rendering data.
Definition: WorldNode.cpp:249
virtual void customPreStep()
If update() is not overloaded, this function will be called at the beginning of each simulation step.
Definition: WorldNode.cpp:148
void setShadowTechnique(::osg::ref_ptr< osgShadow::ShadowTechnique > shadowTechnique=nullptr)
Set the ShadowTechnique If you wish to disable shadows, pass a nullptr.
Definition: WorldNode.cpp:332
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:355
bool mShadowed
Whether the shadows are enabled.
Definition: WorldNode.hpp:200
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:166
void clearUnusedNodes()
Clear any nodes whose utilization flags were not triggered on this render cycle.
Definition: WorldNode.cpp:203
virtual void customPostStep()
If update() is not overloaded, this function will be called at the end of each simulation step.
Definition: WorldNode.cpp:154
void refreshShapeFrameNode(dart::dynamics::Frame *frame)
Definition: WorldNode.cpp:279
bool isShadowed() const
Get whether the WorldNode is casting shadows.
Definition: WorldNode.cpp:326
virtual void customPostRefresh()
If update() is not overloaded, this function will be called at the end of each rendering cycle.
Definition: WorldNode.cpp:142
::osg::ref_ptr< osgShadow::ShadowTechnique > getShadowTechnique() const
Get the current ShadowTechnique nullptr is there are no shadows.
Definition: WorldNode.cpp:348
void clearChildUtilizationFlags()
Clear the utilization flags of each child node.
Definition: WorldNode.cpp:196
virtual void customPreRefresh()
If update() is not overloaded, this function will be called at the beginning of each rendering cycle.
Definition: WorldNode.cpp:136
std::shared_ptr< dart::simulation::World > getWorld() const
Get the World that this WorldNode is associated with.
Definition: WorldNode.cpp:105
std::shared_ptr< dart::simulation::World > mWorld
The World that this WorldNode is associated with.
Definition: WorldNode.hpp:182
::osg::ref_ptr<::osg::Group > mShadowedGroup
OSG group for shadowed objects.
Definition: WorldNode.hpp:197
std::size_t mNumStepsPerCycle
Number of steps to take between rendering cycles.
Definition: WorldNode.hpp:188
Definition: BulletCollisionDetector.cpp:63