DGtal  1.4.beta
WindingNumbersShape.h
1 
17 #pragma once
18 
31 #if !defined WindingNumbersShape_h
33 #define WindingNumbersShape_h
34 
35 #ifndef WITH_LIBIGL
36 #error You need to have activated LIBIGL (WITH_LIBIGL flag) to include this file.
37 #endif
38 
39 #include <vector>
40 #include <algorithm>
41 #include <DGtal/base/Common.h>
42 #include <DGtal/base/CountedConstPtrOrConstPtr.h>
43 #include <DGtal/base/ConstAlias.h>
44 
45 #include <DGtal/shapes/CEuclideanOrientedShape.h>
46 #include <igl/fast_winding_number.h>
47 #include <igl/octree.h>
48 #include <igl/knn.h>
49 #include <igl/copyleft/cgal/point_areas.h>
50 namespace DGtal
51 {
53 
65  template<typename TSpace>
67  {
69  using Space = TSpace;
70  using RealPoint = typename Space::RealPoint;
71  using RealVector = typename Space::RealVector;
73 
74  //Removing Default constructor
75  WindingNumbersShape() = delete;
76 
87  {
88  myPoints = points;
89  myNormals = normals;
90  myPointAreas = Eigen::VectorXd::Ones(myPoints->rows());
91  // Build octree, from libIGL tutorials
92  igl::octree(*myPoints,myO_PI,myO_CH,myO_CN,myO_W);
93  if (points->rows()> 20)
94  {
95  Eigen::MatrixXi I;
96  igl::knn(*myPoints,(int)points->rows(),myO_PI,myO_CH,myO_CN,myO_W,I);
97  // CGAL is only used to help get point areas
98  igl::copyleft::cgal::point_areas(*myPoints,I,*myNormals,myPointAreas);
99  trace.info()<<" Min/max point area : "<<myPointAreas.minCoeff()<<" -- "<<myPointAreas.maxCoeff()<<std::endl;
100  }
101  else
102  {
103  trace.warning()<<"[WindingNumberShape] Too few points to use CGAL point_areas. Using the constant area setting."<<std::endl;
104  }
105  }
106 
115  const Eigen::VectorXd &areas)
116  {
117  myPoints = points;
118  myNormals = normals;
119  myPointAreas = areas;
120  igl::octree(*myPoints,myO_PI,myO_CH,myO_CN,myO_W);
121  }
122 
123 
127  {
128  myPointAreas = areas;
129  }
130 
140  const double threshold = 0.3) const
141  {
142  Eigen::MatrixXd queries(1,3);
143  queries << aPoint(0) , aPoint(1) , aPoint(2);
144  auto singlePoint = orientationBatch(queries, threshold);
145  return singlePoint[0];
146  }
147 
154  std::vector<Orientation> orientationBatch(const Eigen::MatrixXd & queries,
155  const double threshold = 0.3) const
156  {
157  Eigen::VectorXd W;
158  std::vector<Orientation> results( queries.rows() );
159  Eigen::MatrixXd O_CM;
160  Eigen::VectorXd O_R;
161  Eigen::MatrixXd O_EC;
162 
163  //Checking if the areas
164  igl::fast_winding_number(*myPoints,*myNormals,myPointAreas,myO_PI,myO_CH,2,O_CM,O_R,O_EC);
165  igl::fast_winding_number(*myPoints,*myNormals,myPointAreas,myO_PI,myO_CH,O_CM,O_R,O_EC,queries,2,W);
166 
167  //Reformating the output
168  for(auto i=0u; i < queries.rows(); ++i)
169  {
170  if (std::abs(W(i)) < threshold )
171  results[i] = DGtal::OUTSIDE;
172  else
173  if (std::abs(W(i)) > threshold)
174  results[i] = DGtal::INSIDE;
175  else
176  results[i] = DGtal::ON;
177  }
178  return results;
179  }
180 
186  Eigen::VectorXd myPointAreas;
187 
188 
190  std::vector<std::vector<int > > myO_PI;
192  Eigen::MatrixXi myO_CH;
194  Eigen::MatrixXd myO_CN;
196  Eigen::VectorXd myO_W;
197 
198 
199  };
200 }
201 
202 #endif // !defined WindingNumbersShape_h
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
std::ostream & info()
std::ostream & warning()
Space::RealVector RealVector
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Orientation
Definition: Common.h:141
@ INSIDE
Definition: Common.h:141
@ OUTSIDE
Definition: Common.h:141
@ ON
Definition: Common.h:141
Aim: model of a CEuclideanOrientedShape from an implicit function from an oriented point cloud....
Eigen::VectorXd myPointAreas
Const alias to point area measure.
Eigen::MatrixXd myO_CN
libIGL octree for fast queries data structure
Eigen::VectorXd myO_W
libIGL octree for fast queries data structure
WindingNumbersShape(ConstAlias< Eigen::MatrixXd > points, ConstAlias< Eigen::MatrixXd > normals)
Orientation orientation(const RealPoint aPoint, const double threshold=0.3) const
typename Space::RealPoint RealPoint
std::vector< Orientation > orientationBatch(const Eigen::MatrixXd &queries, const double threshold=0.3) const
void setPointAreas(ConstAlias< Eigen::VectorXd > areas)
CountedConstPtrOrConstPtr< Eigen::MatrixXd > myPoints
Const alias to the points.
Eigen::MatrixXi myO_CH
libIGL octree for fast queries data structure
typename Space::RealVector RealVector
WindingNumbersShape(ConstAlias< Eigen::MatrixXd > points, ConstAlias< Eigen::MatrixXd > normals, const Eigen::VectorXd &areas)
std::vector< std::vector< int > > myO_PI
libIGL octree for fast queries data structure
CountedConstPtrOrConstPtr< Eigen::MatrixXd > myNormals
Const alias to the normals.
const Point aPoint(3, 4)
PointVector< 3, double > RealPoint