Ponca  292d8d7132745e0d4242ff9a01e93697fc96b204
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#include "../../defines.h"
9#include "../concepts.h"
10
11#include "../extensions/heightField.h"
12#include "../extensions/weingarten.h"
13#include "../utils.h"
14
15#include PONCA_MULTIARCH_INCLUDE_STD(cmath)
17#include <Eigen/Dense>
18
19#define MONGE_PATCH_REQUIREMENTS ProvidesTangentPlaneBasis<T>&& ProvidesHeightField<T>&& Is3D<DataPoint>
20#define MONGE_PATCH_FIT_REQUIREMENTS ProvidesImplicitPrimitive<T>&& ProvidesMongePatch<T>
21
22namespace Ponca
23{
37
40 template <class DataPoint, class _NFilter, typename T>
41 requires MONGE_PATCH_REQUIREMENTS
42 class MongePatch : public T
43 {
44 PONCA_FITTING_DECLARE_DEFAULT_TYPES
46 PONCA_MULTIARCH inline MongePatch() : Base() { Base::init(); }
47
48 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MongePatch, mongePatchPrimitive)
49 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MongePatch, implicitPrimitive)
50 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MongePatch, firstFondamentalFormComponent)
51 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MongePatch, secondFondamentalFormComponent)
52
55 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential() const { return Base::height(Scalar(0), Scalar(0)); }
56
59 PONCA_MULTIARCH [[nodiscard]] inline Scalar potential(const VectorType& _q) const
60 {
61 const VectorType x = Base::worldToTangentPlane(_q);
62 return Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x)) -
63 Base::getHFromLocalCoordinates(x);
64 }
65
67
69 PONCA_MULTIARCH [[nodiscard]] inline VectorType project(const VectorType& _q) const
70 {
71 VectorType x = Base::worldToTangentPlane(_q);
72 Base::getHFromLocalCoordinates(x) =
73 Base::height(Base::getUFromLocalCoordinates(x), Base::getVFromLocalCoordinates(x));
74 return Base::tangentPlaneToWorld(x);
75 }
76
78 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient() const
79 {
80 return Base::tangentPlaneToWorld(primitiveGradientLocal(), false);
81 }
82
84 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradient(const VectorType& _q) const
85 {
86 return Base::tangentPlaneToWorld(primitiveGradientLocal(Base::worldToTangentPlane(_q)), false);
87 }
88
90 PONCA_MULTIARCH [[nodiscard]] inline VectorType primitiveGradientLocal(
91 const VectorType& _localQ = VectorType::Zero()) const
92 {
93 VectorType uVect = Base::heightTangentULocal(_localQ);
94 VectorType vVect = Base::heightTangentVLocal(_localQ);
95 VectorType cross = uVect.cross(vVect);
96 VectorType crossN = uVect.normalized().cross(vVect.normalized());
97 return Base::heightTangentULocal(_localQ).cross(Base::heightTangentVLocal(_localQ));
98 }
99
100 PONCA_MULTIARCH inline void firstFundamentalFormComponents(Scalar& E, Scalar& F, Scalar& G) const
101 {
102 PONCA_MULTIARCH_STD_MATH(sqrt);
103 const VectorType fu{Base::dh_du(), Scalar(1), Scalar(0)};
104 const VectorType fv{Base::dh_dv(), Scalar(0), Scalar(1)};
105 E = fu.dot(fu);
106 F = fu.dot(fv);
107 G = fv.dot(fv);
108 }
109
110 PONCA_MULTIARCH inline void secondFundamentalFormComponents(Scalar& L, Scalar& M, Scalar& N) const
111 {
112 PONCA_MULTIARCH_STD_MATH(sqrt);
113 const VectorType fuu{Base::d2h_duu(), Scalar(0), Scalar(0)};
114 const VectorType fuv{Base::d2h_duv(), Scalar(0), Scalar(0)};
115 const VectorType fvv{Base::d2h_dvv(), Scalar(0), Scalar(0)};
116 const VectorType fn = primitiveGradientLocal().normalized();
117
118 L = fuu.dot(fn);
119 M = fuv.dot(fn);
120 N = fvv.dot(fn);
121 }
122 }; // class MongePatchPrimitive
123
132 template <class DataPoint, class _NFilter, typename T>
133 requires MONGE_PATCH_FIT_REQUIREMENTS
134 class MongePatchQuadraticFitImpl : public MultipassStatus<DataPoint, _NFilter, T>
135 {
136 PONCA_FITTING_DECLARE_MULTIPASS_TYPES
137 private:
138 // we need to use dynamic matric to use ThinU, ThinV for solving
139 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
140 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
141
142 // protected:
143 public: // temporary DO NOT MERGE THIS
144 SampleMatrix m_A;
145 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
146 public:
147 PONCA_EXPLICIT_BASKET_CAST_OPERATORS(MongePatchQuadraticFitImpl, mongePatchQuadraticFit)
148 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
149
150 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
152 {
153 return Base::operator==(_other) && internal::isApprox(m_A, _other.m_A) &&
154 internal::isApprox(m_b, _other.m_b);
155 }
156 }; // MongePatchQuadraticFitImpl
157
165 template <class DataPoint, class _NFilter, typename T>
166 requires MONGE_PATCH_FIT_REQUIREMENTS
167 class MongePatchRestrictedQuadraticFitImpl : public MultipassStatus<DataPoint, _NFilter, T>
168 {
169 PONCA_FITTING_DECLARE_MULTIPASS_TYPES
170 private:
171 // we need to use dynamic matric to use ThinU, ThinV for solving
172 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
173 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
174
175 protected:
176 SampleMatrix m_A;
177 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
178 public:
180 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
181
182 PONCA_MULTIARCH [[nodiscard]] inline bool operator==(
184 {
185 return Base::operator==(_other) && internal::isApprox(m_A, _other.m_A) &&
186 internal::isApprox(m_b, _other.m_b);
187 }
188 }; // MongePatchRestrictedQuadraticFitImpl
189
190 template <class DataPoint, class _NFilter, typename T>
191 using MongePatchQuadraticFit = WeingartenCurvatureEstimator<
192 DataPoint, _NFilter,
193 FundamentalFormWeingartenEstimator<
194 DataPoint, _NFilter,
195 MongePatchQuadraticFitImpl<
196 DataPoint, _NFilter,
197 MongePatch<DataPoint, _NFilter,
198 QuadraticHeightField<
199 DataPoint, _NFilter,
200 HeightField<DataPoint, _NFilter, CovariancePlaneFit<DataPoint, _NFilter, T>>>>>>>;
201
202 template <class DataPoint, class _NFilter, typename T>
203 using MongePatchRestrictedQuadraticFit = WeingartenCurvatureEstimator<
204 DataPoint, _NFilter,
205 FundamentalFormWeingartenEstimator<
206 DataPoint, _NFilter,
207 MongePatchRestrictedQuadraticFitImpl<
208 DataPoint, _NFilter,
209 MongePatch<DataPoint, _NFilter,
210 RestrictedQuadraticHeightField<
211 DataPoint, _NFilter,
212 HeightField<DataPoint, _NFilter, CovariancePlaneFit<DataPoint, _NFilter, T>>>>>>>;
213
214#include "mongePatch.hpp"
215
216} // namespace Ponca
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:135
MongePatchQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:147
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:144
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:145
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:168
MongePatchRestrictedQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:179
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:177
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:176
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:169
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:169
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:44
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:44
VectorType primitiveGradient(const VectorType &_q) const
Scalar field gradient direction at .
Definition mongePatch.h:84
VectorType primitiveGradient() const
Scalar field gradient direction at the basis center.
Definition mongePatch.h:78
MongePatch< DataPoint, _NFilter, T > & mongePatchPrimitive()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:48
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:90
VectorType project(const VectorType &_q) const
Orthogonal projection on the patch.
Definition mongePatch.h:69
MongePatch()
Default constructor.
Definition mongePatch.h:46
MongePatch< DataPoint, _NFilter, T > & secondFondamentalFormComponent()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:51
MongePatch< DataPoint, _NFilter, T > & firstFondamentalFormComponent()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:50
Scalar potential() const
Value of the scalar field at the evaluation point.
Definition mongePatch.h:55
T Base
Base class of the procedure.
Definition mongePatch.h:44
MongePatch< DataPoint, _NFilter, T > & implicitPrimitive()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition mongePatch.h:49
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11