Ponca  73247abfe24d29406a95aee1d4dfa2d34da85d4c
Point Cloud Analysis library
Loading...
Searching...
No Matches
sphereFit.hpp
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7template <class DataPoint, class _NFilter, typename T>
9{
10 Base::init();
11 m_matA.setZero();
12}
13
14template <class DataPoint, class _NFilter, typename T>
16 const DataPoint& attributes)
17{
18 Base::addLocalNeighbor(w, localQ, attributes);
19 VectorA a;
20#ifdef __CUDACC__
21 a(0) = 1;
22 a.template segment<DataPoint::Dim>(1) = localQ;
23 a(DataPoint::Dim + 1) = localQ.squaredNorm();
24#else
25 a << 1, localQ, localQ.squaredNorm();
26#endif
27 m_matA += w * a * a.transpose();
28}
29
30template <class DataPoint, class _NFilter, typename T>
32{
33 // Compute status
34 if (Base::finalize() != STABLE)
35 return Base::m_eCurrentState;
36 if (Base::getNumNeighbors() < DataPoint::Dim)
37 return Base::m_eCurrentState = UNDEFINED;
38 if (Base::algebraicSphere().isValid())
39 Base::m_eCurrentState = CONFLICT_ERROR_FOUND;
40 else
41 Base::m_eCurrentState = Base::getNumNeighbors() < 2 * DataPoint::Dim ? UNSTABLE : STABLE;
42
43 MatrixA matC;
44 matC.setIdentity();
45 matC.template topRightCorner<1, 1>() << -2;
46 matC.template bottomLeftCorner<1, 1>() << -2;
47 matC.template topLeftCorner<1, 1>() << 0;
48 matC.template bottomRightCorner<1, 1>() << 0;
49
50 MatrixA invCpratt;
51 invCpratt.setIdentity();
52 invCpratt.template topRightCorner<1, 1>() << -0.5;
53 invCpratt.template bottomLeftCorner<1, 1>() << -0.5;
54 invCpratt.template topLeftCorner<1, 1>() << 0;
55 invCpratt.template bottomRightCorner<1, 1>() << 0;
56
57 // Remarks:
58 // A and C are symmetric so all eigenvalues and eigenvectors are real
59 // we look for the minimal positive eigenvalue (eigenvalues may be negative)
60 // C^{-1}A is not symmetric
61 // calling Eigen::GeneralizedEigenSolver on (A,C) and Eigen::EigenSolver on C^{-1}A is equivalent
62 // C is not positive definite so Eigen::GeneralizedSelfAdjointEigenSolver cannot be used
63#ifdef __CUDACC__
64 m_solver.computeDirect(invCpratt * m_matA);
65#else
66 m_solver.compute(invCpratt * m_matA);
67#endif
68 VectorA eivals = m_solver.eigenvalues().real();
69 int minId = -1;
70 for (int i = 0; i < DataPoint::Dim + 2; ++i)
71 {
72 Scalar ev = eivals(i);
73 if ((ev > 0) && (minId == -1 || ev < eivals(minId)))
74 minId = i;
75 }
76
77 // mLambda = eivals(minId);
78 VectorA vecU = m_solver.eigenvectors().col(minId).real();
79 Base::m_uq = vecU[1 + DataPoint::Dim];
80 Base::m_ul = vecU.template segment<DataPoint::Dim>(1);
81 Base::m_uc = vecU[0];
82
83 Base::m_isNormalized = false;
84
85 return Base::m_eCurrentState;
86}
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
Algebraic Sphere fitting procedure on point set without normals.
Definition sphereFit.h:58
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition sphereFit.h:59
typename Base::VectorType VectorType
Alias to vector type.
Definition sphereFit.h:59
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
@ CONFLICT_ERROR_FOUND
Multiple classes of the fitting procedure initialize the primitive.
Definition enums.h:27
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17
@ UNSTABLE
The fitting is ready to use but it is considered as unstable (if the number of neighbors is low for e...
Definition enums.h:20
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators Add neighbors stored in a container using STL-like iterat...
Definition basket.h:153