Ponca  94e4a36411c3364f6192f97adfa8ceee67834d6e
Point Cloud Analysis library
Loading...
Searching...
No Matches
mongePatch.hpp
1
2#include <Eigen/SVD>
3#include <Eigen/Geometry>
4
5#include "mongePatch.h"
6
7template < class DataPoint, class _NFilter, typename T>
8void
10{
11 Base::init();
12
13 m_A = SampleMatrix(6,6);
14 m_A.setZero();
15 m_b.setZero();
16 m_planeIsReady = false;
17}
18
19template < class DataPoint, class _NFilter, typename T>
20bool
22 const VectorType &localQ,
23 const DataPoint &attributes)
24{
25 if(! m_planeIsReady)
26 {
27 return Base::addLocalNeighbor(w, localQ, attributes);
28 }
29 else // base plane is ready, we can now fit the patch
30 {
31 // express neighbor in local coordinate frame
32 const VectorType local = Base::worldToTangentPlane(attributes.pos());
33 const Scalar& h = Base::getHFromLocalCoordinates(local);
34 const Scalar& u = Base::getUFromLocalCoordinates(local);
35 const Scalar& v = Base::getVFromLocalCoordinates(local);
36
37 Eigen::Matrix<Scalar, 6, 1 > p;
38 p << u*u, v*v, u*v, u, v, 1;
39 m_A += w*p*p.transpose();
40 m_b += w*h*p;
41
42 return true;
43 }
44 return false;
45}
46
47template < class DataPoint, class _NFilter, typename T>
50{
51 // end of the fitting process, check plane is ready
52 if (! m_planeIsReady) {
53 FIT_RESULT res = Base::finalize();
54
55 if(res == STABLE) { // plane is ready
56 m_planeIsReady = true;
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 Base::quadraticHeightField().setQuadric
67 (m_A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV | Eigen::NoQRPreconditioner).solve(m_b) );
68
69 return Base::m_eCurrentState = STABLE;
70 }
71}
72
73
74
75template < class DataPoint, class _NFilter, typename T>
76void
78{
79 Base::init();
80
81 m_A = SampleMatrix(4,4);
82 m_A.setZero();
83 m_b.setZero();
84 m_planeIsReady = false;
85}
86
87template < class DataPoint, class _NFilter, typename T>
88bool
90 const VectorType &localQ,
91 const DataPoint &attributes)
92{
93 if(! m_planeIsReady)
94 {
95 return Base::addLocalNeighbor(w, localQ, attributes);
96 }
97 else // base plane is ready, we can now fit the patch
98 {
99 // express neighbor in local coordinate frame
100 const VectorType local = Base::worldToTangentPlane(attributes.pos());
101 const Scalar& h = Base::getHFromLocalCoordinates(local);
102 const Scalar& u = Base::getUFromLocalCoordinates(local);
103 const Scalar& v = Base::getVFromLocalCoordinates(local);
104
105 Eigen::Matrix<Scalar, 4, 1 > p;
106 p << u*u, v*v, u*v, 1;
107 m_A += w*p*p.transpose();
108 m_b += w*h*p;
109
110 return true;
111 }
112 return false;
113}
114
115template < class DataPoint, class _NFilter, typename T>
118{
119 // end of the fitting process, check plane is ready
120 if (! m_planeIsReady) {
121 FIT_RESULT res = Base::finalize();
122
123 if(res == STABLE) { // plane is ready
124 m_planeIsReady = true;
125
126 return Base::m_eCurrentState = NEED_OTHER_PASS;
127 }
128 return res;
129 }
130 // end of the monge patch fitting process
131 else {
132 // we use SVD as the matrix size is 4x4, and skip preconditioner as it is squared
133 Base::quadraticHeightField().setQuadric
134 (m_A.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV | Eigen::NoQRPreconditioner).solve(m_b));
135
136 return Base::m_eCurrentState = STABLE;
137 }
138}
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:138
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:139
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:139
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:172
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:173
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:173
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