Ponca  7b3f8ad3fde25a027e6452783ccee143798a71b8
Point Cloud Analysis library
Loading...
Searching...
No Matches
cnc.h
1
10#pragma once
11
12#include "../defines.h"
13#include "cncFormulaEigen.h"
14
15#include "../Filters/weightFilter.h"
16#include "../Filters/weightKernel.h"
17
18namespace Ponca
19{
20
21 namespace internal
22 {
30 template <class DataPoint>
31 struct Triangle
32 {
33 public:
34 using Scalar = typename DataPoint::Scalar;
35 using VectorType = typename DataPoint::VectorType;
36 using MatrixType = typename DataPoint::MatrixType;
37
38 protected:
39 std::array<VectorType, 3> m_points;
40 std::array<VectorType, 3> m_normals;
41
42 public:
43 Triangle(DataPoint pointA, DataPoint pointB, DataPoint pointC)
44 {
45 m_points = {pointA.pos(), pointB.pos(), pointC.pos()};
46 m_normals = {pointA.normal(), pointB.normal(), pointC.normal()};
47 }
48
49 Triangle(const std::array<VectorType, 3>& points, const std::array<VectorType, 3>& normals)
50 {
51 m_points = points;
52 m_normals = normals;
53 }
54
60 PONCA_MULTIARCH [[nodiscard]] VectorType& getPos(const int index) { return m_points[index]; }
61
62 PONCA_MULTIARCH [[nodiscard]] bool operator==(const Triangle& other) const
63 {
64 return (m_points[0] == other.m_points[0]) && (m_points[1] == other.m_points[1]) &&
65 (m_points[2] == other.m_points[2]);
66 }
67
68 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const Triangle& other) const { return !((*this) == other); }
69
70#define DEFINE_CNC_FUNC(CNC_FUNC, RETURN_TYPE) \
71 template <bool differentOrder = false> \
72 inline RETURN_TYPE CNC_FUNC() \
73 { \
74 return CNCEigen<DataPoint>::CNC_FUNC(m_points[0], m_points[2 - differentOrder], m_points[1 + differentOrder], \
75 m_normals[0], m_normals[2 - differentOrder], \
76 m_normals[1 + differentOrder]); \
77 }
78
79 DEFINE_CNC_FUNC(mu0InterpolatedU, Scalar)
80 DEFINE_CNC_FUNC(mu1InterpolatedU, Scalar)
81 DEFINE_CNC_FUNC(mu2InterpolatedU, Scalar)
82 DEFINE_CNC_FUNC(muXYInterpolatedU, MatrixType)
83 };
84 } // namespace internal
85
90 {
91 UniformGeneration,
92 HexagramGeneration,
93 IndependentGeneration,
94 AvgHexagramGeneration
95 };
96
106 template <class P, TriangleGenerationMethod _method = UniformGeneration>
107 class CNC : ComputeObject<CNC<P, _method>>
108 {
109 public:
110 using DataPoint = P;
111 using MatrixType = typename DataPoint::MatrixType;
112 using Scalar = typename DataPoint::Scalar;
113 using VectorType = typename DataPoint::VectorType;
114 using DenseVector = Eigen::VectorXd;
115 using DenseMatrix = Eigen::MatrixXd;
116 using NeighborFilter =
118 internal::ConvertDataPointToNormal<DataPoint>>;
119
120 protected:
121 // Basis
122 NeighborFilter m_nFilter;
123
124 // Triangles used for the computation
125 int m_nb_vt{0}; // Number of valid triangles
126 std::vector<internal::Triangle<DataPoint>> m_triangles;
127
128 // Results of the fit
129 Scalar m_A{0}; // Area
130 Scalar m_H{0}; // Mean Curvatures
131 Scalar m_G{0}; // Gaussian Curvatures
132 Scalar m_T11{0}; // T11
133 Scalar m_T12{0}; // T12
134 Scalar m_T13{0}; // T13
135 Scalar m_T22{0}; // T22
136 Scalar m_T23{0}; // T23
137 Scalar m_T33{0}; // T33
138
139 Scalar m_k1{0};
140 Scalar m_k2{0};
141
142 VectorType m_v1;
143 VectorType m_v2;
144
149
150 public:
151 PONCA_FITTING_DECLARE_FINALIZE
152
154 PONCA_MULTIARCH inline void init()
155 {
157 m_A = Scalar(0);
158 m_H = Scalar(0);
159 m_G = Scalar(0);
160
161 m_k1 = Scalar(0);
162 m_k2 = Scalar(0);
163
164 m_triangles.clear();
165 }
166
171 template <typename PointContainer>
172 PONCA_MULTIARCH inline FIT_RESULT compute(const PointContainer& points);
173
179 template <typename IndexRange, typename PointContainer>
180 PONCA_MULTIARCH inline FIT_RESULT computeWithIds(const IndexRange& ids, const PointContainer& points);
181
187 PONCA_MULTIARCH [[nodiscard]] inline size_t getNumTriangles() const { return static_cast<size_t>(m_nb_vt); }
188
189 PONCA_FITTING_APIDOC_SETWFUNC
190 PONCA_MULTIARCH inline void setNeighborFilter(const NeighborFilter& _nFilter) { m_nFilter = _nFilter; }
191
197 PONCA_MULTIARCH [[nodiscard]] std::vector<internal::Triangle<DataPoint>>& getTriangles() { return m_triangles; }
198
200 PONCA_MULTIARCH [[nodiscard]] bool operator==(const CNC& other) const
201 {
202 // We use the matrix to compare the fitting results
203 return (m_eCurrentState == other.m_eCurrentState) && (kMean() == other.kMean()) &&
204 (kmin() == other.kmin()) && (kmax() == other.kmax()) && (kminDirection() == other.kminDirection()) &&
205 (kmaxDirection() == other.kmaxDirection()) && (GaussianCurvature() == other.GaussianCurvature()) &&
206 (m_T11 == other.m_T11) && (m_T12 == other.m_T12) && (m_T13 == other.m_T13) &&
207 (m_T22 == other.m_T22) && (m_T23 == other.m_T23) && (m_T33 == other.m_T33);
208 }
209
211 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const CNC& other) const
212 {
213 // We use the matrix to compare the fitting results
214 return !(this == &other);
215 }
216
218 PONCA_MULTIARCH [[nodiscard]] bool isApprox(
219 const CNC& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const
220 {
221 PONCA_MULTIARCH_STD_MATH(abs);
222
223 return (m_eCurrentState == other.m_eCurrentState) && (std::abs(kMean() - other.kMean()) < epsilon) &&
224 (std::abs(GaussianCurvature() - other.GaussianCurvature()) < epsilon) &&
225 (std::abs(kmin() - other.kmin()) < epsilon) && (std::abs(kmax() - other.kmax()) < epsilon);
226 }
227
229 PONCA_MULTIARCH [[nodiscard]] inline bool isStable() const { return m_eCurrentState == STABLE; }
230
232 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmin() const { return m_k1; }
233
235 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmax() const { return m_k2; }
236
238 PONCA_MULTIARCH [[nodiscard]] inline VectorType kminDirection() const { return m_v1; }
239
241 PONCA_MULTIARCH [[nodiscard]] inline VectorType kmaxDirection() const { return m_v2; }
242
244 PONCA_MULTIARCH [[nodiscard]] inline Scalar kMean() const { return m_H; }
245
247 PONCA_MULTIARCH [[nodiscard]] inline Scalar GaussianCurvature() const { return m_G; }
248 }; // class CNC
249
250} // namespace Ponca
251
252#include "cnc.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:294
typename P::Scalar Scalar
Scalar type used for computation, as defined from template parameter P
Definition basket.h:302
Corrected Normal Current Fit type.
Definition cnc.h:108
void setNeighborFilter(const NeighborFilter &_nFilter)
Init the WeightFunc, without changing the other internal states.
Definition cnc.h:190
void init()
Set the scalar field values to 0 and reset the isNormalized() status.
Definition cnc.h:154
size_t getNumTriangles() const
Get the number of triangles that were generated with the compute method.
Definition cnc.h:187
bool operator==(const CNC &other) const
Comparison operator.
Definition cnc.h:200
bool isApprox(const CNC &other, const Scalar &epsilon=Eigen::NumTraits< Scalar >::dummy_precision()) const
Approximate operator.
Definition cnc.h:218
Scalar GaussianCurvature() const
Returns an estimate of the Gaussian curvature.
Definition cnc.h:247
VectorType kmaxDirection() const
Returns an estimate of the maximal principal curvature direction.
Definition cnc.h:241
FIT_RESULT m_eCurrentState
Represent the current state of the fit (finalize function update the state)
Definition cnc.h:148
Scalar kmax() const
Returns an estimate of the maximal principal curvature value.
Definition cnc.h:235
bool operator!=(const CNC &other) const
Comparison operator, convenience function.
Definition cnc.h:211
bool isStable() const
Is the fitted primitive ready to use (finalize has been called and the result is stable)
Definition cnc.h:229
Scalar kMean() const
Returns an estimate of the mean curvature.
Definition cnc.h:244
std::vector< internal::Triangle< DataPoint > > & getTriangles()
Returns the triangles.
Definition cnc.h:197
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:238
Scalar kmin() const
Returns an estimate of the minimal principal curvature value.
Definition cnc.h:232
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:90
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:32
VectorType & getPos(const int index)
Get the position of the point at the given index.
Definition cnc.h:60