Ponca  2cfe00173bb12dda99e12b2b48a0e1f683bc5cdd
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 }; // class OrientedSphereFitImpl
49
52 template <class DataPoint, class _NFilter, typename T>
54 DataPoint, _NFilter,
55 MeanPosition<DataPoint, _NFilter, MeanNormal<DataPoint, _NFilter, AlgebraicSphere<DataPoint, _NFilter, T>>>>;
57
61 template <class DataPoint, class _NFilter, int DiffType, typename T>
62 requires ORIENTED_SPHERE_DER_REQUIREMENTS
63 class OrientedSphereDerImpl : public T
64 {
65 PONCA_FITTING_DECLARE_DEFAULT_TYPES
66 PONCA_FITTING_DECLARE_DEFAULT_DER_TYPES
67
68 protected:
69 // computation data
70 VectorArray m_dSumN{VectorArray::Zero()};
71 ScalarArray m_dSumDotPN{ScalarArray::Zero()},
74 ScalarArray::Zero()},
75 m_dNume{ScalarArray::Zero()},
76 m_dDeno{ScalarArray::Zero()};
77
78 public:
79 // results
80 ScalarArray m_dUc{ScalarArray::Zero()},
81 m_dUq{ScalarArray::Zero()};
82 VectorArray m_dUl{VectorArray::Zero()};
83
84 public:
85 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, orientedSphereDer)
86 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, algebraicSphereDer)
87 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(OrientedSphereDerImpl, implicitPrimitiveDer)
88
89 PONCA_FITTING_DECLARE_INIT_ADDDER_FINALIZE
90
92 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dPotential() const;
93
95 PONCA_MULTIARCH [[nodiscard]] inline VectorArray dNormal() const;
96
98 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm2() const
99 {
100 return Scalar(2.) * Base::m_ul.transpose() * m_dUl - Scalar(4.) * Base::m_uq * m_dUc -
101 Scalar(4.) * Base::m_uc * m_dUq;
103
105 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm2(unsigned int _d) const
106 {
107 return Scalar(2.) * m_dUl.col(_d).dot(Base::m_ul) - Scalar(4.) * m_dUc.col(_d)[0] * Base::m_uq -
108 Scalar(4.) * m_dUq.col(_d)[0] * Base::m_uc;
109 }
110
111
112 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm(unsigned int _d) const
113 {
114 PONCA_MULTIARCH_STD_MATH(sqrt);
115 return sqrt(dprattNorm2(_d));
116 }
117
119 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm() const
120 {
121 PONCA_MULTIARCH_STD_MATH(sqrt);
122 return dprattNorm2().array().sqrt();
123 }
124
125
129 PONCA_MULTIARCH [[nodiscard]] inline bool applyPrattNorm();
130
131 }; // class OrientedSphereDerImpl
132
134 template <class DataPoint, class _NFilter, int DiffType, typename T>
137
138#include "orientedSphereFit.hpp"
139
140} // namespace Ponca
Compute the mean normal of the input points.
Definition mean.h:84
Algebraic Sphere primitive.
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
bool applyPrattNorm()
Normalize the scalar field by the Pratt norm.
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
DiffType
Flags defining which derivatives need to be computed.
Definition enums.h:34
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.