Parasol Planning Library (PPL)
GMSPolyhedron.h
Go to the documentation of this file.
1 #ifndef PMPL_GMS_POLYHEDRON_H_
2 #define PMPL_GMS_POLYHEDRON_H_
3 
4 #include "GMSPolygon.h"
5 
7 
8 #include "Transformation.h"
9 #include "Vector.h"
10 
11 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
12 #include <CGAL/Polyhedron_3.h>
13 #include <CGAL/convex_hull_3.h>
14 
15 #include <iostream>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 class IModel;
22 class PQP_Model;
23 class RAPID_model;
25 
26 using namespace mathtool;
27 namespace glutils {
28  class triangulated_model;
29 }
30 
31 
42 class GMSPolyhedron final {
43 
44  public:
45 
48 
49  typedef CGAL::Exact_predicates_exact_constructions_kernel CGALKernel;
50  typedef CGALKernel::Point_3 CGALPoint;
51  typedef CGAL::Polyhedron_3<CGALKernel> CGALPolyhedron;
52 
65  enum class COMAdjust {COM, Surface, None};
66 
70 
72 
73  GMSPolyhedron(const GMSPolyhedron& _p);
74 
76 
77  GMSPolyhedron(glutils::triangulated_model&& _t);
78 
80 
84 
85  GMSPolyhedron& operator=(const GMSPolyhedron& _p);
86  GMSPolyhedron& operator=(GMSPolyhedron&& _p);
87 
91 
93  GMSPolyhedron& operator*=(const Transformation& _t);
94 
96  void Invert();
97 
101  void Scale(double _scalingFactor);
102 
106 
107  bool operator==(const GMSPolyhedron& _p) const;
108  bool operator!=(const GMSPolyhedron& _p) const;
109 
113 
118  Vector3d Read(const std::string& _fileName, COMAdjust _comAdjust);
119 
125  Vector3d LoadFromIModel(IModel* _imodel, COMAdjust _comAdjust);
126 
129  void WriteBYU(std::ostream& _os) const;
130 
133  void WriteObj(std::ostream& _os) const;
134 
138 
139  std::vector<Vector3d>& GetVertexList() noexcept;
140  std::vector<GMSPolygon>& GetPolygonList() noexcept;
141 
142  const std::vector<Vector3d>& GetVertexList() const noexcept;
143  const std::vector<GMSPolygon>& GetPolygonList() const noexcept;
144 
146  const Vector3d& GetCentroid() const;
147 
149  double GetSurfaceArea() const noexcept;
150 
152  double GetMaxRadius() const noexcept;
153 
155  double GetMinRadius() const noexcept;
156 
160 
162  Point3d GetRandPtOnSurface() const;
163 
165  std::unique_ptr<WorkspaceBoundingBox> ComputeBoundingBox() const;
166 
168  GMSPolyhedron ComputeConvexHull() const;
169 
171  CGALPolyhedron CGAL() const;
172 
176  void UpdateCGALPoints();
177 
181 
184  RAPID_model* GetRapidModel() const noexcept;
185 
188  PQP_Model* GetPQPModel() const noexcept;
189 
192  const Vector3d& GetInsidePoint() const noexcept;
193 
197 
212  static GMSPolyhedron MakeBox(const Range<double>& _x,
213  const Range<double>& _y, const Range<double>& _z);
214 
216 
217  private:
218 
221 
223  void ComputeCentroid() const;
224 
226  void OrderFacets();
227 
229  void ComputeSurfaceArea();
230 
233  void ComputeRadii();
234 
236  void ComputeInsidePoint();
237 
241 
242  std::vector<Vector3d> m_vertexList;
243  std::vector<CGALPoint> m_cgalPoints;
244  std::vector<GMSPolygon> m_polygonList;
245 
246  double m_area{0};
247  double m_maxRadius{0};
248  double m_minRadius{0};
249 
250  Vector3d m_centroid;
251  mutable bool m_centroidCached{false};
252 
253 
256  mutable std::unique_ptr<RAPID_model> m_rapidModel;
257  mutable std::unique_ptr<PQP_Model> m_pqpModel;
258 
259  Vector3d m_insidePoint;
260 
262 
263 };
264 
265 /*----------------------------- Transformation -------------------------------*/
266 
268 operator*(const Transformation& _t, const GMSPolyhedron& _poly);
269 
270 /*----------------------------------------------------------------------------*/
271 
272 #endif
GMSPolyhedron operator*(const Transformation &_t, const GMSPolyhedron &_poly)
Definition: GMSPolyhedron.cpp:232
void Read(GenericStateGraph *_g, const std::string &_filename)
Definition: GenericStateGraph.h:1337
Definition: GMSPolygon.h:21
Definition: GMSPolyhedron.h:42
COMAdjust
Definition: GMSPolyhedron.h:65
CGAL::Exact_predicates_exact_constructions_kernel CGALKernel
Definition: GMSPolyhedron.h:49
CGALKernel::Point_3 CGALPoint
Definition: GMSPolyhedron.h:50
CGAL::Polyhedron_3< CGALKernel > CGALPolyhedron
Definition: GMSPolyhedron.h:51
A two or three dimensional bounding box in workspace.
Definition: WorkspaceBoundingBox.h:10
Definition: GMSPolyhedron.h:27
Definition: Cfg.h:23
A range of numeric values.
Definition: Range.h:17