Ponca  cfb0fcc680f97b3ab7288990161ce80053655869
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 "defines.h"
9#include "enums.h"
10
11#include "./project.h"
12
13#include "Eigen/Core"
14
15namespace Ponca
16{
25 template <typename Scalar>
27 {
28 MLSEvaluationScheme(unsigned int _nIter = nIterDefault, Scalar _eps = epsDefault) : nIter(_nIter), eps(_eps) {}
29
45 template <typename ComputeObject, typename ItB, typename ItE, typename Project = DirectProjectionOperator>
46 PONCA_MULTIARCH inline FIT_RESULT compute(ComputeObject& _co, const ItB& _itb, const ItE& _ite,
47 const Project& _p = Project{}) const
48 {
49 return computeMLSImpl(_co, [&]() { return _co.compute(_itb, _ite); }, _p);
50 }
51
65 template <typename ComputeObject, typename PointContainer, typename Project = DirectProjectionOperator>
66 PONCA_MULTIARCH inline FIT_RESULT compute(ComputeObject& _co, const PointContainer& container,
67 const Project& _p = Project{})
68 {
69 return compute(_co, std::begin(container), std::end(container), _p);
70 }
71
87 template <typename ComputeObject, typename IdxRange, typename PointContainer,
88 typename Project = DirectProjectionOperator>
89 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(ComputeObject& _co, const IdxRange& _range,
90 const PointContainer& _container,
91 const Project& _p = Project{}) const
92 {
93 return computeMLSImpl(_co, [&]() { return _co.computeWithIds(_range, _container); }, _p);
94 }
95
97 static constexpr Scalar epsDefault = Eigen::NumTraits<Scalar>::dummy_precision();
99 static constexpr int nIterDefault = 5;
101 Scalar eps = epsDefault;
103 unsigned int nIter = nIterDefault;
104
105 private:
121 template <typename ComputeObject, typename Func, typename Project = DirectProjectionOperator>
122 PONCA_MULTIARCH inline FIT_RESULT computeMLSImpl(ComputeObject& _co, Func&& _compute,
123 const Project& _p = Project{}) const
124 {
126 auto filter = _co.getNeighborFilter();
127 auto lastPos = filter.evalPos();
128
129 for (unsigned int mm = 0; mm < nIter; ++mm)
130 {
131 filter.changeNeighborhoodFrame(lastPos);
132 _co.setNeighborFilter(filter);
133 res = _compute();
134
135 if (_co.isStable())
136 {
137 auto newPos = _p(_co, lastPos);
138 if (newPos.isApprox(lastPos, eps))
139 return res;
140 lastPos = newPos;
141 }
142 else
143 {
144 return res;
145 }
146 }
147
148 return res;
149 }
150 };
151} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
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)
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:179
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:153
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.