ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvSubMesh.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 "ecvBBox.h"
12 #include "ecvGenericMesh.h"
13 
14 class ccMesh;
15 
17 
20 public:
22  explicit ccSubMesh(ccMesh* parentMesh);
24  ~ccSubMesh() override = default;
25 
27  CV_CLASS_ENUM getClassID() const override { return CV_TYPES::SUB_MESH; }
28 
29  // inherited methods (ccHObject)
30  ccBBox getOwnBB(bool withGLFeatures = false) override;
31  bool isSerializable() const override { return true; }
32 
33  // inherited methods (ccGenericMesh)
34  ccGenericPointCloud* getAssociatedCloud() const override;
35  void refreshBB() override;
36  bool interpolateNormalsBC(unsigned triIndex,
37  const CCVector3d& w,
38  CCVector3& N) override;
39  bool interpolateColors(unsigned triIndex,
40  const CCVector3& P,
41  ecvColor::Rgb& rgb) override;
42  bool getColorFromMaterial(unsigned triIndex,
43  const CCVector3& P,
45  bool interpolateColorIfNoTexture) override;
46  bool getVertexColorFromMaterial(unsigned triIndex,
47  unsigned char vertIndex,
49  bool returnColorIfNoTexture) override;
50  bool hasMaterials() const override;
51  const ccMaterialSet* getMaterialSet() const override;
52  int getTriangleMtlIndex(unsigned triangleIndex) const override;
53  bool hasTextures() const override;
55  void getTexCoordinates(unsigned index, TexCoords2D*& tx) const override;
56  void getTriangleTexCoordinates(unsigned triIndex,
57  TexCoords2D*& tx1,
58  TexCoords2D*& tx2,
59  TexCoords2D*& tx3) const override;
60  bool hasPerTriangleTexCoordIndexes() const override;
61  void getTriangleTexCoordinatesIndexes(unsigned triangleIndex,
62  int& i1,
63  int& i2,
64  int& i3) const override;
65  bool hasTriNormals() const override;
66  void getTriangleNormalIndexes(unsigned triangleIndex,
67  int& i1,
68  int& i2,
69  int& i3) const override;
70  bool getTriangleNormals(unsigned triangleIndex,
71  CCVector3& Na,
72  CCVector3& Nb,
73  CCVector3& Nc) const override;
74  NormsIndexesTableType* getTriNormsTable() const override;
75  unsigned capacity() const override;
76 
77  // inherited methods (ccDrawableObject)
78  bool hasColors() const override;
79  bool hasNormals() const override;
80  bool hasScalarFields() const override;
81  bool hasDisplayedScalarField() const override;
82  bool normalsShown() const override;
83 
84  // inherited methods (GenericIndexedMesh)
85  inline unsigned size() const override {
86  return static_cast<unsigned>(m_triIndexes.size());
87  }
88  void forEach(genericTriangleAction action) override;
89  inline void placeIteratorAtBeginning() override { m_globalIterator = 0; }
91  override; // temporary object
93  unsigned index) override; // temporary object
96  unsigned triangleIndex) override;
97  virtual void getTriangleVertices(unsigned triangleIndex,
98  CCVector3& A,
99  CCVector3& B,
100  CCVector3& C) const override;
101  virtual void getTriangleVertices(unsigned triangleIndex,
102  double A[3],
103  double B[3],
104  double C[3]) const override;
105 
106  void getBoundingBox(CCVector3& bbMin, CCVector3& bbMax) override;
107  bool interpolateNormals(unsigned triIndex,
108  const CCVector3& P,
109  CCVector3& N) override;
110 
113 
116  inline unsigned getTriGlobalIndex(unsigned localIndex) const {
117  return m_triIndexes[localIndex];
118  }
119 
121  inline unsigned getCurrentTriGlobalIndex() const {
122  assert(m_globalIterator < size());
123  return m_triIndexes[m_globalIterator];
124  }
125 
127  inline void forwardIterator() { ++m_globalIterator; }
128 
130  void clear(bool releaseMemory);
131 
133 
136  bool addTriangleIndex(unsigned globalIndex);
137 
139 
143  bool addTriangleIndex(unsigned firstIndex, unsigned lastIndex);
144 
146 
149  void setTriangleIndex(unsigned localIndex, unsigned globalIndex);
150 
152 
154  bool reserve(size_t n);
155 
157 
159  bool resize(size_t n);
160 
162  inline ccMesh* getAssociatedMesh() { return m_associatedMesh; }
163 
165  inline const ccMesh* getAssociatedMesh() const { return m_associatedMesh; }
166 
168 
172  void setAssociatedMesh(ccMesh* mesh, bool unlinkPreviousOne = true);
173 
175  using IndexMap = std::vector<unsigned int>;
176 
178 
185  ccSubMesh* createNewSubMeshFromSelection(
186  bool removeSelectedTriangles,
187  const std::vector<int>& selectedTriangleIndexes,
188  IndexMap* newRemainingTriangleIndexes = nullptr);
189 
191 
203  ccSubMesh* createNewSubMeshFromSelection(bool removeSelectedFaces,
204  IndexMap* indexMap = nullptr);
205 
206 protected:
207  // inherited from ccHObject
208  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
209  short minimumFileVersion_MeOnly() const override;
210  bool fromFile_MeOnly(QFile& in,
211  short dataVersion,
212  int flags,
213  LoadedIDMap& oldToNewIDMap) override;
214  void onUpdateOf(ccHObject* obj) override;
215 
218 
220  using ReferencesContainer = std::vector<unsigned int>;
221 
224 
227 
230 };
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
Array of compressed 3D normals (single index)
Array of 2D texture coordinates.
Bounding box structure.
Definition: ecvBBox.h:25
virtual bool hasDisplayedScalarField() const
Returns whether an active scalar field is available or not.
virtual bool hasColors() const
Returns whether colors are enabled or not.
virtual bool normalsShown() const
Returns whether normals are shown or not.
virtual bool hasNormals() const
Returns whether normals are enabled or not.
virtual bool hasScalarFields() const
Returns whether one or more scalar fields are instantiated.
Generic mesh interface.
virtual TextureCoordsContainer * getTexCoordinatesTable() const =0
Returns per-triangle texture coordinates array.
virtual bool hasTextures() const =0
Returns whether textures are available for this mesh.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
virtual void getTriangleNormalIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const =0
Returns a triplet of normal indexes for a given triangle (if any)
virtual bool hasPerTriangleTexCoordIndexes() const =0
Returns whether this mesh as per-triangle triplets of tex coords indexes.
virtual void getTriangleTexCoordinatesIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const =0
Returns the triplet of tex coords indexes for a given triangle.
virtual const ccMaterialSet * getMaterialSet() const =0
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
virtual bool getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const =0
Returns a given triangle normal.
virtual bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N)=0
Interpolates normal(s) inside a given triangle.
virtual int getTriangleMtlIndex(unsigned triangleIndex) const =0
Returns a given triangle material indexes.
short minimumFileVersion_MeOnly() const override
virtual ccGenericPointCloud * getAssociatedCloud() const =0
Returns the vertices cloud.
virtual bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C)=0
Interpolates RGB colors inside a given triangle.
virtual bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &C, bool returnColorIfNoTexture)=0
virtual void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const =0
Returns per-triangle texture coordinates (pointer to)
virtual NormsIndexesTableType * getTriNormsTable() const =0
Returns per-triangle normals shared array.
virtual void getTexCoordinates(unsigned index, TexCoords2D *&tx) const =0
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
virtual unsigned capacity() const =0
Returns max capacity.
virtual void refreshBB()=0
Forces bounding-box update.
virtual bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture)=0
virtual bool hasMaterials() const =0
A 3D cloud interface with associated features (color, normals, octree, etc.)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
virtual void onUpdateOf(ccHObject *obj)
This method is called when another object (geometry) is updated.
Definition: ecvHObject.h:706
virtual ccBBox getOwnBB(bool withGLFeatures=false)
Returns the entity's own bounding-box.
Definition: ecvHObject.cpp:757
Mesh (triangle) material.
Triangular mesh.
Definition: ecvMesh.h:35
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
A sub-mesh.
Definition: ecvSubMesh.h:19
CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvSubMesh.h:27
std::vector< unsigned int > IndexMap
Indexes map for createNewSubMeshFromSelection.
Definition: ecvSubMesh.h:175
ccBBox m_bBox
Bounding-box.
Definition: ecvSubMesh.h:229
const ccMesh * getAssociatedMesh() const
Returns the associated mesh (const version)
Definition: ecvSubMesh.h:165
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvSubMesh.h:31
unsigned getTriGlobalIndex(unsigned localIndex) const
Definition: ecvSubMesh.h:116
unsigned size() const override
Returns the number of triangles.
Definition: ecvSubMesh.h:85
void placeIteratorAtBeginning() override
Places the mesh iterator at the beginning.
Definition: ecvSubMesh.h:89
ReferencesContainer m_triIndexes
Indexes of (some of) the associated mesh triangles.
Definition: ecvSubMesh.h:223
ccMesh * m_associatedMesh
Associated mesh.
Definition: ecvSubMesh.h:217
void forwardIterator()
Forwards the local element iterator.
Definition: ecvSubMesh.h:127
std::vector< unsigned int > ReferencesContainer
Container of 3D triangles indexes.
Definition: ecvSubMesh.h:220
unsigned getCurrentTriGlobalIndex() const
Returns the global index of the triangle pointed by the current element.
Definition: ecvSubMesh.h:121
unsigned m_globalIterator
Iterator on the triangles references container.
Definition: ecvSubMesh.h:226
ccMesh * getAssociatedMesh()
Returns the associated mesh.
Definition: ecvSubMesh.h:162
~ccSubMesh() override=default
Destructor.
virtual bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N)
Interpolates normal(s) inside a given triangle.
virtual GenericTriangle * _getTriangle(unsigned triangleIndex)=0
Returns the ith triangle.
virtual VerticesIndexes * getNextTriangleVertIndexes()=0
virtual VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex)=0
Returns the indexes of the vertices of a given triangle.
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const =0
Returns the vertices of a given triangle.
virtual unsigned size() const =0
Returns the number of triangles.
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax)=0
Returns the mesh bounding-box.
virtual GenericTriangle * _getNextTriangle()=0
Returns the next triangle (relatively to the global iterator position)
virtual void forEach(genericTriangleAction action)=0
Fast iteration mechanism.
A generic triangle interface.
RGB color structure.
Definition: ecvColorTypes.h:49
normal_z rgb
@ SUB_MESH
Definition: CVTypes.h:106
2D texture coordinates
Triangle described by the indexes of its 3 vertices.