Ponca  6d7f3619cbd70eb6ac131a3267ba1a351b1c9d07
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#include "compute.h"
13
14namespace Ponca
15{
16
17#define BSKNF typename BasketType::NeighborFilter
18#define BSKP typename BasketType::DataPoint
19
20#ifndef PARSED_WITH_DOXYGEN
22 namespace internal
23 {
33 template <class P, class NF, typename Aggregate, template <class, class, typename> class Ext,
34 template <class, class, typename> class... Exts>
35 struct BasketAggregateImpl
36 {
37 using type = typename BasketAggregateImpl<P, NF, Ext<P, NF, Aggregate>, Exts...>::type;
38 };
39
48 template <class P, class NF, typename Aggregate, template <class, class, typename> class Ext>
49 struct BasketAggregateImpl<P, NF, Aggregate, Ext>
50 {
51 using type = Ext<P, NF, Aggregate>;
52 };
53
62 template <class P, class NF, template <class, class, typename> class... Exts>
63 struct BasketAggregate : BasketAggregateImpl<P, NF, PrimitiveBase<P, NF>, Exts...>
64 {
65 };
66
76 template <int Type, typename BasketType, template <class, class, int, typename> class Ext,
77 template <class, class, int, typename> class... Exts>
78 struct BasketDiffAggregateImpl
79 {
80 using type = typename BasketDiffAggregateImpl<Type, Ext<BSKP, BSKNF, Type, BasketType>, Exts...>::type;
81 };
82
90 template <int Type, typename BasketType, template <class, class, int, typename> class Ext>
91 struct BasketDiffAggregateImpl<Type, BasketType, Ext>
92 {
93 using type = Ext<BSKP, BSKNF, Type, BasketType>;
94 };
95
104 template <typename BasketType, int Type, template <class, class, int, typename> class... Exts>
105 struct BasketDiffAggregate : BasketDiffAggregateImpl<Type, BasketType, PrimitiveDer, Exts...>
106 {
107 };
108 } // namespace internal
109#endif
110
132 template <typename _Derived, typename _Base>
133 struct BasketComputeObject : public ComputeObject<_Derived>, public virtual _Base
134 {
135 using Base = _Base;
137 using Scalar = typename Base::Scalar;
138
139 protected:
141
142 public:
143 using ComputeObject<Derived>::compute; // Makes the default compute(container) accessible when using a CPU
144 // architecture
145
152 template <typename IteratorBegin, typename IteratorEnd>
153 PONCA_MULTIARCH inline FIT_RESULT compute(const IteratorBegin& begin, const IteratorEnd& end)
154 {
155 Base::init();
157
158 do
159 {
160 derived().startNewPass();
161 for (auto it = begin; it != end; ++it)
162 {
164 }
165 res = Base::finalize();
166 } while (res == NEED_OTHER_PASS);
167
168 return res;
169 }
170
178 template <typename IndexRange, typename PointContainer>
179 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(IndexRange ids, const PointContainer& points)
180 {
181 Base::init();
183
184 do
185 {
186 derived().startNewPass();
187 for (const auto& i : ids)
188 {
189 derived().addNeighbor(points[i]);
190 }
191 res = Base::finalize();
192 } while (res == NEED_OTHER_PASS);
193
194 return res;
195 }
196 };
197
198#define WRITE_COMPUTE_FUNCTIONS \
199 using BasketComputeObject<Self, Base>::compute; \
200 using BasketComputeObject<Self, Base>::computeWithIds;
201
210 template <typename BasketType, int Type, template <class, class, int, typename> class Ext0,
211 template <class, class, int, typename> class... Exts>
213 : public BasketComputeObject<BasketDiff<BasketType, Type, Ext0, Exts...>,
214 typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type>
215 {
216 private:
217 using Self = BasketDiff;
218
219 public:
220 using Base = typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type;
222 using NeighborFilter = BSKNF;
224 using DataPoint = BSKP;
226 using Scalar = typename BasketType::Scalar;
227 WRITE_COMPUTE_FUNCTIONS
228
230 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint& _nei)
231 {
232 // compute weight
233 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
234 typename Base::ScalarArray dw;
235
236 if (neiFilterOutput.first > Scalar(0.))
237 {
238 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei, dw);
239 return true;
240 }
241 return false;
242 }
243 };
244
253 template <class P, class NF, template <class, class, typename> class Ext0,
254 template <class, class, typename> class... Exts>
255 class Basket : public BasketComputeObject<Basket<P, NF, Ext0, Exts...>,
256 typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type>
257 {
258 private:
259 using Self = Basket;
260
261 public:
263 using Base = typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type;
265 using Scalar = typename P::Scalar;
266 using VectorType = typename P::VectorType;
268 using DataPoint = P;
271
272 WRITE_COMPUTE_FUNCTIONS
273
280 PONCA_MULTIARCH inline bool addNeighbor(const DataPoint& _nei)
281 {
282 // compute weight
283 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
284
285 if (neiFilterOutput.first > Scalar(0.))
286 {
287 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei);
288 return true;
289 }
290 return false;
291 }
292 }; // class Basket
293
294#undef WRITE_COMPUTE_FUNCTIONS
295} // namespace Ponca
296
Aggregator class used to declare specialized structures with derivatives computations,...
Definition basket.h:215
typename BasketType::DataPoint DataPoint
Point type used for computation.
Definition basket.h:224
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.h:230
typename BasketType::NeighborFilter NeighborFilter
Neighbor Filter.
Definition basket.h:222
typename BasketType::Scalar Scalar
Scalar type used for computation, as defined from Basket.
Definition basket.h:226
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
typename internal::BasketAggregate< P, NF, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition basket.h:263
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition basket.h:265
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.h:280
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition bitset.h:16
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
Definition enums.h:15
@ UNDEFINED
The fitting is undefined, you can't use it for valid results.
Definition enums.h:22
@ NEED_OTHER_PASS
The fitting procedure needs to analyse the neighborhood another time.
Definition enums.h:25
Base ComputeObject for the Basket classes.
Definition basket.h:134
FIT_RESULT computeWithIds(IndexRange ids, const PointContainer &points)
Convenience function to iterate over a subset of samples in a PointContainer Add neighbors stored in ...
Definition basket.h:179
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators Add neighbors stored in a container using STL-like iterat...
Definition basket.h:153
typename Base::Scalar Scalar
Alias to the Derived type.
Definition basket.h:137
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
Definition compute.h:24
_Derived & derived()
Retrieve the top layer object Returns a reference to the derived class so that we can use its overwri...
Definition compute.h:28