class mrpt::maps::CGenericPointsMap

Overview

A map of 3D points (X,Y,Z) plus any number of custom, string-keyed per-point data channels.

Supported channel data types are float and uint16_t.

Before inserting points, you must register the fields you want to use via registerField_float() or registerField_uint16().

When inserting points, you must call insertPointFast() (for X,Y,Z) and then insertPointField_float() or insertPointField_uint16() for each registered field to keep data vectors synchronized.

Alternatively, use resize() or setSize() to allocate space, then populate data using setPointFast() and setPointField_float() / setPointField_uint16().

See also:

mrpt::maps::CPointsMap, mrpt::maps::CMetricMap

#include <mrpt/maps/CGenericPointsMap.h>

class CGenericPointsMap: public mrpt::maps::CPointsMap
{
public:
    // construction

    CGenericPointsMap();
    CGenericPointsMap(const CGenericPointsMap& o);

    // methods

    virtual bool registerField_float(const std::string_view& fieldName);
    virtual bool registerField_uint16(const std::string_view& fieldName);
    bool unregisterField(const std::string_view& fieldName);
    const std::unordered_map<std::string_view, mrpt::aligned_std_vector<float>>& float_fields() const;
    const std::unordered_map<std::string_view, mrpt::aligned_std_vector<uint16_t>>& uint16_fields() const;
    virtual void reserve(size_t newLength);
    virtual void resize(size_t newLength);
    virtual void setSize(size_t newLength);
    virtual void getPointAllFieldsFast(size_t index, std::vector<float>& point_data) const;
    virtual void setPointAllFieldsFast(size_t index, const std::vector<float>& point_data);

    virtual void loadFromRangeScan(
        const mrpt::obs::CObservation2DRangeScan& rangeScan,
        const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
        );

    virtual void loadFromRangeScan(
        const mrpt::obs::CObservation3DRangeScan& rangeScan,
        const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
        );

    virtual void getPointRGB(
        size_t index,
        float& x,
        float& y,
        float& z,
        float& R,
        float& G,
        float& B
        ) const;

    void setPointRGB(
        size_t index,
        float x,
        float y,
        float z,
        float R,
        float G,
        float B
        );

    void insertPointRGB(float x, float y, float z, float R, float G, float B);
    virtual bool hasPointField(const std::string_view& fieldName) const;
    virtual std::vector<std::string_view> getPointFieldNames_float() const;
    virtual std::vector<std::string_view> getPointFieldNames_uint16() const;
    virtual float getPointField_float(size_t index, const std::string_view& fieldName) const;
    virtual uint16_t getPointField_uint16(size_t index, const std::string_view& fieldName) const;
    virtual void setPointField_float(size_t index, const std::string_view& fieldName, float value);
    virtual void setPointField_uint16(size_t index, const std::string_view& fieldName, uint16_t value);
    virtual void insertPointField_float(const std::string_view& fieldName, float value);
    virtual void insertPointField_uint16(const std::string_view& fieldName, uint16_t value);

    virtual void reserveField_float(
        const std::string_view& fieldName,
        size_t n
        );

    virtual void reserveField_uint16(
        const std::string_view& fieldName,
        size_t n
        );

    virtual void resizeField_float(
        const std::string_view& fieldName,
        size_t n
        );

    virtual void resizeField_uint16(
        const std::string_view& fieldName,
        size_t n
        );

    virtual auto getPointsBufferRef_float_field(const std::string_view& fieldName) const;
    auto getPointsBufferRef_uint_field(const std::string_view& fieldName) const;
    virtual auto getPointsBufferRef_float_field(const std::string_view& fieldName);
    auto getPointsBufferRef_uint_field(const std::string_view& fieldName);
    CGenericPointsMap& operator = (const CGenericPointsMap& o);
    virtual bool hasColorPoints() const;
    virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& outObj) const;
};

Inherited Members

