Ponca  73247abfe24d29406a95aee1d4dfa2d34da85d4c
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 "./defines.h"
10#include PONCA_MULTIARCH_INCLUDE_CU_STD(utility)
11
12namespace Ponca
13{
14 namespace internal
15 {
31 template <class DataPoint>
33 {
34 public:
36 using Scalar = typename DataPoint::Scalar;
38 using VectorType = typename DataPoint::VectorType;
39
41 static constexpr bool hasLocalFrame = true;
42
43 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const VectorType& _evalPos = VectorType::Zero())
44 : m_p(_evalPos)
45 {
46 }
47
48 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const DataPoint& _evalPoint)
49 : m_p(_evalPoint.pos())
50 {
51 }
52
54 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& _newEvalPos) { m_p = _newEvalPos; };
55
66 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToGlobalBasis(const VectorType& _q,
67 bool _isPositionVector = true) const
68 {
69 return (_isPositionVector ? (_q + m_p) : _q);
70 }
71
83 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToLocalBasis(const VectorType& _q,
84 bool _isPositionVector = true) const
85 {
86 return (_isPositionVector ? (_q - m_p) : _q);
87 }
88
93 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& evalPos() const { return m_p; }
94
95 private:
96 VectorType m_p;
97 };
111 template <class DataPoint>
113 {
114 public:
116 using Scalar = typename DataPoint::Scalar;
118 using VectorType = typename DataPoint::VectorType;
119
121 static constexpr bool hasLocalFrame = false;
122
123 PONCA_MULTIARCH inline explicit GlobalNeighborhoodFrame(const VectorType& /*_evalPos*/ = VectorType::Zero())
124 {
125 }
126
128 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& /*_newEvalPos*/) {};
129
137 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToGlobalBasis(
138 const VectorType& _q, bool /*_isPositionVector*/ = true) const
139 {
140 return _q;
141 }
142
150 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToLocalBasis(
151 const VectorType& _q, bool /*_isPositionVector*/ = true) const
152 {
153 return _q;
154 }
155 };
156 } // namespace internal
157
174 template <class DataPoint, class WeightKernel>
176 {
177 public:
179 using Scalar = typename DataPoint::Scalar;
181 using VectorType = typename DataPoint::VectorType;
183 using MatrixType = typename DataPoint::MatrixType;
185 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
189 static constexpr bool isCompact = WeightKernel::isCompact;
190
195 PONCA_MULTIARCH inline DistWeightFunc(const VectorType& _evalPos = VectorType::Zero(),
196 const Scalar& _t = Scalar(1.))
198 {
199 //\todo manage that assert on __host__ and __device__
200 // assert(_t > Scalar(0));
201 }
202
204 PONCA_MULTIARCH inline DistWeightFunc(const DataPoint& _evalPoint, const Scalar& _t = Scalar(1.))
206 {
207 //\todo manage that assert on __host__ and __device__
208 // assert(_t > Scalar(0));
209 }
210
225 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& q) const;
226
242 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& _q,
243 const DataPoint& /*attributes*/) const;
244
266 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& _q,
267 const DataPoint& /*attributes*/) const;
268
283 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& _q,
284 const DataPoint& /*attributes*/) const;
285
304 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& _q,
305 const DataPoint& /*attributes*/) const;
306
326 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& _q,
327 const DataPoint& /*attributes*/) const;
328
330 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return m_t; }
331
332 protected:
336 }; // class DistWeightFunc
337
338 namespace internal
339 {
347 template <class DataPoint, template <typename> typename _NeighborhoodFrame>
348 class NoWeightFuncBase : public _NeighborhoodFrame<DataPoint>
349 {
350 public:
352 using Scalar = typename DataPoint::Scalar;
354 using VectorType = typename DataPoint::VectorType;
356 using MatrixType = typename DataPoint::MatrixType;
358 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
359
361
365 PONCA_MULTIARCH inline NoWeightFuncBase(const VectorType& v = VectorType::Zero(), Scalar = 0)
367 {
368 }
369
371 PONCA_MULTIARCH inline NoWeightFuncBase(const DataPoint& v, Scalar = 0) : NeighborhoodFrame(v.pos()) {}
372
377 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& _q) const
378 {
379 return {Scalar(1), NeighborhoodFrame::convertToLocalBasis(_q.pos())};
380 }
381
387 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& /*_q*/,
388 const DataPoint& /*attributes*/) const
389 {
390 return VectorType::Zeros();
391 }
392
398 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& /*_q*/,
399 const DataPoint& /*attributes*/) const
400 {
401 return MatrixType::Zeros();
402 }
403
408 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& /*_q*/,
409 const DataPoint& /*attributes*/) const
410 {
411 return Scalar(0);
412 }
413
418 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& /*_q*/,
419 const DataPoint& /*attributes*/) const
420 {
421 return Scalar(0);
422 }
423
429 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
430 const DataPoint& /*attributes*/) const
431 {
432 return VectorType::Zeros();
433 }
434 }; // class NoWeightFuncBase
435 } // namespace internal
436
443 template <class DataPoint, typename NeighborFilter>
444 class NeighborFilterStoreNormal : public NeighborFilter
445 {
446 public:
447 using Base = NeighborFilter;
449 using Scalar = typename DataPoint::Scalar;
451 using VectorType = typename DataPoint::VectorType;
453 using MatrixType = typename DataPoint::MatrixType;
455 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
456
461 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const VectorType& _evalPos = VectorType::Zero(),
462 const Scalar& _t = Scalar(0),
463 const VectorType& _evalNormal = VectorType::Zero())
464 : Base(_evalPos, _t), m_n(_evalNormal)
465 {
466 }
467
468 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const DataPoint& _evalPoint, const Scalar& _t = Scalar(0))
469 : Base(_evalPoint.pos(), _t), m_n(_evalPoint.normal())
470 {
471 }
472
474 PONCA_MULTIARCH inline const VectorType& evalNormal() const { return m_n; }
475
476 protected:
478 }; // class NeighborFilterStoreNormal
479
480 template <class DataPoint>
484 struct NoWeightFunc : public internal::NoWeightFuncBase<DataPoint, internal::CenteredNeighborhoodFrame>
485 {
487 };
488
489 template <class DataPoint>
492 struct NoWeightFuncGlobal : public internal::NoWeightFuncBase<DataPoint, internal::GlobalNeighborhoodFrame>
493 {
495 };
496
497#include "weightFunc.hpp"
498
499} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
Weight neighbors according to the Euclidean distance between a query and a reference position.
Definition weightFunc.h:176
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:183
DistWeightFunc(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.))
Constructor that defines the current evaluation scale.
Definition weightFunc.h:195
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
Definition weightFunc.h:330
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:185
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:179
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:334
static constexpr bool isCompact
Flag indicating if the weighting kernel is compact of not.
Definition weightFunc.h:189
DistWeightFunc(const DataPoint &_evalPoint, const Scalar &_t=Scalar(1.))
!
Definition weightFunc.h:204
Scalar m_t
Evaluation scale.
Definition weightFunc.h:333
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:181
This class extends a NeighborFilter class to also store the normal of the evaluation point,...
Definition weightFunc.h:445
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:449
const VectorType & evalNormal() const
Access to the evaluation normal set during the initialization.
Definition weightFunc.h:474
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:455
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:453
NeighborFilterStoreNormal(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(0), const VectorType &_evalNormal=VectorType::Zero())
Constructor that defines the current evaluation scale.
Definition weightFunc.h:461
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:451
VectorType m_n
Evaluation normal.
Definition weightFunc.h:477
NeighborhoodFrame that express 3d points relatively to a prescribed center.
Definition weightFunc.h:33
const VectorType & evalPos() const
Get access to the stored points of evaluation.
Definition weightFunc.h:93
VectorType convertToLocalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from global to local coordinate system, such as .
Definition weightFunc.h:83
VectorType convertToGlobalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from local to global coordinate system, such as .
Definition weightFunc.h:66
void changeNeighborhoodFrame(const VectorType &_newEvalPos)
Change neighborhood frame (move basis center)
Definition weightFunc.h:54
static constexpr bool hasLocalFrame
Flag indicating that this class modifies the coordinates when passing from global to local.
Definition weightFunc.h:41
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:38
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:36
NeighborhoodFrame that keep points in the global frame without applying any transformation This class...
Definition weightFunc.h:113
void changeNeighborhoodFrame(const VectorType &)
Change neighborhood frame (has no effect for global basis)
Definition weightFunc.h:128
static constexpr bool hasLocalFrame
Flag indicating that this class does not modify the coordinates when passing from global to local.
Definition weightFunc.h:121
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:150
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:118
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:137
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:116
Weighting function that set uniform weight to all samples.
Definition weightFunc.h:349
MatrixType spaced2w(const VectorType &, const DataPoint &) const
Second order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:398
NoWeightFuncBase(const VectorType &v=VectorType::Zero(), Scalar=0)
Default constructor.
Definition weightFunc.h:365
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:356
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:429
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:352
VectorType spacedw(const VectorType &, const DataPoint &) const
First order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:387
Scalar scaled2w(const VectorType &, const DataPoint &) const
Second order derivative in scale , which are always $0$.
Definition weightFunc.h:418
Scalar scaledw(const VectorType &, const DataPoint &) const
First order derivative in scale , which are always $0$.
Definition weightFunc.h:408
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:354
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:358
WeightReturnType operator()(const DataPoint &_q) const
Compute the weight of the given query, which is always $1$.
Definition weightFunc.h:377
NoWeightFuncBase(const DataPoint &v, Scalar=0)
!
Definition weightFunc.h:371
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Weighting function that set uniform weight to all samples and keep neighbors coordinates in global fr...
Definition weightFunc.h:493
Weighting function that set uniform weight to all samples, but transform neighbors coordinates to loc...
Definition weightFunc.h:485