14#include PONCA_MULTIARCH_INCLUDE_STD(iterator)
19#define BSKNF typename BasketType::NeighborFilter
20#define BSKP typename BasketType::DataPoint
22#ifndef PARSED_WITH_DOXYGEN
35 template <
class P,
class NF,
37 template <
class,
class,
typename>
class Ext,
38 template <
class,
class,
typename>
class... Exts>
39 struct BasketAggregateImpl
41 using type =
typename BasketAggregateImpl<P, NF, Ext<P, NF, Aggregate>, Exts...>::type;
52 template <
class P,
class NF,
54 template <
class,
class,
typename>
class Ext>
55 struct BasketAggregateImpl<P, NF, Aggregate, Ext>
57 using type = Ext<P, NF, Aggregate>;
68 template <
class P,
class NF,
69 template <
class,
class,
typename>
class... Exts>
70 struct BasketAggregate : BasketAggregateImpl<P, NF, PrimitiveBase<P, NF>, Exts...>
85 template <
class,
class,
int,
typename>
class Ext,
86 template <
class,
class,
int,
typename>
class... Exts>
87 struct BasketDiffAggregateImpl
89 using type =
typename BasketDiffAggregateImpl<Type, Ext<BSKP, BSKNF, Type, BasketType>, Exts...>::type;
101 template <
class,
class,
int,
typename>
class Ext>
102 struct BasketDiffAggregateImpl<Type, BasketType, Ext>
104 using type = Ext<BSKP, BSKNF, Type, BasketType>;
115 template <
typename BasketType,
int Type,
116 template <
class,
class,
int,
typename>
class... Exts>
117 struct BasketDiffAggregate : BasketDiffAggregateImpl<Type, BasketType, PrimitiveDer, Exts...>
144 template<
typename _Derived,
typename _Base>
160 template <
typename IteratorBegin,
typename IteratorEnd>
167 for (
auto it = begin; it != end; ++it){
170 res = Base::finalize();
183 template <
typename IndexRange,
typename Po
intContainer>
190 for (
const auto& i : ids){
191 derived().addNeighbor(points[i]);
193 res = Base::finalize();
207 template<
typename Func>
210 auto lastPos = Base::getNeighborFilter().evalPos();
212 for (
int mm = 0; mm < mlsIter; ++mm) {
213 Base::getNeighborFilter().changeNeighborhoodFrame(lastPos);
216 if (Base::isStable()) {
217 auto newPos = Base::project(lastPos);
218 if (newPos.isApprox(lastPos, epsilon))
233 template<
typename Po
intContainer>
235 const PointContainer& points,
236 const int mlsIter = 5,
237 const Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision()
240 [&]() {
return compute(points); },
250 template<
typename IndexRange,
typename Po
intContainer>
252 const IndexRange& ids,
253 const PointContainer& points,
254 const int mlsIter = 5,
255 const Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision()
264#define WRITE_COMPUTE_FUNCTIONS \
265 using BasketComputeObject<Self, Base>::compute; \
266 using BasketComputeObject<Self, Base>::computeWithIds; \
267 using BasketComputeObject<Self, Base>::computeMLS; \
268 using BasketComputeObject<Self, Base>::computeWithIdsMLS;
278 template <
typename BasketType,
int Type,
279 template <
class,
class,
int,
typename>
class Ext0,
280 template <
class,
class,
int,
typename>
class... Exts>
282 typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type>
287 using Base =
typename internal::BasketDiffAggregate<BasketType,Type,Ext0,Exts...>::type;
293 using Scalar =
typename BasketType::Scalar;
294 WRITE_COMPUTE_FUNCTIONS
299 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
300 typename Base::ScalarArray dw;
302 if (neiFilterOutput.first >
Scalar(0.)) {
303 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei, dw);
318 template <
class P,
class NF,
319 template <
class,
class,
typename>
class Ext0,
320 template <
class,
class,
typename>
class... Exts>
322 typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type>
328 using Base =
typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type;
331 using VectorType =
typename P::VectorType;
337 WRITE_COMPUTE_FUNCTIONS
347 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
349 if (neiFilterOutput.first >
Scalar(0.)) {
350 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei);
365 PONCA_MULTIARCH [[nodiscard]]
inline VectorType
projectDescent (
const VectorType& _q,
int nbIter = 16)
const
367 PONCA_MULTIARCH_STD_MATH(min)
370 const VectorType lq = Base::getNeighborFilter().convertToLocalBasis(_q);
373 VectorType dir = Base::primitiveGradientLocal(lq);
376 Scalar ad = Base::potentialLocal(lq);
378 VectorType proj = lq + dir*delta;
380 for (
int i=0; i<nbIter; ++i)
382 grad = Base::primitiveGradientLocal(proj);
383 ilg =
Scalar(1.)/grad.norm();
384 delta = -Base::potentialLocal(proj)*min(ilg,
Scalar(1.));
387 return Base::getNeighborFilter().convertToGlobalBasis( proj );
391#undef WRITE_COMPUTE_FUNCTIONS
Aggregator class used to declare specialized structures with derivatives computations,...
typename BasketType::DataPoint DataPoint
Point type used for computation.
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
typename BasketType::NeighborFilter NeighborFilter
Neighbor Filter.
typename BasketType::Scalar Scalar
Scalar type used for computation, as defined from Basket.
Aggregator class used to declare specialized structures using CRTP.
typename internal::BasketAggregate< P, NF, Ext0, Exts... >::type Base
Base type, which aggregates all the computational objects using the CRTP.
P DataPoint
Point type used for computation.
VectorType projectDescent(const VectorType &_q, int nbIter=16) const
Project a point on the primitive using Gradient Descent This projection is realized by following the ...
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
NF NeighborFilter
Weighting function.
bool addNeighbor(const DataPoint &_nei)
Add a neighbor to perform the fit.
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.
@ NEED_OTHER_PASS
The fitting procedure needs to analyse the neighborhood another time.
Base ComputeObject for the Basket classes.
FIT_RESULT computeWithIds(IndexRange ids, const PointContainer &points)
Convenience function to iterate over a subset of samples in a PointContainer Add neighbors stored in ...
FIT_RESULT computeMLS(const PointContainer &points, const int mlsIter=5, const Scalar epsilon=Eigen::NumTraits< Scalar >::dummy_precision())
Computes the fit using the MLS iteration process.
FIT_RESULT computeMLSImpl(Func &&computeFunc, const int mlsIter, const Scalar epsilon)
Computes the fit using the MLS iteration process.
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...
FIT_RESULT computeWithIdsMLS(const IndexRange &ids, const PointContainer &points, const int mlsIter=5, const Scalar epsilon=Eigen::NumTraits< Scalar >::dummy_precision())
Computes the fit using the MLS iteration process.
typename Base::Scalar Scalar
Alias to the Derived type.
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
_Derived & derived()
Retrieve the top layer object Returns a reference to the derived class so that we can use its overwri...