Ponca  f7f7d7cc113b4e53be6bee25005fbdbe7e016293
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 Base::init(); \
96 FIT_RESULT res = UNDEFINED; \
97 do { \
98 Self::startNewPass(); \
99 for (auto it = begin; it != end; ++it){ \
100 Self::addNeighbor(*it); \
101 } \
102 res = Base::finalize(); \
103 } while ( res == NEED_OTHER_PASS ); \
104 return res; \
105 } \
106 \
107 \
108 \
109 \
110 \
111 template <typename IndexRange, typename PointContainer> \
112 PONCA_MULTIARCH inline \
113 FIT_RESULT computeWithIds(IndexRange ids, const PointContainer& points){ \
114 this->init(); \
115 FIT_RESULT res = UNDEFINED; \
116 do { \
117 Self::startNewPass(); \
118 for (const auto& i : ids){ \
119 this->addNeighbor(points[i]); \
120 } \
121 res = this->finalize(); \
122 } while ( res == NEED_OTHER_PASS ); \
123 return res; \
124 } \
125 WRITE_BASKET_SINGLE_HOST_FUNCTIONS
126
152 template <typename BasketType, int Type,
153 template <class, class, int, typename> class Ext0,
154 template <class, class, int, typename> class... Exts>
155 class BasketDiff : public internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type {
156 private:
157 using Self = BasketDiff;
158 public:
160 using Base = typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type;
162 using WeightFunction = BSKW;
164 using DataPoint = BSKP;
166 using Scalar = typename DataPoint::Scalar;
167
168 WRITE_BASKET_FUNCTIONS
169
171 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint &_nei) {
172 // compute weight
173 auto wres = Base::m_w.w(_nei.pos(), _nei);
174 typename Base::ScalarArray dw;
175
176 if (wres.first > Scalar(0.)) {
177 Base::addLocalNeighbor(wres.first, wres.second, _nei, dw);
178 return true;
179 }
180 return false;
181 }
182};
183
209 template <class P, class W,
210 template <class, class, typename> class Ext0,
211 template <class, class, typename> class... Exts>
212 class Basket : public internal::BasketAggregate<P, W, Ext0, Exts...>::type
213 {
214 private:
215 using Self = Basket;
216 public:
218 using Base = typename internal::BasketAggregate<P, W, Ext0, Exts...>::type;
220 using Scalar = typename P::Scalar;
222 using DataPoint = P;
224 using WeightFunction = W;
225
226 WRITE_BASKET_FUNCTIONS;
227
234 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint &_nei) {
235 // compute weight
236 auto wres = Base::m_w.w(_nei.pos(), _nei);
237
238 if (wres.first > Scalar(0.)) {
239 Base::addLocalNeighbor(wres.first, wres.second, _nei);
240 return true;
241 }
242 return false;
243 }
244 }; // class Basket
245
246} //namespace Ponca
247
Aggregator class used to declare specialized structures with derivatives computations,...
Definition basket.h:155
typename BasketType::DataPoint DataPoint
Point type used for computation.
Definition basket.h:164
typename internal::BasketDiffAggregate< BasketType, Type, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition basket.h:160
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.h:171
typename DataPoint::Scalar Scalar
Scalar type used for computation, as defined from Basket.
Definition basket.h:166
typename BasketType::WeightFunction WeightFunction
Weighting function.
Definition basket.h:162
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:213
W WeightFunction
Weighting function.
Definition basket.h:224
P DataPoint
Point type used for computation.
Definition basket.h:222
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition basket.h:220
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.h:234
typename internal::BasketAggregate< P, W, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition basket.h:218
This Source Code Form is subject to the terms of the Mozilla Public License, v.