Ponca  bab7704293a2c36e5bed9dea40def7ba839bfe08
Point Cloud Analysis library
Loading...
Searching...
No Matches
mongePatch.h
1/*
2 This 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 "./curvature.h"
11#include "./weingarten.h"
12#include "./heightField.h"
13
14#include PONCA_MULTIARCH_INCLUDE_STD(cmath)
15
16#include <Eigen/Dense>
17
18namespace Ponca
19{
36 template <class DataPoint, class _NFilter, typename T>
37 class MongePatch : public T
38 {
39 PONCA_FITTING_DECLARE_DEFAULT_TYPES
40 static_assert(DataPoint::Dim == 3, "MongePatch is only valid in 3D");
41
42 protected:
43 enum
44 {
45 Check = Base::PROVIDES_PLANE && Base::PROVIDES_TANGENT_PLANE_BASIS &&
46 Base::PROVIDES_HEIGHTFIELD,
50 };
51
52 public:
54 PONCA_MULTIARCH inline MongePatch() : Base() { Base::init(); }
55
56 PONCA_EXPLICIT_CAST_OPERATORS(MongePatch, mongePatchPrimitive)
57
58
60 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const { return Base::height(Scalar(0), Scalar(0)); }
61
64 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
65 {
66 const VectorType x = Base::worldToTangentPlane(_q);
67 return Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x)) -
68 Base::getHFromLocalCoordinates(x);
69 }
70
74 PONCA_MULTIARCH [[nodiscard]] inline VectorType project(const VectorType& _q) const
75 {
76 VectorType x = Base::worldToTangentPlane(_q);
77 Base::getHFromLocalCoordinates(x) =
78 Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x));
79 return Base::tangentPlaneToWorld(x);
80 }
81
83 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const
84 {
85 return Base::tangentPlaneToWorld(primitiveGradientLocal(), false);
86 }
87
89 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& _q) const
90 {
91 return Base::tangentPlaneToWorld(primitiveGradientLocal(Base::worldToTangentPlane(_q)), false);
92 }
93
95 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(
96 const VectorType& _localQ = VectorType::Zero()) const
97 {
98 VectorType uVect = Base::heightTangentULocal(_localQ);
99 VectorType vVect = Base::heightTangentVLocal(_localQ);
100 VectorType cross = uVect.cross(vVect);
101 VectorType crossN = uVect.normalized().cross(vVect.normalized());
102 return Base::heightTangentULocal(_localQ).cross(Base::heightTangentVLocal(_localQ));
103 }
104
105 PONCA_MULTIARCH inline void firstFundamentalFormComponents(Scalar& E, Scalar& F, Scalar& G) const
106 {
107 PONCA_MULTIARCH_STD_MATH(sqrt);
108 const VectorType fu{Base::dh_du(), Scalar(1), Scalar(0)};
109 const VectorType fv{Base::dh_dv(), Scalar(0), Scalar(1)};
110 E = fu.dot(fu);
111 F = fu.dot(fv);
112 G = fv.dot(fv);
113 }
114
115 PONCA_MULTIARCH inline void secondFundamentalFormComponents(Scalar& L, Scalar& M, Scalar& N) const
116 {
117 PONCA_MULTIARCH_STD_MATH(sqrt);
118 const VectorType fuu{Base::d2h_duu(), Scalar(0), Scalar(0)};
119 const VectorType fuv{Base::d2h_duv(), Scalar(0), Scalar(0)};
120 const VectorType fvv{Base::d2h_dvv(), Scalar(0), Scalar(0)};
121 const VectorType fn = primitiveGradientLocal();
122
123 L = fuu.dot(fn);
124 M = fuv.dot(fn);
125 ;
126 N = fvv.dot(fn);
127 ;
128 }
129 }; // class MongePatchPrimitive
130
139 template <class DataPoint, class _NFilter, typename T>
141 {
142 PONCA_FITTING_DECLARE_DEFAULT_TYPES
143
144 protected:
145 enum
146 {
147 Check = Base::PROVIDES_QUADRIC_HEIGHTFIELD && Base::PROVIDES_MONGE_PATCH
148 };
149
150 public:
151 // we need to use dynamic matric to use ThinU, ThinV for solving
152 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
153 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
154
155 // protected:
156 public: // temporary DO NOT MERGE THIS
157 SampleMatrix m_A;
158 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
160 bool m_planeIsReady{false};
161
162 public:
164 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
165 }; // MongePatchQuadraticFitImpl
174 template <class DataPoint, class _NFilter, typename T>
176 {
177 PONCA_FITTING_DECLARE_DEFAULT_TYPES
178
179 protected:
180 enum
181 {
182 Check = Base::PROVIDES_RESTRICTED_QUADRIC_HEIGHTFIELD && Base::PROVIDES_MONGE_PATCH
183 };
184
185 public:
186 // we need to use dynamic matric to use ThinU, ThinV for solving
187 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
188 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
189
190 protected:
191 SampleMatrix m_A;
192 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
194 bool m_planeIsReady{false};
195
196 public:
198 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
199 }; // MongePatchRestrictedQuadraticFitImpl
200
201 template <class DataPoint, class _NFilter, typename T>
203 DataPoint, _NFilter,
205 DataPoint, _NFilter,
207 DataPoint, _NFilter,
209 DataPoint, _NFilter,
210 MongePatch<DataPoint, _NFilter,
212 DataPoint, _NFilter,
214
215 template <class DataPoint, class _NFilter, typename T>
217 DataPoint, _NFilter,
219 DataPoint, _NFilter,
221 DataPoint, _NFilter,
223 DataPoint, _NFilter,
224 MongePatch<DataPoint, _NFilter,
226 DataPoint, _NFilter,
228
229#include "mongePatch.hpp"
230
231} // namespace Ponca
Make CurvatureEstimatorBase available to standard Basket object.
Definition curvature.h:90
Compute a Weingarten map from fundamental forms.
Definition weingarten.h:34
Internal base classe for height fields.
Definition heightField.h:25
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:141
MongePatchQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchQuadraticFitImpl , to access methods potentially hidden by heritage.
Definition mongePatch.h:163
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:157
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:158
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:176
MongePatchRestrictedQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchRestrictedQuadraticFitImpl , to access methods potentially hidden by...
Definition mongePatch.h:197
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:192
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:191
Monge Patch primitive, defined as , with defined by a Base class.
Definition mongePatch.h:38
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:39
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:39
Scalar potential(const VectorType &_q) const
Value of the scalar field at a given point.
Definition mongePatch.h:64
@ Check
Requires a heightfield function.
Definition mongePatch.h:45
@ PROVIDES_MONGE_PATCH
Provides MongePatch API.
Definition mongePatch.h:47
@ PROVIDES_SECOND_FUNDAMENTAL_FORM_COMPONENTS
Provides second fundamental form.
Definition mongePatch.h:49
@ PROVIDES_FIRST_FUNDAMENTAL_FORM_COMPONENTS
Provides first fundamental form.
Definition mongePatch.h:48
VectorType primitiveGradient(const VectorType &_q) const
Scalar field gradient direction at .
Definition mongePatch.h:89
VectorType primitiveGradient() const
Scalar field gradient direction at the basis center.
Definition mongePatch.h:83
MongePatch< DataPoint, _NFilter, T > & mongePatchPrimitive()
Explicit conversion to MongePatch , to access methods potentially hidden by heritage.
Definition mongePatch.h:56
VectorType primitiveGradientLocal(const VectorType &_localQ=VectorType::Zero()) const
Scalar field gradient direction, both input and output vectors are expressed in the local basis.
Definition mongePatch.h:95
VectorType project(const VectorType &_q) const
Orthogonal projection on the patch.
Definition mongePatch.h:74
MongePatch()
Default constructor.
Definition mongePatch.h:54
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition mongePatch.h:60
T Base
Base class of the procedure.
Definition mongePatch.h:39
Quadratic height field defined as .
Definition heightField.h:82
Quadratic height field defined as .
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Compute principal curvatures from a base class providing fundamental forms.
Definition weingarten.h:194