Ponca  7abd0fd82719106ad460aa0f2070dffbe375d727
Point Cloud Analysis library
Loading...
Searching...
No Matches
weightFilter.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 "./frame.h"
12#include PONCA_MULTIARCH_INCLUDE_CU_STD(utility)
13
14namespace Ponca
15{
32 template <class _DataPoint, class WeightKernel>
34 {
35 public:
37 using DataPoint = _DataPoint;
39 using Scalar = typename DataPoint::Scalar;
41 using VectorType = typename DataPoint::VectorType;
43 using MatrixType = typename DataPoint::MatrixType;
45 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
49 static constexpr bool isCompact = WeightKernel::isCompact;
50
55 PONCA_MULTIARCH inline DistWeightFilter(const VectorType& _evalPos = VectorType::Zero(),
56 const Scalar& _t = Scalar(1.))
57 : NeighborhoodFrame(_evalPos), m_t(_t)
58 {
59 // PONCA_ASSERT(_t > Scalar(0));
60 }
61
63 PONCA_MULTIARCH inline DistWeightFilter(const DataPoint& _evalPoint, const Scalar& _t = Scalar(1.))
64 : NeighborhoodFrame(_evalPoint.pos()), m_t(_t)
65 {
66 // PONCA_ASSERT(_t > Scalar(0));
67 }
68
83 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& q) const;
84
100 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& _q,
101 const DataPoint& /*attributes*/) const
103
125 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& _q,
126 const DataPoint& /*attributes*/) const
128
143 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& _q, const DataPoint& /*attributes*/) const
145
164 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& _q,
165 const DataPoint& /*attributes*/) const
186 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& _q,
187 const DataPoint& /*attributes*/) const
189
191 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return m_t; }
192
193 PONCA_MULTIARCH [[nodiscard]] inline NeighborhoodFrame& frame() { return *this; }
194 PONCA_MULTIARCH [[nodiscard]] inline const NeighborhoodFrame& frame() const { return *this; }
195
196 protected:
198 WeightKernel m_wk;
200 }; // class DistWeightFunc
201
202 namespace internal
203 {
211 template <class _DataPoint, template <typename> typename _NeighborhoodFrame>
212 class NoWeightFilterBase : public _NeighborhoodFrame<_DataPoint>
213 {
214 public:
216 using DataPoint = _DataPoint;
218 using Scalar = typename DataPoint::Scalar;
220 using VectorType = typename DataPoint::VectorType;
222 using MatrixType = typename DataPoint::MatrixType;
224 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
225
226 using NeighborhoodFrame = _NeighborhoodFrame<DataPoint>;
227
231 PONCA_MULTIARCH inline NoWeightFilterBase(const VectorType& v = VectorType::Zero(), Scalar = 0)
232 : NeighborhoodFrame(v)
233 {
234 }
235
237 PONCA_MULTIARCH inline NoWeightFilterBase(const DataPoint& v, Scalar = 0) : NoWeightFilterBase(v.pos()) {}
238
243 PONCA_MULTIARCH inline WeightReturnType operator()(const DataPoint& _q) const
244 {
245 return {Scalar(1), NeighborhoodFrame::convertToLocalBasis(_q.pos())};
246 }
247
253 PONCA_MULTIARCH [[nodiscard]] inline VectorType spacedw(const VectorType& /*_q*/,
254 const DataPoint& /*attributes*/) const
255 {
256 return VectorType::Zero();
257 }
258
264 PONCA_MULTIARCH [[nodiscard]] inline MatrixType spaced2w(const VectorType& /*_q*/,
265 const DataPoint& /*attributes*/) const
266 {
267 return MatrixType::Zero();
268 }
269
271 PONCA_MULTIARCH [[nodiscard]] inline Scalar evalScale() const { return Scalar(1.); }
272
277 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaledw(const VectorType& /*_q*/,
278 const DataPoint& /*attributes*/) const
279 {
280 return Scalar(0);
281 }
282
287 PONCA_MULTIARCH [[nodiscard]] inline Scalar scaled2w(const VectorType& /*_q*/,
288 const DataPoint& /*attributes*/) const
289 {
290 return Scalar(0);
291 }
292
298 PONCA_MULTIARCH [[nodiscard]] inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
299 const DataPoint& /*attributes*/) const
300 {
301 return VectorType::Zero();
302 }
303
304 PONCA_MULTIARCH [[nodiscard]] inline NeighborhoodFrame& frame() { return *this; }
305 PONCA_MULTIARCH [[nodiscard]] inline const NeighborhoodFrame& frame() const { return *this; }
306 }; // class NoWeightFuncBase
307
308 template <ProvidesNormal DataPoint>
309 inline constexpr typename DataPoint::VectorType ConvertDataPointToNormal(const DataPoint& pt)
310 {
311 return pt.normal();
312 }
313 } // namespace internal
314
323 template <class _DataPoint, typename DataType, typename NeighborFilter, auto DataConverter>
324 class FilterWithAttributes : public NeighborFilter
325 {
326 public:
328 using DataPoint = _DataPoint;
329 using Base = NeighborFilter;
331 using Scalar = typename DataPoint::Scalar;
333 using VectorType = typename DataPoint::VectorType;
335 using MatrixType = typename DataPoint::MatrixType;
337 using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;
338
343 PONCA_MULTIARCH inline FilterWithAttributes(const VectorType& _evalPos = VectorType::Zero(),
344 const Scalar& _t = Scalar(1), const DataType& _data = DataType{})
345 : Base(_evalPos, _t), m_data(_data)
346 {
347 }
348
354 PONCA_MULTIARCH inline FilterWithAttributes(const DataPoint& _evalPoint, const Scalar& _t = Scalar(0))
355 : Base(_evalPoint.pos(), _t), m_data(DataConverter(_evalPoint))
356 {
357 }
358
360 PONCA_MULTIARCH inline const DataType& data() const { return m_data; }
361
362 protected:
363 DataType m_data;
364 }; // class FilterWithAttributes
365
366 template <class DataPoint>
370 struct NoWeightFilter : public internal::NoWeightFilterBase<DataPoint, CenteredNeighborhoodFrame>
371 {
373 };
374
375 template <class DataPoint>
382
383#include "weightFilter.hpp"
384
385} // namespace Ponca
NeighborhoodFrame that express 3d points relatively to a prescribed center.
Definition frame.h:28
Weight neighbors according to the Euclidean distance between a query and a reference position.
Scalar scaledw(const VectorType &_q, const DataPoint &) const
First order derivative in scale .
MatrixType spaced2w(const VectorType &_q, const DataPoint &) const
Second order derivative in space (for each spatial dimension .
WeightKernel m_wk
1D function applied to weight queries
_DataPoint DataPoint
Alias to _DataPoint template parameter.
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
Scalar scaled2w(const VectorType &_q, const DataPoint &) const
Second order derivative in scale .
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()
CenteredNeighborhoodFrame< DataPoint > NeighborhoodFrame
Frame used to express the neighbors locally.
Scalar m_t
Evaluation scale.
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
DistWeightFilter(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1.))
Constructor that defines the current evaluation scale.
VectorType scaleSpaced2w(const VectorType &_q, const DataPoint &) const
Cross derivative in scale and in space (for each spatial dimension .
static constexpr bool isCompact
Flag indicating if the weighting kernel is compact of not.
DistWeightFilter(const DataPoint &_evalPoint, const Scalar &_t=Scalar(1.))
!
WeightReturnType operator()(const DataPoint &q) const
Compute the weight of the given query with respect to its coordinates.
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
This class extends a NeighborFilter class to also store additional data, for use outside the scope of...
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
FilterWithAttributes(const DataPoint &_evalPoint, const Scalar &_t=Scalar(0))
Constructor that defines the current evaluation scale and construct the DataType from the _evalPoint ...
FilterWithAttributes(const VectorType &_evalPos=VectorType::Zero(), const Scalar &_t=Scalar(1), const DataType &_data=DataType{})
Constructor that defines the current evaluation scale.
_DataPoint DataPoint
Alias to _DataPoint template parameter.
DataType m_data
Evaluation normal.
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
const DataType & data() const
Access to the evaluation normal set during the initialization.
NeighborhoodFrame that keep points in the global frame without applying any transformation This class...
Definition frame.h:106
Weighting function that set uniform weight to all samples.
Scalar scaled2w(const VectorType &, const DataPoint &) const
Second order derivative in scale , which are always $0$.
typename DataPoint::Scalar Scalar
Scalar type from DataPoint.
std::pair< Scalar, VectorType > WeightReturnType
Return type of the method #w()
Scalar scaledw(const VectorType &, const DataPoint &) const
First order derivative in scale , which are always $0$.
typename DataPoint::VectorType VectorType
Vector type from DataPoint.
VectorType spacedw(const VectorType &, const DataPoint &) const
First order derivative in space (for each spatial dimension , which are always $0$.
typename DataPoint::MatrixType MatrixType
Matrix type from DataPoint.
NoWeightFilterBase(const DataPoint &v, Scalar=0)
!
VectorType scaleSpaced2w(const VectorType &, const DataPoint &) const
Cross derivative in scale and in space (for each spatial dimension , which are always $0$.
WeightReturnType operator()(const DataPoint &_q) const
Compute the weight of the given query, which is always $1$.
Scalar evalScale() const
Access to the evaluation scale set during the initialization.
MatrixType spaced2w(const VectorType &, const DataPoint &) const
Second order derivative in space (for each spatial dimension , which are always $0$.
_DataPoint DataPoint
Alias to _DataPoint template parameter.
NoWeightFilterBase(const VectorType &v=VectorType::Zero(), Scalar=0)
Default constructor.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
Weighting function that set uniform weight to all samples and keep neighbors coordinates in global fr...
Weighting function that set uniform weight to all samples, but transform neighbors coordinates to loc...