Parasol Planning Library (PPL)
Body.h
Go to the documentation of this file.
1 #ifndef PMPL_BODY_H_
2 #define PMPL_BODY_H_
3 
5 #include "Utilities/MPUtils.h"
6 
7 #include "Transformation.h"
8 
9 #include "glutils/color.h"
10 
11 #include <memory>
12 #include <set>
13 #include <string>
14 #include <vector>
15 
16 using namespace mathtool;
17 
19 class Connection;
20 class MultiBody;
21 class XMLNode;
22 
23 
41 class Body {
42 
43  public:
44 
47 
49  enum class Type {
50  Planar,
51  Volumetric,
52  Fixed,
53  Joint
54  };
55 
57  enum class MovementType {
58  Fixed,
59  Joint,
60  Rotational,
61  Translational
62  };
63 
67 
71  Body(MultiBody* const _owner, const size_t _index = 0);
72 
76  Body(MultiBody* const _owner, XMLNode& _node);
77 
81  Body(const Body& _other);
82  Body(Body&& _other);
83 
84  ~Body();
85 
89 
90  Body& operator=(const Body& _other);
91  Body& operator=(Body&& _other);
92 
96 
104  void Validate() const;
105 
109 
111  MultiBody* GetMultiBody() const noexcept;
112 
114  void SetMultiBody(MultiBody* const _owner) noexcept;
115 
117  size_t GetIndex() const noexcept;
118 
120  double GetWeight() const;
124 
127  const std::string& Label() const noexcept;
128 
130  bool IsBase() const noexcept;
131 
133  void SetBodyType(const Body::Type _type) noexcept;
134 
136  Body::Type GetBodyType() const noexcept;
137 
139  void SetMovementType(const MovementType _type) noexcept;
140 
142  MovementType GetMovementType() const noexcept;
143 
147 
149  double GetMass() const;
150 
152  const Matrix3x3& GetMoment() const;
153 
157 
159  void SetPolyhedron(GMSPolyhedron&& _poly);
160 
162  const GMSPolyhedron& GetPolyhedron() const;
163 
165  const GMSPolyhedron& GetWorldPolyhedron() const;
166 
168  const GMSPolyhedron& GetBoundingBox() const;
169 
171  GMSPolyhedron GetWorldBoundingBox() const;
172 
176 
178  void MarkDirty();
179 
182  void Configure(const Transformation& _transformation);
183 
186  const Transformation& GetWorldTransformation() const;
187 
191 
193  size_t ForwardConnectionCount() const noexcept;
194 
196  size_t BackwardConnectionCount() const noexcept;
197 
199  size_t AdjacencyConnectionCount() const noexcept;
200 
203  Connection& GetForwardConnection(const size_t _index) const noexcept;
204 
207  Connection& GetBackwardConnection(const size_t _index) const noexcept;
208 
211  Connection& GetAdjacencyConnection(const size_t _index) const noexcept;
212 
217  Connection* GetConnectionTo(const Body* const _other) const noexcept;
218 
222  bool IsAdjacent(const Body* const _otherBody) const;
223 
227  bool SameParent(const Body* const _otherBody) const;
228 
231  void LinkForward(Connection* const _c);
232 
235  void LinkBackward(Connection* const _c);
236 
239  void LinkAdjacency(Connection* const _c);
240 
243  void Unlink(Connection* const _c);
244 
249 
250  static std::string m_modelDataDir;
251 
253  const std::string& GetFileName() const;
254 
256  std::string GetFilePath() const;
257 
260  void ReadGeometryFile(const std::string& _filename);
261 
264  void ReadGeometryFile(
265  GMSPolyhedron::COMAdjust _comAdjust = GMSPolyhedron::COMAdjust::None);
266 
274  void Read(std::istream& _is, CountingStreamBuffer& _cbs);
275 
279 
281  const glutils::color& GetColor() const;
282 
284  void SetColor(const glutils::color& _c);
285 
287  bool IsTextureLoaded() const;
288 
290  const std::string& GetTexture() const;
291 
293 
294  private:
295 
302 
304  void ComputeMomentOfInertia() const;
305 
307  void ComputeBoundingBox() const;
308 
309  const Transformation& FetchBaseTransform() const noexcept;
310 
311  const Transformation& FetchLinkTransform() const noexcept;
312 
317  const Transformation& ComputeWorldTransformation(std::set<size_t>& _visited)
318  const;
319 
323 
324  MultiBody* m_multibody{nullptr};
325  size_t m_index{0};
326  std::string m_label;
327  std::string m_filename;
328 
329  Body::Type m_bodyType;
330  MovementType m_movementType;
331 
332  GMSPolyhedron m_polyhedron;
333  GMSPolyhedron m_boundingBox;
334 
335  Transformation m_transform;
336  mutable bool m_transformCached{false};
337 
338  mutable GMSPolyhedron m_worldPolyhedron;
339  mutable bool m_worldPolyhedronCached{false};
340 
341  double m_mass{1};
342  double m_weight{0.0};
344  Matrix3x3 m_moment;
346 
347  std::vector<Connection*> m_forwardConnections;
348  std::vector<Connection*> m_backwardConnections;
349  std::vector<Connection*> m_adjacencyConnections;
350 
351  const Transformation& (Body::*m_transformFetcher)(void) const noexcept = nullptr;
352 
360 
361  glutils::color m_color{glutils::color::blue};
362  std::string m_textureFile;
363 
365 
366 };
367 
368 /*-------------------------------- I/O Helpers -------------------------------*/
369 
370 std::ostream& operator<<(std::ostream& _os, const Body& _body);
371 
372 #endif
std::ostream & operator<<(std::ostream &_os, const Body &_body)
Definition: Body.cpp:962
void Read(GenericStateGraph *_g, const std::string &_filename)
Definition: GenericStateGraph.h:1337
@ Rotational
Rotational motion in S = [-1, 1].
@ Joint
Rotational motion in R = [min, max].
Definition: Body.h:41
Body(Body &&_other)
Move.
Type
The type of part this body represents within its owning multi body.
Definition: Body.h:49
Body & operator=(Body &&_other)
Move.
MovementType
The type of movement this body can perform.
Definition: Body.h:57
Definition: CollisionDetectionMethod.h:19
Definition: Connection.h:35
Definition: CountingStreamBuffer.h:20
Definition: GMSPolyhedron.h:42
COMAdjust
Definition: GMSPolyhedron.h:65
Definition: MultiBody.h:65
Definition: XMLNode.h:27
Definition: GMSPolyhedron.h:27
Definition: Cfg.h:23