Ponca  19ef58fd3760f23a8af99a5eeac4f934757e30d9
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
11#include <Eigen/Dense>
12
13namespace Ponca
14{
23 template <class DataPoint, class _NFilter, typename T>
24 class HeightField : public T
25 {
26 PONCA_FITTING_DECLARE_DEFAULT_TYPES
27 static_assert(DataPoint::Dim == 3, "HeightField is only valid in 3D");
28
29 protected:
30 enum
31 {
33 };
34
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 class QuadraticHeightField : public T
82 {
83 PONCA_FITTING_DECLARE_DEFAULT_TYPES
84 using HeightFieldCoefficients = Eigen::Matrix<Scalar, 6, 1>;
85 static_assert(DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
86
87 protected:
88 enum
89 {
90 Check = Base::PROVIDES_HEIGHTFIELD,
92 };
94 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
95
96 public:
98 PONCA_MULTIARCH inline QuadraticHeightField() : Base() { init(); }
99
100 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField, quadraticHeightField)
101
102
103 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
104
105 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
106
108 PONCA_MULTIARCH inline void init()
109 {
110 Base::init();
111 m_coeffs.setZero();
112 }
113
117 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
118 {
119 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
120 }
121
122 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
124 {
125 return m_coeffs.isApprox(other.m_params);
126 }
127
129 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
131 {
132 return !((*this) == other);
133 }
134
136 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const
137 {
138 return h_uu() * u * u + h_vv() * v * v + h_uv() * u * v + h_u() * u + h_v() * v + h_c();
139 }
140
141 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uu() const { return *(m_coeffs.data()); }
142 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_vv() const { return *(m_coeffs.data() + 1); }
143 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_uv() const { return *(m_coeffs.data() + 2); }
144 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_u() const { return *(m_coeffs.data() + 3); }
145 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_v() const { return *(m_coeffs.data() + 4); }
146 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& h_c() const { return *(m_coeffs.data() + 5); }
147
149 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
150 {
151 return Scalar(2) * h_uu() * u + h_uv() * v + h_u();
152 }
153
155 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
156 {
157 return Scalar(2) * h_vv() * v + h_uv() * u + h_v();
158 }
159
161 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
162 {
163 return Scalar(2) * h_uu();
164 }
165
167 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
168 {
169 return Scalar(2) * h_vv();
170 }
171
174 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv(Scalar u = Scalar(0), Scalar v = Scalar(0)) const
175 {
176 return h_uv();
177 }
178
180 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal(const VectorType& _localQ) const
181 {
182 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
183 return VectorType(tu, Scalar(1), Scalar(0)).normalized();
184 }
185
187 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal(const VectorType& _localQ) const
188 {
189 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
190 return VectorType(tv, Scalar(0), Scalar(1)).normalized();
191 }
192 }; // class QuadraticHeightField
204 template <class DataPoint, class _NFilter, typename T>
206 {
207 PONCA_FITTING_DECLARE_DEFAULT_TYPES
208 using HeightFieldCoefficients = Eigen::Matrix<Scalar, 4, 1>;
209 static_assert(DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
210
211 protected:
212 enum
213 {
214 Check = Base::PROVIDES_HEIGHTFIELD,
216 };
218 HeightFieldCoefficients m_coeffs{HeightFieldCoefficients::Zero()};
219
220 public:
222 PONCA_MULTIARCH inline RestrictedQuadraticHeightField() : Base() { init(); }
223
225
226
227 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
228
229 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
230
232 PONCA_MULTIARCH inline void init()
233 {
234 Base::init();
235 m_coeffs.setZero();
236 }
237
241 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const
242 {
243 return !m_coeffs.isApprox(HeightFieldCoefficients::Zero());
244 }
245
246 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
248 {
249 return m_coeffs.isApprox(other.m_params);
250 }
251
253 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(
255 {
256 return !((*this) == other);
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:25
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:26
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:26
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
@ PROVIDES_HEIGHTFIELD
Provides generic heightfield API.
Definition heightField.h:32
Quadratic height field defined as .
Definition heightField.h:82
typename Base::VectorType VectorType
Alias to vector type.
Definition heightField.h:83
void setQuadric(const HeightFieldCoefficients &coeffs)
Set the scalar field values.
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition heightField.h:83
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:94
QuadraticHeightField()
Default constructor.
Definition heightField.h:98
Scalar dh_du(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
T Base
Base class of the procedure.
Definition heightField.h:83
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.
Scalar d2h_duu(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
@ PROVIDES_QUADRIC_HEIGHTFIELD
Provides quadric heightfield API.
Definition heightField.h:91
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.
@ PROVIDES_RESTRICTED_QUADRIC_HEIGHTFIELD
Provides quadric heightfield API.
RestrictedQuadraticHeightField()
Default constructor.
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.