Template Class PointCloudMsgWrapper

Class Documentation

template<typename PointT, template<typename AllocatorT> class PointCloudMsgT, typename FieldGenerators, const bool kIsMutable, typename AllocatorT>
class PointCloudMsgWrapper

This class implements a point cloud message wrapper. Unless otherwise required, use the typedefs of this class: PointCloud2View and PointCloud2Modifier. Only use this class directly if those typedefs do not provide enough flexibility.

This class is designed to simplify working with point cloud messages. The idea is that it wraps a point cloud message reference allowing for simple access and modification. Upon creation, the wrapper checks if the fields of the message correspond to the fields generated from the point type provided by the user. If this check has passed, then the fields are identical (including the offsets of the members) and it is safe to reinterpret the point cloud message as an array of PointT points. Note that due to these checks it is relatively expensive (the complexity of the checks is around O(n^2) where n is the number of field generators) to create this wrapper, thus it should be avoided in very tight scopes. This operation is not slow, but is significantly slower than a single element access. It is better to create the wrapper once per message in a function scope and batch all the read/write operations afterwards.

For convenience, there are two typedefs: PointCloud2View and PointCloud2Modifier.

  • PointCloudView<PointT>{msg} wraps a constant point cloud and allows read-only access. Modification through this view is impossible.

  • PointCloud2Modifier<PointT>{msg} wraps a mutable message and allows read-write access to the underlying data.

  • PointCloud2Modifier<PointT>{msg, new_frame_id} initializes an empty mutable message. This constructor is to be used solely to initialize a new message and will throw if the point cloud message is already initialized (i.e., has non-zero number of fields).

Warning

This class wraps a raw reference, so the user is responsible to use it in such a way that the underlying point cloud message is not deleted before the wrapper.

Template Parameters:
  • PointT – Type of point to use for message reading/writing.

  • PointCloudMsgT – Type of point cloud message.

  • FieldGenerators – A tuple of all field generators that allow generating Field structs from members of a PointT struct. See LIDAR_UTILS__DEFINE_FIELD_GENERATOR_FOR_MEMBER for more details. The class provides a sane default value here, but a custom tuple can be generated by the user by using LIDAR_UTILS__DEFINE_FIELD_GENERATOR_FOR_MEMBER if needed.

  • kIsMutable – Define if the point cloud message is mutable. Used to conditionally compile certain functions.

  • AllocatorT – The message allocator type. This allocator type must be rebindable to the PointT allocator through the use of std::allocator_traits<AllocatorT>::rebind_alloc<PointT>.

Public Types

using value_type = PointT
using iterator = typename PointVectorType::iterator
using const_iterator = typename PointVectorType::const_iterator
using reverse_iterator = typename PointVectorType::reverse_iterator
using const_reverse_iterator = typename PointVectorType::const_reverse_iterator

Public Functions

inline explicit PointCloudMsgWrapper(CloudMsgT &cloud_ref)

Constructor that wraps a point cloud message. Checks if the message fields correspond to the ones generated from the PointT type and throws in case of a mismatch.

Parameters:

cloud_ref – A reference to the wrapped cloud.

inline explicit PointCloudMsgWrapper(CloudMsgT &cloud_ref, const FieldNameT &frame_id)

A constructor that initializes the message and sets a new frame_id. Note that this only compiles for a mutable cloud. It also throws if the message is already initialized.

Parameters:
  • cloud_ref – A reference to the wrapped cloud

  • frame_id[in] A frame id to be set to the message.

inline  COMPILE_IF_MUTABLE (CloudMsgT, void) push_back(const PointT &point)

Push a new point into the message.

inline  COMPILE_IF_MUTABLE (CloudMsgT, void) push_back(PointT &&point)

Push a new point into the message.

inline std::size_t size() const noexcept

Get the number of points in the message.

inline bool empty() const noexcept

Check if the point cloud message stores no points.

inline  COMPILE_IF_MUTABLE (CloudMsgT, PointT &) front() noexcept

Get the first point.

inline const PointT &front() const noexcept

Get the first point.

inline  COMPILE_IF_MUTABLE (CloudMsgT, PointT &) back() noexcept

Get the last point.

inline const PointT &back() const noexcept

Get the last point.

inline const PointT &at(const std::size_t index) const

Get a point reference at the specified index.

Throws:

std::runtime_error – if the index is out of bounds.

inline  COMPILE_IF_MUTABLE (CloudMsgT, PointT &) at(const std

Get a point reference at the specified index. Only compiled if message is not const.

Throws:

std::runtime_error – if the index is out of bounds.

inline const PointT &operator[](const std::size_t index) const noexcept

Get a point reference at the specified index.

inline  COMPILE_IF_MUTABLE (CloudMsgT, PointT &) operator[](const std

Get a point reference as a specified index. Only compiled if message type is not const.

Reset the message fields to match the members of the PointT struct. The point cloud message is ready for modification after this operation.

inline  COMPILE_IF_MUTABLE (CloudMsgT, void) clear()

Clear the message.

inline  COMPILE_IF_MUTABLE (CloudMsgT, void) reserve(const size_t expected_number_of_points)

Allocate memory to hold a specified number of points.

inline  COMPILE_IF_MUTABLE (CloudMsgT, void) resize(const std

Resize the container to hold a given number of points.

inline  COMPILE_IF_MUTABLE (CloudMsgT, iterator) begin() noexcept

An iterator to the beginning of data. Only compiled if point cloud message type is not const.

inline  COMPILE_IF_MUTABLE (CloudMsgT, iterator) end() noexcept

An iterator to the end of data. Only compiled if point cloud message type is not const.

inline  COMPILE_IF_MUTABLE (CloudMsgT, reverse_iterator) rbegin() noexcept

A reverse iterator staring position. Only compiled if point cloud message type is not const.

inline  COMPILE_IF_MUTABLE (CloudMsgT, reverse_iterator) rend() noexcept

A reverse iterator end position. Only compiled if point cloud message type is not const.

inline const_iterator begin() const noexcept

A constant iterator to the beginning of data.

inline const_iterator end() const noexcept

A constant iterator to the end of data.

inline const_reverse_iterator rbegin() const noexcept

A constant reverse iterator to the beginning of the reversed data.

inline const_reverse_iterator rend() const noexcept

A constant reverse iterator to the end of reversed data.

inline const_iterator cbegin() const noexcept

A constant iterator to the beginning of data.

inline const_iterator cend() const noexcept

A constant iterator to the end of data.

inline const_reverse_iterator crbegin() const noexcept

A constant reverse iterator to the reverse beginning of data.

inline const_reverse_iterator crend() const noexcept

A constant reverse iterator to the reverse end of data.

Public Static Functions

static inline bool can_be_created_from(const CloudMsgT &cloud_msg, std::string *error_msg = nullptr)

Determines ability to be created from a given cloud.

Parameters:
  • cloud_msg[in] The cloud message

  • error_msg – Optional error message

Returns:

True if able to be created for the provided cloud, False otherwise.