Class CMesh

Nested Relationships

Nested Types

Inheritance Relationships

Base Types

Class Documentation

class CMesh : public virtual mrpt::viz::CVisualObject, public mrpt::viz::VisualObjectParams_TexturedTriangles, public mrpt::viz::VisualObjectParams_Lines

A planar (XY) grid where each cell has an associated height and, optionally, a texture map. A typical usage example would be an elevation map or a 3D model of a terrain.

The height of each cell/pixel is provided via an elevation Z matrix, where the z coordinate of the grid cell (x,y) is given by Z(x,y) (not Z(y,x)!!), that is:

  • Z column count = number of cells in direction “+y”

  • Z row count = number of cells in direction “+x”

Since MRPT 2.7.0, the texture can be wrapped over the mesh using setMeshTextureExtension().

../../output_staging/generated/doxygen/xml/preview_CMesh.png

See also

opengl::Scene

Public Functions

CMesh(bool enableTransparency = false, float xMin = -1.0f, float xMax = 1.0f, float yMin = -1.0f, float yMax = 1.0f)
virtual ~CMesh() override
template<typename T>
inline void setGridLimits(T xMin, T xMax, T yMin, T yMax)
inline void getGridLimits(float &xMin, float &xMax, float &yMin, float &yMax) const
inline void setMeshTextureExtension(float textureSize_x, float textureSize_y)

Sets the texture physical size (in “meters) using to wrap it over the mesh extension. The default (0) means texture size is equal to whole grid extension.

inline void getMeshTextureExtension(float &textureSize_x, float &textureSize_y) const
inline void enableTransparency(bool v)
inline void enableWireFrame(bool v)
inline void enableColorFromZ(bool v, mrpt::img::TColormap colorMap = mrpt::img::cmHOT)
void setZ(const mrpt::math::CMatrixDynamic<float> &in_Z)

This method sets the matrix of heights for each position (cell) in the mesh grid

inline void getZ(mrpt::math::CMatrixFloat &out) const

Returns a reference to the internal Z matrix, allowing changing it efficiently

inline void getMask(mrpt::math::CMatrixFloat &out) const

Returns a reference to the internal mask matrix, allowing changing it efficiently

void setMask(const mrpt::math::CMatrixDynamic<float> &in_mask)

This method sets the boolean mask of valid heights for each position (cell) in the mesh grid

inline float getxMin() const
inline float getxMax() const
inline float getyMin() const
inline float getyMax() const
inline void setxMin(const float nxm)
inline void setxMax(const float nxm)
inline void setyMin(const float nym)
inline void setyMax(const float nym)
inline void getXBounds(float &min, float &max) const
inline void getYBounds(float &min, float &max) const
inline void setXBounds(const float min, const float max)
inline void setYBounds(const float min, const float max)
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()

void assignImage(const mrpt::img::CImage &img)

Assigns a texture image.

void assignImageAndZ(const mrpt::img::CImage &img, const mrpt::math::CMatrixDynamic<float> &in_Z)

Assigns a texture image and Z simultaneously, and disable transparency.

void adjustGridToImageAR()

Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the Y direction.

virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override

Trace ray

Protected Functions

void updateColorsMatrix() const

Called internally to assure C is updated.

void updateTriangles() const

Called internally to assure the triangle list is updated.

void updatePolygons() const

Protected Attributes

bool m_enableTransparency
bool m_colorFromZ = {false}
bool m_isWireFrame = {false}
bool m_isImage = {false}
math::CMatrixF Z = {0, 0}

Z(x,y): Z-coordinate of the point (x,y)

math::CMatrixF mask = {0, 0}
mutable math::CMatrixF C = {0, 0}

Grayscale Color [0,1] for each cell, updated by updateColorsMatrix

mutable mrpt::math::CMatrixFloat C_r = {0, 0}

Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix

mutable mrpt::math::CMatrixFloat C_g = {0, 0}

Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix

mutable mrpt::math::CMatrixFloat C_b = {0, 0}

Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix

mrpt::img::TColormap m_colorMap = {mrpt::img::cmHOT}

Used when m_colorFromZ is true

mutable bool m_modified_Z = {true}

Whether C is not up-to-date wrt to Z

mutable bool m_modified_Image = {false}

Whether C is not up-to-date wrt to the texture image

float m_xMin

Mesh bounds

float m_xMax
float m_yMin
float m_yMax
float m_textureSize_x = 0

Texture wrap physical size (in “meters). 0=texture size equal to whole grid extension.

float m_textureSize_y = 0
mutable float m_zMin = 0
float m_zMax = 0

Updated in updateTriangles()

mutable mrpt::containers::NonCopiableData<std::shared_mutex> m_meshDataMtx
mutable std::vector<std::pair<mrpt::viz::TTriangle, TTriangleVertexIndices>> actualMesh

List of triangles in the mesh

mutable std::vector<std::pair<mrpt::math::TPoint3D, size_t>> vertex_normals

The accumulated normals & counts for each vertex, so normals can be averaged.

mutable bool m_trianglesUpToDate = {false}

Whether the actual mesh needs to be recalculated

mutable bool m_polygonsUpToDate = {false}

Whether the polygon mesh (auxiliary structure for ray tracing) needs to be recalculated

mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolys
struct TTriangleVertexIndices

Public Members

size_t vind[3] = {0, 0, 0}