Ponca  4a9354998d048bf882a3ee9bac8105216fa08d13
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 "concepts.h"
10#include "basketUnit.h"
11
12#include "../compute.h"
13#include "../defines.h"
14#include "../enums.h"
15
16namespace Ponca
17{
18
19#define BSKNF typename BasketType::NeighborFilter
20#define BSKP typename BasketType::DataPoint
21#define BSKS typename BasketType::Scalar
22#define BSKV typename BasketType::VectorType
23
24#ifndef PARSED_WITH_DOXYGEN
26 namespace internal
27 {
37 template <class P, class NF, typename Aggregate, template <class, class, typename> class Ext,
38 template <class, class, typename> class... Exts>
39 struct BasketAggregateImpl
40 {
41 using type = typename BasketAggregateImpl<P, NF, Ext<P, NF, Aggregate>, Exts...>::type;
42 };
43
52 template <class P, class NF, typename Aggregate, template <class, class, typename> class Ext>
53 struct BasketAggregateImpl<P, NF, Aggregate, Ext>
54 {
55 using type = Ext<P, NF, Aggregate>;
56 };
57
66 template <class P, class NF, template <class, class, typename> class... Exts>
67 struct BasketAggregate : BasketAggregateImpl<P, NF, BasketUnitBase<P, NF>, Exts...>
68 {
69 };
70
80 template <int Type, typename BasketType, template <class, class, int, typename> class Ext,
81 template <class, class, int, typename> class... Exts>
82 struct BasketDiffAggregateImpl
83 {
84 using type = typename BasketDiffAggregateImpl<Type, Ext<BSKP, BSKNF, Type, BasketType>, Exts...>::type;
85 };
86
94 template <int Type, typename BasketType, template <class, class, int, typename> class Ext>
95 struct BasketDiffAggregateImpl<Type, BasketType, Ext>
96 {
97 using type = Ext<BSKP, BSKNF, Type, BasketType>;
98 };
99
108 template <typename BasketType, int Type, template <class, class, int, typename> class... Exts>
109 struct BasketDiffAggregate : BasketDiffAggregateImpl<Type, BasketType, BasketDiffUnitBase, Exts...>
110 {
111 };
112 } // namespace internal
113#endif
114
136 template <typename _Derived, typename _Base>
137 struct BasketComputeObject : public ComputeObject<_Derived>, public _Base
138 {
139 using Base = _Base;
141 using Scalar = typename Base::Scalar;
142
143 protected:
145
146 public:
147 using ComputeObject<Derived>::compute; // Makes the default compute(container) accessible when using a CPU
148 // architecture
149
156 template <typename IteratorBegin, typename IteratorEnd>
157 PONCA_MULTIARCH inline FIT_RESULT compute(const IteratorBegin& begin, const IteratorEnd& end)
158 {
159 Base::init();
161
162 do
163 {
165 for (auto it = begin; it != end; ++it)
166 {
168 }
169 res = Base::finalize();
170 } while (res == NEED_OTHER_PASS);
171
172 return res;
173 }
174
182 template <typename IndexRange, typename PointContainer>
183 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(IndexRange ids, const PointContainer& points)
184 {
185 Base::init();
187
188 do
189 {
191 for (const auto& i : ids)
192 {
193 derived().addNeighbor(points[i]);
194 }
195 res = Base::finalize();
196 } while (res == NEED_OTHER_PASS);
197
198 return res;
199 }
200
201 // WARNING: Do not store anything in this class unless you know what you are doing.
202 // Currently, each BasketDiff inherits "twice" from BasketComputeObject:
203 // - Through BasketComputeObject<Basket>
204 // - Through BasketComputeObject<BasketDiff>
205 // According to the rules of C++, these classes have nothing in common and are as
206 // different as an int and a std::vector. There is a high chance that the
207 // BasketComputeObject<Basket> and BasketComputeObject<BasketDiff> subobjects
208 // will become out of sync. In particular, you need to manually handle value
209 // propagation between them to ensure that both instances see the same values when
210 // needed.
211 };
212
213#define WRITE_COMPUTE_FUNCTIONS \
214 using BasketComputeObject<Self, Base>::compute; \
215 using BasketComputeObject<Self, Base>::computeWithIds;
216
225 template <typename BasketType, int Type, template <class, class, int, typename> class Ext0,
226 template <class, class, int, typename> class... Exts>
228 : public BasketComputeObject<BasketDiff<BasketType, Type, Ext0, Exts...>,
229 typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type>
230 {
231 private:
232 using Self = BasketDiff;
233
234 public:
235 using Base = typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type;
237 using NeighborFilter = BSKNF;
239 using DataPoint = BSKP;
241 using Scalar = BSKS;
243 using VectorType = BSKV;
244 WRITE_COMPUTE_FUNCTIONS
245
247 PONCA_MULTIARCH void init();
248
252 PONCA_MULTIARCH void startNewPass();
253
255 PONCA_MULTIARCH void finalize();
256
263 PONCA_MULTIARCH bool addNeighbor(const DataPoint& _nei);
264
277 PONCA_MULTIARCH void addLocalNeighbor(Scalar _w, const VectorType& _localQ, const DataPoint& _nei,
278 typename Base::ScalarArray& _dw);
279 };
280
289 template <class P, class NF, template <class, class, typename> class Ext0,
290 template <class, class, typename> class... Exts>
291 requires IsPoint<P>
292 class Basket : public BasketComputeObject<Basket<P, NF, Ext0, Exts...>,
293 typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type>
294 {
295 private:
296 using Self = Basket;
297
298 public:
300 using Base = typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type;
302 using Scalar = typename P::Scalar;
303 using VectorType = typename P::VectorType;
305 using DataPoint = P;
308
309 WRITE_COMPUTE_FUNCTIONS
310
312 PONCA_MULTIARCH void init();
313
317 PONCA_MULTIARCH void startNewPass();
318
320 PONCA_MULTIARCH FIT_RESULT finalize();
321
328 PONCA_MULTIARCH bool addNeighbor(const DataPoint& _nei);
329
341 PONCA_MULTIARCH void addLocalNeighbor(typename P::Scalar _w, const typename P::VectorType& _localQ,
342 const P& _nei);
343 }; // class Basket
344
345#undef WRITE_COMPUTE_FUNCTIONS
346} // namespace Ponca
347
348#include "basket.hpp"
Aggregator class used to declare specialized structures with derivatives computations,...
Definition basket.h:230
void init()
Initialize the fit.
Definition basket.hpp:14
typename BasketType::DataPoint DataPoint
Point type used for computation.
Definition basket.h:239
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.hpp:35
typename BasketType::NeighborFilter NeighborFilter
Neighbor Filter.
Definition basket.h:237
typename BasketType::VectorType VectorType
Vector type used for computation, as defined from Basket.
Definition basket.h:243
typename BasketType::Scalar Scalar
Scalar type used for computation, as defined from Basket.
Definition basket.h:241
void addLocalNeighbor(Scalar _w, const VectorType &_localQ, const DataPoint &_nei, typename Base::ScalarArray &_dw)
Add a local neighbor to perform the fit.
Definition basket.hpp:51
void startNewPass()
Start a new iteration over neighbor.
Definition basket.hpp:21
void finalize()
Finalize the fitting procedure.
Definition basket.hpp:28
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
typename internal::BasketAggregate< P, NF, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
Definition basket.h:300
void addLocalNeighbor(typename P::Scalar _w, const typename P::VectorType &_localQ, const P &_nei)
Add a local neighbor to perform the fit.
Definition basket.hpp:100
P DataPoint
Point type used for computation.
Definition basket.h:305
void startNewPass()
Start a new iteration over neighbor.
Definition basket.hpp:68
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
Definition basket.hpp:84
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition basket.h:302
FIT_RESULT finalize()
Finalize the fitting procedure.
Definition basket.hpp:76
void init()
Initialize the fit.
Definition basket.hpp:60
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
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:138
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:183
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:157
typename Base::Scalar Scalar
Alias to the Derived type.
Definition basket.h:141
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