Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
unorientedSphereFit.h
1/*
2 Copyright (C) 2013 Gael Guennebaud <gael.guennebaud@inria.fr>
3
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7*/
8
9#pragma once
10#include "../../defines.h"
11#include "../concepts.h"
12
13#include "../primitive/algebraicSphere.h" // used to define UnorientedSphereFit
14#include "../tools/mean.h" // used to define UnorientedSphereFit
15
16#include <Eigen/Dense>
17
18#define UNORIENTED_SPHERE_FIT_REQUIREMENTS \
19 ProvidesAlgebraicSphere<T>&& ProvidesMeanPosition<T>&& ProvidesNormal<DataPoint>
20#define UNORIENTED_SPHERE_DER_REQUIREMENTS \
21 ProvidesBasketDiffUnitBase<T>&& ProvidesAlgebraicSphere<T>&& ProvidesMeanPositionDerivative<T>
22
23namespace Ponca
24{
54 template <class DataPoint, class _NFilter, typename T>
55 requires UNORIENTED_SPHERE_FIT_REQUIREMENTS
56 class UnorientedSphereFitImpl : public T
57 {
58 PONCA_FITTING_DECLARE_DEFAULT_TYPES
59
60 protected:
61 using VectorB = Eigen::Matrix<Scalar, DataPoint::Dim + 1, 1>;
62 using MatrixBB = Eigen::Matrix<Scalar, DataPoint::Dim + 1, DataPoint::Dim + 1>;
63
64 public:
65 using Solver = Eigen::EigenSolver<MatrixBB>;
66
67 MatrixBB m_matA{MatrixBB::Zero()};
68 MatrixBB m_matQ{MatrixBB::Zero()};
70
71 Solver m_solver;
72
73 public:
74 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(UnorientedSphereFitImpl, unorientedSphereFit)
75 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
76 PONCA_FITTING_IS_SIGNED(false)
77
78 }; // class UnorientedSphereFitImpl
79
81 template <class DataPoint, class _NFilter, typename T>
83 UnorientedSphereFitImpl<DataPoint, _NFilter,
84 MeanPosition<DataPoint, _NFilter, AlgebraicSphere<DataPoint, _NFilter, T>>>;
85
86 template <class DataPoint, class _NFilter, int DiffType, typename T>
88 class UnorientedSphereDerImpl : public T
89 {
90 protected:
91 PONCA_FITTING_DECLARE_DEFAULT_TYPES
92 PONCA_FITTING_DECLARE_DEFAULT_DER_TYPES
93
94 using VectorB = typename Base::VectorB;
95 using MatrixBB = typename Base::MatrixBB;
96
97 protected:
98 // computation data
99 MatrixBB m_dmatA[Base::NbDerivatives];
100 ScalarArray m_dSumDotPP{ScalarArray::Zero()};
101
102 public:
103 // results
104 ScalarArray m_dUc{ScalarArray::Zero()};
105 VectorArray m_dUl{VectorArray::Zero()};
106 ScalarArray m_dUq{ScalarArray::Zero()};
107
108 public:
109 PONCA_MULTIARCH UnorientedSphereDerImpl()
110 {
111 for (int dim = 0; dim < Base::NbDerivatives; ++dim)
112 m_dmatA[dim].setZero();
113 }
114
115 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(UnorientedSphereDerImpl, unorientedSphereDer)
116 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(UnorientedSphereDerImpl, algebraicSphereDer)
117 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(UnorientedSphereDerImpl, implicitPrimitiveDer)
118
119 PONCA_FITTING_DECLARE_INIT_ADDDER_FINALIZE
120
121 PONCA_MULTIARCH inline ScalarArray dPotential() const;
122 PONCA_MULTIARCH inline VectorArray dNormal() const;
123
125 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm2() const
126 {
127 return Scalar(2.) * Base::m_ul.transpose() * m_dUl - Scalar(4.) * Base::m_uq * m_dUc -
128 Scalar(4.) * Base::m_uc * m_dUq;
129 }
130
132 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm2(unsigned int _d) const
133 {
134 return Scalar(2.) * m_dUl.col(_d).dot(Base::m_ul) - Scalar(4.) * m_dUc.col(_d)[0] * Base::m_uq -
135 Scalar(4.) * m_dUq.col(_d)[0] * Base::m_uc;
136 }
137
139 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm(unsigned int _d) const
140 {
141 PONCA_MULTIARCH_STD_MATH(sqrt);
142 return sqrt(dprattNorm2(_d));
143 }
144
146 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm() const
147 {
148 PONCA_MULTIARCH_STD_MATH(sqrt);
149 return dprattNorm2().array().sqrt();
150 }
151
152
156 PONCA_MULTIARCH [[nodiscard]] inline bool applyPrattNorm();
157
158 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
159 const UnorientedSphereDerImpl<DataPoint, _NFilter, DiffType, T>& _other)
160 {
161 return Base::operator==(_other) && internal::isApprox(m_dSumDotPP, _other.m_dSumDotPP) &&
162 internal::isApprox(m_dmatA, _other.m_dmatA) && internal::isApprox(m_dUq, _other.m_dUq) &&
163 internal::isApprox(m_dUl, _other.m_dUl) && internal::isApprox(m_dUc, _other.m_dUc);
164 }
165
166 }; // class UnorientedSphereDerImpl
167
168 template <class DataPoint, class _NFilter, int DiffType, typename T>
169 using UnorientedSphereDer =
170 UnorientedSphereDerImpl<DataPoint, _NFilter, DiffType, MeanPositionDer<DataPoint, _NFilter, DiffType, T>>;
171
172} // namespace Ponca
173
174#include "unorientedSphereFit.hpp"
Algebraic Sphere primitive.
Compute the barycenter of the input points.
Definition mean.h:29
ScalarArray dprattNorm() const
compute the Pratt norm derivative
Scalar dprattNorm2(unsigned int _d) const
compute the square of the Pratt norm derivative for dimension _d
typename Base::ScalarArray ScalarArray
Alias to scalar derivatives array.
Scalar dprattNorm(unsigned int _d) const
compute the Pratt norm derivative for the dimension _d
bool applyPrattNorm()
Normalize the scalar field by the Pratt norm.
Algebraic Sphere fitting procedure on point sets with non-oriented normals.
This concept ensures that the default types and accessors in a BasketDiff are well-formed.
Definition concepts.h:56
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
UnorientedSphereFitImpl< DataPoint, _NFilter, MeanPosition< DataPoint, _NFilter, AlgebraicSphere< DataPoint, _NFilter, T > > > UnorientedSphereFit
Helper alias for Oriented Sphere fitting on 3D points using UnorientedSphereFitImpl.