Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
Point Cloud Analysis library
Loading...
Searching...
No Matches
mean.h
1/*
2 This Source Code Form is subject to the terms of the Mozilla Public
3 License, v. 2.0. If a copy of the MPL was not distributed with this
4 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5*/
6
7#pragma once
8#include "../../defines.h"
9#include "../concepts.h"
10
11#define MEAN_NORMAL_REQUIREMENTS ProvidesNormal<DataPoint>
12#define MEAN_POSITION_DER_REQUIREMENTS ProvidesBasketDiffUnitBase<T>&& ProvidesMeanPosition<T>
13#define MEAN_NORMAL_DER_REQUIREMENTS ProvidesBasketDiffUnitBase<T>&& ProvidesMeanNormal<T>
14
15namespace Ponca
16{
17
19 \brief Compute the barycenter of the input points
20 \inherit Concept::FittingProcedureConcept
21
22 \warning The barycenter is not stored explicitly, but rather computed from the sum of the neighbors positions.
23
24 This primitive respects:
25 \verbatim ProvidesMeanPosition \endverbatim
26 */
27 template <class DataPoint, class _NFilter, typename T>
28 class MeanPosition : public T
29 {
30 PONCA_FITTING_DECLARE_DEFAULT_TYPES
31
32 protected:
33 VectorType m_sumP{VectorType::Zero()};
34
35 public:
36 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MeanPosition, meanPosition)
37 PONCA_FITTING_DECLARE_INIT
38 PONCA_FITTING_DECLARE_ADDNEIGHBOR
39
42
45 /// \f$\mathbf{x}\f$'s neighborhood
46 PONCA_MULTIARCH inline VectorType barycenter() const
47 {
48 return Base::getNeighborFrame().convertToGlobalBasis(barycenterLocal());
49 }
50
53 */
54 PONCA_MULTIARCH inline Scalar barycenterDistance() const { return barycenterLocal().norm(); }
55
56 protected:
59
62 ///
63 /// Defined as \f$ b(\mathbf{x}) = \frac{\sum_i w_\mathbf{x}(\mathbf{p_i}) \mathbf{p_i}}{\sum_i
64 /// w_\mathbf{x}(\mathbf{p_i})} \f$,
65 /// where \f$\left[\mathbf{p_i} \in \text{neighborhood}(\mathbf{x})\right]\f$ are all the point samples in
66 /// \f$\mathbf{x}\f$'s neighborhood
67 PONCA_MULTIARCH inline VectorType barycenterLocal() const { return (m_sumP / Base::getWeightSum()); }
68
69 PONCA_MULTIARCH inline bool operator==(const MeanPosition<DataPoint, NeighborFilter, T>& other) const
70 {
71 return Base::operator==(other) && internal::isApprox(m_sumP, other.m_sumP);
72 }
73 }; // class MeanPosition
74
76
85 template <class DataPoint, class _NFilter, typename T>
86 requires MEAN_NORMAL_REQUIREMENTS
87 class MeanNormal : public T
88 {
89 PONCA_FITTING_DECLARE_DEFAULT_TYPES
90
91 protected:
92 VectorType m_sumN{VectorType::Zero()};
93
94 public:
95 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MeanNormal, meanNormal)
96 PONCA_FITTING_DECLARE_INIT
97 PONCA_FITTING_DECLARE_ADDNEIGHBOR
98
103
105 PONCA_MULTIARCH [[nodiscard]] inline VectorType meanNormalVector() const
106 {
107 return (m_sumN / Base::getWeightSum());
108 }
109
110 PONCA_MULTIARCH inline bool operator==(const MeanNormal<DataPoint, NeighborFilter, T>& other) const
111 {
112 return Base::operator==(other) && internal::isApprox(m_sumN, other.m_sumN);
113 }
114 }; // class MeanNormal
115
128 template <class DataPoint, class _NFilter, int DiffType, typename T>
129 requires MEAN_POSITION_DER_REQUIREMENTS
130 class MeanPositionDer : public T
131 {
132 PONCA_FITTING_DECLARE_DEFAULT_TYPES
133 PONCA_FITTING_DECLARE_DEFAULT_DER_TYPES
134
135 protected:
137 VectorArray m_dSumP{VectorArray::Zero()};
138
139 public:
140 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(MeanPositionDer, meanPositionDer)
141 PONCA_FITTING_DECLARE_INIT
142 PONCA_FITTING_DECLARE_ADDNEIGHBOR_DER
143
150
170 PONCA_MULTIARCH [[nodiscard]] VectorArray barycenterDerivatives() const
171 {
172 return (m_dSumP - Base::barycenterLocal() * Base::m_dSumW) / Base::getWeightSum();
173 }
174
175 PONCA_MULTIARCH inline bool operator==(
177 {
178 return Base::operator==(other) && internal::isApprox(m_dSumP, other.m_dSumP);
179 }
180 }; // class MeanPositionDer
181
194 template <class DataPoint, class _NFilter, int DiffType, typename T>
195 requires MEAN_NORMAL_DER_REQUIREMENTS
196 class MeanNormalDer : public T
197 {
198 PONCA_FITTING_DECLARE_DEFAULT_TYPES
199 PONCA_FITTING_DECLARE_DEFAULT_DER_TYPES
200
201 protected:
203 VectorArray m_dSumN{VectorArray::Zero()};
204
205 public:
206 PONCA_EXPLICIT_BASKET_CAST_OPERATORS_DER(MeanNormalDer, meanNormalDer)
207 PONCA_FITTING_DECLARE_INIT
208 PONCA_FITTING_DECLARE_ADDNEIGHBOR_DER
209
215
237
238 PONCA_MULTIARCH [[nodiscard]] VectorArray dMeanNormal() const
239 {
240 return (m_dSumN - Base::meanNormalVector() * Base::m_dSumW) / Base::getWeightSum();
241 }
242
243 PONCA_MULTIARCH inline bool operator==(const MeanNormalDer<DataPoint, NeighborFilter, DiffType, T>& other) const
244 {
245 return Base::operator==(other) && internal::isApprox(m_dSumN, other.m_dSumN);
246 }
247
248 }; // class MeanNormalDer
249
250#include "mean.hpp"
251
252} // namespace Ponca
Compute the derivatives of the input points mean normal.
Definition mean.h:197
MeanNormalDer< DataPoint, _NFilter, DiffType, T > & meanNormalDer()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mean.h:206
typename Base::VectorArray VectorArray
Alias to vector derivatives array.
Definition mean.h:199
typename Base::VectorType VectorType
Alias to vector type.
Definition mean.h:198
VectorArray m_dSumN
Derivatives of the input normals of the input points vectors.
Definition mean.h:203
Compute the mean normal of the input points.
Definition mean.h:88
typename Base::VectorType VectorType
Alias to vector type.
Definition mean.h:89
MeanNormal< DataPoint, _NFilter, T > & meanNormal()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mean.h:95
VectorType m_sumN
Sum of the normal vectors.
Definition mean.h:92
Compute the derivatives of the input points barycenter.
Definition mean.h:131
typename Base::VectorType VectorType
Alias to vector type.
Definition mean.h:132
MeanPositionDer< DataPoint, _NFilter, DiffType, T > & meanPositionDer()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mean.h:140
VectorArray m_dSumP
Derivatives of the input points vectors.
Definition mean.h:137
typename Base::VectorArray VectorArray
Alias to vector derivatives array.
Definition mean.h:133
Compute the barycenter of the input points.
Definition mean.h:29
VectorType m_sumP
Sum of the input points vectors.
Definition mean.h:33
typename Base::VectorType VectorType
Alias to vector type.
Definition mean.h:30
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
Ponca::MeanPosition T barycenter() const
where are all the point samples in 's neighborhood
Definition mean.h:46
Scalar barycenterDistance() const
The distance between the barycenter and the basis center.
Definition mean.h:54