Ponca  4a9354998d048bf882a3ee9bac8105216fa08d13
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)
16
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{
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_CAST_OPERATORS(MongePatch, mongePatchPrimitive)
49 PONCA_EXPLICIT_CAST_OPERATORS(MongePatch, implicitPrimitive)
50 PONCA_EXPLICIT_CAST_OPERATORS(MongePatch, firstFondamentalFormComponent)
51 PONCA_EXPLICIT_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
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();
117
118 L = fuu.dot(fn);
119 M = fuv.dot(fn);
120 ;
121 N = fvv.dot(fn);
122 ;
123 }
124 }; // class MongePatchPrimitive
125
134 template <class DataPoint, class _NFilter, typename T>
135 requires MONGE_PATCH_FIT_REQUIREMENTS
136 class MongePatchQuadraticFitImpl : public MultipassStatus<DataPoint, _NFilter, T>
137 {
138 PONCA_FITTING_DECLARE_MULTIPASS_TYPES
139 private:
140 // we need to use dynamic matric to use ThinU, ThinV for solving
141 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
142 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
143
144 // protected:
145 public: // temporary DO NOT MERGE THIS
146 SampleMatrix m_A;
147 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
148 public:
150 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
151 }; // MongePatchQuadraticFitImpl
160 template <class DataPoint, class _NFilter, typename T>
161 requires MONGE_PATCH_FIT_REQUIREMENTS
162 class MongePatchRestrictedQuadraticFitImpl : public MultipassStatus<DataPoint, _NFilter, T>
163 {
164 PONCA_FITTING_DECLARE_MULTIPASS_TYPES
165 private:
166 // we need to use dynamic matric to use ThinU, ThinV for solving
167 using SampleMatrix = Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic>;
168 using QuadraticHeightFieldCoefficients = typename Base::HeightFieldCoefficients;
169
170 protected:
171 SampleMatrix m_A;
172 QuadraticHeightFieldCoefficients m_b{QuadraticHeightFieldCoefficients::Zero()};
173 public:
175 PONCA_FITTING_DECLARE_INIT_ADD_FINALIZE
176 }; // MongePatchRestrictedQuadraticFitImpl
177
178 template <class DataPoint, class _NFilter, typename T>
180 DataPoint, _NFilter,
182 DataPoint, _NFilter,
184 DataPoint, _NFilter,
185 MongePatch<DataPoint, _NFilter,
187 DataPoint, _NFilter,
189
190 template <class DataPoint, class _NFilter, typename T>
192 DataPoint, _NFilter,
194 DataPoint, _NFilter,
196 DataPoint, _NFilter,
197 MongePatch<DataPoint, _NFilter,
199 DataPoint, _NFilter,
201
202#include "mongePatch.hpp"
203
204} // namespace Ponca
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
Compute a Weingarten map from fundamental forms.
Definition weingarten.h:40
Extension to compute the best fit quadric on 3d points expressed as .
Definition mongePatch.h:137
MongePatchQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchQuadraticFitImpl , to access methods potentially hidden by heritage.
Definition mongePatch.h:149
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:146
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:147
Extension to compute the best fit restricted quadric on 3d points expressed as .
Definition mongePatch.h:163
MongePatchRestrictedQuadraticFitImpl< DataPoint, _NFilter, T > & mongePatchQuadraticFit()
Explicit conversion to MongePatchRestrictedQuadraticFitImpl , to access methods potentially hidden by...
Definition mongePatch.h:174
QuadraticHeightFieldCoefficients m_b
Observations.
Definition mongePatch.h:172
SampleMatrix m_A
Quadric input samples.
Definition mongePatch.h:171
Monge Patch primitive, defined as , with defined by a Base class.
Definition mongePatch.h:43
typename Base::VectorType VectorType
Alias to vector type.
Definition mongePatch.h:44
typename DataPoint::Scalar Scalar
Alias to scalar type.
Definition mongePatch.h:44
Scalar potential(const VectorType &_q) const
Value of the scalar field at a given point.
Definition mongePatch.h:59
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 MongePatch , 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 MongePatch , to access methods potentially hidden by heritage.
Definition mongePatch.h:51
MongePatch< DataPoint, _NFilter, T > & firstFondamentalFormComponent()
Explicit conversion to MongePatch , 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 MongePatch , to access methods potentially hidden by heritage.
Definition mongePatch.h:49
Helper class to check for status of required extensions.
Definition utils.h:29
Quadratic height field defined as .
Definition heightField.h:83
Quadratic height field defined as .
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
Compute principal curvatures from a base class providing fundamental forms.
Definition weingarten.h:215