Ponca  73247abfe24d29406a95aee1d4dfa2d34da85d4c
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#include <Eigen/SVD>
18#include <Eigen/Geometry>
19
20namespace Ponca
21{
38 template <class DataPoint, class _NFilter, typename T>
39 class MongePatch : public T
40 {
41 PONCA_FITTING_DECLARE_DEFAULT_TYPES
42 static_assert(DataPoint::Dim == 3, "MongePatch is only valid in 3D");
43
44 protected:
45 enum
46 {
47 Check = Base::PROVIDES_PLANE && Base::PROVIDES_TANGENT_PLANE_BASIS &&
48 Base::PROVIDES_HEIGHTFIELD,
52 };
53
54 public:
56 PONCA_MULTIARCH inline MongePatch() : Base() { Base::init(); }
57
58 PONCA_EXPLICIT_CAST_OPERATORS(MongePatch, mongePatchPrimitive)
59
60
62 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const { return Base::height(Scalar(0), Scalar(0)); }
63
66 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
67 {
68 const VectorType x = Base::worldToTangentPlane(_q);
69 return Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x)) -
70 Base::getHFromLocalCoordinates(x);
71 }
72
76 PONCA_MULTIARCH [[nodiscard]] inline VectorType project(const VectorType& _q) const
77 {
78 VectorType x = Base::worldToTangentPlane(_q);
79 Base::getHFromLocalCoordinates(x) =
80 Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x));
81 return Base::tangentPlaneToWorld(x);
82 }
83
85 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const
86 {
87 return Base::tangentPlaneToWorld(primitiveGradientLocal(), false);
88 }
89
91 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& _q) const
92 {
93 return Base::tangentPlaneToWorld(primitiveGradientLocal(Base::worldToTangentPlane(_q)), false);
94 }
95
97 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(
98 const VectorType& _localQ = VectorType::Zero()) const
99 {
100 VectorType uVect = Base::heightTangentULocal(_localQ);
101 VectorType vVect = Base::heightTangentVLocal(_localQ);
102 VectorType cross = uVect.cross(vVect);
103 VectorType crossN = uVect.normalized().cross(vVect.normalized());
104 return Base::heightTangentULocal(_localQ).cross(Base::heightTangentVLocal(_localQ));
105 }
106
107 PONCA_MULTIARCH inline void firstFundamentalFormComponents(Scalar& E, Scalar& F, Scalar& G) const
108 {
109 PONCA_MULTIARCH_STD_MATH(sqrt);
110 const VectorType fu{Base::dh_du(), Scalar(1), Scalar(0)};
111 const VectorType fv{Base::dh_dv(), Scalar(0), Scalar(1)};
112 E = fu.dot(fu);
113 F = fu.dot(fv);
114 G = fv.dot(fv);
115 }
116
117 PONCA_MULTIARCH inline void secondFundamentalFormComponents(Scalar& L, Scalar& M, Scalar& N) const
118 {
119 PONCA_MULTIARCH_STD_MATH(sqrt);
120 const VectorType fuu{Base::d2h_duu(), Scalar(0), Scalar(0)};
121 const VectorType fuv{Base::d2h_duv(), Scalar(0), Scalar(0)};
122 const VectorType fvv{Base::d2h_dvv(), Scalar(0), Scalar(0)};
123 const VectorType fn = primitiveGradientLocal();
124
125 L = fuu.dot(fn);
126 M = fuv.dot(fn);
127 ;
128 N = fvv.dot(fn);
129 ;
130 }
131 }; // class MongePatchPrimitive
132
141 template <class DataPoint, class _NFilter, typename T>
143 {
144 PONCA_FITTING_DECLARE_DEFAULT_TYPES
145
146 protected:
147 enum
148 {
149 Check = Base::PROVIDES_QUADRIC_HEIGHTFIELD && Base::PROVIDES_MONGE_PATCH
150 };
151
152 public:
153 // we need to use dynamic matric to use ThinU, ThinV for solving
154 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
155 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
156
157 // protected:
158 public: // temporary DO NOT MERGE THIS
159 SampleMatrix m_A;
160 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
162 bool m_planeIsReady{false};
163
164 public:
166 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
167 }; // MongePatchQuadraticFitImpl
176 template <class DataPoint, class _NFilter, typename T>
178 {
179 PONCA_FITTING_DECLARE_DEFAULT_TYPES
180
181 protected:
182 enum
183 {
184 Check = Base::PROVIDES_RESTRICTED_QUADRIC_HEIGHTFIELD && Base::PROVIDES_MONGE_PATCH
185 };
186
187 public:
188 // we need to use dynamic matric to use ThinU, ThinV for solving
189 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
190 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
191
192 protected:
193 SampleMatrix m_A;
194 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
196 bool m_planeIsReady{false};
197
198 public:
200 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
201 }; // MongePatchRestrictedQuadraticFitImpl
202
203 template <class DataPoint, class _NFilter, typename T>
205 DataPoint, _NFilter,
207 DataPoint, _NFilter,
209 DataPoint, _NFilter,
211 DataPoint, _NFilter,
212 MongePatch<DataPoint, _NFilter,
214 DataPoint, _NFilter,
216
217 template <class DataPoint, class _NFilter, typename T>
219 DataPoint, _NFilter,
221 DataPoint, _NFilter,
223 DataPoint, _NFilter,
225 DataPoint, _NFilter,
226 MongePatch<DataPoint, _NFilter,
228 DataPoint, _NFilter,
230
231#include "mongePatch.hpp"
232
233} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
Make CurvatureEstimatorBase available to standard Basket object.
Definition curvature.h:90
Compute a Weingarten map from fundamental forms.
Definition weingarten.h:34
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:143
MongePatchQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchQuadraticFitImpl , to access methods potentially hidden by heritage.
Definition mongePatch.h:165
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:159
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:160
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:178
MongePatchRestrictedQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchRestrictedQuadraticFitImpl , to access methods potentially hidden by...
Definition mongePatch.h:199
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:194
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:193
Monge Patch primitive, defined as , with defined by a Base class.
Definition mongePatch.h:40
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:41
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:41
Scalar potential(const VectorType &_q) const
Value of the scalar field at a given point.
Definition mongePatch.h:66
@ Check
Requires a heightfield function.
Definition mongePatch.h:47
@ PROVIDES_MONGE_PATCH
Provides MongePatch API.
Definition mongePatch.h:49
@ PROVIDES_SECOND_FUNDAMENTAL_FORM_COMPONENTS
Provides second fundamental form.
Definition mongePatch.h:51
@ PROVIDES_FIRST_FUNDAMENTAL_FORM_COMPONENTS
Provides first fundamental form.
Definition mongePatch.h:50
VectorType primitiveGradient(const VectorType &_q) const
Scalar field gradient direction at .
Definition mongePatch.h:91
VectorType primitiveGradient() const
Scalar field gradient direction at the basis center.
Definition mongePatch.h:85
MongePatch< DataPoint, _NFilter, T > & mongePatchPrimitive()
Explicit conversion to MongePatch , to access methods potentially hidden by heritage.
Definition mongePatch.h:58
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:97
VectorType project(const VectorType &_q) const
Orthogonal projection on the patch.
Definition mongePatch.h:76
MongePatch()
Default constructor.
Definition mongePatch.h:56
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition mongePatch.h:62
T Base
Base class of the procedure.
Definition mongePatch.h:41
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