Ponca  4a9354998d048bf882a3ee9bac8105216fa08d13
Point Cloud Analysis library
Loading...
Searching...
No Matches
mlsEvaluationScheme.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#pragma once
7
8#include "../concepts.h"
9#include "../Filters/concepts.h" // ProvidesNeighborhoodFrame
10#include "../Basket/concepts.h" // ProvidesBasketUnitBase
11#include "../defines.h"
12#include "../enums.h"
13
14#include "./project.h"
15
16#include "Eigen/Core"
17
18namespace Ponca
19{
28 template <typename Scalar>
30 {
31 MLSEvaluationScheme(unsigned int _nIter = nIterDefault, Scalar _eps = epsDefault) : nIter(_nIter), eps(_eps) {}
32
48 template <typename ComputeObject, typename ItB, typename ItE, typename Project = DirectProjectionOperator>
49 PONCA_MULTIARCH inline FIT_RESULT compute(ComputeObject& _co, const ItB& _itb, const ItE& _ite,
50 const Project& _p = Project{}) const
51 {
52 return computeMLSImpl(_co, [&]() { return _co.compute(_itb, _ite); }, _p);
53 }
54
68 template <typename ComputeObject, typename PointContainer, typename Project = DirectProjectionOperator>
69 PONCA_MULTIARCH inline FIT_RESULT compute(ComputeObject& _co, const PointContainer& container,
70 const Project& _p = Project{})
71 {
72 return compute(_co, std::begin(container), std::end(container), _p);
73 }
74
90 template <typename ComputeObject, typename IdxRange, typename PointContainer,
91 typename Project = DirectProjectionOperator>
92 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(ComputeObject& _co, const IdxRange& _range,
93 const PointContainer& _container,
94 const Project& _p = Project{}) const
95 {
96 return computeMLSImpl(_co, [&]() { return _co.computeWithIds(_range, _container); }, _p);
97 }
98
100 static constexpr Scalar epsDefault = Eigen::NumTraits<Scalar>::dummy_precision();
102 static constexpr int nIterDefault = 5;
104 Scalar eps = epsDefault;
106 unsigned int nIter = nIterDefault;
107
108 private:
124 template <typename ComputeObject, typename Func, typename Project = DirectProjectionOperator>
127 PONCA_MULTIARCH inline FIT_RESULT computeMLSImpl(ComputeObject& _co, Func&& _compute,
128 const Project& _p = Project{}) const
129 {
131 auto& frame = _co.getNeighborFrame();
132 auto lastPos = frame.center();
133
134 for (unsigned int mm = 0; mm < nIter; ++mm)
135 {
136 frame.changeNeighborhoodFrame(lastPos);
137 res = _compute();
138
139 if (_co.isStable())
140 {
141 auto newPos = _p(_co, lastPos);
142 if (newPos.isApprox(lastPos, eps))
143 return res;
144 lastPos = newPos;
145 }
146 else
147 {
148 return res;
149 }
150 }
151
152 return res;
153 }
154 };
155} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
This concept ensures that the default types and accessors in a Basket are well-formed.
Definition concepts.h:27
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
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
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
Definition compute.h:24
Computes the fit using the Moving Least Squares approach.
Scalar eps
Epsilon value for stopping MLS iterations.
static constexpr int nIterDefault
Default maximum number of MLS iterations.
unsigned int nIter
Maximum number of MLS iterations.
static constexpr Scalar epsDefault
Default epsilon value for stopping MLS iterations.
FIT_RESULT computeWithIds(ComputeObject &_co, const IdxRange &_range, const PointContainer &_container, const Project &_p=Project{}) const
Computes the fit using the MLS iteration process.
FIT_RESULT compute(ComputeObject &_co, const ItB &_itb, const ItE &_ite, const Project &_p=Project{}) const
Computes the fit using the MLS iteration process.
FIT_RESULT compute(ComputeObject &_co, const PointContainer &container, const Project &_p=Project{})
Computes the fit using the MLS iteration process.