Ponca  aa50bfdf187919869239c5b44b748842569114c1
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(_evalPos);
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
65
66template < class DataPoint, class _WFunctor, int DiffType, typename T>
67void
69{
70 Base::init(_evalPos);
71
72 for(int k=0; k<Base::NbDerivatives; ++k)
73 m_dCov[k].setZero();
74}
75
76
77
78template < class DataPoint, class _WFunctor, int DiffType, typename T>
79bool
81 const VectorType &localQ,
82 const DataPoint &attributes,
83 ScalarArray &dw)
84{
85 if( Base::addLocalNeighbor(w, localQ, attributes, dw) ) {
86 for(int k=0; k<Base::NbDerivatives; ++k)
87 m_dCov[k] += dw[k] * localQ * localQ.transpose();
88
89 return true;
90 }
91
92 return false;
93}
94
95
96template < class DataPoint, class _WFunctor, int DiffType, typename T>
99{
100 PONCA_MULTIARCH_STD_MATH(sqrt);
101
102 Base::finalize();
103 // Test if base finalize end on a viable case (stable / unstable)
104 if (this->isReady())
105 {
106 VectorType cog = Base::barycenterLocal();
107 MatrixType cogSq = cog * cog.transpose();
108 // \fixme Better use eigen here
109 for(int k=0; k<Base::NbDerivatives; ++k)
110 {
111 // Finalize the computation of dCov.
112 m_dCov[k] = m_dCov[k]
113 - cog * Base::m_dSumP.col(k).transpose()
114 - Base::m_dSumP.col(k) * cog.transpose()
115 + Base::m_dSumW[k] * cogSq;
116 }
117 }
118
119 return Base::m_eCurrentState;
120}
121
Procedure that compute and decompose the covariance matrix of the neighbors positions in .
Definition: covarianceFit.h:51
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition: covarianceFit.h:52
typename Base::VectorType VectorType
Alias to vector type.
Definition: covarianceFit.h:52
Internal generic class computing the derivatives of covariance matrix computed by CovarianceFitBase.
Definition: covarianceFit.h:93
typename DataPoint::MatrixType MatrixType
Alias to matrix type.
Definition: covarianceFit.h:95
typename Base::VectorType VectorType
Alias to vector type.
Definition: covarianceFit.h:94
typename Base::ScalarArray ScalarArray
Alias to scalar derivatives array.
Definition: covarianceFit.h:96
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition: covarianceFit.h:94
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