dart
ShapeFrame.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_DYNAMICS_SHAPEFRAME_HPP_
34 #define DART_DYNAMICS_SHAPEFRAME_HPP_
35 
36 #include <Eigen/Dense>
37 
38 #include "dart/common/AspectWithVersion.hpp"
39 #include "dart/common/Signal.hpp"
40 #include "dart/common/SpecializedForAspect.hpp"
41 #include "dart/dynamics/EllipsoidShape.hpp"
42 #include "dart/dynamics/FixedFrame.hpp"
43 #include "dart/dynamics/TemplatedJacobianNode.hpp"
44 #include "dart/dynamics/detail/ShapeFrameAspect.hpp"
45 
46 namespace dart {
47 namespace dynamics {
48 
49 //==============================================================================
51  VisualAspect,
52  detail::VisualAspectProperties,
53  ShapeFrame>
54 {
55 public:
59  ShapeFrame>;
60 
62  VisualAspect(const PropertiesData& properties = PropertiesData());
63 
64  VisualAspect(const VisualAspect&) = delete;
65 
67  void setRGBA(const Eigen::Vector4d& color);
68 
69  DART_COMMON_GET_ASPECT_PROPERTY(Eigen::Vector4d, RGBA)
70  // const Eigen::Vector4d& getRGBA() const;
71 
72  DART_COMMON_SET_GET_ASPECT_PROPERTY(bool, Hidden)
73  // void setHidden(const bool& value);
74  // const bool& getHidden() const;
75 
76  DART_COMMON_SET_GET_ASPECT_PROPERTY(bool, Shadowed)
77  // void setShadowed(const bool& value);
78  // const bool& getShadowed() const;
79 
80 
81  void setColor(const Eigen::Vector3d& color);
82 
84  void setColor(const Eigen::Vector4d& color);
85 
87  void setRGB(const Eigen::Vector3d& rgb);
88 
90  void setAlpha(const double alpha);
91 
93  Eigen::Vector3d getColor() const;
94 
96  Eigen::Vector3d getRGB() const;
97 
99  double getAlpha() const;
100 
102  void hide();
103 
105  void show();
106 
109  bool isHidden() const;
110 };
111 
112 //==============================================================================
114  CollisionAspect,
115  detail::CollisionAspectProperties,
116  ShapeFrame>
117 {
118 public:
119  CollisionAspect(const CollisionAspect&) = delete;
120  CollisionAspect(const PropertiesData& properties = PropertiesData());
121 
122  DART_COMMON_SET_GET_ASPECT_PROPERTY(bool, Collidable)
123  // void setCollidable(const bool& value);
124  // const bool& getCollidable() const;
125 
126 
127  bool isCollidable() const;
128 };
129 
130 //==============================================================================
132  DynamicsAspect,
133  detail::DynamicsAspectProperties,
134  ShapeFrame>
135 {
136 public:
140  ShapeFrame>;
141 
142  DynamicsAspect(const DynamicsAspect&) = delete;
143 
144  DynamicsAspect(const PropertiesData& properties = PropertiesData());
145 
147  void setFrictionCoeff(const double& value);
149  double getFrictionCoeff() const;
150 
151  // DART_COMMON_SET_GET_ASPECT_PROPERTY(double, PrimaryFrictionCoeff)
152  void setPrimaryFrictionCoeff(const double& value);
153  const double& getPrimaryFrictionCoeff() const;
154 
155  DART_COMMON_SET_GET_ASPECT_PROPERTY(double, SecondaryFrictionCoeff)
156  // void setSecondaryFrictionCoeff(const double& value);
157  // const double& getSecondaryFrictionCoeff() const;
158  DART_COMMON_SET_GET_ASPECT_PROPERTY(double, RestitutionCoeff)
159  // void setRestitutionCoeff(const double& value);
160  // const double& getRestitutionCoeff() const;
161 
162 
163  DART_COMMON_SET_GET_ASPECT_PROPERTY(double, PrimarySlipCompliance)
168  // void sePrimarytSlipCompliance(const double& value);
169  // const double& getPrimarySlipCompliance() const;
170  DART_COMMON_SET_GET_ASPECT_PROPERTY(double, SecondarySlipCompliance)
171  // void setSecondarySlipCompliance(const double& value);
172  // const double& getSecondarySlipCompliance() const;
173 
174 
175  void setFirstFrictionDirectionFrame(const Frame* value);
178 
180  const Frame* getFirstFrictionDirectionFrame() const;
181 
182  DART_COMMON_SET_GET_ASPECT_PROPERTY(Eigen::Vector3d, FirstFrictionDirection)
183  // void setFirstFrictionDirection(const Eigen::Vector3d& value);
184  // const Eigen::Vector3d& getFirstFrictionDirection() const;
185 };
186 
187 //==============================================================================
188 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
189 class ShapeFrame : public virtual common::VersionCounter,
191  public virtual Frame
192 {
193 public:
194  friend class BodyNode;
195 
196  using ShapeUpdatedSignal = common::Signal<void(
197  const ShapeFrame* thisShapeFrame,
198  const ShapePtr& oldShape,
199  const ShapePtr& newShape)>;
200 
202  const ShapeFrame* thisShapeFrame,
203  const Eigen::Isometry3d& oldTransform,
204  const Eigen::Isometry3d& newTransform)>;
205 
206  using UniqueProperties = AspectProperties;
207  using Properties = UniqueProperties;
208 
210  virtual ~ShapeFrame() override;
211 
213  void setProperties(const UniqueProperties& properties);
214 
216  void setAspectProperties(const AspectProperties& properties);
217 
218  const AspectProperties& getAspectProperties() const;
219 
221  void setShape(const ShapePtr& shape);
222 
224  ShapePtr getShape();
225 
227  ConstShapePtr getShape() const;
228 
229  DART_BAKE_SPECIALIZED_ASPECT(VisualAspect)
230 
231  DART_BAKE_SPECIALIZED_ASPECT(CollisionAspect)
232 
233  DART_BAKE_SPECIALIZED_ASPECT(DynamicsAspect)
234 
235  // Documentation inherited
236  ShapeFrame* asShapeFrame() override;
237 
238  // Documentation inherited
239  const ShapeFrame* asShapeFrame() const override;
240 
242  bool isShapeNode() const;
243 
246  virtual ShapeNode* asShapeNode();
247 
253  virtual const ShapeNode* asShapeNode() const;
254 
255 protected:
257  ShapeFrame(Frame* parent, const Properties& properties);
258 
260  ShapeFrame(Frame* parent, const ShapePtr& shape = nullptr);
261 
263  ShapeFrame(const std::tuple<Frame*, Properties>& args);
264 
267 
270 
273 
276 
277 public:
280 
284 };
285 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
286 
287 } // namespace dynamics
288 } // namespace dart
289 
290 #endif // DART_DYNAMICS_SHAPEFRAME_HPP_
common::SlotRegister< ShapeUpdatedSignal > onShapeUpdated
Slot register for shape updated signal.
Definition: ShapeFrame.hpp:279
void setColor(const Eigen::Vector3d &color)
Identical to setRGB(const Eigen::Vector3d&)
Definition: ShapeFrame.cpp:116
Definition: ShapeFrame.hpp:131
Eigen::Vector3d getRGB() const
Get RGB color components.
Definition: ShapeFrame.cpp:153
void hide()
Hide the ShapeNode.
Definition: ShapeFrame.cpp:165
void setProperties(const PropertiesData &properties)
Set the Properties of this Aspect.
Definition: AspectWithVersion.hpp:356
The Frame class serves as the backbone of DART&#39;s kinematic tree structure.
Definition: Frame.hpp:57
VersionCounter is an interface for objects that count their versions.
Definition: VersionCounter.hpp:42
Definition: ShapeFrameAspect.hpp:51
void setRGBA(const Eigen::Vector4d &color)
Set RGBA color.
Definition: ShapeFrame.cpp:106
RelativeTransformUpdatedSignal mRelativeTransformUpdatedSignal
Relative transformation updated signal.
Definition: ShapeFrame.hpp:272
void show()
Show the ShapeNode.
Definition: ShapeFrame.cpp:171
Definition: Aspect.cpp:40
Definition: ShapeFrameAspect.hpp:89
Eigen::Vector3d getColor() const
Get color.
Definition: ShapeFrame.cpp:147
ShapeUpdatedSignal mShapeUpdatedSignal
Shape updated signal.
Definition: ShapeFrame.hpp:269
Definition: ShapeNode.hpp:48
common::SlotRegister< RelativeTransformUpdatedSignal > onRelativeTransformUpdated
Slot register for relative transformation updated signal.
Definition: ShapeFrame.hpp:283
bool isHidden() const
True iff the ShapeNode is set to be hidden.
Definition: ShapeFrame.cpp:177
VisualAspect(const PropertiesData &properties=PropertiesData())
Constructor.
Definition: ShapeFrame.cpp:99
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:74
AspectWithProtectedProperties generates implementations of the Property managing functions for an Asp...
Definition: AspectWithVersion.hpp:108
double getAlpha() const
Get the transparency of the Shape.
Definition: ShapeFrame.cpp:159
common::Connection mConnectionForShapeVersionChange
Connect to changes in the Shape version.
Definition: ShapeFrame.hpp:275
SlotRegister can be used as a public member for connecting slots to a private Signal member...
Definition: Signal.hpp:228
void setRGB(const Eigen::Vector3d &rgb)
Set RGB color components (leave alpha alone)
Definition: ShapeFrame.cpp:128
Definition: ShapeFrame.hpp:189
void setAlpha(const double alpha)
Set the transparency of the Shape.
Definition: ShapeFrame.cpp:137
Definition: ShapeFrame.hpp:113
This is an alternative to EmbedProperties which allows your class to also inherit other Composite obj...
Definition: EmbeddedAspect.hpp:237
class Connection
Definition: Signal.hpp:47
Definition: ShapeFrame.hpp:50
bool mAmShapeNode
Contains whether or not this is a ShapeNode.
Definition: ShapeFrame.hpp:266