Ponca  aa50bfdf187919869239c5b44b748842569114c1
Point Cloud Analysis library
Loading...
Searching...
No Matches
basket.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 "enums.h"
11#include "primitive.h"
12
13#include PONCA_MULTIARCH_INCLUDE_STD(iterator)
14
15namespace Ponca
16{
17
18#define BSKW typename BasketType::WeightFunction
19#define BSKP typename BasketType::DataPoint
20
21#ifndef PARSED_WITH_DOXYGEN
23namespace internal
24{
25 template <class P, class W,
26 typename Aggregate,
27 template <class, class, typename> class Ext,
28 template <class, class, typename> class... Exts>
29 struct BasketAggregateImpl
30 {
31 using type = typename BasketAggregateImpl<P, W, Ext<P, W, Aggregate>, Exts...>::type;
32 };
33
34 template <class P, class W,
35 typename Aggregate,
36 template <class, class, typename> class Ext>
37 struct BasketAggregateImpl<P, W, Aggregate, Ext>
38 {
39 using type = Ext<P, W, Aggregate>;
40 };
41
43 template <class P, class W,
44 template <class, class, typename> class... Exts>
45 struct BasketAggregate : BasketAggregateImpl<P, W, PrimitiveBase<P, W>, Exts...>
46 {
47 };
48
49 template <typename BasketType, int Type,
50 typename Aggregate,
51 template <class, class, int, typename> class Ext,
52 template <class, class, int, typename> class... Exts>
53 struct BasketDiffAggregateImpl
54 {
55 using type = typename BasketDiffAggregateImpl<BasketType, Type, Ext<BSKP, BSKW, Type, Aggregate>, Exts...>::type;
56 };
57
58 template <typename BasketType, int Type,
59 typename Aggregate,
60 template <class, class, int, typename> class Ext>
61 struct BasketDiffAggregateImpl<BasketType, Type, Aggregate, Ext>
62 {
63 using type = Ext<BSKP, BSKW, Type, Aggregate>;
64 };
65
67 template <typename BasketType, int Type,
68 template <class, class, int, typename> class... Exts>
69 struct BasketDiffAggregate : BasketDiffAggregateImpl<BasketType, Type, BasketType, PrimitiveDer, Exts...>
70 {
71 };
72}
73#endif
74
75#ifdef PONCA_CPU_ARCH
76# define WRITE_BASKET_SINGLE_HOST_FUNCTIONS \
77 \
78 template <typename Container> \
79 PONCA_MULTIARCH inline \
80 FIT_RESULT compute(const Container& c){ \
81 return Self::compute(std::begin(c), std::end(c)); \
82 }
83#else
84# define WRITE_BASKET_SINGLE_HOST_FUNCTIONS
85#endif
86
87#define WRITE_BASKET_FUNCTIONS \
88 \
89 \
90 \
91 \
92 template <typename IteratorBegin, typename IteratorEnd> \
93 PONCA_MULTIARCH inline \
94 FIT_RESULT compute(const IteratorBegin& begin, const IteratorEnd& end){ \
95 FIT_RESULT res = UNDEFINED; \
96 do { \
97 Self::startNewPass(); \
98 for (auto it = begin; it != end; ++it){ \
99 Self::addNeighbor(*it); \
100 } \
101 res = Base::finalize(); \
102 } while ( res == NEED_OTHER_PASS ); \
103 return res; \
104 } \
105 \
106 \
107 \
108 \
109 \
110 template <typename IndexRange, typename PointContainer> \
111 PONCA_MULTIARCH inline \
112 FIT_RESULT computeWithIds(IndexRange ids, const PointContainer& points){ \
113 FIT_RESULT res = UNDEFINED; \
114 do { \
115 Self::startNewPass(); \
116 for (const auto& i : ids){ \
117 this->addNeighbor(points[i]); \
118 } \
119 res = this->finalize(); \
120 } while ( res == NEED_OTHER_PASS ); \
121 return res; \
122 } \
123 WRITE_BASKET_SINGLE_HOST_FUNCTIONS
124
150 template <typename BasketType, int Type,
151 template <class, class, int, typename> class Ext0,
152 template <class, class, int, typename> class... Exts>
153 class BasketDiff : public internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type {
154 private:
155 using Self = BasketDiff;
156 public:
158 using Base = typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type;
160 using WeightFunction = BSKW;
162 using DataPoint = BSKP;
164 using Scalar = typename DataPoint::Scalar;
165
166 WRITE_BASKET_FUNCTIONS
167
169 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint &_nei) {
170 // compute weight
171 auto wres = Base::m_w.w(_nei.pos(), _nei);
172 typename Base::ScalarArray dw;
173
174 if (wres.first > Scalar(0.)) {
175 Base::addLocalNeighbor(wres.first, wres.second, _nei, dw);
176 return true;
177 }
178 return false;
179 }
180};
181
207 template <class P, class W,
208 template <class, class, typename> class Ext0,
209 template <class, class, typename> class... Exts>
210 class Basket : public internal::BasketAggregate<P, W, Ext0, Exts...>::type
211 {
212 private:
213 using Self = Basket;
214 public:
216 using Base = typename internal::BasketAggregate<P, W, Ext0, Exts...>::type;
218 using Scalar = typename P::Scalar;
220 using DataPoint = P;
222 using WeightFunction = W;
223
224 WRITE_BASKET_FUNCTIONS;
225
232 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint &_nei) {
233 // compute weight
234 auto wres = Base::m_w.w(_nei.pos(), _nei);
235
236 if (wres.first > Scalar(0.)) {
237 Base::addLocalNeighbor(wres.first, wres.second, _nei);
238 return true;
239 }
240 return false;
241 }
242 }; // class Basket
243
244} //namespace Ponca
245
Aggregator class used to declare specialized structures with derivatives computations,...
Definition: basket.h:153
typename BasketType::DataPoint DataPoint
Point type used for computation.
Definition: basket.h:162
typename internal::BasketDiffAggregate< BasketType, Type, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition: basket.h:158
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition: basket.h:169
typename DataPoint::Scalar Scalar
Scalar type used for computation, as defined from Basket.
Definition: basket.h:164
typename BasketType::WeightFunction WeightFunction
Weighting function.
Definition: basket.h:160
Aggregator class used to declare specialized structures using CRTP.
Definition: basket.h:211
W WeightFunction
Weighting function.
Definition: basket.h:222
P DataPoint
Point type used for computation.
Definition: basket.h:220
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition: basket.h:218
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition: basket.h:232
typename internal::BasketAggregate< P, W, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition: basket.h:216
This Source Code Form is subject to the terms of the Mozilla Public License, v.