ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvNormalVectors.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // cloudViewer
12 
13 // Local
14 #include "ecvGenericPointCloud.h"
15 
16 // System
17 #include <vector>
18 
21 public:
23  static ccNormalVectors* GetUniqueInstance();
24 
26 
28  static void ReleaseUniqueInstance();
29 
31  static inline unsigned GetNumberOfVectors() {
32  return static_cast<unsigned>(
33  GetUniqueInstance()->m_theNormalVectors.size());
34  }
35 
37  static inline const CCVector3& GetNormal(unsigned normIndex) {
38  return GetUniqueInstance()->getNormal(normIndex);
39  }
40  static inline CCVector3& GetNormalPtr(unsigned normIndex) {
41  return GetUniqueInstance()->getNormal(normIndex);
42  }
43  static inline const std::vector<CCVector3>& GetNormals() {
44  return GetUniqueInstance()->getNormals();
45  }
46  static inline std::vector<CCVector3>& GetNormalsPtr() {
47  return GetUniqueInstance()->getNormals();
48  }
49 
51  inline const CCVector3& getNormal(unsigned normIndex) const {
52  return m_theNormalVectors[normIndex];
53  }
54  inline CCVector3& getNormal(unsigned normIndex) {
55  return m_theNormalVectors[normIndex];
56  }
57  inline const std::vector<CCVector3>& getNormals() const {
58  return m_theNormalVectors;
59  }
60  inline std::vector<CCVector3>& getNormals() { return m_theNormalVectors; }
61 
63  static CompressedNormType GetNormIndex(const PointCoordinateType N[]);
65  static inline CompressedNormType GetNormIndex(const CCVector3& N) {
66  return GetNormIndex(N.u);
67  }
68 
70  enum Orientation {
71  PLUS_X = 0,
72  MINUS_X = 1,
73  PLUS_Y = 2,
74  MINUS_Y = 3,
75  PLUS_Z = 4,
76  MINUS_Z = 5,
77  PLUS_BARYCENTER =
78  6,
79  MINUS_BARYCENTER = 7,
80  PLUS_ORIGIN = 8,
81  MINUS_ORIGIN = 9,
82  PREVIOUS = 10,
83  PLUS_SENSOR_ORIGIN =
84  11,
86  MINUS_SENSOR_ORIGIN =
87  12,
89  UNDEFINED = 255
90  };
91 
93 
102  static bool ComputeCloudNormals(
103  ccGenericPointCloud* cloud,
104  NormsIndexesTableType& theNormsCodes,
105  CV_LOCAL_MODEL_TYPES localModel,
106  PointCoordinateType localRadius,
107  Orientation preferredOrientation = UNDEFINED,
108  cloudViewer::GenericProgressCallback* progressCb = nullptr,
109  cloudViewer::DgmOctree* inputOctree = nullptr);
110 
113 
116  static PointCoordinateType GuessNaiveRadius(ccGenericPointCloud* cloud);
117 
120 
126  static PointCoordinateType GuessBestRadius(
127  ccGenericPointCloud* cloud,
128  cloudViewer::DgmOctree* cloudOctree = nullptr,
129  cloudViewer::GenericProgressCallback* progressCb = nullptr);
130 
132 
137  static bool UpdateNormalOrientations(ccGenericPointCloud* theCloud,
138  NormsIndexesTableType& theNormsCodes,
139  Orientation preferredOrientation);
140 
143 
147  static void ConvertNormalToStrikeAndDip(const CCVector3& N,
148  PointCoordinateType& strike_deg,
149  PointCoordinateType& dip_deg);
150 
152 
159  static void ConvertNormalToDipAndDipDir(const CCVector3& N,
160  PointCoordinateType& dip_deg,
161  PointCoordinateType& dipDir_deg);
162 
165 
170  static CCVector3 ConvertDipAndDipDirToNormal(PointCoordinateType dip_deg,
171  PointCoordinateType dipDir_deg,
172  bool upward = true);
173 
176 
180  static QString ConvertStrikeAndDipToString(double& strike_deg,
181  double& dip_deg);
182 
184 
189  static QString ConvertDipAndDipDirToString(PointCoordinateType dip_deg,
190  PointCoordinateType dipDir_deg);
191 
193 
199  static void ConvertNormalToHSV(const CCVector3& N,
200  float& H,
201  float& S,
202  float& V);
203 
205 
209  static ecvColor::Rgb ConvertNormalToRGB(const CCVector3& N);
210 
211 public:
213  virtual ~ccNormalVectors();
214 
216 
218  bool enableNormalHSVColorsArray();
219 
221  const ecvColor::Rgb& getNormalHSVColor(unsigned index) const;
222 
224  inline const std::vector<ecvColor::Rgb>& getNormalHSVColorArray() const {
225  return m_theNormalHSVColors;
226  }
227 
229  static bool ComputeNormalWithLS(
230  cloudViewer::GenericIndexedCloudPersist* pointAndNeighbors,
231  CCVector3& N);
232 
234 
237  static bool ComputeNormalWithTri(
238  cloudViewer::GenericIndexedCloudPersist* pointAndNeighbors,
239  CCVector3& N);
240 
242 
245  static bool ComputeNormalWithQuadric(
247  const CCVector3& P,
248  CCVector3& N);
249 
250 protected:
252 
254  ccNormalVectors();
255 
257  bool init();
258 
260  std::vector<CCVector3> m_theNormalVectors;
261 
263 
266  std::vector<ecvColor::Rgb> m_theNormalHSVColors;
267 
269  static bool ComputeNormsAtLevelWithQuadric(
271  void** additionalParameters,
274  static bool ComputeNormsAtLevelWithLS(
276  void** additionalParameters,
279  static bool ComputeNormsAtLevelWithTri(
281  void** additionalParameters,
283 };
CV_LOCAL_MODEL_TYPES
Definition: CVConst.h:121
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
#define CV_DB_LIB_API
Definition: CV_db.h:15
int points
Array of compressed 3D normals (single index)
Type u[3]
Definition: CVGeom.h:139
A 3D cloud interface with associated features (color, normals, octree, etc.)
Compressed normal vectors handler.
const std::vector< CCVector3 > & getNormals() const
const std::vector< ecvColor::Rgb > & getNormalHSVColorArray() const
Returns the HSV color array.
static CompressedNormType GetNormIndex(const CCVector3 &N)
Returns the compressed index corresponding to a normal vector (shortcut)
const CCVector3 & getNormal(unsigned normIndex) const
Returns the precomputed normal corresponding to a given compressed index.
std::vector< CCVector3 > m_theNormalVectors
Compressed normal vectors.
std::vector< CCVector3 > & getNormals()
std::vector< ecvColor::Rgb > m_theNormalHSVColors
'HSV' colors corresponding to each compressed normal index
static std::vector< CCVector3 > & GetNormalsPtr()
static const CCVector3 & GetNormal(unsigned normIndex)
Static access to ccNormalVectors::getNormal.
static unsigned GetNumberOfVectors()
Returns the number of compressed normal vectors.
Orientation
'Default' orientations
static const std::vector< CCVector3 > & GetNormals()
static CCVector3 & GetNormalPtr(unsigned normIndex)
CCVector3 & getNormal(unsigned normIndex)
The octree structure used throughout the library.
Definition: DgmOctree.h:39
A generic 3D point cloud with index-based and presistent access to points.
RGB color structure.
Definition: ecvColorTypes.h:49
unsigned int CompressedNormType
Compressed normals type.
Definition: ecvBasicTypes.h:16
cloudViewer::NormalizedProgress * nProgress
Octree cell descriptor.
Definition: DgmOctree.h:354