Class CGenericPointsMap

Inheritance Relationships

Base Type

Class Documentation

class CGenericPointsMap : public mrpt::maps::CPointsMap

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, double, uint16_t, and uint8_t.

Before inserting points, you must register the fields you want to use via registerField_float(), registerField_double(), …

When inserting points, you must call insertPointFast() (for X,Y,Z) and then insertPointField_float(), insertPointField_double(),… 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() / …

A mechanism is provided to copy all point fields from one point map to another:

  • const auto ctx = CPointsMap::prepareForInsertPointsFrom(sourcePc), then

  • CPointsMap::insertPointFrom(i, ctx)

Although field names can be freely set by users, these names have reserved uses:

For coloring a mrpt::opengl::CPointCloudColoured using fields from a mrpt::maps::CGenericPointsMap object, use mrpt::obs::recolorize3Dpc() or mrpt::obs::obs_to_viz() for an mrpt::obs::CObservationPointCloud

See also

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

Register/unregister custom data fields

virtual bool registerField_float(const std::string &fieldName) override

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.

bool registerField_double(const std::string &fieldName) override
bool registerField_uint16(const std::string &fieldName) override
bool registerField_uint8(const std::string &fieldName) override
bool unregisterField(const std::string &fieldName)

Removes a data channel.

Returns:

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

inline const std::map<std::string, mrpt::aligned_std_vector<float>> &float_fields() const

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

inline const std::map<std::string, mrpt::aligned_std_vector<double>> &double_fields() const

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

inline const std::map<std::string, mrpt::aligned_std_vector<uint16_t>> &uint16_fields() const

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

inline const std::map<std::string, mrpt::aligned_std_vector<uint8_t>> &uint8_fields() const

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

CPointsMap virtual interface implementation

virtual void reserve(size_t newLength) override

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

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.

virtual void setSize(size_t newLength) override

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

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

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

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

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

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

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

See also

CObservation2DRangeScan, CObservation3DRangeScan

Note

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.

Note

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

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

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

Note

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.

Note

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

String-keyed field access virtual interface implementation

virtual bool hasPointField(const std::string &fieldName) const override

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

See also

getPointField_float, getPointField_double, getPointField_uint16

virtual std::vector<std::string> getPointFieldNames_float() const override

Get list of all float channel names

virtual std::vector<std::string> getPointFieldNames_double() const override

Get list of all double channel names

virtual std::vector<std::string> getPointFieldNames_uint16() const override

Get list of all uint16_t channel names

virtual std::vector<std::string> getPointFieldNames_uint8() const override

Get list of all uint8_t channel names

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

Read the value of a float channel for a given point. Returns 0 if field does not exist.

Throws:

std::exception – on index out of bounds or if field exists but is not float.

double getPointField_double(size_t index, const std::string &fieldName) const override
uint16_t getPointField_uint16(size_t index, const std::string &fieldName) const override
uint8_t getPointField_uint8(size_t index, const std::string &fieldName) const override
virtual void setPointField_float(size_t index, const std::string &fieldName, float value) override

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

Throws:

std::exception – on index out of bounds or if field does not exist or is not float.

void setPointField_double(size_t index, const std::string &fieldName, double value) override
void setPointField_uint16(size_t index, const std::string &fieldName, uint16_t value) override
void setPointField_uint8(size_t index, const std::string &fieldName, uint8_t value) override
void insertPointField_float(const std::string &fieldName, float value) override

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

void insertPointField_double(const std::string &fieldName, double value) override

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

void insertPointField_uint16(const std::string &fieldName, uint16_t value) override

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

void insertPointField_uint8(const std::string &fieldName, uint8_t value) override

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

void reserveField_float(const std::string &fieldName, size_t n) override
void reserveField_double(const std::string &fieldName, size_t n) override
void reserveField_uint16(const std::string &fieldName, size_t n) override
void reserveField_uint8(const std::string &fieldName, size_t n) override
void resizeField_float(const std::string &fieldName, size_t n) override
void resizeField_double(const std::string &fieldName, size_t n) override
void resizeField_uint16(const std::string &fieldName, size_t n) override
void resizeField_uint8(const std::string &fieldName, size_t n) override
inline virtual auto getPointsBufferRef_float_field(const std::string &fieldName) const -> const mrpt::aligned_std_vector<float>* override
inline auto getPointsBufferRef_double_field(const std::string &fieldName) const -> const mrpt::aligned_std_vector<double>* override
inline auto getPointsBufferRef_uint16_field(const std::string &fieldName) const -> const mrpt::aligned_std_vector<uint16_t>* override
inline auto getPointsBufferRef_uint8_field(const std::string &fieldName) const -> const mrpt::aligned_std_vector<uint8_t>* override
inline virtual auto getPointsBufferRef_float_field(const std::string &fieldName) -> mrpt::aligned_std_vector<float>* override
inline auto getPointsBufferRef_double_field(const std::string &fieldName) -> mrpt::aligned_std_vector<double>* override
inline auto getPointsBufferRef_uint16_field(const std::string &fieldName) -> mrpt::aligned_std_vector<uint16_t>* override
inline auto getPointsBufferRef_uint8_field(const std::string &fieldName) -> mrpt::aligned_std_vector<uint8_t>* override

Public Functions

CGenericPointsMap() = default
CGenericPointsMap(const CGenericPointsMap &o)
CGenericPointsMap &operator=(const CGenericPointsMap &o)

Protected Attributes

std::map<std::string, mrpt::aligned_std_vector<float>> m_float_fields
std::map<std::string, mrpt::aligned_std_vector<double>> m_double_fields
std::map<std::string, mrpt::aligned_std_vector<uint16_t>> m_uint16_fields
std::map<std::string, mrpt::aligned_std_vector<uint8_t>> m_uint8_fields