Ponca  cb266528645085a12930c827fbb8336cd937ecbb
Point Cloud Analysis library
Loading...
Searching...
No Matches
cnc.h
1
9
10#pragma once
11
12#include "../defines.h"
13#include "../concepts.h"
14#include "cncFormulaEigen.h"
15
16#include "../Filters/weightFilter.h"
17#include "../Filters/weightKernel.h"
18
19#define CNC_REQUIREMENTS ProvidesNormal<P>
20
21namespace Ponca
22{
23
24 namespace internal
25 {
33 template <class DataPoint>
34 struct Triangle
35 {
36 public:
37 using Scalar = typename DataPoint::Scalar;
38 using VectorType = typename DataPoint::VectorType;
39 using MatrixType = typename DataPoint::MatrixType;
40
41 protected:
42 std::array<VectorType, 3> m_points;
43 std::array<VectorType, 3> m_normals;
44
45 public:
46 Triangle(DataPoint pointA, DataPoint pointB, DataPoint pointC)
47 {
48 m_points = {pointA.pos(), pointB.pos(), pointC.pos()};
49 m_normals = {pointA.normal(), pointB.normal(), pointC.normal()};
50 }
51
52 Triangle(const std::array<VectorType, 3>& points, const std::array<VectorType, 3>& normals)
53 {
54 m_points = points;
55 m_normals = normals;
56 }
57
63 PONCA_MULTIARCH [[nodiscard]] VectorType& getPos(const int index) { return m_points[index]; }
64
65 PONCA_MULTIARCH [[nodiscard]] bool operator==(const Triangle& other) const
66 {
67 return (m_points[0] == other.m_points[0]) && (m_points[1] == other.m_points[1]) &&
68 (m_points[2] == other.m_points[2]);
69 }
70
71 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const Triangle& other) const { return !((*this) == other); }
72
73#define DEFINE_CNC_FUNC(CNC_FUNC, RETURN_TYPE) \
74 template <bool differentOrder = false> \
75 inline RETURN_TYPE CNC_FUNC() \
76 { \
77 return CNCEigen<DataPoint>::CNC_FUNC(m_points[0], m_points[2 - differentOrder], m_points[1 + differentOrder], \
78 m_normals[0], m_normals[2 - differentOrder], \
79 m_normals[1 + differentOrder]); \
80 }
81
82 DEFINE_CNC_FUNC(mu0InterpolatedU, Scalar)
83 DEFINE_CNC_FUNC(mu1InterpolatedU, Scalar)
84 DEFINE_CNC_FUNC(mu2InterpolatedU, Scalar)
85 DEFINE_CNC_FUNC(muXYInterpolatedU, MatrixType)
86 };
87 } // namespace internal
88
93 {
94 UniformGeneration,
95 HexagramGeneration,
96 IndependentGeneration,
97 AvgHexagramGeneration
98 };
99
109 template <class P, TriangleGenerationMethod _method = UniformGeneration>
110 requires CNC_REQUIREMENTS
111 class CNC : ComputeObject<CNC<P, _method>>
112 {
113 public:
114 using DataPoint = P;
115 using MatrixType = typename DataPoint::MatrixType;
116 using Scalar = typename DataPoint::Scalar;
117 using VectorType = typename DataPoint::VectorType;
118 using DenseVector = Eigen::VectorXd;
119 using DenseMatrix = Eigen::MatrixXd;
120 using NeighborFilter =
122 internal::ConvertDataPointToNormal<DataPoint>>;
123
124 protected:
125 // Basis
126 NeighborFilter m_nFilter;
127
128 // Triangles used for the computation
129 int m_nb_vt{0}; // Number of valid triangles
130 std::vector<internal::Triangle<DataPoint>> m_triangles;
131
132 // Results of the fit
133 Scalar m_A{0}; // Area
134 Scalar m_H{0}; // Mean Curvatures
135 Scalar m_G{0}; // Gaussian Curvatures
136 Scalar m_T11{0}; // T11
137 Scalar m_T12{0}; // T12
138 Scalar m_T13{0}; // T13
139 Scalar m_T22{0}; // T22
140 Scalar m_T23{0}; // T23
141 Scalar m_T33{0}; // T33
142
143 Scalar m_k1{0};
144 Scalar m_k2{0};
145
146 VectorType m_v1{VectorType::Zero()};
147 VectorType m_v2{VectorType::Zero()};
148
153
154 public:
155 PONCA_EXPLICIT_CAST_OPERATOR(meanCurvature, CNC<P, _method>)
156 PONCA_EXPLICIT_CAST_OPERATOR(curvatureTensor, CNC<P, _method>)
157
158 PONCA_FITTING_DECLARE_FINALIZE
159
161 PONCA_MULTIARCH inline void init()
162 {
164 m_nb_vt = 0;
165 m_A = Scalar(0);
166 m_H = Scalar(0);
167 m_G = Scalar(0);
168 m_T11 = m_T12 = m_T13 = m_T22 = m_T23 = m_T33 = Scalar(0);
169
170 m_k1 = Scalar(0);
171 m_k2 = Scalar(0);
172 m_v1 = VectorType::Zero();
173 m_v2 = VectorType::Zero();
174
175 m_triangles.clear();
176 }
177
183 template <typename IteratorBegin, typename IteratorEnd>
184 PONCA_MULTIARCH [[nodiscard]] inline FIT_RESULT compute(const IteratorBegin& begin, const IteratorEnd& end);
185
190 template <typename PointContainer>
191 PONCA_MULTIARCH [[nodiscard]] inline FIT_RESULT compute(const PointContainer& points);
192
198 template <typename IndexRange, typename PointContainer>
199 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(IndexRange&& ids, const PointContainer& points);
200
206 PONCA_MULTIARCH [[nodiscard]] inline size_t getNumTriangles() const { return static_cast<size_t>(m_nb_vt); }
207
208 PONCA_FITTING_APIDOC_SETWFUNC
209 PONCA_MULTIARCH [[nodiscard]] inline bool setNeighborFilter(const NeighborFilter& _nFilter)
210 {
211 m_nFilter = _nFilter;
212 return Eigen::internal::isApprox(m_nFilter.data().squaredNorm(), Scalar(1.0));
213 }
214
216 PONCA_MULTIARCH inline const NeighborFilter& getNeighborFilter() const { return m_nFilter; }
217
223 PONCA_MULTIARCH [[nodiscard]] std::vector<internal::Triangle<DataPoint>>& getTriangles() { return m_triangles; }
224
226 PONCA_MULTIARCH [[nodiscard]] bool operator==(const CNC& other) const
227 {
228 // We use the matrix to compare the fitting results
229 return (m_eCurrentState == other.m_eCurrentState) && (kMean() == other.kMean()) &&
230 (kmin() == other.kmin()) && (kmax() == other.kmax()) && (kminDirection() == other.kminDirection()) &&
231 (kmaxDirection() == other.kmaxDirection()) && (GaussianCurvature() == other.GaussianCurvature()) &&
232 (m_T11 == other.m_T11) && (m_T12 == other.m_T12) && (m_T13 == other.m_T13) &&
233 (m_T22 == other.m_T22) && (m_T23 == other.m_T23) && (m_T33 == other.m_T33);
234 }
235
237 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const CNC& other) const
238 {
239 // We use the matrix to compare the fitting results
240 return !(this == &other);
241 }
242
244 PONCA_MULTIARCH [[nodiscard]] bool isApprox(
245 const CNC& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const
246 {
247 PONCA_MULTIARCH_STD_MATH(abs);
248
249 return (m_eCurrentState == other.m_eCurrentState) && (std::abs(kMean() - other.kMean()) < epsilon) &&
250 (std::abs(GaussianCurvature() - other.GaussianCurvature()) < epsilon) &&
251 (std::abs(kmin() - other.kmin()) < epsilon) && (std::abs(kmax() - other.kmax()) < epsilon);
252 }
253
255 PONCA_MULTIARCH [[nodiscard]] inline bool isStable() const { return m_eCurrentState == STABLE; }
256
258 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmin() const { return m_k1; }
259
261 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmax() const { return m_k2; }
262
264 PONCA_MULTIARCH [[nodiscard]] inline VectorType kminDirection() const { return m_v1; }
265
267 PONCA_MULTIARCH [[nodiscard]] inline VectorType kmaxDirection() const { return m_v2; }
268
270 PONCA_MULTIARCH [[nodiscard]] inline Scalar kMean() const { return m_H; }
271
273 PONCA_MULTIARCH [[nodiscard]] inline Scalar GaussianCurvature() const { return m_G; }
274 }; // class CNC
275
276} // namespace Ponca
277
278#include "cnc.hpp"
Corrected Normal Current Fit type.
Definition cnc.h:112
void init()
Set the scalar field values to 0 and reset the isNormalized() status.
Definition cnc.h:161
size_t getNumTriangles() const
Get the number of triangles that were generated with the compute method.
Definition cnc.h:206
CNC< P, _method > & curvatureTensor()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition cnc.h:156
bool operator==(const CNC &other) const
Comparison operator.
Definition cnc.h:226
bool isApprox(const CNC &other, const Scalar &epsilon=Eigen::NumTraits< Scalar >::dummy_precision()) const
Approximate operator.
Definition cnc.h:244
Scalar GaussianCurvature() const
Returns an estimate of the Gaussian curvature.
Definition cnc.h:273
VectorType kmaxDirection() const
Returns an estimate of the maximal principal curvature direction.
Definition cnc.h:267
FIT_RESULT m_eCurrentState
Represent the current state of the fit (finalize function update the state).
Definition cnc.h:152
FIT_RESULT computeWithIds(IndexRange &&ids, const PointContainer &points)
Compute function that iterates over a subset of sampled points from an STL-Like container.
Definition cnc.hpp:432
Scalar kmax() const
Returns an estimate of the maximal principal curvature value.
Definition cnc.h:261
CNC< P, _method > & meanCurvature()
Explicit conversion to CLASSNAME, to access methods potentially hidden by heritage.
Definition cnc.h:155
bool operator!=(const CNC &other) const
Comparison operator, convenience function.
Definition cnc.h:237
const NeighborFilter & getNeighborFilter() const
Read access to the NeighborFilter.
Definition cnc.h:216
bool isStable() const
Is the fitted primitive ready to use (finalize has been called and the result is stable).
Definition cnc.h:255
Scalar kMean() const
Returns an estimate of the mean curvature.
Definition cnc.h:270
FIT_RESULT compute(const IteratorBegin &begin, const IteratorEnd &end)
Convenience function for STL-like iterators Add neighbors stored in a container using STL-like iterat...
Definition cnc.hpp:399
std::vector< internal::Triangle< DataPoint > > & getTriangles()
Returns the triangles.
Definition cnc.h:223
VectorType kminDirection() const
Returns an estimate of the minimal principal curvature direction.
Definition cnc.h:264
Scalar kmin() const
Returns an estimate of the minimal principal curvature value.
Definition cnc.h:258
This class extends a NeighborFilter class to also store additional data, for use outside the scope of...
const DataType & data() const
Access to the evaluation normal set during the initialization.
Copyright (c) 2022 Jacques-Olivier Lachaud (jacques-olivier.lachaud@univ-savoie.fr) Laboratory of Mat...
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition concepts.h:11
TriangleGenerationMethod
\breif Generation method of the triangles for the Corrected Normal Current formula
Definition cnc.h:93
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:35
VectorType & getPos(const int index)
Get the position of the point at the given index.
Definition cnc.h:63