Ponca  7abd0fd82719106ad460aa0f2070dffbe375d727
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()};
71 Solver m_solver;
72
73 public:
74 PONCA_EXPLICIT_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,
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_EXPLICIT_CAST_OPERATORS_DER(UnorientedSphereDerImpl, unorientedSphereDer)
110 PONCA_EXPLICIT_CAST_OPERATORS_DER(UnorientedSphereDerImpl, algebraicSphereDer)
111 PONCA_EXPLICIT_CAST_OPERATORS_DER(UnorientedSphereDerImpl, implicitPrimitiveDer)
112
113 PONCA_FITTING_DECLARE_INIT_ADDDER_FINALIZE
114
115 PONCA_MULTIARCH inline ScalarArray dPotential() const;
116 PONCA_MULTIARCH inline VectorArray dNormal() const;
117
119 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm2() const
120 {
121 return Scalar(2.) * Base::m_ul.transpose() * m_dUl - Scalar(4.) * Base::m_uq * m_dUc -
122 Scalar(4.) * Base::m_uc * m_dUq;
123 }
124
126 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm2(unsigned int _d) const
127 {
128 return Scalar(2.) * m_dUl.col(_d).dot(Base::m_ul) - Scalar(4.) * m_dUc.col(_d)[0] * Base::m_uq -
129 Scalar(4.) * m_dUq.col(_d)[0] * Base::m_uc;
130 }
131
133 PONCA_MULTIARCH [[nodiscard]] inline Scalar dprattNorm(unsigned int _d) const
134 {
135 PONCA_MULTIARCH_STD_MATH(sqrt);
136 return sqrt(dprattNorm2(_d));
137 }
138
140 PONCA_MULTIARCH [[nodiscard]] inline ScalarArray dprattNorm() const
141 {
142 PONCA_MULTIARCH_STD_MATH(sqrt);
143 return dprattNorm2().array().sqrt();
144 }
146
150 PONCA_MULTIARCH [[nodiscard]] inline bool applyPrattNorm();
151
152 }; // class UnorientedSphereDerImpl
153
154 template <class DataPoint, class _NFilter, int DiffType, typename T>
155 using UnorientedSphereDer =
156 UnorientedSphereDerImpl<DataPoint, _NFilter, DiffType, MeanPositionDer<DataPoint, _NFilter, DiffType, T>>;
157
158} // namespace Ponca
159
160#include "unorientedSphereFit.hpp"
Compute the barycenter of the input points.
Definition mean.h:29
UnorientedSphereDerImpl< DataPoint, _NFilter, DiffType, T > & implicitPrimitiveDer()
Explicit conversion to UnorientedSphereDerImpl , to access methods potentially hidden by heritage.
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.
UnorientedSphereDerImpl< DataPoint, _NFilter, DiffType, T > & algebraicSphereDer()
Explicit conversion to UnorientedSphereDerImpl , to access methods potentially hidden by heritage.
Scalar dprattNorm(unsigned int _d) const
compute the Pratt norm derivative for the dimension _d
ScalarArray dprattNorm2() const
compute the square of the Pratt norm derivative
typename DataPoint::Scalar Scalar
Alias to scalar type.
typename Base::VectorArray VectorArray
Alias to vector derivatives array.
bool applyPrattNorm()
Normalize the scalar field by the Pratt norm.
UnorientedSphereDerImpl< DataPoint, _NFilter, DiffType, T > & unorientedSphereDer()
Explicit conversion to UnorientedSphereDerImpl , to access methods potentially hidden by heritage.
Algebraic Sphere fitting procedure on point sets with non-oriented normals.
Scalar m_sumDotPP
Sum of the squared relative positions.
UnorientedSphereFitImpl< DataPoint, _NFilter, T > & unorientedSphereFit()
Explicit conversion to UnorientedSphereFitImpl , to access methods potentially hidden by heritage.
MatrixBB m_matA
The accumulated covariance matrix.
MatrixBB m_matQ
The constraint matrix.
typename DataPoint::Scalar Scalar
Alias to scalar type.
This concept ensures that the default types and accessors in a BasketDiff are well-formed.
Definition concepts.h:51
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11