DART 6.13.2
Loading...
Searching...
No Matches
Shape.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, 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_DYNAMICS_SHAPE_HPP_
34#define DART_DYNAMICS_SHAPE_HPP_
35
36#include <memory>
37
38#include <Eigen/Dense>
39
48
49namespace dart {
50namespace dynamics {
51
53class Shape : public virtual common::Subject,
54 public virtual common::VersionCounter,
55 public common::Castable<Shape>
56{
57public:
59 = common::Signal<void(Shape* shape, std::size_t version)>;
60
80
84 {
85 STATIC = 0,
87 = 1 << 1,
91 = 1 << 3,
93 = 1 << 4,
97 = 1 << 5,
100 DYNAMIC = 0xFF
101 };
102
105 explicit Shape(ShapeType _type);
106
108 Shape();
109
111 virtual ~Shape();
112
115 virtual const std::string& getType() const = 0;
116
120 const math::BoundingBox& getBoundingBox() const;
121
123 virtual Eigen::Matrix3d computeInertia(double mass) const = 0;
124
125 Eigen::Matrix3d computeInertiaFromDensity(double density) const;
126
127 Eigen::Matrix3d computeInertiaFromMass(double mass) const;
128
133 double getVolume() const;
134
136 std::size_t getID() const;
137
139 DART_DEPRECATED(6.1)
140 ShapeType getShapeType() const;
141
145 void setDataVariance(unsigned int _variance);
146
149 void addDataVariance(unsigned int _variance);
150
153 void removeDataVariance(unsigned int _variance);
154
156 unsigned int getDataVariance() const;
157
160
162 virtual void refreshData();
163
165 DART_DEPRECATED(6.2)
166 virtual void notifyAlphaUpdate(double alpha);
167
169 virtual void notifyAlphaUpdated(double alpha);
170
172 DART_DEPRECATED(6.2)
173 virtual void notifyColorUpdate(const Eigen::Vector4d& color);
174
176 virtual void notifyColorUpdated(const Eigen::Vector4d& color);
177
179 std::size_t incrementVersion() override final;
180
182 virtual ShapePtr clone() const = 0;
183
184protected:
186 virtual void updateVolume() const = 0;
187
189 virtual void updateBoundingBox() const = 0;
190
192 mutable math::BoundingBox mBoundingBox;
193
196
198 mutable double mVolume;
199
201 mutable bool mIsVolumeDirty;
202
204 const std::size_t mID;
205
207 unsigned int mVariance;
208
210 static std::atomic_int mCounter;
211
215
216private:
219
220public:
223};
225
226} // namespace dynamics
227} // namespace dart
228
229#endif // DART_DYNAMICS_SHAPE_HPP_
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
Definition ClassWithVirtualBase.hpp:44
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
Definition ClassWithVirtualBase.hpp:43
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
std::string type
Definition SdfParser.cpp:82
A CRTP base class that provides an interface for easily casting to the derived types.
Definition Castable.hpp:58
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition Subject.hpp:58
VersionCounter is an interface for objects that count their versions.
Definition VersionCounter.hpp:43
Definition Shape.hpp:56
bool mIsBoundingBoxDirty
Whether bounding box needs update.
Definition Shape.hpp:195
ShapeType mType
Definition Shape.hpp:214
double mVolume
Volume enclosed by the geometry.
Definition Shape.hpp:198
virtual const std::string & getType() const =0
Returns a string representing the shape type.
ShapeType getShapeType() const
Definition Shape.cpp:111
math::BoundingBox mBoundingBox
The bounding box (in the local coordinate frame) of the shape.
Definition Shape.hpp:192
static std::atomic_int mCounter
Definition Shape.hpp:210
virtual void notifyAlphaUpdated(double alpha)
Notify that the alpha of this shape has updated.
Definition Shape.cpp:162
bool mIsVolumeDirty
Whether volume needs update.
Definition Shape.hpp:201
std::size_t incrementVersion() override final
Increment the version of this Shape and notify its subscribers.
Definition Shape.cpp:180
bool checkDataVariance(DataVariance type) const
True iff this Shape has the specified type of DataVariance.
Definition Shape.cpp:141
ShapeType
Definition Shape.hpp:63
@ MESH
Definition Shape.hpp:74
@ PYRAMID
Definition Shape.hpp:70
@ LINE_SEGMENT
Definition Shape.hpp:76
@ CONE
Definition Shape.hpp:69
@ CYLINDER
Definition Shape.hpp:67
@ SPHERE
Definition Shape.hpp:64
@ MULTISPHERE
Definition Shape.hpp:73
@ ELLIPSOID
Definition Shape.hpp:66
@ RECTANGULAR_PYRAMID
Definition Shape.hpp:71
@ HEIGHTMAP
Definition Shape.hpp:77
@ PLANE
Definition Shape.hpp:72
@ BOX
Definition Shape.hpp:65
@ SOFT_MESH
Definition Shape.hpp:75
@ CAPSULE
Definition Shape.hpp:68
@ UNSUPPORTED
Definition Shape.hpp:78
std::size_t getID() const
Definition Shape.cpp:105
Shape()
Constructor.
Definition Shape.cpp:57
DataVariance
DataVariance can be used by renderers to determine whether it should expect data for this shape to ch...
Definition Shape.hpp:84
@ DYNAMIC_VERTICES
The coloring or textures of the shape might change.
Definition Shape.hpp:92
@ DYNAMIC_TRANSFORM
No data will ever change.
Definition Shape.hpp:86
@ STATIC
Definition Shape.hpp:85
@ DYNAMIC_PRIMITIVE
The relative transform of the Shape might change.
Definition Shape.hpp:88
@ DYNAMIC_ELEMENTS
Vertex positions of a mesh might change (this does not include adding or removing vertices) (this enu...
Definition Shape.hpp:96
@ DYNAMIC_COLOR
The primitive properties (such as x/y/z scaling) of the shape might change.
Definition Shape.hpp:90
@ DYNAMIC
The number of elements and/or arrangement of elements might change (this includes adding and removing...
Definition Shape.hpp:100
virtual void notifyAlphaUpdate(double alpha)
Notify that the alpha of this shape has updated.
Definition Shape.cpp:156
virtual void updateBoundingBox() const =0
Updates bounding box.
Eigen::Matrix3d computeInertiaFromDensity(double density) const
Definition Shape.cpp:84
Eigen::Matrix3d computeInertiaFromMass(double mass) const
Definition Shape.cpp:90
virtual void notifyColorUpdated(const Eigen::Vector4d &color)
Notify that the color (rgba) of this shape has updated.
Definition Shape.cpp:174
virtual void refreshData()
Instruct this shape to update its data.
Definition Shape.cpp:150
virtual ShapePtr clone() const =0
Deep copy shape.
void removeDataVariance(unsigned int _variance)
Remove a type of variance from this shape.
Definition Shape.cpp:129
VersionChangedSignal mVersionChangedSignal
Triggered by incrementVersion()
Definition Shape.hpp:218
unsigned int mVariance
The DataVariance of this Shape.
Definition Shape.hpp:207
const math::BoundingBox & getBoundingBox() const
Get the bounding box of the shape in its local coordinate frame.
Definition Shape.cpp:75
virtual void updateVolume() const =0
Updates volume.
const std::size_t mID
Unique id.
Definition Shape.hpp:204
common::SlotRegister< VersionChangedSignal > onVersionChanged
Use this to subscribe to version change signals.
Definition Shape.hpp:222
void addDataVariance(unsigned int _variance)
Add a type of variance to this shape.
Definition Shape.cpp:123
virtual void notifyColorUpdate(const Eigen::Vector4d &color)
Notify that the color (rgba) of this shape has updated.
Definition Shape.cpp:168
double getVolume() const
Returns volume of this shape.
Definition Shape.cpp:96
void setDataVariance(unsigned int _variance)
Set the data variance of this shape.
Definition Shape.cpp:117
unsigned int getDataVariance() const
Get the data variance of this shape.
Definition Shape.cpp:135
virtual ~Shape()
Destructor.
Definition Shape.cpp:69
virtual Eigen::Matrix3d computeInertia(double mass) const =0
Computes the inertia.
Definition Geometry.hpp:606
Definition Random-impl.hpp:92
std::shared_ptr< Shape > ShapePtr
Definition SmartPointer.hpp:81
Definition BulletCollisionDetector.cpp:60