struct mrpt::math::TObject3D

A variant type for any lightweight 3D type: point, segment, line, plane, polygon.

Use provided helper method, or directly access the variant data.

See also:

TPoint3D, TSegment3D, TLine3D, TPlane, TPolygon3D

#include <mrpt/math/TObject3D.h>

struct TObject3D
{
    // typedefs

    typedef std::variant<std::monostate, TPoint3D, TSegment3D, TLine3D, TPolygon3D, TPlane> variant_t;

    //
fields

    variant_t data;

    //
methods

    bool isPoint() const;
    bool isSegment() const;
    bool isLine() const;
    bool isPolygon() const;
    bool isPlane() const;
    bool empty() const;

    template <typename T>
    const T& getAs() const;

    template <typename T>
    T& getAs();

    bool getPoint(TPoint3D& out) const;
    bool getSegment(TSegment3D& out) const;
    bool getLine(TLine3D& out) const;
    bool getPolygon(TPolygon3D& out) const;
    bool getPlane(TPlane& out) const;
    std::string asString() const;
    TObject2D generate2DObject() const;

    template <typename T>
    static TObject3D From(const T& p);
};

Methods

bool isPoint() const

Checks whether content is a point.

bool isSegment() const

Checks whether content is a segment.

bool isLine() const

Checks whether content is a line.

bool isPolygon() const

Checks whether content is a polygon.

bool isPlane() const

Checks whether content is a plane.

template <typename T>
const T& getAs() const

Gets the content as a given expected type (an exception will be thrown if type is wrong, check type first).

template <typename T>
T& getAs()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool getPoint(TPoint3D& out) const

returns true if the objects is a point, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getSegment(TSegment3D& out) const

returns true if the objects is a segment, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getLine(TLine3D& out) const

returns true if the objects is a line, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getPolygon(TPolygon3D& out) const

returns true if the objects is a TPolygon3D, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

bool getPlane(TPlane& out) const

returns true if the objects is a TPlane, and retrieves its value in out.

Prefer getAs(). This method was left in mrpt 2.3.0 for backwards compatibility.

std::string asString() const

Gets a string with the type and the parameters of the object.

empty if not defined. New in MRPT 2.3.0

TObject2D generate2DObject() const

Cast into 2D space.

Parameters:

std::logic_error

if the 3D object loses its properties when projecting into 2D space (for example, it’s a plane or a vertical line).

template <typename T>
static TObject3D From(const T& p)

Constructor from point, segment, line, polygon, or plane.