Ponca  7abd0fd82719106ad460aa0f2070dffbe375d727
Point Cloud Analysis library
Loading...
Searching...
No Matches
heightField.h
1/*
2This 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
7#pragma once
8
9#include "../../defines.h"
10#include "../concepts.h"
11
12#include <Eigen/Dense>
13
14#define HEIGHT_FIELD_REQUIREMENTS Is3D<DataPoint>
15#define QUADRATIC_HEIGHT_FIELD_REQUIREMENTS ProvidesHeightFieldBase<T>&& Is3D<DataPoint>
16
17namespace Ponca
18{
27 template <class DataPoint, class _NFilter, typename T>
28 requires HEIGHT_FIELD_REQUIREMENTS
29 class HeightField : public T
30 {
31 PONCA_FITTING_DECLARE_DEFAULT_TYPES
32
33 PONCA_EXPLICIT_CAST_OPERATORS(HeightField, heightFieldBase)
34
35
36 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getHFromLocalCoordinates(const VectorType& _lq) const
37 {
38 return *(_lq.data());
39 }
40
42 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getHFromLocalCoordinates(VectorType& _lq) const
43 {
44 return *(_lq.data());
45 }
46
48 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getUFromLocalCoordinates(const VectorType& _lq) const
49 {
50 return *(_lq.data() + 1);
51 }
52
54 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getUFromLocalCoordinates(VectorType& _lq) const
55 {
56 return *(_lq.data() + 1);
57 }
58
60 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getVFromLocalCoordinates(const VectorType& _lq) const
61 {
62 return *(_lq.data() + 2);
63 }
64
66 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getVFromLocalCoordinates(VectorType& _lq)
67 {
68 return *(_lq.data() + 2);
69 }
70 };
71
80 template <class DataPoint, class _NFilter, typename T>
81 requires QUADRATIC_HEIGHT_FIELD_REQUIREMENTS
82 class QuadraticHeightField : public T
83 {
84 PONCA_FITTING_DECLARE_DEFAULT_TYPES
85 using HeightFieldCoefficients = Eigen::Matrix<Scalar, 6, 1>;
86
87 protected:
89 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
90
91 public:
93 PONCA_MULTIARCH inline QuadraticHeightField() : Base() { init(); }
94
95 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, heightField)
96 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, quadraticHeightField)
97
99 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
100
101 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
102
104 PONCA_MULTIARCH inline void init()
105 {
106 Base::init();
107 m_coeffs.setZero();
108 }
109
113 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
114 {
115 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
116 }
117
118 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
120 {
121 return m_coeffs.isApprox(other.m_coeffs);
122 }
123
125 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
127 {
128 return !((*this) == other);
129 }
130
132 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const
133 {
134 return h_uu() * u * u + h_vv() * v * v + h_uv() * u * v + h_u() * u + h_v() * v + h_c();
135 }
136
137 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uu() const { return *(m_coeffs.data()); }
138 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_vv() const { return *(m_coeffs.data() + 1); }
139 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uv() const { return *(m_coeffs.data() + 2); }
140 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_u() const { return *(m_coeffs.data() + 3); }
141 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_v() const { return *(m_coeffs.data() + 4); }
142 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_c() const { return *(m_coeffs.data() + 5); }
143
145 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
146 {
147 return Scalar(2) * h_uu() * u + h_uv() * v + h_u();
148 }
149
151 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
152 {
153 return Scalar(2) * h_vv() * v + h_uv() * u + h_v();
154 }
155
157 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
158 {
159 return Scalar(2) * h_uu();
160 }
161
163 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
164 {
165 return Scalar(2) * h_vv();
166 }
167
170 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
171 {
172 return h_uv();
173 }
174
176 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal(const VectorType& _localQ) const
177 {
178 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
179 return VectorType(tu, Scalar(1), Scalar(0)).normalized();
180 }
181
183 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal(const VectorType& _localQ) const
184 {
185 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
186 return VectorType(tv, Scalar(0), Scalar(1)).normalized();
187 }
188 }; // class QuadraticHeightField
200 template <class DataPoint, class _NFilter, typename T>
201 requires QUADRATIC_HEIGHT_FIELD_REQUIREMENTS
203 {
204 PONCA_FITTING_DECLARE_DEFAULT_TYPES
205 using HeightFieldCoefficients = Eigen::Matrix<Scalar, 4, 1>;
206
207 protected:
209 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
210
211 public:
213 PONCA_MULTIARCH inline RestrictedQuadraticHeightField() : Base() { init(); }
214
215 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, heightField)
217
219 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
220
221 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
222
224 PONCA_MULTIARCH inline void init()
225 {
226 Base::init();
227 m_coeffs.setZero();
228 }
229
233 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
234 {
235 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
236 }
237
238 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
240 {
241 return m_coeffs.isApprox(other.m_coeffs);
242 }
243
245 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
247 {
248 return !((*this) == other);
249 }
250
252 template <typename Other>
253 PONCA_MULTIARCH [[nodiscard]] inline bool isApprox(
254 const Other& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const
255 {
256 return m_coeffs.isApprox(other.m_params, epsilon);
257 }
258
260 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const
261 {
262 return h_uu() * u * u + h_vv() * v * v + h_uv() * u * v + h_c();
263 }
264
265 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uu() const { return *(m_coeffs.data()); }
266 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_vv() const { return *(m_coeffs.data() + 1); }
267 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uv() const { return *(m_coeffs.data() + 2); }
268 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_c() const { return *(m_coeffs.data() + 3); }
269
271 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
272 {
273 return Scalar(2) * h_uu() * u + h_uv() * v;
274 }
275
277 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
278 {
279 return Scalar(2) * h_vv() * v + h_uv() * u;
280 }
281
283 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
284 {
285 return Scalar(2) * h_uu();
286 }
287
289 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
290 {
291 return Scalar(2) * h_vv();
292 }
293
296 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
297 {
298 return h_uv();
299 }
300
302 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal(const VectorType& _localQ) const
303 {
304 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
305 return VectorType(tu, Scalar(1), Scalar(0)).normalized();
306 }
307
309 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal(const VectorType& _localQ) const
310 {
311 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
312 return VectorType(tv, Scalar(0), Scalar(1)).normalized();
313 }
314 }; // class RestrictedQuadraticHeightField
315
316} // namespace Ponca
317
Internal base classe for height fields.
Definition heightField.h:30
HeightField< DataPoint, _NFilter, T > & heightFieldBase()
Explicit conversion to HeightField , to access methods potentially hidden by heritage.
Definition heightField.h:33
Scalar & getVFromLocalCoordinates(VectorType &_lq)
get access to v from local coordinate vector
Definition heightField.h:66
const Scalar & getVFromLocalCoordinates(const VectorType &_lq) const
get access to v from local coordinate vector
Definition heightField.h:60
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition heightField.h:31
Scalar & getUFromLocalCoordinates(VectorType &_lq) const
get access to u from local coordinate vector
Definition heightField.h:54
typename Base::VectorType VectorType
Alias to vector type.
Definition heightField.h:31
const Scalar & getHFromLocalCoordinates(const VectorType &_lq) const
get access to height from local coordinate vector
Definition heightField.h:36
Scalar & getHFromLocalCoordinates(VectorType &_lq) const
get access to height from local coordinate vector
Definition heightField.h:42
const Scalar & getUFromLocalCoordinates(const VectorType &_lq) const
get access to u from local coordinate vector
Definition heightField.h:48
Quadratic height field defined as .
Definition heightField.h:83
typename Base::VectorType VectorType
Alias to vector type.
Definition heightField.h:84
QuadraticHeightField< DataPoint, _NFilter, T > & heightField()
Explicit conversion to QuadraticHeightField , to access methods potentially hidden by heritage.
Definition heightField.h:95
void setQuadric(const HeightFieldCoefficients &coeffs)
Set the scalar field values.
Definition heightField.h:99
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition heightField.h:84
void init()
Set the scalar field values to 0.
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
HeightFieldCoefficients m_coeffs
Quadric parameters, stored as .
Definition heightField.h:89
QuadraticHeightField()
Default constructor.
Definition heightField.h:93
Scalar dh_du(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
T Base
Base class of the procedure.
Definition heightField.h:84
Scalar dh_dv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
Scalar d2h_dvv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
bool operator!=(const QuadraticHeightField< DataPoint, _NFilter, T > &other) const
Comparison operator, convenience function.
Scalar height(Scalar u, Scalar v) const
Height value at local uv.
QuadraticHeightField< DataPoint, _NFilter, T > & quadraticHeightField()
Explicit conversion to QuadraticHeightField , to access methods potentially hidden by heritage.
Definition heightField.h:96
Scalar d2h_duu(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
Quadratic height field defined as .
Scalar d2h_dvv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
Scalar d2h_duu(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
Scalar dh_du(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
void setQuadric(const HeightFieldCoefficients &coeffs)
Set the scalar field values.
Scalar dh_dv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
Scalar height(Scalar u, Scalar v) const
Height value at local uv.
T Base
Base class of the procedure.
RestrictedQuadraticHeightField()
Default constructor.
QuadraticHeightField< DataPoint, _NFilter, T > & heightField()
Explicit conversion to QuadraticHeightField , to access methods potentially hidden by heritage.
bool isApprox(const Other &other, const Scalar &epsilon=Eigen::NumTraits< Scalar >::dummy_precision()) const
Approximate comparison operator operator.
void init()
Set the scalar field values to 0.
RestrictedQuadraticHeightField< DataPoint, _NFilter, T > & quadraticHeightField()
Explicit conversion to RestrictedQuadraticHeightField , to access methods potentially hidden by herit...
bool isValid() const
Tell if the plane as been correctly set. Used to set CONFLICT_ERROR_FOUND during fitting.
typename DataPoint::Scalar Scalar
Alias to scalar type.
HeightFieldCoefficients m_coeffs
Quadric parameters, stored as .
bool operator!=(const RestrictedQuadraticHeightField< DataPoint, _NFilter, T > &other) const
Comparison operator, convenience function.
typename Base::VectorType VectorType
Alias to vector type.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11