13#include PONCA_MULTIARCH_INCLUDE_STD(iterator)
18#define BSKW typename BasketType::WeightFunction
19#define BSKP typename BasketType::DataPoint
21#ifndef PARSED_WITH_DOXYGEN
25 template <
class P,
class W,
27 template <
class,
class,
typename>
class Ext,
28 template <
class,
class,
typename>
class... Exts>
29 struct BasketAggregateImpl
31 using type =
typename BasketAggregateImpl<P, W, Ext<P, W, Aggregate>, Exts...>::type;
34 template <
class P,
class W,
36 template <
class,
class,
typename>
class Ext>
37 struct BasketAggregateImpl<P, W, Aggregate, Ext>
39 using type = Ext<P, W, Aggregate>;
43 template <
class P,
class W,
44 template <
class,
class,
typename>
class... Exts>
45 struct BasketAggregate : BasketAggregateImpl<P, W, PrimitiveBase<P, W>, Exts...>
49 template <
typename BasketType,
int Type,
51 template <
class,
class,
int,
typename>
class Ext,
52 template <
class,
class,
int,
typename>
class... Exts>
53 struct BasketDiffAggregateImpl
55 using type =
typename BasketDiffAggregateImpl<BasketType, Type, Ext<BSKP, BSKW, Type, Aggregate>, Exts...>::type;
58 template <
typename BasketType,
int Type,
60 template <
class,
class,
int,
typename>
class Ext>
61 struct BasketDiffAggregateImpl<BasketType, Type, Aggregate, Ext>
63 using type = Ext<BSKP, BSKW, Type, Aggregate>;
67 template <
typename BasketType,
int Type,
68 template <
class,
class,
int,
typename>
class... Exts>
69 struct BasketDiffAggregate : BasketDiffAggregateImpl<BasketType, Type, BasketType, PrimitiveDer, Exts...>
81 template <
typename Derived>
86 Derived&
derived() {
return static_cast<Derived&
>(*this); }
94 template <
typename Container>
96 return derived().compute(std::begin(c), std::end(c));
104 template <
typename IteratorBegin,
typename IteratorEnd>
112 template <
typename IndexRange,
typename Po
intContainer>
116#define WRITE_COMPUTE_FUNCTIONS \
121 template <typename IteratorBegin, typename IteratorEnd> \
122 PONCA_MULTIARCH inline \
123 FIT_RESULT compute(const IteratorBegin& begin, const IteratorEnd& end){ \
125 FIT_RESULT res = UNDEFINED; \
127 Self::startNewPass(); \
128 for (auto it = begin; it != end; ++it){ \
129 Self::addNeighbor(*it); \
131 res = Base::finalize(); \
132 } while ( res == NEED_OTHER_PASS ); \
140 template <typename IndexRange, typename PointContainer> \
141 PONCA_MULTIARCH inline \
142 FIT_RESULT computeWithIds(IndexRange ids, const PointContainer& points){ \
144 FIT_RESULT res = UNDEFINED; \
146 Self::startNewPass(); \
147 for (const auto& i : ids){ \
148 this->addNeighbor(points[i]); \
150 res = this->finalize(); \
151 } while ( res == NEED_OTHER_PASS ); \
180 template <
typename BasketType,
int Type,
181 template <
class,
class,
int,
typename>
class Ext0,
182 template <
class,
class,
int,
typename>
class... Exts>
184 public internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type {
189 using Base =
typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type;
195 using Scalar =
typename DataPoint::Scalar;
198 WRITE_COMPUTE_FUNCTIONS
203 auto wres = Base::m_w.w(_nei.pos(), _nei);
204 typename Base::ScalarArray dw;
206 if (wres.first >
Scalar(0.)) {
207 Base::addLocalNeighbor(wres.first, wres.second, _nei, dw);
239 template <
class P,
class W,
240 template <
class,
class,
typename>
class Ext0,
241 template <
class,
class,
typename>
class... Exts>
243 public internal::BasketAggregate<P, W, Ext0, Exts...>::type
249 using Base =
typename internal::BasketAggregate<P, W, Ext0, Exts...>::type;
258 WRITE_COMPUTE_FUNCTIONS;
268 auto wres = Base::m_w.w(_nei.pos(), _nei);
270 if (wres.first >
Scalar(0.)) {
271 Base::addLocalNeighbor(wres.first, wres.second, _nei);
Aggregator class used to declare specialized structures with derivatives computations,...
typename BasketType::DataPoint DataPoint
Point type used for computation.
typename internal::BasketDiffAggregate< BasketType, Type, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
typename DataPoint::Scalar Scalar
Scalar type used for computation, as defined from Basket.
typename BasketType::WeightFunction WeightFunction
Weighting function.
Aggregator class used to declare specialized structures using CRTP.
W WeightFunction
Weighting function.
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators
P DataPoint
Point type used for computation.
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
typename internal::BasketAggregate< P, W, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
@ UNDEFINED
The fitting is undefined, you can't use it for valid results.
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
FIT_RESULT computeWithIds(IndexRange, const PointContainer &)
Convenience function to iterate over a subset of samples in a PointContainer.
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators.
FIT_RESULT compute(const Container &c)
Convenience function for STL-like container
Derived & derived()
Retrieve the top layer object Returns a reference to the derived class so that we can use its overwri...