class mrpt::viz::CMesh

Overview

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().

mrpt::viz::CMesh

See also:

opengl::Scene

#include <mrpt/viz/CMesh.h>

class CMesh:
    public mrpt::viz::CVisualObject,
    public mrpt::viz::VisualObjectParams_TexturedTriangles,
    public mrpt::viz::VisualObjectParams_Lines
{
public:
    // typedefs

    typedef std::shared_ptr<mrpt::viz ::CMesh> Ptr;
    typedef std::shared_ptr<const mrpt::viz ::CMesh> ConstPtr;
    typedef std::unique_ptr<mrpt::viz ::CMesh> UniquePtr;
    typedef std::unique_ptr<const mrpt::viz ::CMesh> ConstUniquePtr;

    // structs

    struct TTriangleVertexIndices;

    // fields

    static constexpr const char* className = "mrpt::viz" "::" "CMesh";

    // construction

    CMesh(
        bool enableTransparency = false,
        float xMin = -1.0f,
        float xMax = 1.0f,
        float yMin = -1.0f,
        float yMax = 1.0f
        );

    // methods

    static constexpr auto getClassName();
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    static std::shared_ptr<CObject> CreateObject();

    template <typename... Args>
    static Ptr Create(Args&&... args);

    template <typename Alloc, typename... Args>
    static Ptr CreateAlloc(
        const Alloc& alloc,
        Args&&... args
        );

    template <typename... Args>
    static UniquePtr CreateUnique(Args&&... args);

    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual mrpt::rtti::CObject* clone() const;

    template <typename T>
    void setGridLimits(
        T xMin,
        T xMax,
        T yMin,
        T yMax
        );

    void getGridLimits(
        float& xMin,
        float& xMax,
        float& yMin,
        float& yMax
        ) const;

    void setMeshTextureExtension(float textureSize_x, float textureSize_y);

    void getMeshTextureExtension(
        float& textureSize_x,
        float& textureSize_y
        ) const;

    void enableTransparency(bool v);
    void enableWireFrame(bool v);

    void enableColorFromZ(
        bool v,
        mrpt::img::TColormap colorMap = mrpt::img::cmHOT
        );

    void setZ(const mrpt::math::CMatrixDynamic<float>& in_Z);
    void getZ(mrpt::math::CMatrixFloat& out) const;
    void getMask(mrpt::math::CMatrixFloat& out) const;
    void setMask(const mrpt::math::CMatrixDynamic<float>& in_mask);
    float getxMin() const;
    float getxMax() const;
    float getyMin() const;
    float getyMax() const;
    void setxMin(const float nxm);
    void setxMax(const float nxm);
    void setyMin(const float nym);
    void setyMax(const float nym);

    void getXBounds(
        float& min,
        float& max
        ) const;

    void getYBounds(
        float& min,
        float& max
        ) const;

    void setXBounds(
        const float min,
        const float max
        );

    void setYBounds(
        const float min,
        const float max
        );

    virtual void updateBuffers() const;
    virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const;
    void assignImage(const mrpt::img::CImage& img);
    void assignImageAndZ(const mrpt::img::CImage& img, const mrpt::math::CMatrixDynamic<float>& in_Z);
    void adjustGridToImageAR();
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    void assignImage(const mrpt::img::CImage& img, const mrpt::img::CImage& imgAlpha);
    void assignImage(mrpt::img::CImage&& img, mrpt::img::CImage&& imgAlpha);
    void assignImage(mrpt::img::CImage&& img);
    void cullFaces(const TCullFace& cf);
    void assignNormalMap(const mrpt::img::CImage& img);
    void assignNormalMap(mrpt::img::CImage&& img);
    void enableTextureLinearInterpolation(bool enable);
};

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<CObject> Ptr;
    typedef std::shared_ptr<const CObject> ConstPtr;
    typedef std::shared_ptr<CSerializable> Ptr;
    typedef std::shared_ptr<const CSerializable> ConstPtr;

    // structs

    struct PoseAndScale;
    struct State;

    // methods

    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    const auto& shaderTexturedTrianglesBuffer() const;
    auto& shaderTexturedTrianglesBufferMutex() const;
    bool isLightEnabled() const;
    void enableLight(bool enable = true);
    TCullFace cullFaces() const;
    const mrpt::img::CImage& getTextureImage() const;
    const mrpt::img::CImage& getTextureAlphaImage() const;
    bool textureImageHasBeenAssigned() const;
    const mrpt::img::CImage& getNormalMapImage() const;
    bool normalMapHasBeenAssigned() const;
    bool textureLinearInterpolation() const;
    void enableTextureMipMap(bool enable);
    bool textureMipMap() const;
    const auto& shaderLinesVertexPointBuffer() const;
    const auto& shaderLinesVertexColorBuffer() const;
    auto& shaderLinesBufferMutex() const;
    void setLineWidth(float w);
    float getLineWidth() const;
    void enableAntiAliasing(bool enable = true);
    bool isAntiAliasingEnabled() const;

Typedefs

typedef std::shared_ptr<mrpt::viz ::CMesh> Ptr

A type for the associated smart pointer.

Methods

virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const

Returns information about the class of an object in runtime.

virtual mrpt::rtti::CObject* clone() const

Returns a deep copy (clone) of the object, indepently of its class.

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.

void setZ(const mrpt::math::CMatrixDynamic<float>& in_Z)

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

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

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

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.

virtual void updateBuffers() const

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.

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

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

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

Trace ray.

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

Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M, they will be internally filled to its dimensions to be powers of two)

Images are copied, the original ones can be deleted.

void assignImage(mrpt::img::CImage&& img, mrpt::img::CImage&& imgAlpha)

Similar to assignImage, but the passed images are moved in (move semantic).

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

Similar to assignImage, but with move semantics.

void cullFaces(const TCullFace& cf)

Control whether to render the FRONT, BACK, or BOTH (default) set of faces.

Refer to docs for glCullFace(). Example: If set to cullFaces(TCullFace::BACK);, back faces will not be drawn (“culled”)

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

Assigns a normal map image for tangent-space normal mapping.

The image should encode normals in tangent space as RGB where (128,128,255) represents the unperturbed surface normal. Images are copied, the original ones can be deleted.

void assignNormalMap(mrpt::img::CImage&& img)

Similar to assignNormalMap, but with move semantics.

void enableTextureLinearInterpolation(bool enable)

Enable linear interpolation of textures (default=false, use nearest pixel)