Ponca  40f245e28b920cbb763a1c6282156c87c626f24c
Point Cloud Analysis library
Loading...
Searching...
No Matches
mongePatch.hpp
1
2#include <Eigen/SVD>
3#include <Eigen/Geometry>
4#include PONCA_MULTIARCH_INCLUDE_CU_STD(cmath)
5
6template < class DataPoint, class _WFunctor, typename T>
7void
9{
10 Base::init();
11
12 m_b.setZero();
13 m_x.setZero();
14 m_planeIsReady = false;
15}
16
17template < class DataPoint, class _WFunctor, typename T>
18bool
20 const VectorType &localQ,
21 const DataPoint &attributes)
22{
23 if(! m_planeIsReady)
24 {
25 return Base::addLocalNeighbor(w, localQ, attributes);
26 }
27 else // base plane is ready, we can now fit the patch
28 {
29 // express neighbor in local coordinate frame
30 const VectorType local = Base::worldToTangentPlane(attributes.pos());
31 const Scalar& h = *(local.data());
32 const Scalar& u = *(local.data()+1);
33 const Scalar& v = *(local.data()+2);
34
35 Eigen::Matrix<Scalar, 6, 1 > p;
36 p << u*u, v*v, u*v, u, v, 1;
37 m_A += w*p*p.transpose();
38 m_b += w*h*p;
39
40 return true;
41 }
42 return false;
43}
44
45template < class DataPoint, class _WFunctor, typename T>
48{
49 // end of the fitting process, check plane is ready
50 if (! m_planeIsReady) {
51 FIT_RESULT res = Base::finalize();
52
53 if(res == STABLE) { // plane is ready
54 m_planeIsReady = true;
55 m_A = SampleMatrix(6,6);
56 m_A.setZero();
57 m_b.setZero();
58
59 return Base::m_eCurrentState = NEED_OTHER_PASS;
60 }
61 return res;
62 }
63 // end of the monge patch fitting process
64 else {
65 // we use BDCSVD as the matrix size is 36
66 // http://eigen.tuxfamily.org/dox/classEigen_1_1BDCSVD.html
67 m_x = m_A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(m_b);
68 return Base::m_eCurrentState = STABLE;
69 }
70}
71
72template < class DataPoint, class _WFunctor, typename T>
75 PONCA_MULTIARCH_STD_MATH(pow);
76 static const Scalar one (1);
77 static const Scalar two (2);
78 static const Scalar threeOverTwo (Scalar(3)/Scalar(2));
79 return ((one + pow(h_v(),two) ) * h_uu() * two*h_u()*h_v()*h_uv() + (one+pow(h_u(),two))*h_vv()) /
80 (two * pow(one +pow(h_u(),two) + pow(h_v(),two),threeOverTwo));
81}
82
83template < class DataPoint, class _WFunctor, typename T>
86 PONCA_MULTIARCH_STD_MATH(pow);
87 static const Scalar one (1);
88 static const Scalar two (2);
89 return (h_uu()*h_vv() - pow(h_uv(),two)) /
90 pow((one + pow(h_u(),two) + pow(h_v(),two) ), two);
91}
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