Ponca  4d2a58fa5c6375adef5c4b208f4d47e016cecd6d
Point Cloud Analysis library
Loading...
Searching...
No Matches
basketUnit.h
1/*
2 Copyright (C) 2014 Nicolas Mellado <nmellado0@gmail.com>
3
4 This Source Code Form is subject to the terms of the Mozilla Public
5 License, v. 2.0. If a copy of the MPL was not distributed with this
6 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7*/
8
9#pragma once
10#include "../defines.h"
11#include "concepts.h"
12
13#include <Eigen/Dense>
14
15namespace Ponca
16{
17
25 template <class DataPoint, class _NFilter, typename T = void>
27 {
28 public:
29 using Scalar = typename DataPoint::Scalar;
30 using VectorType = typename DataPoint::VectorType;
32 using NeighborFrame = typename NeighborFilter::NeighborhoodFrame;
33
34 private:
36 int m_nbNeighbors{0};
37
39 Scalar m_sumW{0};
40
41 protected:
44
48
49 public:
50 /**************************************************************************/
51 /* Initialization */
52 /**************************************************************************/
53 PONCA_FITTING_APIDOC_SETWFUNC
54 PONCA_MULTIARCH inline void setNeighborFilter(const NeighborFilter& _nFilter) { m_nFilter = _nFilter; }
55
56 PONCA_FITTING_APIDOC_INIT
57 PONCA_MULTIARCH inline void init()
58 {
61 }
62
67 PONCA_MULTIARCH [[nodiscard]] inline bool isReady() const
68 {
70 }
71
73 PONCA_MULTIARCH [[nodiscard]] inline bool isStable() const { return m_eCurrentState == STABLE; }
74
77 PONCA_MULTIARCH [[nodiscard]] inline bool needAnotherPass() const { return m_eCurrentState == NEED_OTHER_PASS; }
78
80 PONCA_MULTIARCH [[nodiscard]] inline int getNumNeighbors() const { return m_nbNeighbors; }
81
83 PONCA_MULTIARCH [[nodiscard]] inline Scalar getWeightSum() const { return m_sumW; }
84
86 PONCA_MULTIARCH inline void startNewPass()
87 {
88 m_nbNeighbors = 0;
89 m_sumW = Scalar(0);
90 }
91
93 PONCA_MULTIARCH inline const NeighborFilter& getNeighborFilter() const { return m_nFilter; }
94
95 PONCA_MULTIARCH inline NeighborFrame& getNeighborFrame() { return m_nFilter.frame(); }
96 PONCA_MULTIARCH inline const NeighborFrame& getNeighborFrame() const { return m_nFilter.frame(); }
97
98 public:
100 PONCA_MULTIARCH [[nodiscard]] inline FIT_RESULT getCurrentState() const { return m_eCurrentState; }
101
102 PONCA_FITTING_APIDOC_ADDNEIGHBOR
103 PONCA_MULTIARCH inline void addLocalNeighbor(Scalar w, const VectorType&, const DataPoint&)
104 {
105 m_sumW += w;
106 ++(m_nbNeighbors);
107 }
108
109 PONCA_FITTING_APIDOC_FINALIZE
110 PONCA_MULTIARCH inline FIT_RESULT finalize()
111 {
112 // handle specific configurations
113 if (m_sumW == Scalar(0.) || m_nbNeighbors < 1)
114 {
115 return m_eCurrentState = UNDEFINED;
116 }
117 return m_eCurrentState = STABLE;
118 }
119
120 }; // class BasketUnit
121
140 template <class DataPoint, class _NFilter, int Type, typename T>
141 requires ProvidesBasketUnitBase<T>
142 class BasketDiffUnitBase : public T
143 {
144 PONCA_FITTING_DECLARE_DEFAULT_TYPES
145 PONCA_FITTING_DECLARE_MATRIX_TYPE
146 protected:
147 static constexpr int NbDerivatives =
148 ((Type & FitScaleDer) ? 1 : 0) + ((Type & FitSpaceDer) ? DataPoint::Dim : 0);
149 static constexpr int DerStorageOrder = (Type & FitSpaceDer) ? Eigen::RowMajor : Eigen::ColMajor;
150
151 public:
153 using VectorArray = Eigen::Matrix<Scalar, DataPoint::Dim, NbDerivatives, DerStorageOrder>;
154
156 using ScalarArray = Eigen::Matrix<Scalar, 1, NbDerivatives>;
157
158 protected:
159 // computation data
162 public:
163 /************************************************************************/
164 /* Initialization */
165 /************************************************************************/
167 PONCA_MULTIARCH inline void init()
168 {
169 Base::init();
170 m_dSumW.setZero();
171 }
172
173 /************************************************************************/
174 /* Processing */
175 /************************************************************************/
178 PONCA_MULTIARCH inline void addLocalNeighbor(Scalar w, const VectorType& localQ, const DataPoint& attributes,
180 {
181 Base::addLocalNeighbor(w, localQ, attributes);
182 // call the Primitive Fit (without dw)
183 int spaceId = (Type & FitScaleDer) ? 1 : 0;
184 // compute weight
185 if (Type & FitScaleDer)
186 dw[0] = Base::getNeighborFilter().scaledw(attributes.pos(), attributes);
187
188 if (Type & FitSpaceDer)
190 -Base::getNeighborFilter().spacedw(attributes.pos(), attributes).transpose();
191
192 m_dSumW += dw;
193 }
194
195 /**************************************************************************/
196 /* Use results */
197 /**************************************************************************/
199 PONCA_MULTIARCH [[nodiscard]] static inline constexpr bool isScaleDer() { return bool(Type & FitScaleDer); }
201 PONCA_MULTIARCH [[nodiscard]] static inline constexpr bool isSpaceDer() { return bool(Type & FitSpaceDer); }
203 PONCA_MULTIARCH [[nodiscard]] static inline constexpr unsigned int derDimension() { return NbDerivatives; }
204 };
205
206} // namespace Ponca
Base class of any computation unit of a BasketDiff.
Definition basketUnit.h:143
Eigen::Matrix< Scalar, DataPoint::Dim, NbDerivatives, DerStorageOrder > VectorArray
Static array of scalars with a size adapted to the differentiation type.
Definition basketUnit.h:153
void addLocalNeighbor(Scalar w, const VectorType &localQ, const DataPoint &attributes, ScalarArray &dw)
Definition basketUnit.h:178
static constexpr bool isSpaceDer()
State specified at compilation time to compute derivatives in space.
Definition basketUnit.h:201
static constexpr bool isScaleDer()
State specified at compilation time to compute derivatives in scale.
Definition basketUnit.h:199
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition basketUnit.h:144
typename Base::VectorType VectorType
Alias to vector type.
Definition basketUnit.h:144
Eigen::Matrix< Scalar, 1, NbDerivatives > ScalarArray
Static array of scalars with a size adapted to the differentiation type.
Definition basketUnit.h:156
ScalarArray m_dSumW
Sum of weight derivatives.
Definition basketUnit.h:160
static constexpr unsigned int derDimension()
Number of dimensions used for the differentiation.
Definition basketUnit.h:203
Base class of any computation unit of a Basket.
Definition basketUnit.h:27
Scalar getWeightSum() const
Get the sum of the weights.
Definition basketUnit.h:83
int getNumNeighbors() const
Get number of points added in the neighborhood (with positive weight)
Definition basketUnit.h:80
void setNeighborFilter(const NeighborFilter &_nFilter)
Init the WeightFunc, without changing the other internal states.
Definition basketUnit.h:54
FIT_RESULT finalize()
Finalize the procedure.
Definition basketUnit.h:110
bool isStable() const
Is the fitted primitive ready to use (finalize has been called and the result is stable)
Definition basketUnit.h:73
void addLocalNeighbor(Scalar w, const VectorType &, const DataPoint &)
Add a neighbor to perform the fit.
Definition basketUnit.h:103
const NeighborFilter & getNeighborFilter() const
Read access to the NeighborFilter.
Definition basketUnit.h:93
void init()
Set the evaluation position and reset the internal states.
Definition basketUnit.h:57
bool needAnotherPass() const
Is another pass required for fitting (finalize has been called and the result is NEED_OTHER_PASS)
Definition basketUnit.h:77
typename DataPoint::VectorType VectorType
Inherited vector type.
Definition basketUnit.h:30
NeighborFilter m_nFilter
Neighborhood filter.
Definition basketUnit.h:43
FIT_RESULT getCurrentState() const
Definition basketUnit.h:100
void startNewPass()
To be called when starting a new processing pass, ie.
Definition basketUnit.h:86
bool isReady() const
Is the primitive well-fitted and ready to use (finalize has been called) ?
Definition basketUnit.h:67
typename DataPoint::Scalar Scalar
Inherited scalar type.
Definition basketUnit.h:29
FIT_RESULT m_eCurrentState
Represent the current state of the fit (finalize function update the state)
Definition basketUnit.h:47
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:260
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
@ FitSpaceDer
Flag indicating a space differentiation.
Definition enums.h:36
@ FitScaleDer
Flag indicating a scale differentiation.
Definition enums.h:35
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
@ NEED_OTHER_PASS
The fitting procedure needs to analyse the neighborhood another time.
Definition enums.h:25
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17
@ UNSTABLE
The fitting is ready to use but it is considered as unstable (if the number of neighbors is low for e...
Definition enums.h:20