17#define BSKNF typename BasketType::NeighborFilter
18#define BSKP typename BasketType::DataPoint
20#ifndef PARSED_WITH_DOXYGEN
33 template <
class P,
class NF,
35 template <
class,
class,
typename>
class Ext,
36 template <
class,
class,
typename>
class... Exts>
37 struct BasketAggregateImpl
39 using type =
typename BasketAggregateImpl<P, NF, Ext<P, NF, Aggregate>, Exts...>::type;
50 template <
class P,
class NF,
52 template <
class,
class,
typename>
class Ext>
53 struct BasketAggregateImpl<P, NF, Aggregate, Ext>
55 using type = Ext<P, NF, Aggregate>;
66 template <
class P,
class NF,
67 template <
class,
class,
typename>
class... Exts>
68 struct BasketAggregate : BasketAggregateImpl<P, NF, PrimitiveBase<P, NF>, Exts...>
83 template <
class,
class,
int,
typename>
class Ext,
84 template <
class,
class,
int,
typename>
class... Exts>
85 struct BasketDiffAggregateImpl
87 using type =
typename BasketDiffAggregateImpl<Type, Ext<BSKP, BSKNF, Type, BasketType>, Exts...>::type;
99 template <
class,
class,
int,
typename>
class Ext>
100 struct BasketDiffAggregateImpl<Type, BasketType, Ext>
102 using type = Ext<BSKP, BSKNF, Type, BasketType>;
113 template <
typename BasketType,
int Type,
114 template <
class,
class,
int,
typename>
class... Exts>
115 struct BasketDiffAggregate : BasketDiffAggregateImpl<Type, BasketType, PrimitiveDer, Exts...>
142 template<
typename _Derived,
typename _Base>
158 template <
typename IteratorBegin,
typename IteratorEnd>
165 for (
auto it = begin; it != end; ++it){
168 res = Base::finalize();
181 template <
typename IndexRange,
typename Po
intContainer>
188 for (
const auto& i : ids){
189 derived().addNeighbor(points[i]);
191 res = Base::finalize();
205 template<
typename Func>
208 auto lastPos = Base::getNeighborFilter().evalPos();
210 for (
int mm = 0; mm < mlsIter; ++mm) {
211 Base::getNeighborFilter().changeNeighborhoodFrame(lastPos);
214 if (Base::isStable()) {
215 auto newPos = Base::project(lastPos);
216 if (newPos.isApprox(lastPos, epsilon))
231 template<
typename Po
intContainer>
233 const PointContainer& points,
234 const int mlsIter = 5,
235 const Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision()
238 [&]() {
return compute(points); },
248 template<
typename IndexRange,
typename Po
intContainer>
250 const IndexRange& ids,
251 const PointContainer& points,
252 const int mlsIter = 5,
253 const Scalar epsilon = Eigen::NumTraits<Scalar>::dummy_precision()
262#define WRITE_COMPUTE_FUNCTIONS \
263 using BasketComputeObject<Self, Base>::compute; \
264 using BasketComputeObject<Self, Base>::computeWithIds; \
265 using BasketComputeObject<Self, Base>::computeMLS; \
266 using BasketComputeObject<Self, Base>::computeWithIdsMLS;
276 template <
typename BasketType,
int Type,
277 template <
class,
class,
int,
typename>
class Ext0,
278 template <
class,
class,
int,
typename>
class... Exts>
280 typename internal::BasketDiffAggregate<BasketType, Type, Ext0, Exts...>::type>
285 using Base =
typename internal::BasketDiffAggregate<BasketType,Type,Ext0,Exts...>::type;
291 using Scalar =
typename BasketType::Scalar;
292 WRITE_COMPUTE_FUNCTIONS
297 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
298 typename Base::ScalarArray dw;
300 if (neiFilterOutput.first >
Scalar(0.)) {
301 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei, dw);
316 template <
class P,
class NF,
317 template <
class,
class,
typename>
class Ext0,
318 template <
class,
class,
typename>
class... Exts>
320 typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type>
326 using Base =
typename internal::BasketAggregate<P, NF, Ext0, Exts...>::type;
329 using VectorType =
typename P::VectorType;
335 WRITE_COMPUTE_FUNCTIONS
345 auto neiFilterOutput = Base::getNeighborFilter()(_nei);
347 if (neiFilterOutput.first >
Scalar(0.)) {
348 Base::addLocalNeighbor(neiFilterOutput.first, neiFilterOutput.second, _nei);
363 PONCA_MULTIARCH [[nodiscard]]
inline VectorType
projectDescent (
const VectorType& _q,
int nbIter = 16)
const
365 PONCA_MULTIARCH_STD_MATH(min)
368 const VectorType lq = Base::getNeighborFilter().convertToLocalBasis(_q);
371 VectorType dir = Base::primitiveGradientLocal(lq);
374 Scalar ad = Base::potentialLocal(lq);
376 VectorType proj = lq + dir*delta;
378 for (
int i=0; i<nbIter; ++i)
380 grad = Base::primitiveGradientLocal(proj);
381 ilg =
Scalar(1.)/grad.norm();
382 delta = -Base::potentialLocal(proj)*min(ilg,
Scalar(1.));
385 return Base::getNeighborFilter().convertToGlobalBasis( proj );
389#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...