dart
WorldNode.hpp
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 
162  void clearChildUtilizationFlags();
163 
166  void clearUnusedNodes();
167 
169  void refreshSkeletons();
170 
172  void refreshSimpleFrames();
173 
174  void refreshBaseFrameNode(dart::dynamics::Frame* frame);
175 
176  void refreshShapeFrameNode(dart::dynamics::Frame* frame);
177 
178  using NodeMap = std::
179  unordered_map<dart::dynamics::Frame*, ::osg::ref_ptr<ShapeFrameNode>>;
180 
182  NodeMap mFrameToNode;
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_
bool mShadowed
Whether the shadows are enabled.
Definition: WorldNode.hpp:203
Viewer * mViewer
Viewer that this WorldNode is inside of.
Definition: WorldNode.hpp:194
std::shared_ptr< dart::simulation::World > mWorld
The World that this WorldNode is associated with.
Definition: WorldNode.hpp:185
::osg::ref_ptr<::osgShadow::ShadowedScene > mShadowedGroup
OSG group for shadowed objects.
Definition: WorldNode.hpp:200
::osg::ref_ptr<::osg::Group > mNormalGroup
OSG group for non-shadowed objects.
Definition: WorldNode.hpp:197
The Frame class serves as the backbone of DART&#39;s kinematic tree structure.
Definition: Frame.hpp:57
Definition: test_Signal.cpp:68
WorldNode class encapsulates a World to be displayed in OpenSceneGraph.
Definition: WorldNode.hpp:64
Definition: Aspect.cpp:40
bool mSimulating
True iff simulation is active.
Definition: WorldNode.hpp:188
Definition: Viewer.hpp:111
NodeMap mFrameToNode
Map from Frame pointers to FrameNode pointers.
Definition: WorldNode.hpp:182
std::size_t mNumStepsPerCycle
Number of steps to take between rendering cycles.
Definition: WorldNode.hpp:191