Ponca  4a9354998d048bf882a3ee9bac8105216fa08d13
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>
8 requires SPHERE_FIT_REQUIREMENTS
10{
11 Base::init();
12 m_matA.setZero();
13}
14
15template <class DataPoint, class _NFilter, typename T>
16 requires SPHERE_FIT_REQUIREMENTS
18 const DataPoint& attributes)
19{
20 Base::addLocalNeighbor(w, localQ, attributes);
21 VectorA a;
22#ifdef __CUDACC__
23 a(0) = 1;
24 a.template segment<DataPoint::Dim>(1) = localQ;
25 a(DataPoint::Dim + 1) = localQ.squaredNorm();
26#else
27 a << 1, localQ, localQ.squaredNorm();
28#endif
29 m_matA += w * a * a.transpose();
30}
31
32template <class DataPoint, class _NFilter, typename T>
33 requires SPHERE_FIT_REQUIREMENTS
35{
36 // Compute status
37 if (Base::finalize() != STABLE)
38 return Base::m_eCurrentState;
39 if (Base::getNumNeighbors() < DataPoint::Dim)
40 return Base::m_eCurrentState = UNDEFINED;
41 if (Base::algebraicSphere().isValid())
42 Base::m_eCurrentState = CONFLICT_ERROR_FOUND;
43 else
44 Base::m_eCurrentState = Base::getNumNeighbors() < 2 * DataPoint::Dim ? UNSTABLE : STABLE;
45
46 MatrixA matC;
47 matC.setIdentity();
48 matC.template topRightCorner<1, 1>() << -2;
49 matC.template bottomLeftCorner<1, 1>() << -2;
50 matC.template topLeftCorner<1, 1>() << 0;
51 matC.template bottomRightCorner<1, 1>() << 0;
52
53 MatrixA invCpratt;
54 invCpratt.setIdentity();
55 invCpratt.template topRightCorner<1, 1>() << -0.5;
56 invCpratt.template bottomLeftCorner<1, 1>() << -0.5;
57 invCpratt.template topLeftCorner<1, 1>() << 0;
58 invCpratt.template bottomRightCorner<1, 1>() << 0;
59
60 // Remarks:
61 // A and C are symmetric so all eigenvalues and eigenvectors are real
62 // we look for the minimal positive eigenvalue (eigenvalues may be negative)
63 // C^{-1}A is not symmetric
64 // calling Eigen::GeneralizedEigenSolver on (A,C) and Eigen::EigenSolver on C^{-1}A is equivalent
65 // C is not positive definite so Eigen::GeneralizedSelfAdjointEigenSolver cannot be used
66#ifdef __CUDACC__
67 m_solver.computeDirect(invCpratt * m_matA);
68#else
69 m_solver.compute(invCpratt * m_matA);
70#endif
71 VectorA eivals = m_solver.eigenvalues().real();
72 int minId = -1;
73 for (int i = 0; i < DataPoint::Dim + 2; ++i)
74 {
75 Scalar ev = eivals(i);
76 if ((ev > 0) && (minId == -1 || ev < eivals(minId)))
77 minId = i;
78 }
79
80 // mLambda = eivals(minId);
81 VectorA vecU = m_solver.eigenvectors().col(minId).real();
82 Base::m_uq = vecU[1 + DataPoint::Dim];
83 Base::m_ul = vecU.template segment<DataPoint::Dim>(1);
84 Base::m_uc = vecU[0];
85
86 Base::m_isNormalized = false;
87
88 return Base::m_eCurrentState;
89}
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
Algebraic Sphere fitting procedure on point set without normals.
Definition sphereFit.h:63
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition sphereFit.h:64
typename Base::VectorType VectorType
Alias to vector type.
Definition sphereFit.h:64
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:157