ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvGenericPointCloud.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 // Local
11 #include "ecvAdvancedTypes.h"
12 #include "ecvBBox.h"
13 #include "ecvOctree.h"
14 #include "ecvOrientedBBox.h"
15 #include "ecvShiftedObject.h"
16 
17 // System
18 #include <vector>
19 
20 namespace cloudViewer {
21 class GenericProgressCallback;
22 class ReferenceCloud;
23 } // namespace cloudViewer
24 
25 class ccOctreeProxy;
26 
27 /***************************************************
28  ccGenericPointCloud
29 ***************************************************/
30 
31 // default material for clouds (with normals)
32 #define CC_DEFAULT_CLOUD_AMBIENT_COLOR ecvColor::bright
33 #define CC_DEFAULT_CLOUD_SPECULAR_COLOR ecvColor::bright
34 #define CC_DEFAULT_CLOUD_DIFFUSE_COLOR ecvColor::bright
35 #define CC_DEFAULT_CLOUD_EMISSION_COLOR ecvColor::night
36 #define CC_DEFAULT_CLOUD_SHININESS 50.0f
37 
39 
46  : public ccShiftedObject,
48  friend class ccMesh;
49 
50 public:
52  ccGenericPointCloud(QString name = QString());
53 
56 
59 
60  /***************************************************
61  Clone/Copy
62  ***************************************************/
63 
65 
72  virtual ccGenericPointCloud* clone(ccGenericPointCloud* destCloud = nullptr,
73  bool ignoreChildren = false) = 0;
74 
75  /***************************************************
76  Features deletion/clearing
77  ***************************************************/
78 
80 
82  virtual void clear();
83 
84  /***************************************************
85  Octree management
86  ***************************************************/
87 
89 
99  cloudViewer::GenericProgressCallback* progressCb = nullptr,
100  bool autoAddChild = true);
101 
103  virtual ccOctree::Shared getOctree() const;
105  virtual void setOctree(ccOctree::Shared octree, bool autoAddChild = true);
107  virtual ccOctreeProxy* getOctreeProxy() const;
108 
110  virtual void deleteOctree();
111 
112  /***************************************************
113  Features getters
114  ***************************************************/
115 
117 
122  virtual const ecvColor::Rgb* getScalarValueColor(ScalarType d) const = 0;
123 
125 
131  unsigned pointIndex) const = 0;
132 
134 
138  virtual ScalarType getPointDisplayedDistance(unsigned pointIndex) const = 0;
139 
141 
143  virtual const ecvColor::Rgb& getPointColor(unsigned pointIndex) const = 0;
144 
146 
150  unsigned pointIndex) const = 0;
151 
153 
156  virtual const CCVector3& getPointNormal(unsigned pointIndex) const = 0;
157 
158  /***************************************************
159  Visibility array
160  ***************************************************/
161 
163 
165  using VisibilityTableType = std::vector<unsigned char>;
166 
169  return m_pointsVisibility;
170  }
171 
173  virtual inline const VisibilityTableType& getTheVisibilityArray() const {
174  return m_pointsVisibility;
175  }
176 
178 
184  const VisibilityTableType* visTable = nullptr,
185  bool silent = false,
186  cloudViewer::ReferenceCloud* selection = nullptr) const;
187 
189  virtual bool isVisibilityTableInstantiated() const;
190 
192 
194  virtual bool resetVisibilityArray();
195 
197  virtual void invertVisibilityArray();
198 
201 
202  /***************************************************
203  Other methods
204  ***************************************************/
205 
206  // Inherited from ccHObject
207  ccBBox getOwnBB(bool withGLFeatures = false) override;
208 
210  virtual void refreshBB() = 0;
211 
214 
225  bool removeSelectedPoints = false,
226  VisibilityTableType* visTable = nullptr,
227  std::vector<int>* newIndexesOfRemainingPoints = nullptr,
228  bool silent = false,
229  cloudViewer::ReferenceCloud* selection = nullptr) = 0;
230 
232 
237  virtual bool removeVisiblePoints(
238  VisibilityTableType* visTable = nullptr,
239  std::vector<int>* newIndexes = nullptr) = 0;
240 
242  virtual void applyRigidTransformation(const ccGLMatrix& trans) = 0;
243 
245 
251  bool inside = true) = 0;
253 
254  virtual void removePoints(size_t index) = 0;
255 
257 
263  virtual void scale(PointCoordinateType fx,
266  CCVector3 center = CCVector3(0, 0, 0)) = 0;
267 
268  // inherited from ccSerializableObject
269  bool isSerializable() const override { return true; }
270 
272 
275  void setPointSize(unsigned size = 0) {
276  m_pointSize = static_cast<unsigned char>(size);
277  }
278 
280 
283  unsigned char getPointSize() const { return m_pointSize; }
284 
286 
289 
291 
293  bool pointPicking(const CCVector2d& clickPos,
294  const ccGLCameraParameters& camera,
295  int& nearestPointIndex,
296  double& nearestSquareDist,
297  double pickWidth = 2.0,
298  double pickHeight = 2.0,
299  bool autoComputeOctree = false);
300 
301  std::tuple<Eigen::Vector3d, Eigen::Matrix3d> computeMeanAndCovariance()
302  const;
304 
305 protected:
306  // inherited from ccHObject
307  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
308  short minimumFileVersion_MeOnly() const override;
309  bool fromFile_MeOnly(QFile& in,
310  short dataVersion,
311  int flags,
312  LoadedIDMap& oldToNewIDMap) override;
313 
315 
319 
321  unsigned char m_pointSize;
322 };
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Definition: CVGeom.h:798
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 size
std::string name
Bounding box structure.
Definition: ecvBBox.h:25
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual void scale(PointCoordinateType fx, PointCoordinateType fy, PointCoordinateType fz, CCVector3 center=CCVector3(0, 0, 0))=0
Multiplies all coordinates by constant factors (one per dimension)
virtual const CCVector3 & getPointNormal(unsigned pointIndex) const =0
Returns normal corresponding to a given point.
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
virtual const ecvColor::Rgb * getScalarValueColor(ScalarType d) const =0
Returns color corresponding to a given scalar value.
virtual const ecvColor::Rgb * getPointScalarValueColor(unsigned pointIndex) const =0
Returns color corresponding to a given point associated scalar value.
ccGenericPointCloud(QString name=QString())
Default constructor.
virtual const VisibilityTableType & getTheVisibilityArray() const
Returns associated visibility array (const version)
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
VisibilityTableType m_pointsVisibility
Per-point visibility table.
unsigned char getPointSize() const
Returns current point size.
virtual void refreshBB()=0
Forces bounding-box update.
virtual cloudViewer::ReferenceCloud * crop(const ecvOrientedBBox &box)=0
virtual bool isVisibilityTableInstantiated() const
Returns whether the visibility array is allocated or not.
unsigned char m_pointSize
Point size (won't be applied if 0)
virtual ccGenericPointCloud * createNewCloudFromVisibilitySelection(bool removeSelectedPoints=false, VisibilityTableType *visTable=nullptr, std::vector< int > *newIndexesOfRemainingPoints=nullptr, bool silent=false, cloudViewer::ReferenceCloud *selection=nullptr)=0
virtual void deleteOctree()
Erases the octree.
short minimumFileVersion_MeOnly() const override
ccGenericPointCloud(const ccGenericPointCloud &cloud)
Copy constructor.
virtual void removePoints(size_t index)=0
void setPointSize(unsigned size=0)
Sets point size.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
~ccGenericPointCloud() override
Default destructor.
bool isSerializable() const override
Returns whether object is serializable of not.
virtual ccOctreeProxy * getOctreeProxy() const
Returns the associated octree proxy (if any)
virtual const ecvColor::Rgb & getPointColor(unsigned pointIndex) const =0
Returns color corresponding to a given point.
virtual void setOctree(ccOctree::Shared octree, bool autoAddChild=true)
Sets the associated octree.
std::tuple< Eigen::Vector3d, Eigen::Matrix3d > computeMeanAndCovariance() const
virtual void invertVisibilityArray()
Inverts the visibility array.
virtual cloudViewer::ReferenceCloud * getTheVisiblePoints(const VisibilityTableType *visTable=nullptr, bool silent=false, cloudViewer::ReferenceCloud *selection=nullptr) const
Returns a ReferenceCloud equivalent to the visibility array.
virtual void applyRigidTransformation(const ccGLMatrix &trans)=0
Applies a rigid transformation (rotation + translation)
virtual VisibilityTableType & getTheVisibilityArray()
Returns associated visibility array.
bool pointPicking(const CCVector2d &clickPos, const ccGLCameraParameters &camera, int &nearestPointIndex, double &nearestSquareDist, double pickWidth=2.0, double pickHeight=2.0, bool autoComputeOctree=false)
Point picking (brute force or octree-driven)
virtual ccGenericPointCloud * clone(ccGenericPointCloud *destCloud=nullptr, bool ignoreChildren=false)=0
Clones this entity.
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
virtual ScalarType getPointDisplayedDistance(unsigned pointIndex) const =0
Returns scalar value associated to a given point.
virtual bool resetVisibilityArray()
Resets the associated visibility array.
virtual cloudViewer::ReferenceCloud * crop(const ccBBox &box, bool inside=true)=0
Crops the cloud inside (or outside) a bounding box.
std::vector< unsigned char > VisibilityTableType
Array of "visibility" information for each point.
virtual const CompressedNormType & getPointNormalIndex(unsigned pointIndex) const =0
Returns compressed normal corresponding to a given point.
void importParametersFrom(const ccGenericPointCloud *cloud)
Imports the parameters from another cloud.
virtual void unallocateVisibilityArray()
Erases the points visibility information.
virtual bool removeVisiblePoints(VisibilityTableType *visTable=nullptr, std::vector< int > *newIndexes=nullptr)=0
Removes all the 'visible' points (as defined by the visibility array)
virtual void clear()
Clears the entity from all its points and features.
cloudViewer::SquareMatrixd computeCovariance() const
Triangular mesh.
Definition: ecvMesh.h:35
Octree structure proxy.
QSharedPointer< ccOctree > Shared
Shared pointer.
Definition: ecvOctree.h:32
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
Shifted entity interface.
A generic 3D point cloud with index-based and presistent access to points.
A very simple point cloud (no point duplication)
RGB color structure.
Definition: ecvColorTypes.h:49
unsigned int CompressedNormType
Compressed normals type.
Definition: ecvBasicTypes.h:16
Generic file read and write utility for python interface.
cloudViewer::DgmOctree * octree
OpenGL camera parameters.