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 };
TexCoords2D
2D texture coordinates
Definition: ecvAdvancedTypes.h:138
ccSubMesh
A sub-mesh.
Definition: ecvSubMesh.h:19
ccSubMesh::IndexMap
std::vector< unsigned int > IndexMap
Indexes map for createNewSubMeshFromSelection.
Definition: ecvSubMesh.h:175
rgb
normal_z rgb
Definition: my_point_types.h:168
ccSerializableObject::LoadedIDMap
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
Definition: ecvSerializableObject.h:61
ccGenericMesh::getTriangleTexCoordinatesIndexes
virtual void getTriangleTexCoordinatesIndexes(unsigned triangleIndex, int &i1, int &i2, int &i3) const =0
Returns the triplet of tex coords indexes for a given triangle.
ccSubMesh::size
unsigned size() const override
Returns the number of triangles.
Definition: ecvSubMesh.h:85
ccGenericMesh::getTriangleNormals
virtual bool getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const =0
Returns a given triangle normal.
ccSubMesh::m_globalIterator
unsigned m_globalIterator
Iterator on the triangles references container.
Definition: ecvSubMesh.h:226
ccHObject::onUpdateOf
virtual void onUpdateOf(ccHObject *obj)
This method is called when another object (geometry) is updated.
Definition: ecvHObject.h:706
cloudViewer::GenericMesh::size
virtual unsigned size() const =0
Returns the number of triangles.
ccDrawableObject::normalsShown
virtual bool normalsShown() const
Returns whether normals are shown or not.
Definition: ecvDrawableObject.h:91
ccGenericMesh::hasTriNormals
virtual bool hasTriNormals() const =0
Returns whether the mesh has per-triangle normals.
ccGenericMesh::getTriangleMtlIndex
virtual int getTriangleMtlIndex(unsigned triangleIndex) const =0
Returns a given triangle material indexes.
cloudViewer::VerticesIndexes
Triangle described by the indexes of its 3 vertices.
Definition: GenericIndexedMesh.h:16
ccGenericMesh::hasPerTriangleTexCoordIndexes
virtual bool hasPerTriangleTexCoordIndexes() const =0
Returns whether this mesh as per-triangle triplets of tex coords indexes.
ccGenericMesh::getTexCoordinatesTable
virtual TextureCoordsContainer * getTexCoordinatesTable() const =0
Returns per-triangle texture coordinates array.
ccGenericMesh::getMaterialSet
virtual const ccMaterialSet * getMaterialSet() const =0
ccBBox
Bounding box structure.
Definition: ecvBBox.h:25
ccGenericMesh::getTexCoordinates
virtual void getTexCoordinates(unsigned index, TexCoords2D *&tx) const =0
ccGenericMesh::getAssociatedCloud
virtual ccGenericPointCloud * getAssociatedCloud() const =0
Returns the vertices cloud.
ecvBBox.h
ccSubMesh::m_associatedMesh
ccMesh * m_associatedMesh
Associated mesh.
Definition: ecvSubMesh.h:217
ccGenericMesh::getTriangleTexCoordinates
virtual void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const =0
Returns per-triangle texture coordinates (pointer to)
ccGenericMesh::toFile_MeOnly
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
Definition: ecvGenericMesh.cpp:253
ccGenericMesh::hasTextures
virtual bool hasTextures() const =0
Returns whether textures are available for this mesh.
ccGenericMesh::hasMaterials
virtual bool hasMaterials() const =0
ecvGenericMesh.h
ccDrawableObject::hasScalarFields
virtual bool hasScalarFields() const
Returns whether one or more scalar fields are instantiated.
Definition: ecvDrawableObject.h:105
ccDrawableObject::hasNormals
virtual bool hasNormals() const
Returns whether normals are enabled or not.
Definition: ecvDrawableObject.h:89
NormsIndexesTableType
Array of compressed 3D normals (single index)
Definition: ecvAdvancedTypes.h:21
CV_CLASS_ENUM
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
cloudViewer::GenericIndexedMesh::getTriangleVertices
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const =0
Returns the vertices of a given triangle.
ccGenericMesh::interpolateNormalsBC
virtual bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N)=0
Interpolates normal(s) inside a given triangle.
cloudViewer::GenericMesh::forEach
virtual void forEach(genericTriangleAction action)=0
Fast iteration mechanism.
ccSubMesh::ReferencesContainer
std::vector< unsigned int > ReferencesContainer
Container of 3D triangles indexes.
Definition: ecvSubMesh.h:220
ccSubMesh::getClassID
CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvSubMesh.h:27
ccGenericPointCloud
A 3D cloud interface with associated features (color, normals, octree, etc.)
Definition: ecvGenericPointCloud.h:45
Vector3Tpl< double >
cloudViewer::GenericIndexedMesh::getNextTriangleVertIndexes
virtual VerticesIndexes * getNextTriangleVertIndexes()=0
ccSubMesh::forwardIterator
void forwardIterator()
Forwards the local element iterator.
Definition: ecvSubMesh.h:127
cloudViewer::GenericMesh::_getNextTriangle
virtual GenericTriangle * _getNextTriangle()=0
Returns the next triangle (relatively to the global iterator position)
cloudViewer::GenericIndexedMesh::interpolateNormals
virtual bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N)
Interpolates normal(s) inside a given triangle.
Definition: GenericIndexedMesh.h:89
ccDrawableObject::hasDisplayedScalarField
virtual bool hasDisplayedScalarField() const
Returns whether an active scalar field is available or not.
Definition: ecvDrawableObject.h:99
ccGenericMesh::minimumFileVersion_MeOnly
short minimumFileVersion_MeOnly() const override
Definition: ecvGenericMesh.cpp:289
ccSubMesh::getTriGlobalIndex
unsigned getTriGlobalIndex(unsigned localIndex) const
Definition: ecvSubMesh.h:116
ccGenericMesh
Generic mesh interface.
Definition: ecvGenericMesh.h:28
ccSubMesh::m_bBox
ccBBox m_bBox
Bounding-box.
Definition: ecvSubMesh.h:229
TextureCoordsContainer
Array of 2D texture coordinates.
Definition: ecvAdvancedTypes.h:151
ccGenericMesh::interpolateColors
virtual bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C)=0
Interpolates RGB colors inside a given triangle.
ccSubMesh::isSerializable
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvSubMesh.h:31
ccGenericMesh::fromFile_MeOnly
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
Definition: ecvGenericMesh.cpp:294
cloudViewer::GenericIndexedMesh::getTriangleVertIndexes
virtual VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex)=0
Returns the indexes of the vertices of a given triangle.
ccSubMesh::getAssociatedMesh
ccMesh * getAssociatedMesh()
Returns the associated mesh.
Definition: ecvSubMesh.h:162
cloudViewer::GenericMesh::getBoundingBox
virtual void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax)=0
Returns the mesh bounding-box.
ccGenericMesh::refreshBB
virtual void refreshBB()=0
Forces bounding-box update.
ccSubMesh::getAssociatedMesh
const ccMesh * getAssociatedMesh() const
Returns the associated mesh (const version)
Definition: ecvSubMesh.h:165
ccGenericMesh::getTriNormsTable
virtual NormsIndexesTableType * getTriNormsTable() const =0
Returns per-triangle normals shared array.
CV_TYPES::SUB_MESH
@ SUB_MESH
Definition: CVTypes.h:106
cloudViewer::GenericIndexedMesh::_getTriangle
virtual GenericTriangle * _getTriangle(unsigned triangleIndex)=0
Returns the ith triangle.
ecvColor::RgbTpl
RGB color structure.
Definition: ecvColorTypes.h:49
ccMesh
Triangular mesh.
Definition: ecvMesh.h:35
ccDrawableObject::hasColors
virtual bool hasColors() const
Returns whether colors are enabled or not.
Definition: ecvDrawableObject.h:80
ccMaterialSet
Mesh (triangle) material.
Definition: ecvMaterialSet.h:16
ccGenericMesh::capacity
virtual unsigned capacity() const =0
Returns max capacity.
ccHObject
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
ccHObject::getOwnBB
virtual ccBBox getOwnBB(bool withGLFeatures=false)
Returns the entity's own bounding-box.
Definition: ecvHObject.cpp:757
ccGenericMesh::getTriangleNormalIndexes
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)
CV_DB_LIB_API
#define CV_DB_LIB_API
Definition: CV_db.h:15
ccGenericMesh::getColorFromMaterial
virtual bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture)=0
ccGenericMesh::getVertexColorFromMaterial
virtual bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &C, bool returnColorIfNoTexture)=0
ccSubMesh::placeIteratorAtBeginning
void placeIteratorAtBeginning() override
Places the mesh iterator at the beginning.
Definition: ecvSubMesh.h:89
ccSubMesh::getCurrentTriGlobalIndex
unsigned getCurrentTriGlobalIndex() const
Returns the global index of the triangle pointed by the current element.
Definition: ecvSubMesh.h:121
cloudViewer::GenericTriangle
A generic triangle interface.
Definition: GenericTriangle.h:18
ccSubMesh::m_triIndexes
ReferencesContainer m_triIndexes
Indexes of (some of) the associated mesh triangles.
Definition: ecvSubMesh.h:223