DGtal  1.4.2
LinearLeastSquareFittingNormalVectorEstimator.h
1 
17 #pragma once
18 
34 #if defined(LinearLeastSquareFittingNormalVectorEstimator_RECURSES)
35 #error Recursive header files inclusion detected in LinearLeastSquareFittingNormalVectorEstimator.h
36 #else // defined(LinearLeastSquareFittingNormalVectorEstimator_RECURSES)
38 #define LinearLeastSquareFittingNormalVectorEstimator_RECURSES
39 
40 #if !defined LinearLeastSquareFittingNormalVectorEstimator_h
42 #define LinearLeastSquareFittingNormalVectorEstimator_h
43 
45 // Inclusions
46 #include <iostream>
47 #include <DGtal/base/Common.h>
48 #include <DGtal/topology/SCellsFunctors.h>
49 
50 #ifndef WITH_CGAL
51 #error You need to have activated CGAL (WITH_CGAL) to include this file.
52 #endif
53 
54 //CGAL
55 #include <CGAL/Cartesian.h>
56 #include <CGAL/linear_least_squares_fitting_3.h>
57 #include <vector>
58 
60 
61 namespace DGtal
62 {
63  namespace functors
64  {
66  // template class LinearLeastSquareFittingNormalVectorEstimator
78  template <typename TSurfel, typename TEmbedder>
80  {
81  public:
82 
83  typedef TSurfel Surfel;
84  typedef TEmbedder SCellEmbedder;
87 
88  typedef CGAL::Cartesian<double> CGALKernel;
89  typedef CGALKernel::Point_3 CGALPoint;
90  typedef CGALKernel::Plane_3 CGALPlane;
91  typedef CGALKernel::Vector_3 CGALVector;
92 
100  myEmbedder(&anEmbedder), myH(h)
101  {
102  }
103 
110  void pushSurfel(const Surfel & aSurf,
111  const double aDistance)
112  {
113  BOOST_VERIFY(aDistance == aDistance);
114  RealPoint p = myEmbedder->operator()(aSurf);
115  CGALPoint pp(p[0],p[1],p[2]);
116  myPoints.push_back(pp);
117  }
118 
125  {
126  CGALPlane plane;
127  CGAL::linear_least_squares_fitting_3(myPoints.begin(),myPoints.end(), plane, CGAL::Dimension_tag<0>());
128  CGALVector v = plane.orthogonal_vector();
129  RealPoint vv(v.x(),v.y(),v.z());
130  return vv.getNormalized();
131  }
132 
137  void reset()
138  {
139  myPoints.clear();
140  }
141 
142 
143  private:
144 
147 
149  std::vector<CGALPoint> myPoints;
150 
152  double myH;
153 
154 
155 
156  }; // end of class LinearLeastSquareFittingNormalVectorEstimator
157  }
158 } // namespace DGtal
159 
160 
161 // //
163 
164 #endif // !defined LinearLeastSquareFittingNormalVectorEstimator_h
165 
166 #undef LinearLeastSquareFittingNormalVectorEstimator_RECURSES
167 #endif // else defined(LinearLeastSquareFittingNormalVectorEstimator_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: Estimates normal vector using CGAL linear least squares plane fitting.
LinearLeastSquareFittingNormalVectorEstimator(ConstAlias< SCellEmbedder > anEmbedder, const double h)
DGtal is the top-level namespace which contains all DGtal functions and types.
PointVector< 3, double > RealPoint