26 m_associatedMesh(nullptr),
37 bool unlinkPreviousOne ) {
121 bool interpolateColorIfNoTexture) {
125 interpolateColorIfNoTexture);
133 unsigned char vertIndex,
135 bool returnColorIfNoTexture) {
139 returnColorIfNoTexture);
204 if (verticesVisibility.size() < vertices->
size()) {
205 CVLog::Error(QString(
"[Sub-mesh %1] Internal error: vertex visibility "
206 "table not instantiated!")
213 size_t visibleFaces = 0;
228 if (visibleFaces == 0) {
232 globalIndex = indexMap->at(globalIndex);
241 "[ccSubMesh::createNewSubMeshFromSelection] Not enough "
248 unsigned lastTri = 0;
249 for (
size_t i = 0; i < triNum; ++i) {
255 globalIndex = indexMap->at(globalIndex);
262 }
else if (removeSelectedFaces)
266 assert(lastTri <= i);
272 if (removeSelectedFaces && lastTri < triNum) {
279 if (newSubMesh->
size()) {
292 newSubMesh =
nullptr;
299 bool removeSelectedTriangles,
300 const std::vector<int>& selectedTriangleIndexes,
301 IndexMap* newRemainingTriangleIndexes ) {
307 CVLog::Error(QString(
"[Sub-mesh %1] Internal error: input triangle "
308 "indexes vector size is invalid")
314 size_t selectedTriangleCount = 0;
318 if (selectedTriangleIndexes[globalIndex] >= 0) {
319 ++selectedTriangleCount;
325 if (selectedTriangleCount == 0) {
326 if (newRemainingTriangleIndexes)
330 globalIndex = newRemainingTriangleIndexes->at(globalIndex);
339 "[ccSubMesh::createNewSubMeshFromSelection] Not enough "
348 unsigned lastTriIndex = 0;
349 for (
size_t i = 0; i < triCount; ++i) {
355 if (selectedTriangleIndexes[globalIndex] >= 0) {
357 selectedTriangleIndexes[globalIndex]));
358 }
else if (removeSelectedTriangles)
362 assert(lastTriIndex <= i);
364 newRemainingTriangleIndexes
365 ? newRemainingTriangleIndexes->at(globalIndex)
371 if (removeSelectedTriangles && lastTriIndex < triCount) {
378 if (newSubMesh->
size() != 0) {
390 newSubMesh =
nullptr;
400 #define CC_SUB_MESH_TRANSIENT_CONST_TEST(method) \
401 bool ccSubMesh::method() const { \
402 return m_associatedMesh ? m_associatedMesh->method() : false; \
443 tx1 = tx2 = tx3 =
nullptr;
502 }
catch (
const std::bad_alloc&) {
513 if (firstIndex >= lastIndex) {
518 unsigned range = lastIndex - firstIndex;
522 }
catch (
const std::bad_alloc&) {
527 for (
unsigned i = firstIndex; i < lastIndex; ++i) {
537 assert(localIndex <
size());
545 }
catch (
const std::bad_alloc&) {
555 }
catch (
const std::bad_alloc&) {
602 assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
603 if (dataVersion < 29) {
614 uint32_t meshUniqueID =
618 if (out.write((
const char*)&meshUniqueID, 4) < 0)
return WriteError();
621 if (!ccSerializationHelper::GenericArrayToFile<unsigned, 1, unsigned>(
630 std::max(
static_cast<short>(29),
646 uint32_t meshUniqueID = 0;
647 if (in.read((
char*)&meshUniqueID, 4) < 0)
return ReadError();
653 if (!ccSerializationHelper::GenericArrayFromFile<unsigned, 1, unsigned>(
constexpr unsigned char POINT_VISIBLE
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Array of compressed 3D normals (single index)
Array of 2D texture coordinates.
virtual bool colorsShown() const
Returns whether colors are shown or not.
virtual bool sfShown() const
Returns whether active scalar field is visible.
virtual bool normalsShown() const
Returns whether normals are shown or not.
virtual void showColors(bool state)
Sets colors visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
virtual bool materialsShown() const
Sets whether textures/material should be displayed or not.
void showNormals(bool state) override
Sets normals visibility.
virtual void showWired(bool state)
Sets whether mesh should be displayed as a wire or with plain facets.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
virtual bool triNormsShown() const
Returns whether per-triangle normals are shown or not.
virtual bool isShownAsWire() const
Returns whether the mesh is displayed as wired or with plain facets.
short minimumFileVersion_MeOnly() const override
void enableStippling(bool state)
Enables polygon stippling.
virtual void showMaterials(bool state)
Sets whether textures should be displayed or not.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
virtual bool stipplingEnabled() const
Returns whether polygon stippling is enabled or not.
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual VisibilityTableType & getTheVisibilityArray()
Returns associated visibility array.
std::vector< unsigned char > VisibilityTableType
Array of "visibility" information for each point.
Hierarchical CLOUDVIEWER Object.
virtual void notifyGeometryUpdate()
void removeDependencyWith(ccHObject *otherObject)
Removes any dependency flags with a given object.
void addDependency(ccHObject *otherObject, int flags, bool additive=true)
Adds a new dependence (additive or not)
@ DP_NOTIFY_OTHER_ON_UPDATE
Mesh (triangle) material.
bool interpolateNormalsBC(unsigned triIndex, const CCVector3d &w, CCVector3 &N) override
Interpolates normal(s) inside 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.
const ccMaterialSet * getMaterialSet() const override
TextureCoordsContainer * getTexCoordinatesTable() const override
Returns per-triangle texture coordinates array.
NormsIndexesTableType * getTriNormsTable() const override
Returns per-triangle normals shared array.
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 getTriangleNormals(unsigned triangleIndex, CCVector3 &Na, CCVector3 &Nb, CCVector3 &Nc) const override
Returns a given triangle normal.
bool normalsShown() const override
Returns whether normals are shown or not.
virtual unsigned size() const override
Returns the number of triangles.
void getTriangleTexCoordinates(unsigned triIndex, TexCoords2D *&tx1, TexCoords2D *&tx2, TexCoords2D *&tx3) const override
Returns per-triangle texture coordinates (pointer to)
bool getColorFromMaterial(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C, bool interpolateColorIfNoTexture) override
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const override
Returns the vertices of a given triangle.
bool hasPerTriangleTexCoordIndexes() const override
Returns whether this mesh as per-triangle triplets of tex coords indexes.
bool interpolateNormals(unsigned triIndex, const CCVector3 &P, CCVector3 &N) override
Interpolates normal(s) inside a given triangle.
void getTexCoordinates(unsigned index, TexCoords2D *&tx) const override
bool getVertexColorFromMaterial(unsigned triIndex, unsigned char vertIndex, ecvColor::Rgb &C, bool returnColorIfNoTexture) override
int getTriangleMtlIndex(unsigned triangleIndex) const override
Returns a given triangle material indexes.
cloudViewer::GenericTriangle * _getTriangle(unsigned triangleIndex) override
Returns the ith triangle.
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
bool interpolateColors(unsigned triIndex, const CCVector3 &P, ecvColor::Rgb &C) override
Interpolates RGB colors inside a given triangle.
virtual QString getName() const
Returns object name.
virtual unsigned getUniqueID() const
Returns object unique ID.
virtual void setName(const QString &name)
Sets object name.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
static bool ReadError()
Sends a custom error message (read error) and returns 'false'.
static bool WriteError()
Sends a custom error message (write error) and returns 'false'.
static short GenericArrayToFileMinVersion()
Returns the minimum file version to save/load a 'generic array'.
void setAssociatedMesh(ccMesh *mesh, bool unlinkPreviousOne=true)
Sets the associated mesh.
void forEach(genericTriangleAction action) override
Fast iteration mechanism.
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.
NormsIndexesTableType * getTriNormsTable() const override
Returns per-triangle normals shared array.
cloudViewer::VerticesIndexes * getNextTriangleVertIndexes() override
const ccMaterialSet * getMaterialSet() const override
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.
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 fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
void clear(bool releaseMemory)
Clears the mesh.
void getBoundingBox(CCVector3 &bbMin, CCVector3 &bbMax) override
Returns the mesh bounding-box.
cloudViewer::GenericTriangle * _getTriangle(unsigned index) override
Returns the ith triangle.
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.
ccBBox m_bBox
Bounding-box.
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.
TextureCoordsContainer * getTexCoordinatesTable() const override
Returns per-triangle texture coordinates array.
unsigned getTriGlobalIndex(unsigned localIndex) const
virtual void getTriangleVertices(unsigned triangleIndex, CCVector3 &A, CCVector3 &B, CCVector3 &C) const override
Returns the vertices of a given triangle.
ccSubMesh * createNewSubMeshFromSelection(bool removeSelectedTriangles, const std::vector< int > &selectedTriangleIndexes, IndexMap *newRemainingTriangleIndexes=nullptr)
Creates a new sub mesh with the visible vertices only.
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
cloudViewer::GenericTriangle * _getNextTriangle() override
Returns the next triangle (relatively to the global iterator position)
unsigned size() const override
Returns the number of triangles.
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.
ReferencesContainer m_triIndexes
Indexes of (some of) the associated mesh triangles.
ccMesh * m_associatedMesh
Associated mesh.
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
bool resize(size_t n)
Presets the size of the vector used to store triangle references.
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.
void setTriangleIndex(unsigned localIndex, unsigned globalIndex)
Sets global index for a given element.
unsigned m_globalIterator
Iterator on the triangles references container.
bool addTriangleIndex(unsigned globalIndex)
Triangle global index insertion mechanism.
unsigned capacity() const override
Returns max capacity.
cloudViewer::VerticesIndexes * getTriangleVertIndexes(unsigned triangleIndex) override
Returns the indexes of the vertices of a given triangle.
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
void setValidity(bool state)
Sets bonding box validity.
void clear()
Resets the bounding box.
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
bool isValid() const
Returns whether bounding box is valid or not.
void add(const Vector3Tpl< T > &P)
'Enlarges' the bounding box with a point
virtual unsigned size() const =0
Returns the number of points.
std::function< void(GenericTriangle &)> genericTriangleAction
Generic function to apply to a triangle (used by foreach)
A generic triangle interface.
virtual const CCVector3 * _getA() const =0
Returns the first vertex (A)
virtual const CCVector3 * _getC() const =0
Returns the third vertex (C)
virtual const CCVector3 * _getB() const =0
Returns the second vertex (B)
#define CC_SUB_MESH_TRANSIENT_CONST_TEST(method)
Triangle described by the indexes of its 3 vertices.