DART 6.12.2
Loading...
Searching...
No Matches
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
39#include <osg/Group>
40#include <osgShadow/ShadowTechnique>
41
43
44namespace dart {
45
46namespace simulation {
47class World;
48} // namespace simulation
49
50namespace dynamics {
51class Frame;
52class Entity;
53class ShapeFrame;
54} // namespace dynamics
55
56namespace gui {
57namespace osg {
58
59class FrameNode;
60class ShapeFrameNode;
61class EntityNode;
62class Viewer;
63
65class WorldNode : public ::osg::Group
66{
67public:
68 friend class Viewer;
69
72 explicit WorldNode(
73 std::shared_ptr<dart::simulation::World> world = nullptr,
74 ::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
75
77 void setWorld(std::shared_ptr<dart::simulation::World> newWorld);
78
80 std::shared_ptr<dart::simulation::World> getWorld() const;
81
91 virtual void refresh();
92
98 virtual void customPreRefresh();
99
105 virtual void customPostRefresh();
106
112 virtual void customPreStep();
113
119 virtual void customPostStep();
120
122 bool isSimulating() const;
123
126 void simulate(bool on);
127
130 void setNumStepsPerCycle(std::size_t steps);
131
134 std::size_t getNumStepsPerCycle() const;
135
137 bool isShadowed() const;
138
142 ::osg::ref_ptr<osgShadow::ShadowTechnique> shadowTechnique = nullptr);
143
146 ::osg::ref_ptr<osgShadow::ShadowTechnique> getShadowTechnique() const;
147
150 static ::osg::ref_ptr<osgShadow::ShadowTechnique>
152
154 virtual ~WorldNode();
155
156protected:
160 virtual void setupViewer();
161
164
167 void clearUnusedNodes();
168
170 void refreshSkeletons();
171
173 void refreshSimpleFrames();
174
176
178
179 using NodeMap = std::
180 unordered_map<dart::dynamics::Frame*, ::osg::ref_ptr<ShapeFrameNode>>;
181
184
186 std::shared_ptr<dart::simulation::World> mWorld;
187
190
192 std::size_t mNumStepsPerCycle;
193
196
198 ::osg::ref_ptr<::osg::Group> mNormalGroup;
199
201 ::osg::ref_ptr<::osgShadow::ShadowedScene> mShadowedGroup;
202
205};
206
207} // namespace osg
208} // namespace gui
209} // namespace dart
210
211#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:111
WorldNode class encapsulates a World to be displayed in OpenSceneGraph.
Definition WorldNode.hpp:66
void refreshSkeletons()
Refresh all the Skeleton rendering data.
Definition WorldNode.cpp:228
void refreshBaseFrameNode(dart::dynamics::Frame *frame)
Definition WorldNode.cpp:256
Viewer * mViewer
Viewer that this WorldNode is inside of.
Definition WorldNode.hpp:195
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:183
bool mSimulating
True iff simulation is active.
Definition WorldNode.hpp:189
virtual void setupViewer()
Called when this world gets added to an dart::gui::osg::Viewer.
Definition WorldNode.cpp:190
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:198
void refreshSimpleFrames()
Refresh all the custom Frame rendering data.
Definition WorldNode.cpp:246
virtual void customPreStep()
If update() is not overloaded, this function will be called at the beginning of each simulation step.
Definition WorldNode.cpp:148
std::unordered_map< dart::dynamics::Frame *, ::osg::ref_ptr< ShapeFrameNode > > NodeMap
Definition WorldNode.hpp:180
void setShadowTechnique(::osg::ref_ptr< osgShadow::ShadowTechnique > shadowTechnique=nullptr)
Set the ShadowTechnique If you wish to disable shadows, pass a nullptr.
Definition WorldNode.cpp:339
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:364
bool mShadowed
Whether the shadows are enabled.
Definition WorldNode.hpp:204
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:276
::osg::ref_ptr<::osgShadow::ShadowedScene > mShadowedGroup
OSG group for shadowed objects.
Definition WorldNode.hpp:201
bool isShadowed() const
Get whether the WorldNode is casting shadows.
Definition WorldNode.cpp:333
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:355
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:186
std::size_t mNumStepsPerCycle
Number of steps to take between rendering cycles.
Definition WorldNode.hpp:192
Definition BulletCollisionDetector.cpp:60