Ponca  7d8ac87a7de01d881c9fde3c42e397b44bffb901
Point Cloud Analysis library
Loading...
Searching...
No Matches
cnc.h
1
10#pragma once
11
12#include "defines.h"
13#include "cncFormulaEigen.h"
14#include "weightFunc.h"
15#include "weightKernel.h"
16
17namespace Ponca
18{
19
20 namespace internal
21 {
29 template <class DataPoint>
30 struct Triangle
31 {
32 public:
33 using Scalar = typename DataPoint::Scalar;
34 using VectorType = typename DataPoint::VectorType;
35 using MatrixType = typename DataPoint::MatrixType;
36
37 protected:
38 std::array<VectorType, 3> m_points;
39 std::array<VectorType, 3> m_normals;
40
41 public:
42 Triangle(DataPoint pointA, DataPoint pointB, DataPoint pointC)
43 {
44 m_points = {pointA.pos(), pointB.pos(), pointC.pos()};
45 m_normals = {pointA.normal(), pointB.normal(), pointC.normal()};
46 }
47
48 Triangle(const std::array<VectorType, 3>& points, const std::array<VectorType, 3>& normals)
49 {
50 m_points = points;
51 m_normals = normals;
52 }
53
59 PONCA_MULTIARCH [[nodiscard]] VectorType& getPos(const int index) { return m_points[index]; }
60
61 PONCA_MULTIARCH [[nodiscard]] bool operator==(const Triangle& other) const
62 {
63 return (m_points[0] == other.m_points[0]) && (m_points[1] == other.m_points[1]) &&
64 (m_points[2] == other.m_points[2]);
65 }
66
67 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const Triangle& other) const { return !((*this) == other); }
68
69#define DEFINE_CNC_FUNC(CNC_FUNC, RETURN_TYPE) \
70 template <bool differentOrder = false> \
71 inline RETURN_TYPE CNC_FUNC() \
72 { \
73 return CNCEigen<DataPoint>::CNC_FUNC(m_points[0], m_points[2 - differentOrder], m_points[1 + differentOrder], \
74 m_normals[0], m_normals[2 - differentOrder], \
75 m_normals[1 + differentOrder]); \
76 }
77
78 DEFINE_CNC_FUNC(mu0InterpolatedU, Scalar)
79 DEFINE_CNC_FUNC(mu1InterpolatedU, Scalar)
80 DEFINE_CNC_FUNC(mu2InterpolatedU, Scalar)
81 DEFINE_CNC_FUNC(muXYInterpolatedU, MatrixType)
82 };
83 } // namespace internal
84
89 {
90 UniformGeneration,
91 HexagramGeneration,
92 IndependentGeneration,
93 AvgHexagramGeneration
94 };
95
105 template <class P, TriangleGenerationMethod _method = UniformGeneration>
106 class CNC : ComputeObject<CNC<P, _method>>
107 {
108 protected:
109 enum
110 {
111 PROVIDES_PRINCIPAL_CURVATURES
112 };
113
114 public:
115 using DataPoint = P;
116 using MatrixType = typename DataPoint::MatrixType;
117 using Scalar = typename DataPoint::Scalar;
118 using VectorType = typename DataPoint::VectorType;
119 using DenseVector = Eigen::VectorXd;
120 using DenseMatrix = Eigen::MatrixXd;
122
123 protected:
124 // Basis
125 NeighborFilter m_nFilter;
126
127 // Triangles used for the computation
128 int m_nb_vt{0}; // Number of valid triangles
129 std::vector<internal::Triangle<DataPoint>> m_triangles;
130
131 // Results of the fit
132 Scalar m_A{0}; // Area
133 Scalar m_H{0}; // Mean Curvatures
134 Scalar m_G{0}; // Gaussian Curvatures
135 Scalar m_T11{0}; // T11
136 Scalar m_T12{0}; // T12
137 Scalar m_T13{0}; // T13
138 Scalar m_T22{0}; // T22
139 Scalar m_T23{0}; // T23
140 Scalar m_T33{0}; // T33
141
142 Scalar m_k1{0};
143 Scalar m_k2{0};
144
145 VectorType m_v1;
146 VectorType m_v2;
147
152
153 public:
154 PONCA_FITTING_DECLARE_FINALIZE
155
157 PONCA_MULTIARCH inline void init()
158 {
160 m_A = Scalar(0);
161 m_H = Scalar(0);
162 m_G = Scalar(0);
163
164 m_k1 = Scalar(0);
165 m_k2 = Scalar(0);
166
167 m_triangles.clear();
168 }
169
174 template <typename PointContainer>
175 PONCA_MULTIARCH inline FIT_RESULT compute(const PointContainer& points);
176
182 template <typename IndexRange, typename PointContainer>
183 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(const IndexRange& ids, const PointContainer& points);
184
190 PONCA_MULTIARCH [[nodiscard]] inline size_t getNumTriangles() const { return static_cast<size_t>(m_nb_vt); }
191
192 PONCA_FITTING_APIDOC_SETWFUNC
193 PONCA_MULTIARCH inline void setNeighborFilter(const NeighborFilter& _nFilter) { m_nFilter = _nFilter; }
194
200 PONCA_MULTIARCH [[nodiscard]] std::vector<internal::Triangle<DataPoint>>& getTriangles() { return m_triangles; }
201
203 PONCA_MULTIARCH [[nodiscard]] bool operator==(const CNC& other) const
204 {
205 // We use the matrix to compare the fitting results
206 return (m_eCurrentState == other.m_eCurrentState) && (kMean() == other.kMean()) &&
207 (kmin() == other.kmin()) && (kmax() == other.kmax()) && (kminDirection() == other.kminDirection()) &&
208 (kmaxDirection() == other.kmaxDirection()) && (GaussianCurvature() == other.GaussianCurvature()) &&
209 (m_T11 == other.m_T11) && (m_T12 == other.m_T12) && (m_T13 == other.m_T13) &&
210 (m_T22 == other.m_T22) && (m_T23 == other.m_T23) && (m_T33 == other.m_T33);
211 }
212
214 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const CNC& other) const
215 {
216 // We use the matrix to compare the fitting results
217 return !(this == &other);
218 }
219
221 PONCA_MULTIARCH [[nodiscard]] bool isApprox(
222 const CNC& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const
223 {
224 PONCA_MULTIARCH_STD_MATH(abs);
225
226 return (m_eCurrentState == other.m_eCurrentState) && (std::abs(kMean() - other.kMean()) < epsilon) &&
227 (std::abs(GaussianCurvature() - other.GaussianCurvature()) < epsilon) &&
228 (std::abs(kmin() - other.kmin()) < epsilon) && (std::abs(kmax() - other.kmax()) < epsilon);
229 }
230
232 PONCA_MULTIARCH [[nodiscard]] inline bool isStable() const { return m_eCurrentState == STABLE; }
233
235 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmin() const { return m_k1; }
236
238 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmax() const { return m_k2; }
239
241 PONCA_MULTIARCH [[nodiscard]] inline VectorType kminDirection() const { return m_v1; }
242
244 PONCA_MULTIARCH [[nodiscard]] inline VectorType kmaxDirection() const { return m_v2; }
245
247 PONCA_MULTIARCH [[nodiscard]] inline Scalar kMean() const { return m_H; }
248
250 PONCA_MULTIARCH [[nodiscard]] inline Scalar GaussianCurvature() const { return m_G; }
251 }; // class CNC
252
253} // namespace Ponca
254
255#include "cnc.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:318
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition basket.h:326
Corrected Normal Current Fit type.
Definition cnc.h:107
void setNeighborFilter(const NeighborFilter &_nFilter)
Init the WeightFunc, without changing the other internal states.
Definition cnc.h:193
void init()
Set the scalar field values to 0 and reset the isNormalized() status.
Definition cnc.h:157
size_t getNumTriangles() const
Get the number of triangles that were generated with the compute method.
Definition cnc.h:190
bool operator==(const CNC &other) const
Comparison operator.
Definition cnc.h:203
bool isApprox(const CNC &other, const Scalar &epsilon=Eigen::NumTraits< Scalar >::dummy_precision()) const
Approximate operator.
Definition cnc.h:221
Scalar GaussianCurvature() const
Returns an estimate of the Gaussian curvature.
Definition cnc.h:250
VectorType kmaxDirection() const
Returns an estimate of the maximal principal curvature direction.
Definition cnc.h:244
FIT_RESULT m_eCurrentState
Represent the current state of the fit (finalize function update the state)
Definition cnc.h:151
Scalar kmax() const
Returns an estimate of the maximal principal curvature value.
Definition cnc.h:238
bool operator!=(const CNC &other) const
Comparison operator, convenience function.
Definition cnc.h:214
bool isStable() const
Is the fitted primitive ready to use (finalize has been called and the result is stable)
Definition cnc.h:232
Scalar kMean() const
Returns an estimate of the mean curvature.
Definition cnc.h:247
std::vector< internal::Triangle< DataPoint > > & getTriangles()
Returns the triangles.
Definition cnc.h:200
FIT_RESULT compute(const PointContainer &points)
Compute function for STL-like containers.
Definition cnc.hpp:355
FIT_RESULT computeWithIds(const IndexRange &ids, const PointContainer &points)
Compute function that iterates over a subset of sampled points from an STL-Like container.
Definition cnc.hpp:370
VectorType kminDirection() const
Returns an estimate of the minimal principal curvature direction.
Definition cnc.h:241
Scalar kmin() const
Returns an estimate of the minimal principal curvature value.
Definition cnc.h:235
This Source Code Form is subject to the terms of the Mozilla Public License, v.
TriangleGenerationMethod
\breif Generation method of the triangles for the Corrected Normal Current formula
Definition cnc.h:89
FIT_RESULT
Enum corresponding to the state of a fitting method (and what the finalize function returns)
Definition enums.h:15
@ UNDEFINED
The fitting is undefined, you can't use it for valid results.
Definition enums.h:22
@ STABLE
The fitting is stable and ready to use.
Definition enums.h:17
ComputeObject is a virtual object that represents an algorithm which can be used with the compute fun...
Definition compute.h:24
Stores the three points and normals of the triangles and provides access to Corrected Normal Current ...
Definition cnc.h:31
VectorType & getPos(const int index)
Get the position of the point at the given index.
Definition cnc.h:59