Ponca  94e4a36411c3364f6192f97adfa8ceee67834d6e
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{
35 template < class DataPoint, class _NFilter, typename T >
36 class MongePatch : public T
37 {
38 PONCA_FITTING_DECLARE_DEFAULT_TYPES
39 static_assert ( DataPoint::Dim == 3, "MongePatch is only valid in 3D");
40
41 protected:
42 enum {
43 Check = Base::PROVIDES_PLANE &&
44 Base::PROVIDES_TANGENT_PLANE_BASIS &&
45 Base::PROVIDES_HEIGHTFIELD,
49 };
50
51 public:
52
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
61 {
62 return Base::height(Scalar(0),Scalar(0));
63 }
64
67 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const {
68 const VectorType x = Base::worldToTangentPlane(_q);
69 return Base::height(Base::getUFromLocalCoordinates(x),Base::getVFromLocalCoordinates(x)) - Base::getHFromLocalCoordinates(x);
70 }
71
75 PONCA_MULTIARCH [[nodiscard]] inline VectorType project (const VectorType& _q) const
76 {
77 VectorType x = Base::worldToTangentPlane(_q);
78 Base::getHFromLocalCoordinates(x) = 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());
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 (const VectorType& _localQ = VectorType::Zero()) const
96 {
97 VectorType uVect = Base::heightTangentULocal(_localQ);
98 VectorType vVect = Base::heightTangentVLocal(_localQ);
99 VectorType cross = uVect.cross(vVect);
100 VectorType crossN = uVect.normalized().cross(vVect.normalized());
101 return Base::heightTangentULocal(_localQ).cross(Base::heightTangentVLocal(_localQ));
102 }
103
104 PONCA_MULTIARCH inline void firstFundamentalFormComponents (Scalar &E, Scalar &F, Scalar &G) const
105 {
106 PONCA_MULTIARCH_STD_MATH(sqrt);
107 const VectorType fu {Base::dh_du(), Scalar(1), Scalar(0)};
108 const VectorType fv {Base::dh_dv(), Scalar(0), Scalar(1)};
109 E = fu.dot(fu);
110 F = fu.dot(fv);
111 G = fv.dot(fv);
112 }
113
114 PONCA_MULTIARCH inline void secondFundamentalFormComponents (Scalar &L, Scalar &M, Scalar &N) const
115 {
116 PONCA_MULTIARCH_STD_MATH(sqrt);
117 const VectorType fuu {Base::d2h_duu(), Scalar(0), Scalar(0)};
118 const VectorType fuv {Base::d2h_duv(), Scalar(0), Scalar(0)};
119 const VectorType fvv {Base::d2h_dvv(), Scalar(0), Scalar(0)};
121
122 L = fuu.dot(fn);
123 M = fuv.dot(fn);;
124 N = fvv.dot(fn);;
125 }
126 }; //class MongePatchPrimitive
127
136 template < class DataPoint, class _NFilter, typename T>
138 {
139 PONCA_FITTING_DECLARE_DEFAULT_TYPES
140
141 protected:
142 enum {
143 Check = Base::PROVIDES_QUADRIC_HEIGHTFIELD &&
144 Base::PROVIDES_MONGE_PATCH
145 };
146
147 public:
148 // we need to use dynamic matric to use ThinU, ThinV for solving
149 using SampleMatrix = Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic>;
150 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
151
152//protected:
153 public: //temporary DO NOT MERGE THIS
154 SampleMatrix m_A;
155 QuadraticHeightFieldCoefficients m_b {QuadraticHeightFieldCoefficients::Zero()};
157 bool m_planeIsReady {false};
158 public:
160 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
161 }; // MongePatchQuadraticFitImpl
170 template < class DataPoint, class _NFilter, typename T>
172 {
173 PONCA_FITTING_DECLARE_DEFAULT_TYPES
174
175 protected:
176 enum {
177 Check = Base::PROVIDES_RESTRICTED_QUADRIC_HEIGHTFIELD &&
178 Base::PROVIDES_MONGE_PATCH
179 };
180
181 public:
182 // we need to use dynamic matric to use ThinU, ThinV for solving
183 using SampleMatrix = Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic>;
184 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
185
186protected:
187 SampleMatrix m_A;
188 QuadraticHeightFieldCoefficients m_b {QuadraticHeightFieldCoefficients::Zero()};
190 bool m_planeIsReady {false};
191 public:
193 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
194 }; // MongePatchRestrictedQuadraticFitImpl
195
196template < class DataPoint, class _NFilter, typename T>
198 WeingartenCurvatureEstimator<DataPoint, _NFilter,
199 CurvatureEstimator<DataPoint, _NFilter,
200 FundamentalFormWeingartenEstimator<DataPoint, _NFilter,
201 MongePatchQuadraticFitImpl<DataPoint, _NFilter,
202 MongePatch<DataPoint, _NFilter,
203 QuadraticHeightField<DataPoint, _NFilter,
204 HeightField<DataPoint, _NFilter,
206
207template < class DataPoint, class _NFilter, typename T>
209 WeingartenCurvatureEstimator<DataPoint, _NFilter,
210 CurvatureEstimator<DataPoint, _NFilter,
211 FundamentalFormWeingartenEstimator<DataPoint, _NFilter,
212 MongePatchRestrictedQuadraticFitImpl<DataPoint, _NFilter,
213 MongePatch<DataPoint, _NFilter,
214 RestrictedQuadraticHeightField<DataPoint, _NFilter,
215 HeightField<DataPoint, _NFilter,
217
218#include "mongePatch.hpp"
219
220} //namespace Ponca
Plane fitting procedure using only points position.
Make CurvatureEstimatorBase available to standard Basket object.
Definition curvature.h:88
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:138
MongePatchQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchQuadraticFitImpl , to access methods potentially hidden by heritage.
Definition mongePatch.h:159
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:154
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:155
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:172
MongePatchRestrictedQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchRestrictedQuadraticFitImpl , to access methods potentially hidden by...
Definition mongePatch.h:192
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:188
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:187
Monge Patch primitive, defined as , with defined by a Base class.
Definition mongePatch.h:37
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:38
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:38
Scalar potential(const VectorType &_q) const
Value of the scalar field at a given point.
Definition mongePatch.h:67
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:75
MongePatch()
Default constructor.
Definition mongePatch.h:54
@ Check
Requires a heightfield function.
Definition mongePatch.h:43
@ PROVIDES_MONGE_PATCH
Provides MongePatch API.
Definition mongePatch.h:46
@ PROVIDES_SECOND_FUNDAMENTAL_FORM_COMPONENTS
Provides second fundamental form.
Definition mongePatch.h:48
@ PROVIDES_FIRST_FUNDAMENTAL_FORM_COMPONENTS
Provides first fundamental form.
Definition mongePatch.h:47
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:38
Quadratic height field defined as .
Definition heightField.h:68
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:191