Ponca  94e4a36411c3364f6192f97adfa8ceee67834d6e
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 protected:
29 enum {
31 };
32
34 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getHFromLocalCoordinates (const VectorType& _lq) const
35 { return *(_lq.data()); }
36
38 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getHFromLocalCoordinates (VectorType& _lq) const
39 { return *(_lq.data()); }
40
42 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getUFromLocalCoordinates (const VectorType& _lq) const
43 { return *(_lq.data()+1); }
44
46 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getUFromLocalCoordinates (VectorType& _lq) const
47 { return *(_lq.data()+1); }
48
50 PONCA_MULTIARCH [[nodiscard]] inline const Scalar& getVFromLocalCoordinates (const VectorType& _lq) const
51 { return *(_lq.data()+2); }
52
54 PONCA_MULTIARCH [[nodiscard]] inline Scalar& getVFromLocalCoordinates (VectorType& _lq)
55 { return *(_lq.data()+2); }
56 };
57
66 template < class DataPoint, class _NFilter, typename T >
67 class QuadraticHeightField : public T
68 {
69 PONCA_FITTING_DECLARE_DEFAULT_TYPES
70 using HeightFieldCoefficients = Eigen::Matrix<Scalar,6,1>;
71 static_assert ( DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
72
73 protected:
74 enum {
75 Check = Base::PROVIDES_HEIGHTFIELD,
77 };
79 HeightFieldCoefficients m_coeffs {HeightFieldCoefficients::Zero()};
80
81 public:
82
84 PONCA_MULTIARCH inline QuadraticHeightField() : Base() { init(); }
85
86 PONCA_EXPLICIT_CAST_OPERATORS(QuadraticHeightField,quadraticHeightField)
87
88
89 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
90
91 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
92
94 PONCA_MULTIARCH inline void init()
95 {
96 Base::init();
97 m_coeffs.setZero();
98 }
99
103 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const{
104 return ! m_coeffs.isApprox(HeightFieldCoefficients::Zero());
105 }
106
107 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(const QuadraticHeightField<DataPoint, _NFilter, T>& other) const{
108 return m_coeffs.isApprox(other.m_params);
109 }
110
112 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(const QuadraticHeightField<DataPoint, _NFilter, T>& other) const{
113 return ! ((*this) == other);
114 }
115
117 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const {
118 return h_uu()*u*u + h_vv()*v*v + h_uv()*u*v + h_u()*u + h_v()*v + h_c();
119 }
120
121 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_uu () const { return *(m_coeffs.data()); }
122 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_vv () const { return *(m_coeffs.data()+1); }
123 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_uv () const { return *(m_coeffs.data()+2); }
124 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_u () const { return *(m_coeffs.data()+3); }
125 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_v () const { return *(m_coeffs.data()+4); }
126 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_c () const { return *(m_coeffs.data()+5); }
127
129 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
130 { return Scalar(2)*h_uu() * u + h_uv()*v + h_u(); }
131
133 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
134 { return Scalar(2)*h_vv() * v + h_uv()*u + h_v(); }
135
137 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
138 { return Scalar(2)*h_uu(); }
139
141 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
142 { return Scalar(2)*h_vv(); }
143
145 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
146 { return h_uv(); }
147
149 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal (const VectorType& _localQ) const {
150 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
151 return VectorType (tu, Scalar(1), Scalar(0)).normalized();
152 }
153
155 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal (const VectorType& _localQ) const {
156 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
157 return VectorType (tv, Scalar(0), Scalar(1)).normalized();
158 }
159 }; //class QuadraticHeightField
171 template < class DataPoint, class _NFilter, typename T >
173 {
174 PONCA_FITTING_DECLARE_DEFAULT_TYPES
175 using HeightFieldCoefficients = Eigen::Matrix<Scalar,4,1>;
176 static_assert ( DataPoint::Dim == 3, "QuadraticHeightField is only valid in 3D");
177
178 protected:
179 enum {
180 Check = Base::PROVIDES_HEIGHTFIELD,
182 };
184 HeightFieldCoefficients m_coeffs {HeightFieldCoefficients::Zero()};
185
186 public:
187
189 PONCA_MULTIARCH inline RestrictedQuadraticHeightField() : Base() { init(); }
190
192
193
194 PONCA_MULTIARCH inline void setQuadric(const HeightFieldCoefficients& coeffs) { m_coeffs = coeffs; }
195
196 PONCA_MULTIARCH [[nodiscard]] inline const HeightFieldCoefficients& coeffs() const { return m_coeffs; }
197
199 PONCA_MULTIARCH inline void init()
200 {
201 Base::init();
202 m_coeffs.setZero();
203 }
204
208 PONCA_MULTIARCH [[nodiscard]] inline bool isValid() const{
209 return ! m_coeffs.isApprox(HeightFieldCoefficients::Zero());
210 }
211
212 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(const RestrictedQuadraticHeightField<DataPoint, _NFilter, T>& other) const{
213 return m_coeffs.isApprox(other.m_params);
214 }
215
217 PONCA_MULTIARCH [[nodiscard]] inline bool operator!=(const RestrictedQuadraticHeightField<DataPoint, _NFilter, T>& other) const{
218 return ! ((*this) == other);
219 }
220
222 PONCA_MULTIARCH [[nodiscard]] inline Scalar height(Scalar u, Scalar v) const {
223 return h_uu()*u*u + h_vv()*v*v + h_uv()*u*v + h_c();
224 }
225
226 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_uu () const { return *(m_coeffs.data()); }
227 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_vv () const { return *(m_coeffs.data()+1); }
228 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_uv () const { return *(m_coeffs.data()+2); }
229 PONCA_MULTIARCH [[nodiscard]] inline const Scalar & h_c () const { return *(m_coeffs.data()+3); }
230
232 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_du (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
233 { return Scalar(2)*h_uu() * u + h_uv()*v; }
234
236 PONCA_MULTIARCH [[nodiscard]] inline Scalar dh_dv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
237 { return Scalar(2)*h_vv() * v + h_uv()*u ; }
238
240 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duu (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
241 { return Scalar(2)*h_uu(); }
242
244 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_dvv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
245 { return Scalar(2)*h_vv(); }
246
248 PONCA_MULTIARCH [[nodiscard]] inline Scalar d2h_duv (Scalar u = Scalar(0), Scalar v = Scalar(0)) const
249 { return h_uv(); }
250
252 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentULocal (const VectorType& _localQ) const {
253 const Scalar tu = dh_du(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
254 return VectorType (tu, Scalar(1), Scalar(0)).normalized();
255 }
256
258 PONCA_MULTIARCH [[nodiscard]] inline VectorType heightTangentVLocal (const VectorType& _localQ) const {
259 const Scalar tv = dh_dv(Base::getUFromLocalCoordinates(_localQ), Base::getVFromLocalCoordinates(_localQ));
260 return VectorType (tv, Scalar(0), Scalar(1)).normalized();
261 }
262 }; //class RestrictedQuadraticHeightField
263
264} //namespace Ponca
265
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:54
const Scalar & getVFromLocalCoordinates(const VectorType &_lq) const
get access to v from local coordinate vector
Definition heightField.h:50
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:46
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:34
Scalar & getHFromLocalCoordinates(VectorType &_lq) const
get access to height from local coordinate vector
Definition heightField.h:38
const Scalar & getUFromLocalCoordinates(const VectorType &_lq) const
get access to u from local coordinate vector
Definition heightField.h:42
@ PROVIDES_HEIGHTFIELD
Provides generic heightfield API.
Definition heightField.h:30
Quadratic height field defined as .
Definition heightField.h:68
typename Base::VectorType VectorType
Alias to vector type.
Definition heightField.h:69
void setQuadric(const HeightFieldCoefficients &coeffs)
Set the scalar field values.
Definition heightField.h:89
Scalar d2h_duv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition heightField.h:69
void init()
Set the scalar field values to 0.
Definition heightField.h:94
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:79
QuadraticHeightField()
Default constructor.
Definition heightField.h:84
Scalar dh_du(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Partial derivative .
T Base
Base class of the procedure.
Definition heightField.h:69
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:86
VectorType heightTangentULocal(const VectorType &_localQ) const
Local tangent vector in the direction of .
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:76
VectorType heightTangentVLocal(const VectorType &_localQ) const
Local tangent vector in the direction of .
Quadratic height field defined as .
VectorType heightTangentULocal(const VectorType &_localQ) const
Local tangent vector in the direction of .
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.
VectorType heightTangentVLocal(const VectorType &_localQ) const
Local tangent vector in the direction of .
Scalar d2h_duv(Scalar u=Scalar(0), Scalar v=Scalar(0)) const
Second order partial derivative .
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.