Ponca  94e4a36411c3364f6192f97adfa8ceee67834d6e
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{
26template<class DataPoint>
28public:
30 using Scalar = typename DataPoint::Scalar;
32 using VectorType = typename DataPoint::VectorType;
33
35 static constexpr bool hasLocalFrame = true;
36
37 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const VectorType & _evalPos = VectorType::Zero())
38 : m_p(_evalPos) {}
39
40 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const DataPoint & _evalPoint)
41 : m_p(_evalPoint.pos()) {}
42
44 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& _newEvalPos) { m_p = _newEvalPos; };
45
55 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToGlobalBasis(const VectorType& _q,
56 bool _isPositionVector = true) const {
57 return ( _isPositionVector ? (_q + m_p) : _q );
58 }
59
70 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToLocalBasis(const VectorType& _q,
71 bool _isPositionVector = true) const {
72 return ( _isPositionVector ? (_q - m_p) : _q );
73 }
74
79 PONCA_MULTIARCH [[nodiscard]] inline VectorType evalPos() const { return m_p; }
80
81private:
82 VectorType m_p;
83};
94template<class DataPoint>
96public:
98 using Scalar = typename DataPoint::Scalar;
100 using VectorType = typename DataPoint::VectorType;
101
103 static constexpr bool hasLocalFrame = false;
104
105 PONCA_MULTIARCH inline explicit GlobalNeighborhoodFrame(const VectorType & /*_evalPos*/ = VectorType::Zero()) {}
106
108 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& /*_newEvalPos*/) {};
109
117 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToGlobalBasis(const VectorType& _q,
118 bool /*_isPositionVector*/ = true) const {
119 return _q;
120 }
121
129 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToLocalBasis(const VectorType& _q,
130 bool /*_isPositionVector*/ = true) const {
131 return _q;
132 }
133};
134
135
152template <class DataPoint, class WeightKernel>
154{
155public:
157 using Scalar = typename DataPoint::Scalar;
159 using VectorType = typename DataPoint::VectorType;
161 using MatrixType = typename DataPoint::MatrixType;
163 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
167 static constexpr bool isCompact = WeightKernel::isCompact;
168
173 PONCA_MULTIARCH inline DistWeightFunc(const VectorType & _evalPos = VectorType::Zero(),
174 const Scalar& _t = Scalar(1.))
175 : NeighborhoodFrame(_evalPos), m_t(_t)
176 {
177 //\todo manage that assert on __host__ and __device__
178 //assert(_t > Scalar(0));
179 }
180
182 PONCA_MULTIARCH inline DistWeightFunc(const DataPoint & _evalPoint,
183 const Scalar& _t = Scalar(1.))
184 : NeighborhoodFrame(_evalPoint.pos()), m_t(_t)
185 {
186 //\todo manage that assert on __host__ and __device__
187 //assert(_t > Scalar(0));
188 }
189
204 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& q) const;
205
206
222 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& _q,
223 const DataPoint& /*attributes*/) const;
224
225
246 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& _q,
247 const DataPoint& /*attributes*/) const;
248
263 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& _q,
264 const DataPoint& /*attributes*/) const;
265
284 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& _q,
285 const DataPoint& /*attributes*/) const;
286
306 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& _q,
307 const DataPoint& /*attributes*/) const;
308
310 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return m_t; }
311
312protected:
314 WeightKernel m_wk;
316};// class DistWeightFunc
317
325template <class DataPoint, template <typename>typename _NeighborhoodFrame>
326class NoWeightFuncBase : public _NeighborhoodFrame<DataPoint>
327{
328public:
330 using Scalar = typename DataPoint::Scalar;
332 using VectorType = typename DataPoint::VectorType;
334 using MatrixType = typename DataPoint::MatrixType;
336 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
337
338 using NeighborhoodFrame = _NeighborhoodFrame<DataPoint>;
339
343 PONCA_MULTIARCH inline NoWeightFuncBase(const VectorType& v = VectorType::Zero(), Scalar = 0)
344 : NeighborhoodFrame(v){ }
345
347 PONCA_MULTIARCH inline NoWeightFuncBase(const DataPoint& v, Scalar = 0)
348 : NeighborhoodFrame(v.pos()){ }
349
354 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& _q) const
355 {
356 return {Scalar(1), NeighborhoodFrame::convertToLocalBasis(_q.pos())};
357 }
358
359
364 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& /*_q*/,
365 const DataPoint& /*attributes*/) const
366 { return VectorType::Zeros(); }
367
368
373 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& /*_q*/,
374 const DataPoint& /*attributes*/) const
375 { return MatrixType::Zeros(); }
376
381 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& /*_q*/,
382 const DataPoint& /*attributes*/) const
383 { return Scalar(0); }
384
389 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& /*_q*/,
390 const DataPoint& /*attributes*/) const
391 { return Scalar(0); }
392
398 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
399 const DataPoint& /*attributes*/) const
400 { return VectorType::Zeros(); }
401};// class NoWeightFuncBase
402
408template <class DataPoint, typename NeighborFilter>
409class NeighborFilterStoreNormal : public NeighborFilter {
410public:
411 using Base = NeighborFilter;
413 using Scalar = typename DataPoint::Scalar;
415 using VectorType = typename DataPoint::VectorType;
417 using MatrixType = typename DataPoint::MatrixType;
419 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
420
425 PONCA_MULTIARCH inline NeighborFilterStoreNormal(
426 const VectorType & _evalPos = VectorType::Zero(),
427 const Scalar& _t = Scalar(0),
428 const VectorType & _evalNormal = VectorType::Zero())
429 : Base(_evalPos, _t), m_n(_evalNormal) {}
430
431 PONCA_MULTIARCH inline NeighborFilterStoreNormal(
432 const DataPoint& _evalPoint,
433 const Scalar& _t = Scalar(0))
434 : Base(_evalPoint.pos(), _t), m_n(_evalPoint.normal()) {}
435
437 PONCA_MULTIARCH inline const VectorType & evalNormal() const { return m_n; }
438protected:
440}; // class NeighborFilterStoreNormal
441
442template <class DataPoint>
445
446template <class DataPoint>
449#include "weightFunc.hpp"
450
451}// namespace Ponca
NeighborhoodFrame that express 3d points relatively to a prescribed center.
Definition weightFunc.h:27
VectorType convertToLocalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from global to local coordinate system, such as .
Definition weightFunc.h:70
VectorType convertToGlobalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from local to global coordinate system, such as .
Definition weightFunc.h:55
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:32
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:30
void changeNeighborhoodFrame(const VectorType &_newEvalPos)
Change neighborhood frame (move basis center)
Definition weightFunc.h:44
static constexpr bool hasLocalFrame
Flag indicating that this class modifies the coordinates when passing from global to local.
Definition weightFunc.h:35
VectorType evalPos() const
Get access to the stored points of evaluation.
Definition weightFunc.h:79
Weight neighbors according to the euclidean distance between a query and a reference position.
Definition weightFunc.h:154
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:161
DistWeightFunc(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.))
Constructor that defines the current evaluation scale.
Definition weightFunc.h:173
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
Definition weightFunc.h:310
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:163
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:157
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:314
static constexpr bool isCompact
Flag indicating if the weighting kernel is compact of not.
Definition weightFunc.h:167
DistWeightFunc(const DataPoint &_evalPoint, const Scalar &_t=Scalar(1.))
!
Definition weightFunc.h:182
Scalar m_t
Evaluation scale.
Definition weightFunc.h:313
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:159
NeighborhoodFrame that keep points in the global frame without applying any transformation.
Definition weightFunc.h:95
static constexpr bool hasLocalFrame
Flag indicating that this class does not modify the coordinates when passing from global to local.
Definition weightFunc.h:103
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:98
void changeNeighborhoodFrame(const VectorType &)
Change neighborhood frame (has no effect for global basis)
Definition weightFunc.h:108
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:100
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:117
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:129
This class extends a NeighborFilter class to also store the normal of the evaluation point,...
Definition weightFunc.h:409
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:413
const VectorType & evalNormal() const
Access to the evaluation normal set during the initialization.
Definition weightFunc.h:437
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:419
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:417
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:425
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:415
VectorType m_n
Evaluation normal.
Definition weightFunc.h:439
Base Weighting function that set uniform weight to all samples.
Definition weightFunc.h:327
WeightReturnType operator()(const DataPoint &_q) const
Compute the weight of the given query, which is always $1$.
Definition weightFunc.h:354
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:334
NoWeightFuncBase(const DataPoint &v, Scalar=0)
!
Definition weightFunc.h:347
VectorType spacedw(const VectorType &, const DataPoint &) const
First order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:364
Scalar scaledw(const VectorType &, const DataPoint &) const
First order derivative in scale , which are always $0$.
Definition weightFunc.h:381
Scalar scaled2w(const VectorType &, const DataPoint &) const
Second order derivative in scale , which are always $0$.
Definition weightFunc.h:389
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:332
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:336
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:398
NoWeightFuncBase(const VectorType &v=VectorType::Zero(), Scalar=0)
Default constructor.
Definition weightFunc.h:343
MatrixType spaced2w(const VectorType &, const DataPoint &) const
Second order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:373
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:330
This Source Code Form is subject to the terms of the Mozilla Public License, v.