Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
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>
9{
10 Base::init();
11
12 m_A = SampleMatrix(6, 6);
13 m_A.setZero();
14 m_b.setZero();
15 m_planeIsReady = false;
16}
17
18template <class DataPoint, class _NFilter, typename T>
20 const DataPoint& attributes)
21{
22 if (!m_planeIsReady)
23 {
24 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 = Base::getHFromLocalCoordinates(local);
31 const Scalar& u = Base::getUFromLocalCoordinates(local);
32 const Scalar& v = Base::getVFromLocalCoordinates(local);
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}
40
41template <class DataPoint, class _NFilter, typename T>
43{
44 // end of the fitting process, check plane is ready
45 if (!m_planeIsReady)
46 {
47 FIT_RESULT res = Base::finalize();
48
49 if (res == STABLE)
50 { // plane is ready
51 m_planeIsReady = true;
52
53 return Base::m_eCurrentState = NEED_OTHER_PASS;
54 }
55 return res;
56 }
57 // end of the monge patch fitting process
58 else
59 {
60 // we use BDCSVD as the matrix size is 36
61 // http://eigen.tuxfamily.org/dox/classEigen_1_1BDCSVD.html
62 Base::quadraticHeightField().setQuadric(
63 m_A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV | Eigen::NoQRPreconditioner).solve(m_b));
64
65 return Base::m_eCurrentState = STABLE;
66 }
67}
68
69template <class DataPoint, class _NFilter, typename T>
71{
72 Base::init();
73
74 m_A = SampleMatrix(4, 4);
75 m_A.setZero();
76 m_b.setZero();
77 m_planeIsReady = false;
78}
79
80template <class DataPoint, class _NFilter, typename T>
82 const DataPoint& attributes)
83{
84 if (!m_planeIsReady)
85 {
86 Base::addLocalNeighbor(w, localQ, attributes);
87 }
88 else // base plane is ready, we can now fit the patch
89 {
90 // express neighbor in local coordinate frame
91 const VectorType local = Base::worldToTangentPlane(attributes.pos());
92 const Scalar& h = Base::getHFromLocalCoordinates(local);
93 const Scalar& u = Base::getUFromLocalCoordinates(local);
94 const Scalar& v = Base::getVFromLocalCoordinates(local);
95
96 Eigen::Matrix<Scalar, 4, 1> p;
97 p << u * u, v * v, u * v, 1;
98 m_A += w * p * p.transpose();
99 m_b += w * h * p;
100 }
101}
102
103template <class DataPoint, class _NFilter, typename T>
105{
106 // end of the fitting process, check plane is ready
107 if (!m_planeIsReady)
108 {
109 FIT_RESULT res = Base::finalize();
110
111 if (res == STABLE)
112 { // plane is ready
113 m_planeIsReady = true;
114
115 return Base::m_eCurrentState = NEED_OTHER_PASS;
116 }
117 return res;
118 }
119 // end of the monge patch fitting process
120 else
121 {
122 // we use SVD as the matrix size is 4x4, and skip preconditioner as it is squared
123 Base::quadraticHeightField().setQuadric(
124 m_A.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV | Eigen::NoQRPreconditioner).solve(m_b));
125
126 return Base::m_eCurrentState = STABLE;
127 }
128}
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:141
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:142
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:142
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:176
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:177
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:177
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