Class CMesh3D

Inheritance Relationships

Base Types

Class Documentation

class CMesh3D : public virtual mrpt::viz::CVisualObject, public mrpt::viz::VisualObjectParams_Lines, public mrpt::viz::VisualObjectParams_Triangles

A 3D mesh composed of triangles and/or quads. A typical usage example would be a 3D model of an object.

../../output_staging/generated/doxygen/xml/preview_CMesh3D.png

See also

opengl::Scene,opengl::CMesh,opengl::CAssimpModel

Public Functions

CMesh3D() = default
virtual ~CMesh3D() override
inline void enableShowEdges(bool v)
inline void enableShowFaces(bool v)
inline void enableShowVertices(bool v)
inline void enableFaceNormals(bool v)
void loadMesh(unsigned int num_verts, unsigned int num_faces, int *verts_per_face, int *face_verts, float *vert_coords)

Load a 3D mesh. The arguments indicate:

  • num_verts: Number of vertices of the mesh

  • num_faces: Number of faces of the mesh

  • verts_per_face: An array (pointer) with the number of vertices of each face. The elements must be set either to 3 (triangle) or 4 (quad).

  • face_verts: An array (pointer) with the vertices of each face. The vertices of each face must be consecutive in this array.

  • vert_coords: An array (pointer) with the coordinates of each vertex. The xyz coordinates of each vertex must be consecutive in this array.

void loadMesh(unsigned int num_verts, unsigned int num_faces, const mrpt::math::CMatrixDynamic<bool> &is_quad, const mrpt::math::CMatrixDynamic<int> &face_verts, const mrpt::math::CMatrixDynamic<float> &vert_coords)

Load a 3D mesh. The arguments indicate:

  • num_verts: Number of vertices of the mesh

  • num_faces: Number of faces of the mesh

  • is_quad: A binary array saying whether the face is a quad (1) or a triangle (0)

  • face_verts: An array with the vertices of each face. For every column (face), each row contains the num of a vertex. The fourth does not need to be filled if the face is a triangle.

  • vert_coords: An array with the coordinates of each vertex. For every column (vertex), each row contains the xyz coordinates of the vertex.

inline void setEdgeColor(float r, float g, float b, float a = 1.f)
inline void setFaceColor(float r, float g, float b, float a = 1.f)
inline void setVertColor(float r, float g, float b, float a = 1.f)
virtual void updateBuffers() const override

Called by the rendering system to update internal geometry buffers.

Derived classes should override this to populate their data buffers (triangles, points, lines) when the object geometry changes.

This is called automatically when hasToUpdateBuffers() returns true, which happens after notifyChange() was called.

The base implementation does nothing; derived classes should override.

Note

Thread safety: implementations should lock the appropriate mutexes when writing to shared buffers.

virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const override

Must be implemented by derived classes to provide the updated bounding box in the object local frame of coordinates. This will be called only once after each time the derived class reports to notifyChange() that the object geometry changed.

See also

getBoundingBox(), getBoundingBoxLocal(), getBoundingBoxLocalf()

Protected Types

using vertex_indices_t = mrpt::math::CMatrixFixed<uint32_t, 1, 4>

Protected Attributes

bool m_showEdges = true
bool m_showFaces = true
bool m_showVertices = false
bool m_computeNormals = true
std::vector<bool> m_is_quad

Pointer storing whether a face is a quad (1) or a triangle (0)

std::vector<vertex_indices_t> m_face_verts

Pointer storing the vertices that compose each face. Size: 4 x num_faces (4 for the possible max number - quad)

std::vector<mrpt::math::TPoint3Df> m_vertices

Pointer storing the coordinates of the vertices. Size: 3 x num_vertices

std::vector<mrpt::math::TPoint3Df> m_normals

Pointer storing the face normals. Size: 3 x num_faces

mrpt::img::TColorf edge_color = {.9f, .9f, .9f, 1.0f}

Color of the edges

mrpt::img::TColorf face_color = {.7f, .7f, .8f, 1.0f}

Color of the faces

mrpt::img::TColorf vert_color = {.3f, .3f, .3f, 1.0f}

Color of the vertices