Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
orientedSphereFit.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 OrientedSphereFit
12#include "../tools/mean.h" // used to define OrientedSphereFit
13
14#define ORIENTED_SPHERE_FIT_REQUIREMENTS \
15 ProvidesAlgebraicSphere<T>&& ProvidesMeanPosition<T>&& ProvidesMeanNormal<T>&& ProvidesNormal<DataPoint>
16#define ORIENTED_SPHERE_DER_REQUIREMENTS \
17 ProvidesBasketDiffUnitBase<T>&& ProvidesAlgebraicSphere<T>&& ProvidesMeanPositionDerivative<T>
18
19namespace Ponca
20{
21
23 \brief Algebraic Sphere fitting procedure on oriented point sets
24
25 Method published in \cite Guennebaud:2007:APSS.
26
27 \inherit Concept::FittingProcedureConcept
28
29 \see AlgebraicSphere
30 */
31 template <class DataPoint, class _NFilter, typename T>
32 requires ORIENTED_SPHERE_FIT_REQUIREMENTS
33 class OrientedSphereFitImpl : public T
34 {
35 PONCA_FITTING_DECLARE_DEFAULT_TYPES
36
37 protected:
38 // computation data
41 m_nume{0},
42 m_deno{0};
43
44 public:
45 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(OrientedSphereFitImpl, orientedSphereFit)
46 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
47 PONCA_FITTING_IS_SIGNED(true)
48
49 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
50 const OrientedSphereFitImpl<DataPoint, _NFilter, T>& _other) const
51 {
52 return Base::operator==(_other) && internal::isApprox(m_sumDotPN, _other.m_sumDotPN) &&
53 internal::isApprox(m_sumDotPP, _other.m_sumDotPP) && internal::isApprox(m_nume, _other.m_nume) &&
54 internal::isApprox(m_deno, _other.m_deno);
55 }
56 }; // class OrientedSphereFitImpl
57
60 template <class DataPoint, class _NFilter, typename T>
62 DataPoint, _NFilter,
65
69 template <class DataPoint, class _NFilter, int DiffType, typename T>
70 requires ORIENTED_SPHERE_DER_REQUIREMENTS
71 class OrientedSphereDerImpl : public T
72 {
73 PONCA_FITTING_DECLARE_DEFAULT_TYPES
74 PONCA_FITTING_DECLARE_DEFAULT_DER_TYPES
75
76 protected:
77 // computation data
78 VectorArray m_dSumN{VectorArray::Zero()};
79 ScalarArray m_dSumDotPN{ScalarArray::Zero()},
82 ScalarArray::Zero()},
83 m_dNume{ScalarArray::Zero()},
84 m_dDeno{ScalarArray::Zero()};
85
86 public:
87 // results
88 ScalarArray m_dUc{ScalarArray::Zero()},
89 m_dUq{ScalarArray::Zero()};
90 VectorArray m_dUl{VectorArray::Zero()};
91
92 public:
93 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, orientedSphereDer)
94 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, algebraicSphereDer)
95 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, implicitPrimitiveDer)
96
97 PONCA_FITTING_DECLARE_INIT_ADDDER_FINALIZE
98
99
100 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dPotential() const;
101
102 /*! \brief Returns the derivatives of the primitive normal */
103 PONCA_MULTIARCH [[nodiscard]] inline VectorArray dNormal() const;
104
106 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm2() const
107 {
108 return Scalar(2.) * Base::m_ul.transpose() * m_dUl - Scalar(4.) * Base::m_uq * m_dUc -
109 Scalar(4.) * Base::m_uc * m_dUq;
110 }
111
113 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm2(unsigned int _d) const
114 {
115 return Scalar(2.) * m_dUl.col(_d).dot(Base::m_ul) - Scalar(4.) * m_dUc.col(_d)[0] * Base::m_uq -
116 Scalar(4.) * m_dUq.col(_d)[0] * Base::m_uc;
117 }
118
120 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm(unsigned int _d) const
121 {
122 PONCA_MULTIARCH_STD_MATH(sqrt);
123 return sqrt(dprattNorm2(_d));
124 }
125
127 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm() const
128 {
129 PONCA_MULTIARCH_STD_MATH(sqrt);
130 return dprattNorm2().array().sqrt();
131 }
132
133
137 PONCA_MULTIARCH [[nodiscard]] inline bool applyPrattNorm();
138
139 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
141 {
142 return Base::operator==(_other) && internal::isApprox(m_dSumDotPP, _other.m_dSumDotPP) &&
143 internal::isApprox(m_dNume, _other.m_dNume) && internal::isApprox(m_dDeno, _other.m_dDeno) &&
144 internal::isApprox(m_dUq, _other.m_dUq) && internal::isApprox(m_dUl, _other.m_dUl) &&
145 internal::isApprox(m_dUc, _other.m_dUc);
146 }
147
148 }; // class OrientedSphereDerImpl
149
151 template <class DataPoint, class _NFilter, int DiffType, typename T>
154
155#include "orientedSphereFit.hpp"
156
157} // namespace Ponca
Compute the barycenter of the input points.
Definition mean.h:29
[OrientedSphereFit Definition]
Scalar dprattNorm2(unsigned int _d) const
compute the square of the Pratt norm derivative for dimension _d
ScalarArray dprattNorm() const
compute the Pratt norm derivative
typename DataPoint::Scalar Scalar
Alias to scalar type.
bool applyPrattNorm()
Normalize the scalar field by the Pratt norm.
ScalarArray m_dDeno
Derivatives of the denominator of the quadratic parameter.
Scalar dprattNorm(unsigned int _d) const
compute the Pratt norm derivative for the dimension _d
Algebraic Sphere fitting procedure on oriented point sets.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
OrientedSphereFitImpl< DataPoint, _NFilter, MeanPosition< DataPoint, _NFilter, MeanNormal< DataPoint, _NFilter, AlgebraicSphere< DataPoint, _NFilter, T > > > > OrientedSphereFit
Helper alias for Oriented Sphere fitting on 3D points using OrientedSphereFitImpl [OrientedSphereFit ...
OrientedSphereDerImpl< DataPoint, _NFilter, DiffType, MeanPositionDer< DataPoint, _NFilter, DiffType, T > > OrientedSphereDer
Helper alias for Oriented Sphere fitting on 3D points using OrientedSphereDerImpl.