public:
    // typedefs

    typedef KDTreeCapable<Derived, num_t, metric_t> self_t;

    // structs

    template <int _DIM = -1>
    struct TKDTreeDataHolder;

    struct TKDTreeSearchParams;
    struct InsertCtx;
    struct TInsertionOptions;
    struct TLaserRange2DInsertContext;
    struct TLaserRange3DInsertContext;
    struct TLikelihoodOptions;
    struct TRenderOptions;

    // methods

    virtual bool isEmpty() const = 0;
    virtual void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const = 0;
    virtual std::string asString() const = 0;
    virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& o) const = 0;
    float kdTreeClosestPoint2DsqrError(const TPoint2D& p0) const;
    void kdTreeTwoClosestPoint2D(const TPoint2D& p0, TPoint2D& pOut1, TPoint2D& pOut2, float& outDistSqr1, float& outDistSqr2) const;

    std::vector<size_t> kdTreeNClosestPoint2D(
        const TPoint2D& p0,
        size_t N,
        std::vector<TPoint2D>& pOut,
        std::vector<float>& outDistSqr,
        const std::optional<float>& maximumSearchDistanceSqr = std::nullopt
        ) const;

    void kdTreeNClosestPoint2DIdx(
        const TPoint2D& p0,
        size_t N,
        std::vector<size_t>& outIdx,
        std::vector<float>& outDistSqr
        ) const;

    void kdTreeNClosestPoint3D(
        const TPoint3D& p0,
        size_t N,
        std::vector<TPoint3D>& pOut,
        std::vector<float>& outDistSqr,
        const std::optional<float>& maximumSearchDistanceSqr = std::nullopt
        ) const;

    void kdTreeNClosestPoint3DIdx(
        const TPoint3D& p0,
        size_t N,
        std::vector<size_t>& outIdx,
        std::vector<float>& outDistSqr,
        const std::optional<float>& maximumSearchDistanceSqr = std::nullopt
        ) const;

    void kdTreeEnsureIndexBuilt3D();
    void kdTreeEnsureIndexBuilt2D();
    KDTreeCapable& operator = (const KDTreeCapable&);
    virtual bool nn_has_indices_or_ids() const = 0;
    virtual size_t nn_index_count() const = 0;

    virtual bool nn_single_search(
        const mrpt::math::TPoint3Df& query,
        mrpt::math::TPoint3Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrIDOrID
        ) const = 0;

    virtual bool nn_single_search(
        const mrpt::math::TPoint2Df& query,
        mrpt::math::TPoint2Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrIDOrID
        ) const = 0;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint3Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const = 0;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint2Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const = 0;

    virtual void nn_radius_search(
        const mrpt::math::TPoint3Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints = 0
        ) const = 0;

    virtual void nn_radius_search(
        const mrpt::math::TPoint2Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints = 0
        ) const = 0;

    virtual void reserve(size_t newLength) = 0;
    virtual void resize(size_t newLength) = 0;
    virtual void setSize(size_t newLength) = 0;
    virtual void getPointAllFieldsFast(size_t index, std::vector<float>& point_data) const = 0;
    virtual void setPointAllFieldsFast(size_t index, const std::vector<float>& point_data) = 0;
    CPointsMap& operator = (const CPointsMap& o);

    virtual void getPointRGB(
        size_t index,
        float& x,
        float& y,
        float& z,
        float& R,
        float& G,
        float& B
        ) const;

    virtual void loadFromRangeScan(
        const mrpt::obs::CObservation2DRangeScan& rangeScan,
        const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
        ) = 0;

    virtual void loadFromRangeScan(
        const mrpt::obs::CObservation3DRangeScan& rangeScan,
        const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
        ) = 0;

Methods

virtual bool registerField_float(const std::string_view& fieldName)

Registers a new data channel of type float.

If the map is not empty, the new channel is filled with default values (0) to match the current point count.

Returns:

true if the field could effectively be added to the underlying point map class.

See also:

hasPointField(), getPointFieldNames_float()

virtual bool registerField_uint16(const std::string_view& fieldName)

Registers a new data channel of type uint16_t.

If the map is not empty, the new channel is filled with default values (0) to match the current point count.

Returns:

true if the field could effectively be added to the underlying point map class.

See also:

hasPointField(), getPointFieldNames_uint16()

bool unregisterField(const std::string_view& fieldName)

Removes a data channel.

Returns:

True if the field existed and was removed, false otherwise.

const std::unordered_map<std::string_view, mrpt::aligned_std_vector<float>>& float_fields() const

Returns the map of float fields: map<field_name, vector_of_data>

const std::unordered_map<std::string_view, mrpt::aligned_std_vector<uint16_t>>& uint16_fields() const

Returns the map of uint16_t fields: map<field_name, vector_of_data>

virtual void reserve(size_t newLength)

Reserves memory for a given number of points: the size of the map does not change, it only reserves the memory.

This is useful for situations where it is approximately known the final size of the map. This method is more efficient than constantly increasing the size of the buffers. Refer to the STL C++ library’s “reserve” methods.

virtual void resize(size_t newLength)

Resizes all point buffers so they can hold the given number of points: newly created points are set to default values, and old contents are not changed.

See also:

reserve, setPoint, setPointFast, setSize

virtual void setSize(size_t newLength)

Resizes all point buffers so they can hold the given number of points, erasing all previous contents and leaving all points to default values.

See also:

reserve, setPoint, setPointFast, setSize

virtual void getPointAllFieldsFast(size_t index, std::vector<float>& point_data) const

Get all the data fields for one point as a vector: depending on the implementation class this can be [X Y Z] or [X Y Z R G B], etc…

