class mrpt::math::CPolygon

Overview

A wrapper of a TPolygon2D class, implementing CSerializable.

#include <mrpt/math/CPolygon.h>

class CPolygon:
    public mrpt::serialization::CSerializable,
    public mrpt::math::TPolygon2D
{
public:
    // typedefs

    typedef std::shared_ptr<mrpt::math ::CPolygon> Ptr;
    typedef std::shared_ptr<const mrpt::math ::CPolygon> ConstPtr;
    typedef std::unique_ptr<mrpt::math ::CPolygon> UniquePtr;
    typedef std::unique_ptr<const mrpt::math ::CPolygon> ConstUniquePtr;

    // fields

    static constexpr const char* className = "mrpt::math" "::" "CPolygon";
    T elements;

    // construction

    CPolygon();

    // 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;
    static TPolygon2D FromYAML(const mrpt::containers::yaml& c);
    static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D& poly);
    static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D& poly, const mrpt::math::TPose2D& pose);
    void add_vertex(double x, double y);
    double get_vertex_x(size_t i) const;
    double get_vertex_y(size_t i) const;
    void set_vertices(const std::vector<double>& x, const std::vector<double>& y);
    void set_vertices(size_t nVertices, const double* xs, const double* ys);
    void set_vertices(size_t nVertices, const float* xs, const float* ys);
    void get_vertices(std::vector<double>& x, std::vector<double>& y) const;
    double distance(const TPoint2D& point) const;
    bool contains(const TPoint2D& point) const;
    void getAsSegmentList(std::vector<TSegment2D>& v) const;
    void generate3DObject(TPolygon3D& p) const;
    void getCenter(TPoint2D& p) const;
    bool isConvex() const;
    void removeRepeatedVertices();
    void removeRedundantVertices();
    void getPlotData(std::vector<double>& x, std::vector<double>& y) const;
    mrpt::containers::yaml asYAML() const;
    void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const;
};

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;

    // 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();
    std::tuple<std::vector<double>, std::vector<double>> getPlotData() const;

Typedefs

typedef std::shared_ptr<mrpt::math ::CPolygon> Ptr

A type for the associated smart pointer.

Fields

T elements

STL member.

Construction

CPolygon()

Default constructor (empty polygon, 0 vertices)

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.

static TPolygon2D FromYAML(const mrpt::containers::yaml& c)

Builds a polygon from a YAML sequence (vertices) of sequences ([x y] coordinates).

User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation

(New in MRPT 2.4.1)

See also:

asYAML

static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D& poly)

Static method to create a regular polygon, given its size and radius.

Parameters:

std::logic_error

if radius is near zero or the number of edges is less than three.

static void createRegularPolygon(
    size_t numEdges,
    double radius,
    TPolygon2D& poly,
    const mrpt::math::TPose2D& pose
    )

Static method to create a regular polygon from its size and radius.

The center will correspond to the given pose.

Parameters:

std::logic_error

if radius is near zero or the number of edges is less than three.

void add_vertex(double x, double y)

Add a new vertex to polygon.

double get_vertex_x(size_t i) const

Methods for accessing the vertices.

See also:

verticesCount

void set_vertices(const std::vector<double>& x, const std::vector<double>& y)

Set all vertices at once.

void set_vertices(size_t nVertices, const double* xs, const double* ys)

Set all vertices at once.

Please use the std::vector version whenever possible unless efficiency is really an issue

void set_vertices(size_t nVertices, const float* xs, const float* ys)

Set all vertices at once.

Please use the std::vector version whenever possible unless efficiency is really an issue

void get_vertices(std::vector<double>& x, std::vector<double>& y) const

Get all vertices at once.

double distance(const TPoint2D& point) const

Distance to a point (always >=0)

bool contains(const TPoint2D& point) const

Check whether a point is inside (or within geometryEpsilon of a polygon edge).

This works for concave or convex polygons.

void getAsSegmentList(std::vector<TSegment2D>& v) const

Gets as set of segments, instead of points.

void generate3DObject(TPolygon3D& p) const

Projects into 3D space, zeroing the z.

void getCenter(TPoint2D& p) const

Polygon’s central point.

bool isConvex() const

Checks whether is convex.

void removeRepeatedVertices()

Erase repeated vertices.

See also:

removeRedundantVertices

void removeRedundantVertices()

Erase every redundant vertex from the polygon, saving space.

See also:

removeRepeatedVertices

void getPlotData(std::vector<double>& x, std::vector<double>& y) const

Gets plot data, ready to use on a 2D plot.

See also:

mrpt::gui::CDisplayWindowPlots

mrpt::containers::yaml asYAML() const

Returns a YAML representation of the polygon as a sequence (vertices) of sequences ([x y] coordinates).

User must include #include <mrpt/containers/yaml.h> if using this method, only a forward declaration is defined here to speed up compilation

(New in MRPT 2.4.1)

See also:

FromYAML

void getBoundingBox(TPoint2D& min_coords, TPoint2D& max_coords) const

Get polygon bounding box.

Parameters:

On

empty polygon