Ponca  5b0151ad2869758185d699615c3cca5855cc2cee
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
17
18namespace Ponca
19{
20
21namespace internal {
29template < class DataPoint >
30struct Triangle {
31public:
32 typedef typename DataPoint::Scalar Scalar;
33 typedef typename DataPoint::VectorType VectorType;
34 typedef typename DataPoint::MatrixType MatrixType;
35protected:
36 std::array < VectorType, 3 > m_points;
37 std::array < VectorType, 3 > m_normals;
38public:
39 Triangle(DataPoint pointA, DataPoint pointB, DataPoint pointC) {
40 m_points = {
41 pointA.pos(),
42 pointB.pos(),
43 pointC.pos()
44 };
45 m_normals = {
46 pointA.normal(),
47 pointB.normal(),
48 pointC.normal()
49 };
50 }
51
52 Triangle(const std::array < VectorType, 3 >& points, const std::array < VectorType, 3 >& normals) {
53 m_points = points;
54 m_normals = normals;
55 }
56
62 PONCA_MULTIARCH [[nodiscard]] VectorType& getPos(const int index) {
63 return m_points[index];
64 }
65
66 PONCA_MULTIARCH [[nodiscard]] bool operator==(const Triangle& other) const {
67 return (m_points[0] == other.m_points[0])
68 && (m_points[1] == other.m_points[1])
69 && (m_points[2] == other.m_points[2]);
70 }
71
72 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const Triangle& other) const {
73 return !((*this) == other);
74 }
75
76#define DEFINE_CNC_FUNC(CNC_FUNC, RETURN_TYPE) \
77 template<bool differentOrder = false> \
78 inline RETURN_TYPE CNC_FUNC () { \
79 return CNCEigen<DataPoint>::CNC_FUNC( \
80 m_points[0] , m_points[2-differentOrder], m_points[1+differentOrder], \
81 m_normals[0], m_normals[2-differentOrder], m_normals[1+differentOrder] \
82 ); \
83 }
84
85 DEFINE_CNC_FUNC(mu0InterpolatedU , Scalar)
86 DEFINE_CNC_FUNC(mu1InterpolatedU , Scalar)
87 DEFINE_CNC_FUNC(mu2InterpolatedU , Scalar)
88 DEFINE_CNC_FUNC(muXYInterpolatedU, MatrixType)
89};
90} // namespace internal
91
92
97 UniformGeneration, HexagramGeneration, IndependentGeneration, AvgHexagramGeneration
98};
99
109template < class P, TriangleGenerationMethod _method = UniformGeneration>
110class CNC : ComputeObject<CNC<P, _method>> {
111protected:
112 enum
113 {
114 PROVIDES_PRINCIPAL_CURVATURES
115 };
116public:
117 using DataPoint = P;
118 using MatrixType = typename DataPoint::MatrixType;
119 using Scalar = typename DataPoint::Scalar;
120 using VectorType = typename DataPoint::VectorType;
121 typedef Eigen::VectorXd DenseVector;
122 typedef Eigen::MatrixXd DenseMatrix;
124protected:
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;
147 VectorType m_v2;
148
153public:
154 PONCA_FITTING_DECLARE_FINALIZE
155
157 PONCA_MULTIARCH inline void init() {
159 m_A = Scalar(0);
160 m_H = Scalar(0);
161 m_G = Scalar(0);
162
163 m_k1 = Scalar(0);
164 m_k2 = Scalar(0);
165
166 m_triangles.clear();
167 }
168
173 template <typename PointContainer>
174 PONCA_MULTIARCH inline FIT_RESULT compute( const PointContainer& points);
175
181 template <typename IndexRange, typename PointContainer>
182 PONCA_MULTIARCH inline FIT_RESULT computeWithIds( const IndexRange& ids, const PointContainer& points );
183
189 PONCA_MULTIARCH [[nodiscard]] inline size_t getNumTriangles() const {
190 return static_cast<size_t>(m_nb_vt);
191 }
192
193 PONCA_FITTING_APIDOC_SETWFUNC
194 PONCA_MULTIARCH inline void setNeighborFilter (const NeighborFilter& _nFilter) {
195 m_nFilter = _nFilter;
196 }
197
203 PONCA_MULTIARCH [[nodiscard]] std::vector< internal::Triangle<DataPoint> >& getTriangles() {
204 return m_triangles;
205 }
206
208 PONCA_MULTIARCH [[nodiscard]] bool operator==(const CNC& other) const {
209 // We use the matrix to compare the fitting results
210 return (m_eCurrentState == other.m_eCurrentState)
211 && (kMean() == other.kMean())
212 && (kmin() == other.kmin())
213 && (kmax() == other.kmax())
214 && (kminDirection() == other.kminDirection())
215 && (kmaxDirection() == other.kmaxDirection())
216 && (GaussianCurvature() == other.GaussianCurvature())
217 && (m_T11 == other.m_T11) && (m_T12 == other.m_T12) && (m_T13 == other.m_T13)
218 && (m_T22 == other.m_T22) && (m_T23 == other.m_T23)
219 && (m_T33 == other.m_T33);
220 }
221
223 PONCA_MULTIARCH [[nodiscard]] bool operator!=(const CNC& other) const {
224 // We use the matrix to compare the fitting results
225 return !(this == &other);
226 }
227
229 PONCA_MULTIARCH [[nodiscard]] bool isApprox(const CNC& other, const Scalar& epsilon = Eigen::NumTraits<Scalar>::dummy_precision()) const {
230 PONCA_MULTIARCH_STD_MATH(abs);
231
232 return (m_eCurrentState == other.m_eCurrentState)
233 && (std::abs(kMean() - other.kMean()) < epsilon)
234 && (std::abs(GaussianCurvature() - other.GaussianCurvature()) < epsilon)
235 && (std::abs(kmin() - other.kmin()) < epsilon)
236 && (std::abs(kmax() - other.kmax()) < epsilon);
237 }
238
240 PONCA_MULTIARCH [[nodiscard]] inline bool isStable() const { return m_eCurrentState == STABLE; }
241
243 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmin() const { return m_k1; }
244
246 PONCA_MULTIARCH [[nodiscard]] inline Scalar kmax() const { return m_k2; }
247
249 PONCA_MULTIARCH [[nodiscard]] inline VectorType kminDirection() const { return m_v1; }
250
252 PONCA_MULTIARCH [[nodiscard]] inline VectorType kmaxDirection() const { return m_v2; }
253
255 PONCA_MULTIARCH [[nodiscard]] inline Scalar kMean() const { return m_H; }
256
258 PONCA_MULTIARCH [[nodiscard]] inline Scalar GaussianCurvature() const { return m_G; }
259}; //class CNC
260
261} // namespace Ponca
262
263#include "cnc.hpp"
Corrected Normal Current Fit type.
Definition cnc.h:110
void setNeighborFilter(const NeighborFilter &_nFilter)
Init the WeightFunc, without changing the other internal states.
Definition cnc.h:194
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:189
bool operator==(const CNC &other) const
Comparison operator.
Definition cnc.h:208
bool isApprox(const CNC &other, const Scalar &epsilon=Eigen::NumTraits< Scalar >::dummy_precision()) const
Approximate operator.
Definition cnc.h:229
Scalar GaussianCurvature() const
Returns an estimate of the Gaussian curvature.
Definition cnc.h:258
VectorType kmaxDirection() const
Returns an estimate of the maximal principal curvature direction.
Definition cnc.h:252
FIT_RESULT m_eCurrentState
Represent the current state of the fit (finalize function update the state)
Definition cnc.h:152
Scalar kmax() const
Returns an estimate of the maximal principal curvature value.
Definition cnc.h:246
bool operator!=(const CNC &other) const
Comparison operator, convenience function.
Definition cnc.h:223
bool isStable() const
Is the fitted primitive ready to use (finalize has been called and the result is stable)
Definition cnc.h:240
Scalar kMean() const
Returns an estimate of the mean curvature.
Definition cnc.h:255
std::vector< internal::Triangle< DataPoint > > & getTriangles()
Returns the triangles.
Definition cnc.h:203
FIT_RESULT compute(const PointContainer &points)
Compute function for STL-like containers.
Definition cnc.hpp:345
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:358
VectorType kminDirection() const
Returns an estimate of the minimal principal curvature direction.
Definition cnc.h:249
Scalar kmin() const
Returns an estimate of the minimal principal curvature value.
Definition cnc.h:243
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:96
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:21
Stores the three points and normals of the triangles and provides access to Corrected Normal Current ...
Definition cnc.h:30
VectorType & getPos(const int index)
Get the position of the point at the given index.
Definition cnc.h:62