Ponca  4d2a58fa5c6375adef5c4b208f4d47e016cecd6d
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>
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
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
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 static_assert(DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
87
88 protected:
90 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
91
92 public:
94 PONCA_MULTIARCH inline QuadraticHeightField() : Base() { init(); }
95
96 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, heightField)
97 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, quadraticHeightField)
98
100 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
101
102 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
103
105 PONCA_MULTIARCH inline void init()
106 {
107 Base::init();
108 m_coeffs.setZero();
109 }
110
114 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
115 {
116 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
117 }
118
119 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
121 {
122 return m_coeffs.isApprox(other.m_params);
123 }
124
126 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
128 {
129 return !((*this) == other);
130 }
131
133 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const
134 {
135 return h_uu() * u * u + h_vv() * v * v + h_uv() * u * v + h_u() * u + h_v() * v + h_c();
136 }
137
138 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uu() const { return *(m_coeffs.data()); }
139 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_vv() const { return *(m_coeffs.data() + 1); }
140 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uv() const { return *(m_coeffs.data() + 2); }
141 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_u() const { return *(m_coeffs.data() + 3); }
142 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_v() const { return *(m_coeffs.data() + 4); }
143 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_c() const { return *(m_coeffs.data() + 5); }
144
146 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
147 {
148 return Scalar(2) * h_uu() * u + h_uv() * v + h_u();
149 }
150
152 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
153 {
154 return Scalar(2) * h_vv() * v + h_uv() * u + h_v();
155 }
156
158 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
159 {
160 return Scalar(2) * h_uu();
161 }
162
164 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
165 {
166 return Scalar(2) * h_vv();
167 }
168
171 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
172 {
173 return h_uv();
174 }
175
177 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal(const VectorType& _localQ) const
178 {
179 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
180 return VectorType(tu, Scalar(1), Scalar(0)).normalized();
181 }
182
184 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal(const VectorType& _localQ) const
185 {
186 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
187 return VectorType(tv, Scalar(0), Scalar(1)).normalized();
188 }
189 }; // class QuadraticHeightField
201 template <class DataPoint, class _NFilter, typename T>
202 requires QUADRATIC_HEIGHT_FIELD_REQUIREMENTS
204 {
205 PONCA_FITTING_DECLARE_DEFAULT_TYPES
206 using HeightFieldCoefficients = Eigen::Matrix<Scalar, 4, 1>;
207 static_assert(DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
208
209 protected:
211 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
212
213 public:
215 PONCA_MULTIARCH inline RestrictedQuadraticHeightField() : Base() { init(); }
216
217 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, heightField)
219
221 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
222
223 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
224
226 PONCA_MULTIARCH inline void init()
227 {
228 Base::init();
229 m_coeffs.setZero();
230 }
231
235 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
236 {
237 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
238 }
239
240 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
242 {
243 return m_coeffs.isApprox(other.m_params);
244 }
245
247 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
249 {
250 return !((*this) == other);
251 }
252
254 template <typename Other>
255 PONCA_MULTIARCH [[nodiscard]] inline bool isApprox(
256 const Other& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const
257 {
258 return m_coeffs.isApprox(other.m_params, epsilon);
259 }
260
262 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const
263 {
264 return h_uu() * u * u + h_vv() * v * v + h_uv() * u * v + h_c();
265 }
266
267 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uu() const { return *(m_coeffs.data()); }
268 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_vv() const { return *(m_coeffs.data() + 1); }
269 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uv() const { return *(m_coeffs.data() + 2); }
270 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_c() const { return *(m_coeffs.data() + 3); }
271
273 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
274 {
275 return Scalar(2) * h_uu() * u + h_uv() * v;
276 }
277
279 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
280 {
281 return Scalar(2) * h_vv() * v + h_uv() * u;
282 }
283
285 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
286 {
287 return Scalar(2) * h_uu();
288 }
289
291 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
292 {
293 return Scalar(2) * h_vv();
294 }
295
298 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
299 {
300 return h_uv();
301 }
302
304 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal(const VectorType& _localQ) const
305 {
306 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
307 return VectorType(tu, Scalar(1), Scalar(0)).normalized();
308 }
309
311 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal(const VectorType& _localQ) const
312 {
313 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
314 return VectorType(tv, Scalar(0), Scalar(1)).normalized();
315 }
316 }; // class RestrictedQuadraticHeightField
317
318} // namespace Ponca
319
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:260
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:96
void setQuadric(const HeightFieldCoefficients &coeffs)
Set the scalar field values.
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:90
QuadraticHeightField()
Default constructor.
Definition heightField.h:94
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:97
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