Ponca  aa50bfdf187919869239c5b44b748842569114c1
Point Cloud Analysis library
Loading...
Searching...
No Matches
mongePatch.hpp
1
2#include <Eigen/SVD>
3#include <Eigen/Geometry>
4
5template < class DataPoint, class _WFunctor, typename T>
6void
8{
9 Base::init(_evalPos);
10
11 m_b.setZero();
12 m_x.setZero();
13 m_planeIsReady = false;
14}
15
16template < class DataPoint, class _WFunctor, typename T>
17bool
19 const VectorType &localQ,
20 const DataPoint &attributes)
21{
22 if(! m_planeIsReady)
23 {
24 return Base::addLocalNeighbor(w, localQ, attributes);
25 }
26 else // base plane is ready, we can now fit the patch
27 {
28 // express neighbor in local coordinate frame
29 const VectorType local = Base::worldToTangentPlane(attributes.pos());
30 const Scalar& h = *(local.data());
31 const Scalar& u = *(local.data()+1);
32 const Scalar& v = *(local.data()+2);
33
34 Eigen::Matrix<Scalar, 6, 1 > p;
35 p << u*u, v*v, u*v, u, v, 1;
36 m_A += w*p*p.transpose();
37 m_b += w*h*p;
38
39 return true;
40 }
41 return false;
42}
43
44template < class DataPoint, class _WFunctor, typename T>
47{
48 // end of the fitting process, check plane is ready
49 if (! m_planeIsReady) {
50 FIT_RESULT res = Base::finalize();
51
52 if(res == STABLE) { // plane is ready
53 m_planeIsReady = true;
54 m_A = SampleMatrix(6,6);
55 m_A.setZero();
56 m_b.setZero();
57
58 return Base::m_eCurrentState = NEED_OTHER_PASS;
59 }
60 return res;
61 }
62 // end of the monge patch fitting process
63 else {
64 // we use BDCSVD as the matrix size is 36
65 // http://eigen.tuxfamily.org/dox/classEigen_1_1BDCSVD.html
66 m_x = m_A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(m_b);
67 return Base::m_eCurrentState = STABLE;
68 }
69}
70
71template < class DataPoint, class _WFunctor, typename T>
74 PONCA_MULTIARCH_STD_MATH(pow);
75 static const Scalar one (1);
76 static const Scalar two (2);
77 static const Scalar threeOverTwo (Scalar(3)/Scalar(2));
78 return ((one + pow(h_v(),two) ) * h_uu() * two*h_u()*h_v()*h_uv() + (one+pow(h_u(),two))*h_vv()) /
79 (two * pow(one +pow(h_u(),two) + pow(h_v(),two),threeOverTwo));
80}
81
82template < class DataPoint, class _WFunctor, typename T>
85 PONCA_MULTIARCH_STD_MATH(pow);
86 static const Scalar one (1);
87 static const Scalar two (2);
88 return (h_uu()*h_vv() - pow(h_uv(),two)) /
89 pow((one + pow(h_u(),two) + pow(h_v(),two) ), two);
90}
Extension to compute the best fit quadric on 3d points expressed as .
Definition: mongePatch.h:28
typename Base::VectorType VectorType
Alias to vector type.
Definition: mongePatch.h:29
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition: mongePatch.h:29
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
Definition: enums.h:15
@ NEED_OTHER_PASS
The fitting procedure needs to analyse the neighborhood another time.
Definition: enums.h:25
@ STABLE
The fitting is stable and ready to use.
Definition: enums.h:17