Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
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
10template <class DataPoint, class _NFilter, typename T>
12{
13 Base::init();
14 m_cov.setZero();
15}
16
17template <class DataPoint, class _NFilter, typename T>
19 const DataPoint& attributes)
20{
21 Base::addLocalNeighbor(w, localQ, attributes);
22 m_cov += w * localQ * localQ.transpose();
23}
24
25template <class DataPoint, class _NFilter, typename T>
27{
28 // handle specific configurations
29 if (Base::finalize() != STABLE)
30 return Base::m_eCurrentState;
31 // With less than Dim neighbors the fitting is undefined
32 if (Base::getNumNeighbors() < DataPoint::Dim)
33 return Base::m_eCurrentState = UNDEFINED;
34
35 // Center the covariance on the centroid
36 auto centroid = Base::barycenterLocal();
37 m_cov = m_cov / Base::getWeightSum() - centroid * centroid.transpose();
38
39#ifdef __CUDACC__
40 m_solver.computeDirect(m_cov);
41#else
42 m_solver.compute(m_cov);
43#endif
44 Base::m_eCurrentState = (m_solver.info() == Eigen::Success ? STABLE : UNDEFINED);
45
46 return Base::m_eCurrentState;
47}
48
49template <class DataPoint, class _NFilter, typename T>
51 const
52{
53 return m_solver.eigenvalues()(0) / m_solver.eigenvalues().mean();
54}
55
56template <class DataPoint, class _WFunctor, typename T>
58 const
59{
60 return (m_solver.eigenvalues()(1) - m_solver.eigenvalues()(0)) / m_solver.eigenvalues()(2);
61}
62
63template <class DataPoint, class _WFunctor, typename T>
65 const
66{
67 return (m_solver.eigenvalues()(2) - m_solver.eigenvalues()(1)) / m_solver.eigenvalues()(2);
68}
69
70template <class DataPoint, class _WFunctor, typename T>
72 const
73{
74 return (m_solver.eigenvalues()(0)) / m_solver.eigenvalues()(2);
75}
76
77template <class DataPoint, class _WFunctor, typename T>
79 const
80{
81 return (m_solver.eigenvalues()(2) - m_solver.eigenvalues()(0)) / m_solver.eigenvalues()(2);
82}
83
84template <class DataPoint, class _WFunctor, typename T>
86 const
87{
88 return -(m_solver.eigenvalues()(0) * log(m_solver.eigenvalues()(0)) +
89 m_solver.eigenvalues()(1) * log(m_solver.eigenvalues()(1)) +
90 m_solver.eigenvalues()(2) * log(m_solver.eigenvalues()(2)));
91}
92
93template <class DataPoint, class _WFunctor, typename T>
98
99template <class DataPoint, class _WFunctor, typename T>
104
105template <class DataPoint, class _WFunctor, typename T>
110
111template <class DataPoint, class _NFilter, int DiffType, typename T>
113{
114 Base::init();
115
116 for (int k = 0; k < Base::NbDerivatives; ++k)
117 m_dCov[k].setZero();
118}
119
120template <class DataPoint, class _NFilter, int DiffType, typename T>
122 const DataPoint& attributes, ScalarArray& dw)
123{
124 Base::addLocalNeighbor(w, localQ, attributes, dw);
125 for (int k = 0; k < Base::NbDerivatives; ++k)
126 m_dCov[k] += dw[k] * localQ * localQ.transpose();
127}
128
129template <class DataPoint, class _NFilter, int DiffType, typename T>
131{
132 PONCA_MULTIARCH_STD_MATH(sqrt);
133
134 Base::finalize();
135 // Test if base finalize end on a viable case (stable / unstable)
136 if (this->isReady())
137 {
138 VectorType cog = Base::barycenterLocal();
139 MatrixType cogSq = cog * cog.transpose();
140 // \fixme Better use eigen here
141 for (int k = 0; k < Base::NbDerivatives; ++k)
142 {
143 // Finalize the computation of dCov.
144 m_dCov[k] = m_dCov[k] - cog * Base::m_dSumP.col(k).transpose() - Base::m_dSumP.col(k) * cog.transpose() +
145 Base::m_dSumW[k] * cogSq;
146 }
147 }
148
149 return Base::m_eCurrentState;
150}
151
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::Scalar Scalar
Alias to scalar type.
typename DataPoint::MatrixType MatrixType
Alias to matrix type.
typename Base::ScalarArray ScalarArray
Alias to scalar derivatives array.
typename Base::VectorType VectorType
Alias to vector 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