15 #ifndef BELUGA_ROS_POINT_CLOUD_HPP
16 #define BELUGA_ROS_POINT_CLOUD_HPP
18 #include <range/v3/view/iota.hpp>
22 #include <beluga_ros/messages.hpp>
24 #include <sophus/se3.hpp>
26 #include <Eigen/Dense>
28 #include "beluga/eigen_compatibility.hpp"
55 std::is_same_v<Scalar, float> || std::is_same_v<Scalar, double>,
56 "Pointcloud3 only supports float or double datatype");
62 explicit PointCloud3(beluga_ros::msg::PointCloud2ConstSharedPtr cloud, Sophus::SE3d
origin = Sophus::SE3d())
64 assert(cloud_ !=
nullptr);
65 constexpr uint8_t fieldType = sensor_msgs::typeAsPointFieldType<T>::value;
67 if (cloud_->fields.size() < 3) {
68 throw std::invalid_argument(
"PointCloud is not 3D");
71 if (cloud_->fields.at(0).name !=
"x" || cloud_->fields.at(1).name !=
"y" || cloud_->fields.at(2).name !=
"z") {
72 throw std::invalid_argument(
"PointCloud not XYZ...");
75 if (cloud_->fields.at(0).datatype != fieldType || cloud_->fields.at(1).datatype != fieldType ||
76 cloud_->fields.at(2).datatype != fieldType) {
77 throw std::invalid_argument(
"XYZ datatype are not same");
80 if (cloud_->point_step %
sizeof(
Scalar) != 0) {
81 throw std::invalid_argument(
"Data is not memory-aligned");
83 stride_ =
static_cast<int>(cloud_->point_step /
sizeof(
Scalar));
87 [[nodiscard]]
const auto&
origin()
const {
return origin_; }
91 const beluga_ros::msg::PointCloud2ConstIterator<Scalar> iter_points(*cloud_,
"x");
92 return Eigen::Map<const Eigen::Matrix3X<Scalar>, 0, Eigen::OuterStride<>>(
93 &iter_points[0], 3, cloud_->width * cloud_->height, stride_);
97 beluga_ros::msg::PointCloud2ConstSharedPtr cloud_;
Thin wrapper type for 3D sensor_msgs/PointCloud2 messages.
Definition: point_cloud.hpp:48
const auto & origin() const
Get the point cloud frame origin in the filter frame.
Definition: point_cloud.hpp:87
auto points() const
Get the unorganized 3D point collection as an Eigen Map<Eigen::Matrix3X>.
Definition: point_cloud.hpp:90
PointCloud3(beluga_ros::msg::PointCloud2ConstSharedPtr cloud, Sophus::SE3d origin=Sophus::SE3d())
Check type is float or double.
Definition: point_cloud.hpp:62
T Scalar
PointCloud type.
Definition: point_cloud.hpp:51
The main Beluga ROS namespace.
Definition: amcl.hpp:44