class mrpt::opengl::CFrustum

Overview

A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assymetric) field-of-view angles.

You can switch whether to show only the lines, the surface of the frustum, or both. By default only the lines are drawn.

The color of the object (via CRenderizable::setColor()) affects the color of lines. To set the color of planes use setPlaneColor()

As usual in MRPT, the +X axis is assumed to by the main direction, in this case of the pyramid axis.

The horizontal and vertical FOVs can be set directly with setHorzFOV() and setVertFOV() if they are symmetric, or with setHorzFOVAsymmetric() and setVertFOVAsymmetric() otherwise.

All FOV angles are positive numbers. FOVs must be below 90deg on each side (below 180deg in total). If you try to set FOVs to larger values they’ll truncated to 89.9deg.

mrpt::opengl::CFrustum mrpt::opengl::CFrustum mrpt::opengl::CFrustum mrpt::opengl::CFrustum

See also:

opengl::Scene, opengl::CRenderizable

#include <mrpt/opengl/CFrustum.h>

class CFrustum:
    public mrpt::opengl::CRenderizableShaderTriangles,
    public mrpt::opengl::CRenderizableShaderWireFrame
{
public:
    // construction

    CFrustum();

    CFrustum(
        float near_distance,
        float far_distance,
        float horz_FOV_degrees,
        float vert_FOV_degrees,
        float lineWidth,
        bool draw_lines,
        bool draw_planes
        );

    CFrustum(const mrpt::img::TCamera& intrinsics, double focalDistScale = 5e-3);

    // methods

    virtual void render(const RenderContext& rc) const;
    virtual void renderUpdateBuffers() const;
    virtual void freeOpenGLResources();
    virtual shader_list_t requiredShaders() const;
    virtual void onUpdateBuffers_Wireframe();
    virtual void onUpdateBuffers_Triangles();
    void setPlaneColor(const mrpt::img::TColor& c);
    const mrpt::img::TColor& getPlaneColor() const;
    void setNearFarPlanes(const float near_distance, const float far_distance);
    float getNearPlaneDistance() const;
    float getFarPlaneDistance() const;
    void setHorzFOV(const float fov_horz_degrees);
    void setVertFOV(const float fov_vert_degrees);
    void setHorzFOVAsymmetric(const float fov_horz_left_degrees, const float fov_horz_right_degrees);
    void setVertFOVAsymmetric(const float fov_vert_down_degrees, const float fov_vert_up_degrees);
    float getHorzFOV() const;
    float getVertFOV() const;
    float getHorzFOVLeft() const;
    float getHorzFOVRight() const;
    float getVertFOVDown() const;
    float getVertFOVUp() const;
    virtual bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const;
    virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const;
};

Inherited Members

public:
    // structs

    struct OutdatedState;
    struct RenderContext;
    struct State;

    // methods

    virtual void render(const RenderContext& rc) const = 0;
    virtual void renderUpdateBuffers() const = 0;
    virtual shader_list_t requiredShaders() const;
    virtual void freeOpenGLResources() = 0;
    virtual void onUpdateBuffers_Triangles() = 0;
    virtual void onUpdateBuffers_Wireframe() = 0;

Construction

CFrustum()

Basic empty constructor.

Set all parameters to default.

CFrustum(
    float near_distance,
    float far_distance,
    float horz_FOV_degrees,
    float vert_FOV_degrees,
    float lineWidth,
    bool draw_lines,
    bool draw_planes
    )

Constructor with some parameters

CFrustum(const mrpt::img::TCamera& intrinsics, double focalDistScale = 5e-3)

Constructor from camera intrinsic parameters: creates a frustrum with the correct vertical and horizontal FOV angles for the given camera model, in wireframe.

(New in MRPT 2.1.8)

Parameters:

intrinsics

Camera intrinsics. Distortion is ignored here.

focalDistScale

Scale for the far plane, in meters/pixels.

Methods

virtual void render(const RenderContext& rc) const

Implements the rendering of 3D objects in each class derived from CRenderizable.

This can be called more than once (one per required shader program) if the object registered several shaders.

See also:

renderUpdateBuffers

virtual void renderUpdateBuffers() const

Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.

before they are sent for rendering in render()

virtual void freeOpenGLResources()

Free opengl buffers.

virtual shader_list_t requiredShaders() const

Returns the ID of the OpenGL shader program required to render this class.

See also:

DefaultShaderID

virtual void onUpdateBuffers_Wireframe()

Must be implemented in derived classes to update the geometric entities to be drawn in “m_*_buffer” fields.

virtual void onUpdateBuffers_Triangles()

Must be implemented in derived classes to update the geometric entities to be drawn in “m_*_buffer” fields.

void setPlaneColor(const mrpt::img::TColor& c)

Changes the color of the planes; to change color of lines, use CRenderizable base methods.

void setNearFarPlanes(const float near_distance, const float far_distance)

Changes distance of near & far planes.

void setHorzFOV(const float fov_horz_degrees)

Changes horizontal FOV (symmetric)

void setVertFOV(const float fov_vert_degrees)

Changes vertical FOV (symmetric)

void setHorzFOVAsymmetric(
    const float fov_horz_left_degrees,
    const float fov_horz_right_degrees
    )

Changes horizontal FOV (asymmetric)

void setVertFOVAsymmetric(
    const float fov_vert_down_degrees,
    const float fov_vert_up_degrees
    )

Changes vertical FOV (asymmetric)

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

Simulation of ray-trace, given a pose.

Returns true if the ray effectively collisions with the object (returning the distance to the origin of the ray in “dist”), or false in other case. “dist” variable yields undefined behaviour when false is returned

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