DART  6.6.2
Shape.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_DYNAMICS_SHAPE_HPP_
34 #define DART_DYNAMICS_SHAPE_HPP_
35 
36 #include <memory>
37 
38 #include <Eigen/Dense>
39 
41 #include "dart/common/Subject.hpp"
42 #include "dart/math/Geometry.hpp"
44 
45 namespace dart {
46 namespace dynamics {
47 
48 class Shape : public virtual common::Subject
49 {
50 public:
51 
53  enum ShapeType {
55  BOX,
67  };
68 
71  enum DataVariance {
72  STATIC=0,
73  DYNAMIC_TRANSFORM = 1 << 1,
74  DYNAMIC_PRIMITIVE = 1 << 2,
75  DYNAMIC_COLOR = 1 << 3,
76  DYNAMIC_VERTICES = 1 << 4,
77  DYNAMIC_ELEMENTS = 1 << 5,
78  DYNAMIC = 0xFF
79  };
80 
83  explicit Shape(ShapeType _type);
84 
86  Shape();
87 
89  virtual ~Shape();
90 
93  virtual const std::string& getType() const = 0;
94 
107  template <typename ShapeT>
108  bool is() const;
109 
113  const math::BoundingBox& getBoundingBox() const;
114 
116  virtual Eigen::Matrix3d computeInertia(double mass) const = 0;
117 
118  Eigen::Matrix3d computeInertiaFromDensity(double density) const;
119 
120  Eigen::Matrix3d computeInertiaFromMass(double mass) const;
121 
126  double getVolume() const;
127 
129  int getID() const;
130 
132  DART_DEPRECATED(6.1)
133  ShapeType getShapeType() const;
134 
138  void setDataVariance(unsigned int _variance);
139 
142  void addDataVariance(unsigned int _variance);
143 
146  void removeDataVariance(unsigned int _variance);
147 
149  unsigned int getDataVariance() const;
150 
152  bool checkDataVariance(DataVariance type) const;
153 
155  virtual void refreshData();
156 
158  DART_DEPRECATED(6.2)
159  virtual void notifyAlphaUpdate(double alpha);
160 
162  virtual void notifyAlphaUpdated(double alpha);
163 
165  DART_DEPRECATED(6.2)
166  virtual void notifyColorUpdate(const Eigen::Vector4d& color);
167 
169  virtual void notifyColorUpdated(const Eigen::Vector4d& color);
170 
171 protected:
173  virtual void updateVolume() const = 0;
174 
176  virtual void updateBoundingBox() const = 0;
177 
179  mutable math::BoundingBox mBoundingBox;
180 
182  mutable bool mIsBoundingBoxDirty;
183 
185  mutable double mVolume;
186 
188  mutable bool mIsVolumeDirty;
189 
191  int mID;
192 
194  unsigned int mVariance;
195 
197  static int mCounter;
198 
202 };
203 
204 } // namespace dynamics
205 } // namespace dart
206 
207 #include "dart/dynamics/detail/Shape.hpp"
208 
209 #endif // DART_DYNAMICS_SHAPE_HPP_
#define DART_DEPRECATED(version)
Definition: Deprecated.hpp:51
std::string type
Definition: SdfParser.cpp:82
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition: Subject.hpp:58
Definition: Shape.hpp:49
bool mIsBoundingBoxDirty
Whether bounding box needs update.
Definition: Shape.hpp:182
ShapeType mType
Definition: Shape.hpp:201
double mVolume
Volume enclosed by the geometry.
Definition: Shape.hpp:185
ShapeType getShapeType() const
Definition: Shape.cpp:109
math::BoundingBox mBoundingBox
The bounding box (in the local coordinate frame) of the shape.
Definition: Shape.hpp:179
int getID() const
Definition: Shape.cpp:103
virtual void notifyAlphaUpdated(double alpha)
Notify that the alpha of this shape has updated.
Definition: Shape.cpp:160
bool mIsVolumeDirty
Whether volume needs update.
Definition: Shape.hpp:188
bool checkDataVariance(DataVariance type) const
True iff this Shape has the specified type of DataVariance.
Definition: Shape.cpp:139
ShapeType
Definition: Shape.hpp:53
@ MESH
Definition: Shape.hpp:62
@ LINE_SEGMENT
Definition: Shape.hpp:64
@ CONE
Definition: Shape.hpp:59
@ CYLINDER
Definition: Shape.hpp:57
@ SPHERE
Definition: Shape.hpp:54
@ MULTISPHERE
Definition: Shape.hpp:61
@ ELLIPSOID
Definition: Shape.hpp:56
@ HEIGHTMAP
Definition: Shape.hpp:65
@ PLANE
Definition: Shape.hpp:60
@ BOX
Definition: Shape.hpp:55
@ SOFT_MESH
Definition: Shape.hpp:63
@ CAPSULE
Definition: Shape.hpp:58
@ UNSUPPORTED
Definition: Shape.hpp:66
Shape()
Constructor.
Definition: Shape.cpp:56
DataVariance
DataVariance can be used by renderers to determine whether it should expect data for this shape to ch...
Definition: Shape.hpp:71
@ DYNAMIC_VERTICES
The coloring or textures of the shape might change.
Definition: Shape.hpp:76
@ DYNAMIC_TRANSFORM
No data will ever change.
Definition: Shape.hpp:73
@ STATIC
Definition: Shape.hpp:72
@ DYNAMIC_PRIMITIVE
The relative transform of the Shape might change.
Definition: Shape.hpp:74
@ DYNAMIC_ELEMENTS
Vertex positions of a mesh might change (this does not include adding or removing vertices) (this enu...
Definition: Shape.hpp:77
@ DYNAMIC_COLOR
The primitive properties (such as x/y/z scaling) of the shape might change.
Definition: Shape.hpp:75
@ DYNAMIC
The number of elements and/or arrangement of elements might change (this includes adding and removing...
Definition: Shape.hpp:78
virtual void notifyAlphaUpdate(double alpha)
Notify that the alpha of this shape has updated.
Definition: Shape.cpp:154
virtual void updateBoundingBox() const =0
Updates bounding box.
Eigen::Matrix3d computeInertiaFromDensity(double density) const
Definition: Shape.cpp:82
Eigen::Matrix3d computeInertiaFromMass(double mass) const
Definition: Shape.cpp:88
virtual const std::string & getType() const =0
Returns a string representing the shape type.
virtual void notifyColorUpdated(const Eigen::Vector4d &color)
Notify that the color (rgba) of this shape has updated.
Definition: Shape.cpp:172
virtual void refreshData()
Instruct this shape to update its data.
Definition: Shape.cpp:148
void removeDataVariance(unsigned int _variance)
Remove a type of variance from this shape.
Definition: Shape.cpp:127
unsigned int mVariance
The DataVariance of this Shape.
Definition: Shape.hpp:194
bool is() const
Get true if the types of this Shape and the template parameter (a shape class) are identical.
Definition: Shape.hpp:42
const math::BoundingBox & getBoundingBox() const
Get the bounding box of the shape in its local coordinate frame.
Definition: Shape.cpp:73
virtual void updateVolume() const =0
Updates volume.
void addDataVariance(unsigned int _variance)
Add a type of variance to this shape.
Definition: Shape.cpp:121
virtual void notifyColorUpdate(const Eigen::Vector4d &color)
Notify that the color (rgba) of this shape has updated.
Definition: Shape.cpp:166
double getVolume() const
Returns volume of this shape.
Definition: Shape.cpp:94
void setDataVariance(unsigned int _variance)
Set the data variance of this shape.
Definition: Shape.cpp:115
unsigned int getDataVariance() const
Get the data variance of this shape.
Definition: Shape.cpp:133
int mID
Unique id.
Definition: Shape.hpp:191
virtual ~Shape()
Destructor.
Definition: Shape.cpp:67
virtual Eigen::Matrix3d computeInertia(double mass) const =0
Computes the inertia.
static int mCounter
Definition: Shape.hpp:197
Definition: Geometry.hpp:578
Definition: MathTypes.hpp:47
Definition: BulletCollisionDetector.cpp:63