Unlike getPointAllFields(), this method does not check for index out of bounds

See also:

getPointAllFields, setPointAllFields, setPointAllFieldsFast

virtual void setPointAllFieldsFast(
    size_t index,
    const std::vector<float>& point_data
    )

Set all the data fields for one point as a vector: depending on the implementation class this can be [X Y Z] or [X Y Z R G B], etc…

Unlike setPointAllFields(), this method does not check for index out of bounds

See also:

setPointAllFields, getPointAllFields, getPointAllFieldsFast

virtual void loadFromRangeScan(
    const mrpt::obs::CObservation2DRangeScan& rangeScan,
    const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
    )

Transform the range scan into a set of cartessian coordinated points.

The options in “insertionOptions” are considered in this method. Only ranges marked as “valid=true” in the observation will be inserted

Each derived class may enrich points in different ways (color, weight, etc..), so please refer to the description of the specific implementation of mrpt::maps::CPointsMap you are using.

The actual generic implementation of this file lives in <src>/CPointsMap_crtp_common.h, but specific instantiations are generated at each derived class.

Parameters:

rangeScan

The scan to be inserted into this map

robotPose

Default to (0,0,0|0deg,0deg,0deg). Changes the frame of reference for the point cloud (i.e. the vehicle/robot pose in world coordinates).

See also:

CObservation2DRangeScan, CObservation3DRangeScan

virtual void loadFromRangeScan(
    const mrpt::obs::CObservation3DRangeScan& rangeScan,
    const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
    )

Overload of loadFromRangeScan() for 3D range scans (for example, Kinect observations).

Each derived class may enrich points in different ways (color, weight, etc..), so please refer to the description of the specific implementation of mrpt::maps::CPointsMap you are using.

The actual generic implementation of this file lives in <src>/CPointsMap_crtp_common.h, but specific instantiations are generated at each derived class.

Parameters:

rangeScan

The scan to be inserted into this map

robotPose

Default to (0,0,0|0deg,0deg,0deg). Changes the frame of reference for the point cloud (i.e. the vehicle/robot pose in world coordinates).

See also:

loadFromVelodyneScan

virtual void getPointRGB(
    size_t index,
    float& x,
    float& y,
    float& z,
    float& R,
    float& G,
    float& B
    ) const

Access to a given point from map, and its colors, if the map defines them (othersise, R=G=B=1.0).

First index is 0.

Parameters:

Throws

std::exception on index out of bound.

Returns:

The return value is the weight of the point (the times it has been fused)

void insertPointRGB(float x, float y, float z, float R, float G, float B)

Tries to insert R,G,B into fields “R”,”G”,”B” or “intensity” if they exist.

virtual bool hasPointField(const std::string_view& fieldName) const

Returns true if the map has a data channel with the given name.

See also:

getPointField_float, getPointField_uint16

virtual std::vector<std::string_view> getPointFieldNames_float() const

Get list of all float channel names.

virtual std::vector<std::string_view> getPointFieldNames_uint16() const

Get list of all uint16_t channel names.

virtual float getPointField_float(
    size_t index,
    const std::string_view& fieldName
    ) const

Read the value of a float channel for a given point.

Returns 0 if field does not exist.

Parameters:

std::exception

on index out of bounds or if field exists but is not float.

virtual uint16_t getPointField_uint16(
    size_t index,
    const std::string_view& fieldName
    ) const

Read the value of a uint16_t channel for a given point.

Returns 0 if field does not exist.

Parameters:

std::exception

on index out of bounds or if field exists but is not uint16_t.

virtual void setPointField_float(
    size_t index,
    const std::string_view& fieldName,
    float value
    )

Sets the value of a float channel for a given point.

Parameters:

std::exception

on index out of bounds or if field does not exist or is not float.

virtual void setPointField_uint16(
    size_t index,
    const std::string_view& fieldName,
    uint16_t value
    )

Sets the value of a uint16_t channel for a given point.

Parameters:

std::exception

on index out of bounds or if field does not exist or is not uint16_t.

virtual void insertPointField_float(
    const std::string_view& fieldName,
    float value
    )

Appends a value to the given field.

The field must be registered. Asserts that the field vector’s size is exactly this->size() - 1 (i.e. you just called insertPointFast()).

virtual void insertPointField_uint16(
    const std::string_view& fieldName,
    uint16_t value
    )

Appends a value to the given field.

The field must be registered. Asserts that the field vector’s size is exactly this->size() - 1 (i.e. you just called insertPointFast()).

virtual bool hasColorPoints() const

Returns true if the point map has a color field for each point.

virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& outObj) const

Returns a 3D object representing the map.

The color of the points is controlled by renderOptions