Ponca  6d7f3619cbd70eb6ac131a3267ba1a351b1c9d07
Point Cloud Analysis library
Loading...
Searching...
No Matches
weightFunc.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
9#include "../Common/Assert.h"
10#include "./defines.h"
11#include PONCA_MULTIARCH_INCLUDE_CU_STD(utility)
12
13namespace Ponca
14{
15 namespace internal
16 {
32 template <class DataPoint>
34 {
35 public:
37 using Scalar = typename DataPoint::Scalar;
39 using VectorType = typename DataPoint::VectorType;
40
42 static constexpr bool hasLocalFrame = true;
43
44 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const VectorType& _evalPos = VectorType::Zero())
45 : m_p(_evalPos)
46 {
47 }
48
49 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const DataPoint& _evalPoint)
50 : m_p(_evalPoint.pos())
51 {
52 }
53
55 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& _newEvalPos) { m_p = _newEvalPos; };
56
67 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToGlobalBasis(const VectorType& _q,
68 bool _isPositionVector = true) const
69 {
70 return (_isPositionVector ? (_q + m_p) : _q);
71 }
72
84 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToLocalBasis(const VectorType& _q,
85 bool _isPositionVector = true) const
86 {
87 return (_isPositionVector ? (_q - m_p) : _q);
88 }
89
94 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& evalPos() const { return m_p; }
95
96 private:
97 VectorType m_p;
98 };
112 template <class DataPoint>
114 {
115 public:
117 using Scalar = typename DataPoint::Scalar;
119 using VectorType = typename DataPoint::VectorType;
120
122 static constexpr bool hasLocalFrame = false;
123
124 PONCA_MULTIARCH inline explicit GlobalNeighborhoodFrame(const VectorType& /*_evalPos*/ = VectorType::Zero())
125 {
126 }
127
129 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& /*_newEvalPos*/) {};
130
138 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToGlobalBasis(
139 const VectorType& _q, bool /*_isPositionVector*/ = true) const
140 {
141 return _q;
142 }
143
151 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToLocalBasis(
152 const VectorType& _q, bool /*_isPositionVector*/ = true) const
153 {
154 return _q;
155 }
156 };
157 } // namespace internal
158
175 template <class DataPoint, class WeightKernel>
177 {
178 public:
180 using Scalar = typename DataPoint::Scalar;
182 using VectorType = typename DataPoint::VectorType;
184 using MatrixType = typename DataPoint::MatrixType;
186 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
190 static constexpr bool isCompact = WeightKernel::isCompact;
191
196 PONCA_MULTIARCH inline DistWeightFunc(const VectorType& _evalPos = VectorType::Zero(),
197 const Scalar& _t = Scalar(1.))
199 {
200 PONCA_ASSERT(_t > Scalar(0));
201 }
202
204 PONCA_MULTIARCH inline DistWeightFunc(const DataPoint& _evalPoint, const Scalar& _t = Scalar(1.))
206 {
207 PONCA_ASSERT(_t > Scalar(0));
208 }
209
224 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& q) const;
225
241 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& _q,
242 const DataPoint& /*attributes*/) const;
243
265 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& _q,
266 const DataPoint& /*attributes*/) const;
267
282 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& _q,
283 const DataPoint& /*attributes*/) const;
284
303 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& _q,
304 const DataPoint& /*attributes*/) const;
305
325 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& _q,
326 const DataPoint& /*attributes*/) const;
327
329 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return m_t; }
330
331 protected:
335 }; // class DistWeightFunc
336
337 namespace internal
338 {
346 template <class DataPoint, template <typename> typename _NeighborhoodFrame>
347 class NoWeightFuncBase : public _NeighborhoodFrame<DataPoint>
348 {
349 public:
351 using Scalar = typename DataPoint::Scalar;
353 using VectorType = typename DataPoint::VectorType;
355 using MatrixType = typename DataPoint::MatrixType;
357 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
358
360
364 PONCA_MULTIARCH inline NoWeightFuncBase(const VectorType& v = VectorType::Zero(), Scalar = 0)
366 {
367 }
368
370 PONCA_MULTIARCH inline NoWeightFuncBase(const DataPoint& v, Scalar = 0) : NeighborhoodFrame(v.pos()) {}
371
376 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& _q) const
377 {
378 return {Scalar(1), NeighborhoodFrame::convertToLocalBasis(_q.pos())};
379 }
380
386 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& /*_q*/,
387 const DataPoint& /*attributes*/) const
388 {
389 return VectorType::Zeros();
390 }
391
397 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& /*_q*/,
398 const DataPoint& /*attributes*/) const
399 {
400 return MatrixType::Zeros();
401 }
402
407 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& /*_q*/,
408 const DataPoint& /*attributes*/) const
409 {
410 return Scalar(0);
411 }
412
417 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& /*_q*/,
418 const DataPoint& /*attributes*/) const
419 {
420 return Scalar(0);
421 }
422
428 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
429 const DataPoint& /*attributes*/) const
430 {
431 return VectorType::Zeros();
432 }
433 }; // class NoWeightFuncBase
434 } // namespace internal
435
442 template <class DataPoint, typename NeighborFilter>
443 class NeighborFilterStoreNormal : public NeighborFilter
444 {
445 public:
446 using Base = NeighborFilter;
448 using Scalar = typename DataPoint::Scalar;
450 using VectorType = typename DataPoint::VectorType;
452 using MatrixType = typename DataPoint::MatrixType;
454 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
455
460 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const VectorType& _evalPos = VectorType::Zero(),
461 const Scalar& _t = Scalar(1.),
462 const VectorType& _evalNormal = VectorType::Zero())
463 : Base(_evalPos, _t), m_n(_evalNormal)
464 {
465 }
466
467 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const DataPoint& _evalPoint, const Scalar& _t = Scalar(1.))
468 : Base(_evalPoint.pos(), _t), m_n(_evalPoint.normal())
469 {
470 }
471
473 PONCA_MULTIARCH inline const VectorType& evalNormal() const { return m_n; }
474
475 protected:
477 }; // class NeighborFilterStoreNormal
478
479 template <class DataPoint>
483 struct NoWeightFunc : public internal::NoWeightFuncBase<DataPoint, internal::CenteredNeighborhoodFrame>
484 {
486 };
487
488 template <class DataPoint>
491 struct NoWeightFuncGlobal : public internal::NoWeightFuncBase<DataPoint, internal::GlobalNeighborhoodFrame>
492 {
494 };
495
496#include "weightFunc.hpp"
497
498} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
Weight neighbors according to the Euclidean distance between a query and a reference position.
Definition weightFunc.h:177
Scalar scaledw(const VectorType &_q, const DataPoint &) const
First order derivative in scale .
Scalar scaled2w(const VectorType &_q, const DataPoint &) const
Second order derivative in scale .
VectorType scaleSpaced2w(const VectorType &_q, const DataPoint &) const
Cross derivative in scale and in space (for each spatial dimension .
MatrixType spaced2w(const VectorType &_q, const DataPoint &) const
Second order derivative in space (for each spatial dimension .
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:184
DistWeightFunc(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.))
Constructor that defines the current evaluation scale.
Definition weightFunc.h:196
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
Definition weightFunc.h:329
VectorType spacedw(const VectorType &_q, const DataPoint &) const
First order derivative in space (for each spatial dimension .
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:186
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:180
WeightReturnType operator()(const DataPoint &q) const
Compute the weight of the given query with respect to its coordinates.
WeightKernel m_wk
1D function applied to weight queries
Definition weightFunc.h:333
static constexpr bool isCompact
Flag indicating if the weighting kernel is compact of not.
Definition weightFunc.h:190
DistWeightFunc(const DataPoint &_evalPoint, const Scalar &_t=Scalar(1.))
!
Definition weightFunc.h:204
Scalar m_t
Evaluation scale.
Definition weightFunc.h:332
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:182
This class extends a NeighborFilter class to also store the normal of the evaluation point,...
Definition weightFunc.h:444
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:448
const VectorType & evalNormal() const
Access to the evaluation normal set during the initialization.
Definition weightFunc.h:473
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:454
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:452
NeighborFilterStoreNormal(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.), const VectorType &_evalNormal=VectorType::Zero())
Constructor that defines the current evaluation scale.
Definition weightFunc.h:460
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:450
VectorType m_n
Evaluation normal.
Definition weightFunc.h:476
NeighborhoodFrame that express 3d points relatively to a prescribed center.
Definition weightFunc.h:34
const VectorType & evalPos() const
Get access to the stored points of evaluation.
Definition weightFunc.h:94
VectorType convertToLocalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from global to local coordinate system, such as .
Definition weightFunc.h:84
VectorType convertToGlobalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from local to global coordinate system, such as .
Definition weightFunc.h:67
void changeNeighborhoodFrame(const VectorType &_newEvalPos)
Change neighborhood frame (move basis center)
Definition weightFunc.h:55
static constexpr bool hasLocalFrame
Flag indicating that this class modifies the coordinates when passing from global to local.
Definition weightFunc.h:42
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:39
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:37
NeighborhoodFrame that keep points in the global frame without applying any transformation This class...
Definition weightFunc.h:114
void changeNeighborhoodFrame(const VectorType &)
Change neighborhood frame (has no effect for global basis)
Definition weightFunc.h:129
static constexpr bool hasLocalFrame
Flag indicating that this class does not modify the coordinates when passing from global to local.
Definition weightFunc.h:122
const VectorType & convertToLocalBasis(const VectorType &_q, bool=true) const
Convert query from global to local coordinate system : does nothing as this is global frame.
Definition weightFunc.h:151
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:119
const VectorType & convertToGlobalBasis(const VectorType &_q, bool=true) const
Convert position from local to global coordinate system : does nothing as this is global frame.
Definition weightFunc.h:138
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:117
Weighting function that set uniform weight to all samples.
Definition weightFunc.h:348
MatrixType spaced2w(const VectorType &, const DataPoint &) const
Second order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:397
NoWeightFuncBase(const VectorType &v=VectorType::Zero(), Scalar=0)
Default constructor.
Definition weightFunc.h:364
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:355
VectorType scaleSpaced2w(const VectorType &, const DataPoint &) const
Cross derivative in scale and in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:428
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:351
VectorType spacedw(const VectorType &, const DataPoint &) const
First order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:386
Scalar scaled2w(const VectorType &, const DataPoint &) const
Second order derivative in scale , which are always $0$.
Definition weightFunc.h:417
Scalar scaledw(const VectorType &, const DataPoint &) const
First order derivative in scale , which are always $0$.
Definition weightFunc.h:407
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:353
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:357
WeightReturnType operator()(const DataPoint &_q) const
Compute the weight of the given query, which is always $1$.
Definition weightFunc.h:376
NoWeightFuncBase(const DataPoint &v, Scalar=0)
!
Definition weightFunc.h:370
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition bitset.h:16
Weighting function that set uniform weight to all samples and keep neighbors coordinates in global fr...
Definition weightFunc.h:492
Weighting function that set uniform weight to all samples, but transform neighbors coordinates to loc...
Definition weightFunc.h:484