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)
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,
44  ecvColor::Rgb& rgb,
45  bool interpolateColorIfNoTexture) override;
46  bool getVertexColorFromMaterial(unsigned triIndex,
47  unsigned char vertIndex,
48  ecvColor::Rgb& rgb,
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;
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 
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
Generic mesh interface.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
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
bool hasScalarFields() const override
Returns whether one or more scalar fields are instantiated.
void setAssociatedMesh(ccMesh *mesh, bool unlinkPreviousOne=true)
Sets the associated mesh.
void forEach(genericTriangleAction action) override
Fast iteration mechanism.
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const override
Returns the vertices of a given triangle.
void getTriangleTexCoordinatesIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const override
Returns the triplet of tex coords indexes for a given triangle.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
TextureCoordsContainer * getTexCoordinatesTable() const override
Returns per-triangle texture coordinates array.
ccSubMesh * createNewSubMeshFromSelection(bool removeSelectedFaces, IndexMap *indexMap=nullptr)
Creates a new sub mesh with the selected vertices only.
bool getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const override
Returns a given triangle normal.
bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &rgb, bool interpolateColorIfNoTexture) override
ccSubMesh(ccMesh *parentMesh)
Default constructor.
CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvSubMesh.h:27
bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &rgb, bool returnColorIfNoTexture) override
void getTriangleNormalIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const override
Returns a triplet of normal indexes for a given triangle (if any)
bool hasTriNormals() const override
Returns whether the mesh has per-triangle normals.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
cloudViewer::GenericTriangle * _getNextTriangle() override
Returns the next triangle (relatively to the global iterator position)
void clear(bool releaseMemory)
Clears the mesh.
ccSubMesh * createNewSubMeshFromSelection(bool removeSelectedTriangles, const std::vector< int > &selectedTriangleIndexes, IndexMap *newRemainingTriangleIndexes=nullptr)
Creates a new sub mesh with the visible vertices only.
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the mesh bounding-box.
bool hasPerTriangleTexCoordIndexes() const override
Returns whether this mesh as per-triangle triplets of tex coords indexes.
std::vector< unsigned int > IndexMap
Indexes map for createNewSubMeshFromSelection.
Definition: ecvSubMesh.h:175
bool addTriangleIndex(unsigned firstIndex, unsigned lastIndex)
Triangle global index insertion mechanism (range)
ccBBox m_bBox
Bounding-box.
Definition: ecvSubMesh.h:229
void refreshBB() override
Forces bounding-box update.
bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N) override
Interpolates normal(s) inside a given triangle.
bool normalsShown() const override
Returns whether normals are shown or not.
bool hasNormals() const override
Returns whether normals are enabled or not.
const ccMesh * getAssociatedMesh() const
Returns the associated mesh (const version)
Definition: ecvSubMesh.h:165
virtual void getTriangleVertices(unsigned triangleIndex, double A[3], double B[3], double C[3]) const override
bool hasDisplayedScalarField() const override
Returns whether an active scalar field is available or not.
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvSubMesh.h:31
cloudViewer::GenericTriangle * _getTriangle(unsigned index) override
Returns the ith triangle.
unsigned getTriGlobalIndex(unsigned localIndex) const
Definition: ecvSubMesh.h:116
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
NormsIndexesTableType * getTriNormsTable() const override
Returns per-triangle normals shared array.
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
unsigned size() const override
Returns the number of triangles.
Definition: ecvSubMesh.h:85
bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &rgb) override
Interpolates RGB colors inside a given triangle.
int getTriangleMtlIndex(unsigned triangleIndex) const override
Returns a given triangle material indexes.
void onUpdateOf(ccHObject *obj) override
This method is called when another object (geometry) is updated.
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 getTexCoordinates(unsigned index, TexCoords2D *&tx) const override
void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const override
Returns per-triangle texture coordinates (pointer to)
short minimumFileVersion_MeOnly() const override
void forwardIterator()
Forwards the local element iterator.
Definition: ecvSubMesh.h:127
bool resize(size_t n)
Presets the size of the vector used to store triangle references.
std::vector< unsigned int > ReferencesContainer
Container of 3D triangles indexes.
Definition: ecvSubMesh.h:220
bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N) override
Interpolates normal(s) inside a given triangle.
bool reserve(size_t n)
Reserves some memory for hosting the triangle references.
unsigned getCurrentTriGlobalIndex() const
Returns the global index of the triangle pointed by the current element.
Definition: ecvSubMesh.h:121
bool hasColors() const override
Returns whether colors are enabled or not.
cloudViewer::VerticesIndexes * getNextTriangleVertIndexes() override
bool hasTextures() const override
Returns whether textures are available for this mesh.
void setTriangleIndex(unsigned localIndex, unsigned globalIndex)
Sets global index for a given element.
unsigned m_globalIterator
Iterator on the triangles references container.
Definition: ecvSubMesh.h:226
bool addTriangleIndex(unsigned globalIndex)
Triangle global index insertion mechanism.
ccMesh * getAssociatedMesh()
Returns the associated mesh.
Definition: ecvSubMesh.h:162
~ccSubMesh() override=default
Destructor.
unsigned capacity() const override
Returns max capacity.
bool hasMaterials() const override
const ccMaterialSet * getMaterialSet() const override
virtual unsigned size() const =0
Returns the number of triangles.
std::function< void(GenericTriangle &)> genericTriangleAction
Generic function to apply to a triangle (used by foreach)
Definition: GenericMesh.h:53
A generic triangle interface.
RGB color structure.
Definition: ecvColorTypes.h:49
@ SUB_MESH
Definition: CVTypes.h:106
2D texture coordinates
Triangle described by the indexes of its 3 vertices.