Parasol Planning Library (PPL)
MeanCurvatureSkeleton3D.h
Go to the documentation of this file.
1 #ifndef MEAN_CURVATURE_3D_H_
2 #define MEAN_CURVATURE_3D_H_
3 
4 #ifndef CGAL_EIGEN3_ENABLED
5 #define CGAL_EIGEN3_ENABLED
6 #endif
7 
8 #include <memory>
9 #include <map>
10 #include <limits>
11 #include <algorithm>
12 #include <unordered_map>
13 #include <tuple>
14 #include <sstream>
15 #include <CGAL/Simple_cartesian.h>
16 #include <CGAL/Surface_mesh.h>
17 #include <CGAL/Polyhedron_3.h>
18 #include <CGAL/Polyhedron_items_with_id_3.h>
19 #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
20 #include <CGAL/extract_mean_curvature_flow_skeleton.h>
21 #include <containers/sequential/graph/graph.h>
22 #include <containers/sequential/graph/algorithms/graph_algo_util.h>
23 #include <boost/functional/hash.hpp>
24 #include "Utilities/IOUtils.h"
28 #include "Workspace/PropertyMap.h"
29 #include "Vector.h"
30 
31 using namespace std;
32 using namespace mathtool;
33 
34 class Environment;
35 class XMLNode;
37 
38 
43 
44  public:
45 
46  struct Parameters {
47  double m_wM{0.2};
48  double m_wH{0.1};
49  double m_refine{1};
50  size_t m_iterations{1000};
51  std::string ioType;
52  std::string filebase;
53  bool useConvex{false};
54  double scaleConvex{1.2};
55  size_t space;
56  };
57 
59 
64  typedef CGAL::Simple_cartesian<double> CGALKernel;
65  typedef typename CGALKernel::Point_3 Point3;
66  typedef CGAL::Surface_mesh<Point3> SurfaceMesh;
67  typedef CGAL::Polyhedron_3<CGALKernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
68  typedef CGAL::Mean_curvature_flow_skeletonization<SurfaceMesh> Skeletonization;
69  typedef Skeletonization::Skeleton MCSkeleton;
70  typedef MCSkeleton::vertex_descriptor MCVD;
71  typedef MCSkeleton::edge_descriptor MCED;
72  typedef Skeletonization::Meso_skeleton MESO;
73  typedef vector<Point3d> WitnessType;
75 
79 
81 
84  static void SetDefaultParameters(XMLNode& _node);
85 
88  void SetEnvironment(const Environment* _env);
89 
93  template<typename PolyhedronType>
94  MeanCurvatureSkeleton3D(PolyhedronType& _poly, bool _d = false) : m_debug(_d) {
95  AddPolyhedron(_poly);
96  }
97 
99 
103 
106  void Write(string _filename);
107 
110  void Read(string _filename);
111 
115 
117  template<typename PolyhedronType>
118  void AddPolyhedron(PolyhedronType& _poly, double _refine = 1.32);
119 
121  void BuildSkeleton(bool _curve = true);
122 
124  void BuildSkeleton(const WorkspaceDecomposition* _decomposition, bool _curve = true);
125 
129 
132  pair<WorkspaceSkeleton, AnnotationType> GetSkeleton();
133 
136  pair<WorkspaceSkeleton, AnnotationType> GetMesoSkeleton();
137 
140  void SetParameters(Parameters& _p) { m_params = _p; }
141 
143 
144  private:
145 
148 
150  void InitializeFreeSpace(const Environment* _env);
151 
153  void InitializeObstacleSpace(const Environment* _env);
154 
159  void GetWitnesses(MCVD& _v, vector<Point3d>& _witness);
160 
165  void GetWitnesses(MESO::Vertex& _v, vector<Point3d>& _witness);
166 
171  void GetWitnesses(Skeletonization::vertex_descriptor& _v, vector<Point3d>& _witness);
172 
174  void Reset();
175 
178  void Refine(SurfaceMesh& _m, double _f=1.00);
179 
182  void ToPolyLines(vector<vector<MCVD>>& _plines, bool _isSimplify = true);
183 
185  Point3 Point(MCVD& _vd) { return m_mcs[_vd].point; }
186 
190 
191  SurfaceMesh m_input;
192  MCSkeleton m_mcs;
193  MESO m_meso;
194  WorkspaceSkeleton m_skeleton;
195  AnnotationType m_annotation;
196  bool m_debug{false};
197  Parameters m_params;
198 
200 };
201 
202 /*------------------------Templated Modifiers---------------------------------*/
203 template<typename PolyhedronType>
204 void
206 AddPolyhedron(PolyhedronType& _poly, double _refine) {
207  stringstream ss;
208  ss << _poly;
209  ss >> m_input;
210  Refine(m_input, _refine); //1.32
211 }
212 
213 #endif
void Read(GenericStateGraph *_g, const std::string &_filename)
Definition: GenericStateGraph.h:1337
Definition: Environment.h:137
3D Mean Curvature Skeleton implementation from CGAL
Definition: MeanCurvatureSkeleton3D.h:42
CGAL::Simple_cartesian< double > CGALKernel
Definition: MeanCurvatureSkeleton3D.h:64
Skeletonization::Skeleton MCSkeleton
Definition: MeanCurvatureSkeleton3D.h:69
MCSkeleton::vertex_descriptor MCVD
Definition: MeanCurvatureSkeleton3D.h:70
void AddPolyhedron(PolyhedronType &_poly, double _refine=1.32)
Add an input polyhedron in the input mesh.
Definition: MeanCurvatureSkeleton3D.h:206
CGAL::Surface_mesh< Point3 > SurfaceMesh
Definition: MeanCurvatureSkeleton3D.h:66
void SetParameters(Parameters &_p)
Definition: MeanCurvatureSkeleton3D.h:140
vector< Point3d > WitnessType
Definition: MeanCurvatureSkeleton3D.h:73
MeanCurvatureSkeleton3D(PolyhedronType &_poly, bool _d=false)
Definition: MeanCurvatureSkeleton3D.h:94
MCSkeleton::edge_descriptor MCED
Definition: MeanCurvatureSkeleton3D.h:71
CGALKernel::Point_3 Point3
Definition: MeanCurvatureSkeleton3D.h:65
Skeletonization::Meso_skeleton MESO
Definition: MeanCurvatureSkeleton3D.h:72
CGAL::Mean_curvature_flow_skeletonization< SurfaceMesh > Skeletonization
Definition: MeanCurvatureSkeleton3D.h:68
static Parameters m_defaultParams
Parameters.
Definition: MeanCurvatureSkeleton3D.h:58
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > Polyhedron
Definition: MeanCurvatureSkeleton3D.h:67
PropertyMap< vector< WitnessType >, WitnessType > AnnotationType
Definition: MeanCurvatureSkeleton3D.h:74
Definition: PropertyMap.h:38
Definition: WorkspaceDecomposition.h:24
Geometric skeleton of the workspace.
Definition: WorkspaceSkeleton.h:22
Definition: XMLNode.h:27
Definition: Cfg.h:23
Definition: MeanCurvatureSkeleton3D.h:46
std::string ioType
Definition: MeanCurvatureSkeleton3D.h:51
size_t space
Definition: MeanCurvatureSkeleton3D.h:55
std::string filebase
Definition: MeanCurvatureSkeleton3D.h:52