Ponca  2cfe00173bb12dda99e12b2b48a0e1f683bc5cdd
Point Cloud Analysis library
Loading...
Searching...
No Matches
sphereFit.h
1/*
2This Source Code Form is subject to the terms of the Mozilla Public
3License, v. 2.0. If a copy of the MPL was not distributed with this
4file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7#pragma once
8#include "../../defines.h"
9#include "../concepts.h"
11#include "../primitive/algebraicSphere.h" // used to define SphereFit
12
13#define SPHERE_FIT_REQUIREMENTS ProvidesAlgebraicSphere<T>
14
15namespace Ponca
16{
17
18 /*!
19 \brief Algebraic Sphere fitting procedure on point set without normals
20
21 This method published in \cite Guennebaud:2007:APSS minimizes
22 \f[
23 \mathcal{L}(\mathbf{u}) = \frac{1}{2} \sum_i w_i f_{\mathbf{u}}(\mathbf{x}_i)^2 = \frac{1}{2} \mathbf{u}^T A
24 \mathbf{u}
25 \f]
26 with \f$ A = \sum_i w_i \tilde{\mathbf{x}_i} \tilde{\mathbf{x}_i}^T\f$ and \f$ f_{\mathbf{u}} \f$ the algebraic
27 sphere defined by
28 \f[
29 f_{\mathbf{u}}(\mathbf{x}) =
30 u_c + \mathbf{u}_l.\mathbf{x} + u_q \mathbf{x}.\mathbf{x} =
31 \begin{bmatrix}
32 1 & \mathbf{x}^T & \mathbf{x}.\mathbf{x}
33 \end{bmatrix}
34 \begin{bmatrix}
35 u_c \\ u_l \\ u_q
36 \end{bmatrix}
37 = \tilde{\mathbf{x}}^T \mathbf{u},
38 \f]
39 under the constraint (unitary gradient onto the surface)
40 \f[
41 \|\mathbf{u}_l\|^2 - 4 u_c u_q = \mathbf{u}^T C \mathbf{u} = 1
42 \f]
43 where
44 \f[
45 C =
46 \begin{bmatrix}
47 0 & & & & -2 \\
48 & 1 & & & \\
49 & & \ddots & & \\
50 & & & 1 & \\
51 -2 & & & & 0
52 \end{bmatrix}
53 \f]
54 which amounts to solve the generalized eigenvalue problem \f$ A\mathbf{u} = \lambda C \mathbf{u} \f$.
55
56 \inherit Concept::FittingProcedureConcept
57
58 \see AlgebraicSphere
59 */
60 template <class DataPoint, class _NFilter, typename T>
61 requires SPHERE_FIT_REQUIREMENTS
62 class SphereFitImpl : public T
63 {
64 PONCA_FITTING_DECLARE_DEFAULT_TYPES
65 protected:
66 using VectorA = Eigen::Matrix<Scalar, DataPoint::Dim + 2, 1>;
67 using MatrixA = Eigen::Matrix<Scalar, DataPoint::Dim + 2, DataPoint::Dim + 2>;
68
69 public:
70 using Solver = Eigen::EigenSolver<MatrixA>;
71
72 protected:
73 // computation data
74 MatrixA m_matA{MatrixA::Zero()};
75
76 Solver m_solver;
77
78 public:
79 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(SphereFitImpl, sphereFit)
80 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
81 PONCA_FITTING_IS_SIGNED(false)
82
83 PONCA_MULTIARCH inline const Solver& solver() const { return m_solver; }
84
85 }; // class SphereFit
86
88 template <class DataPoint, class _NFilter, typename T>
90
91#include "sphereFit.hpp"
92
93} // namespace Ponca
Algebraic Sphere fitting procedure on point set without normals.
Definition sphereFit.h:63
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
SphereFitImpl< DataPoint, _NFilter, AlgebraicSphere< DataPoint, _NFilter, T > > SphereFit
Helper alias for Sphere fitting on 3D points using SphereFitImpl.
Definition sphereFit.h:89