Ponca  40f245e28b920cbb763a1c6282156c87c626f24c
Point Cloud Analysis library
Loading...
Searching...
No Matches
covarianceFit.hpp
1/*
2 Copyright (C) 2014 Nicolas Mellado <nmellado0@gmail.com>
3 Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
4
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
8*/
9
10
11template < class DataPoint, class _WFunctor, typename T>
12void
14{
15 Base::init();
16 m_cov.setZero();
17}
18
19template < class DataPoint, class _WFunctor, typename T>
20bool
22 const VectorType &localQ,
23 const DataPoint &attributes)
24{
25 if( Base::addLocalNeighbor(w, localQ, attributes) ) {
26 m_cov += w * localQ * localQ.transpose();
27 return true;
28 }
29 return false;
30}
31
32
33template < class DataPoint, class _WFunctor, typename T>
36{
37 // handle specific configurations
38 if(Base::finalize() != STABLE)
39 return Base::m_eCurrentState;
40 // With less than Dim neighbors the fitting is undefined
41 if(Base::getNumNeighbors() < DataPoint::Dim)
42 return Base::m_eCurrentState = UNDEFINED;
43
44 // Center the covariance on the centroid
45 auto centroid = Base::barycenterLocal();
46 m_cov = m_cov/Base::getWeightSum() - centroid * centroid.transpose();
47
48#ifdef __CUDACC__
49 m_solver.computeDirect(m_cov);
50#else
51 m_solver.compute(m_cov);
52#endif
53 Base::m_eCurrentState = ( m_solver.info() == Eigen::Success ? STABLE : UNDEFINED );
54
55 return Base::m_eCurrentState;
56}
57
58template < class DataPoint, class _WFunctor, typename T>
61{
62 return m_solver.eigenvalues()(0) / m_solver.eigenvalues().mean();
63}
64
65template <class DataPoint, class _WFunctor, typename T>
68{
69 return (m_solver.eigenvalues()(1) - m_solver.eigenvalues()(0)) /
70 m_solver.eigenvalues()(2);
71}
72
73template <class DataPoint, class _WFunctor, typename T>
76{
77 return (m_solver.eigenvalues()(2) - m_solver.eigenvalues()(1)) /
78 m_solver.eigenvalues()(2);
79}
80
81template <class DataPoint, class _WFunctor, typename T>
84{
85 return (m_solver.eigenvalues()(0)) / m_solver.eigenvalues()(2);
86}
87
88template <class DataPoint, class _WFunctor, typename T>
91{
92 return (m_solver.eigenvalues()(2) - m_solver.eigenvalues()(0)) /
93 m_solver.eigenvalues()(2);
94}
95
96template <class DataPoint, class _WFunctor, typename T>
99{
100 return -(m_solver.eigenvalues()(0) * log(m_solver.eigenvalues()(0)) +
101 m_solver.eigenvalues()(1) * log(m_solver.eigenvalues()(1)) +
102 m_solver.eigenvalues()(2) * log(m_solver.eigenvalues()(2)));
103}
104
105template <class DataPoint, class _WFunctor, typename T>
108{
109 return m_solver.eigenvalues()(0);
110}
111
112template <class DataPoint, class _WFunctor, typename T>
115{
116 return m_solver.eigenvalues()(1);
117}
118
119template <class DataPoint, class _WFunctor, typename T>
122{
123 return m_solver.eigenvalues()(2);
124}
125
126template < class DataPoint, class _WFunctor, int DiffType, typename T>
127void
129{
130 Base::init();
131
132 for(int k=0; k<Base::NbDerivatives; ++k)
133 m_dCov[k].setZero();
134}
135
136
137
138template < class DataPoint, class _WFunctor, int DiffType, typename T>
139bool
141 const VectorType &localQ,
142 const DataPoint &attributes,
143 ScalarArray &dw)
144{
145 if( Base::addLocalNeighbor(w, localQ, attributes, dw) ) {
146 for(int k=0; k<Base::NbDerivatives; ++k)
147 m_dCov[k] += dw[k] * localQ * localQ.transpose();
148
149 return true;
150 }
151
152 return false;
153}
154
155
156template < class DataPoint, class _WFunctor, int DiffType, typename T>
159{
160 PONCA_MULTIARCH_STD_MATH(sqrt);
161
162 Base::finalize();
163 // Test if base finalize end on a viable case (stable / unstable)
164 if (this->isReady())
165 {
166 VectorType cog = Base::barycenterLocal();
167 MatrixType cogSq = cog * cog.transpose();
168 // \fixme Better use eigen here
169 for(int k=0; k<Base::NbDerivatives; ++k)
170 {
171 // Finalize the computation of dCov.
172 m_dCov[k] = m_dCov[k]
173 - cog * Base::m_dSumP.col(k).transpose()
174 - Base::m_dSumP.col(k) * cog.transpose()
175 + Base::m_dSumW[k] * cogSq;
176 }
177 }
178
179 return Base::m_eCurrentState;
180}
181
Procedure that compute and decompose the covariance matrix of the neighbors positions in .
typename DataPoint::Scalar Scalar
Alias to scalar type.
typename Base::VectorType VectorType
Alias to vector type.
Internal generic class computing the derivatives of covariance matrix computed by CovarianceFitBase.
typename DataPoint::MatrixType MatrixType
Alias to matrix type.
typename Base::VectorType VectorType
Alias to vector type.
typename Base::ScalarArray ScalarArray
Alias to scalar derivatives array.
typename DataPoint::Scalar Scalar
Alias to scalar type.
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
Definition enums.h:15
@ UNDEFINED
The fitting is undefined, you can't use it for valid results.
Definition enums.h:22
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17