Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
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{
26 template <class DataPoint>
28 {
29 public:
31 using Scalar = typename DataPoint::Scalar;
33 using VectorType = typename DataPoint::VectorType;
34
36 static constexpr bool hasLocalFrame = true;
37
38 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const VectorType& _evalPos = VectorType::Zero())
39 : m_p(_evalPos)
40 {
41 }
42
43 PONCA_MULTIARCH inline explicit CenteredNeighborhoodFrame(const DataPoint& _evalPoint) : m_p(_evalPoint.pos())
44 {
45 }
46
48 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& _newEvalPos) { m_p = _newEvalPos; };
49
59 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToGlobalBasis(const VectorType& _q,
60 bool _isPositionVector = true) const
61 {
62 return (_isPositionVector ? (_q + m_p) : _q);
63 }
64
75 PONCA_MULTIARCH [[nodiscard]] inline VectorType convertToLocalBasis(const VectorType& _q,
76 bool _isPositionVector = true) const
77 {
78 return (_isPositionVector ? (_q - m_p) : _q);
79 }
80
85 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& evalPos() const { return m_p; }
86
87 private:
88 VectorType m_p;
89 };
100 template <class DataPoint>
102 {
103 public:
105 using Scalar = typename DataPoint::Scalar;
107 using VectorType = typename DataPoint::VectorType;
108
110 static constexpr bool hasLocalFrame = false;
111
112 PONCA_MULTIARCH inline explicit GlobalNeighborhoodFrame(const VectorType& /*_evalPos*/ = VectorType::Zero()) {}
113
115 PONCA_MULTIARCH inline void changeNeighborhoodFrame(const VectorType& /*_newEvalPos*/) {};
116
124 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToGlobalBasis(
125 const VectorType& _q, bool /*_isPositionVector*/ = true) const
126 {
127 return _q;
128 }
129
137 PONCA_MULTIARCH [[nodiscard]] inline const VectorType& convertToLocalBasis(
138 const VectorType& _q, bool /*_isPositionVector*/ = true) const
139 {
140 return _q;
141 }
142 };
143
160 template <class DataPoint, class WeightKernel>
162 {
163 public:
165 using Scalar = typename DataPoint::Scalar;
167 using VectorType = typename DataPoint::VectorType;
169 using MatrixType = typename DataPoint::MatrixType;
171 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
175 static constexpr bool isCompact = WeightKernel::isCompact;
176
181 PONCA_MULTIARCH inline DistWeightFunc(const VectorType& _evalPos = VectorType::Zero(),
182 const Scalar& _t = Scalar(1.))
183 : NeighborhoodFrame(_evalPos), m_t(_t)
184 {
185 //\todo manage that assert on __host__ and __device__
186 // assert(_t > Scalar(0));
187 }
188
190 PONCA_MULTIARCH inline DistWeightFunc(const DataPoint& _evalPoint, const Scalar& _t = Scalar(1.))
191 : NeighborhoodFrame(_evalPoint.pos()), m_t(_t)
192 {
193 //\todo manage that assert on __host__ and __device__
194 // assert(_t > Scalar(0));
195 }
196
211 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& q) const;
212
228 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& _q,
229 const DataPoint& /*attributes*/) const;
230
252 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& _q,
253 const DataPoint& /*attributes*/) const;
254
269 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& _q,
270 const DataPoint& /*attributes*/) const;
271
290 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& _q,
291 const DataPoint& /*attributes*/) const;
292
312 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& _q,
313 const DataPoint& /*attributes*/) const;
314
316 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return m_t; }
317
318 protected:
320 WeightKernel m_wk;
322 }; // class DistWeightFunc
323
331 template <class DataPoint, template <typename> typename _NeighborhoodFrame>
332 class NoWeightFuncBase : public _NeighborhoodFrame<DataPoint>
333 {
334 public:
336 using Scalar = typename DataPoint::Scalar;
338 using VectorType = typename DataPoint::VectorType;
340 using MatrixType = typename DataPoint::MatrixType;
342 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
343
344 using NeighborhoodFrame = _NeighborhoodFrame<DataPoint>;
345
349 PONCA_MULTIARCH inline NoWeightFuncBase(const VectorType& v = VectorType::Zero(), Scalar = 0)
350 : NeighborhoodFrame(v)
351 {
352 }
353
355 PONCA_MULTIARCH inline NoWeightFuncBase(const DataPoint& v, Scalar = 0) : NeighborhoodFrame(v.pos()) {}
356
361 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& _q) const
362 {
363 return {Scalar(1), NeighborhoodFrame::convertToLocalBasis(_q.pos())};
364 }
365
370 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& /*_q*/,
371 const DataPoint& /*attributes*/) const
372 {
373 return VectorType::Zeros();
374 }
375
380 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& /*_q*/,
381 const DataPoint& /*attributes*/) const
382 {
383 return MatrixType::Zeros();
384 }
385
390 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& /*_q*/,
391 const DataPoint& /*attributes*/) const
392 {
393 return Scalar(0);
394 }
395
400 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& /*_q*/,
401 const DataPoint& /*attributes*/) const
402 {
403 return Scalar(0);
404 }
405
411 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
412 const DataPoint& /*attributes*/) const
413 {
414 return VectorType::Zeros();
415 }
416 }; // class NoWeightFuncBase
417
424 template <class DataPoint, typename NeighborFilter>
425 class NeighborFilterStoreNormal : public NeighborFilter
426 {
427 public:
428 using Base = NeighborFilter;
430 using Scalar = typename DataPoint::Scalar;
432 using VectorType = typename DataPoint::VectorType;
434 using MatrixType = typename DataPoint::MatrixType;
436 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
437
442 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const VectorType& _evalPos = VectorType::Zero(),
443 const Scalar& _t = Scalar(0),
444 const VectorType& _evalNormal = VectorType::Zero())
445 : Base(_evalPos, _t), m_n(_evalNormal)
446 {
447 }
448
449 PONCA_MULTIARCH inline NeighborFilterStoreNormal(const DataPoint& _evalPoint, const Scalar& _t = Scalar(0))
450 : Base(_evalPoint.pos(), _t), m_n(_evalPoint.normal())
451 {
452 }
453
455 PONCA_MULTIARCH inline const VectorType& evalNormal() const { return m_n; }
456
457 protected:
459 }; // class NeighborFilterStoreNormal
460
461 template <class DataPoint>
464
465 template <class DataPoint>
468#include "weightFunc.hpp"
469
470} // namespace Ponca
NeighborhoodFrame that express 3d points relatively to a prescribed center.
Definition weightFunc.h:28
VectorType convertToLocalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from global to local coordinate system, such as .
Definition weightFunc.h:75
const VectorType & evalPos() const
Get access to the stored points of evaluation.
Definition weightFunc.h:85
VectorType convertToGlobalBasis(const VectorType &_q, bool _isPositionVector=true) const
Convert query from local to global coordinate system, such as .
Definition weightFunc.h:59
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:33
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:31
void changeNeighborhoodFrame(const VectorType &_newEvalPos)
Change neighborhood frame (move basis center)
Definition weightFunc.h:48
static constexpr bool hasLocalFrame
Flag indicating that this class modifies the coordinates when passing from global to local.
Definition weightFunc.h:36
Weight neighbors according to the euclidean distance between a query and a reference position.
Definition weightFunc.h:162
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:169
DistWeightFunc(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.))
Constructor that defines the current evaluation scale.
Definition weightFunc.h:181
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
Definition weightFunc.h:316
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:171
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:165
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:320
static constexpr bool isCompact
Flag indicating if the weighting kernel is compact of not.
Definition weightFunc.h:175
DistWeightFunc(const DataPoint &_evalPoint, const Scalar &_t=Scalar(1.))
!
Definition weightFunc.h:190
Scalar m_t
Evaluation scale.
Definition weightFunc.h:319
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:167
NeighborhoodFrame that keep points in the global frame without applying any transformation.
Definition weightFunc.h:102
static constexpr bool hasLocalFrame
Flag indicating that this class does not modify the coordinates when passing from global to local.
Definition weightFunc.h:110
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:105
void changeNeighborhoodFrame(const VectorType &)
Change neighborhood frame (has no effect for global basis)
Definition weightFunc.h:115
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:107
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:124
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:137
This class extends a NeighborFilter class to also store the normal of the evaluation point,...
Definition weightFunc.h:426
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:430
const VectorType & evalNormal() const
Access to the evaluation normal set during the initialization.
Definition weightFunc.h:455
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:436
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:434
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:442
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:432
VectorType m_n
Evaluation normal.
Definition weightFunc.h:458
Base Weighting function that set uniform weight to all samples.
Definition weightFunc.h:333
WeightReturnType operator()(const DataPoint &_q) const
Compute the weight of the given query, which is always $1$.
Definition weightFunc.h:361
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Definition weightFunc.h:340
NoWeightFuncBase(const DataPoint &v, Scalar=0)
!
Definition weightFunc.h:355
VectorType spacedw(const VectorType &, const DataPoint &) const
First order derivative in space (for each spatial dimension , which are always $0$.
Definition weightFunc.h:370
Scalar scaledw(const VectorType &, const DataPoint &) const
First order derivative in scale , which are always $0$.
Definition weightFunc.h:390
Scalar scaled2w(const VectorType &, const DataPoint &) const
Second order derivative in scale , which are always $0$.
Definition weightFunc.h:400
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
Definition weightFunc.h:338
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Definition weightFunc.h:342
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:411
NoWeightFuncBase(const VectorType &v=VectorType::Zero(), Scalar=0)
Default constructor.
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:380
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
Definition weightFunc.h:336
This Source Code Form is subject to the terms of the Mozilla Public License, v.