33#ifndef EASYNAV_COMMON_TYPES__POINTPERCEPTIONS_HPP_
34#define EASYNAV_COMMON_TYPES__POINTPERCEPTIONS_HPP_
40#include "pcl_conversions/pcl_conversions.h"
41#include "pcl/point_types_conversion.h"
42#include "pcl/common/transforms.h"
43#include "pcl/point_cloud.h"
44#include "pcl/point_types.h"
45#include "pcl/PointIndices.h"
47#include "sensor_msgs/msg/laser_scan.hpp"
48#include "sensor_msgs/msg/point_cloud2.hpp"
50#include "rclcpp/time.hpp"
51#include "rclcpp_lifecycle/lifecycle_node.hpp"
60struct hash<
std::tuple<int, int, int>>
62 std::size_t
operator()(
const std::tuple<int, int, int> & key)
const
64 std::size_t h1 = std::hash<int>()(std::get<0>(key));
65 std::size_t h2 = std::hash<int>()(std::get<1>(key));
66 std::size_t h3 = std::hash<int>()(std::get<2>(key));
67 return h1 ^ (h2 << 1) ^ (h3 << 2);
85 pcl::PointCloud<pcl::PointXYZ>
data;
91 data.points.resize(size);
104 std::string
group()
const override {
return "points";}
109 std::shared_ptr<PerceptionBase>
create(
const std::string &)
override
111 return std::make_shared<PointPerception>();
116 rclcpp_lifecycle::LifecycleNode & node,
117 const std::string & topic,
118 const std::string & type,
119 std::shared_ptr<PerceptionBase> target,
120 rclcpp::CallbackGroup::SharedPtr cb_group)
override;
126void convert(
const sensor_msgs::msg::LaserScan & scan, pcl::PointCloud<pcl::PointXYZ> & pc);
136sensor_msgs::msg::PointCloud2
points_to_rosmsg(
const pcl::PointCloud<pcl::PointXYZ> & points);
141 std::vector<std::shared_ptr<PointPerception>>;
162 return x == other.
x &&
y == other.
y &&
z == other.
z;
172 std::size_t h1 = std::hash<int>{}(key.
x);
173 std::size_t h2 = std::hash<int>{}(key.
y);
174 std::size_t h3 = std::hash<int>{}(key.
z);
175 return h1 ^ (h2 << 1) ^ (h3 << 2);
192 const std::vector<double> & min_bounds,
193 const std::vector<double> & max_bounds);
203 std::shared_ptr<PointPerceptionsOpsView>
collapse(
204 const std::vector<double> & collapse_dims)
const;
208 pcl::PointCloud<pcl::PointXYZ>
as_points()
const;
213 const pcl::PointCloud<pcl::PointXYZ> &
as_points(
int idx)
const;
218 std::shared_ptr<PointPerceptionsOpsView>
fuse(
const std::string & target_frame)
const;
225 std::optional<PointPerceptions> owned_;
227 std::vector<pcl::PointIndices> indices_;
Defines data structures and utilities for representing and processing sensor perceptions.
Abstract base class for representing a single sensor perception.
Definition Perceptions.hpp:50
Abstract base interface for group-specific perception handlers.
Definition Perceptions.hpp:87
PerceptionHandler implementation for sensors producing point-based data.
Definition PointPerception.hpp:101
std::shared_ptr< PerceptionBase > create(const std::string &) override
Creates a new PointPerception instance.
Definition PointPerception.hpp:109
std::string group() const override
Returns the sensor group handled by this handler: "points".
Definition PointPerception.hpp:104
rclcpp::SubscriptionBase::SharedPtr create_subscription(rclcpp_lifecycle::LifecycleNode &node, const std::string &topic, const std::string &type, std::shared_ptr< PerceptionBase > target, rclcpp::CallbackGroup::SharedPtr cb_group) override
Creates a subscription to LaserScan or PointCloud2 messages and updates the perception.
Definition PointPerception.cpp:48
Concrete perception class for 3D point cloud data.
Definition PointPerception.hpp:82
pcl::PointCloud< pcl::PointXYZ > data
The 3D point cloud data associated with this perception.
Definition PointPerception.hpp:85
void resize(std::size_t size)
Resize the internal point cloud to a fixed number of points.
Definition PointPerception.hpp:89
Provides efficient, non-destructive, chainable operations over a set of point-based perceptions.
Definition PointPerception.hpp:151
PointPerceptionsOpsView & downsample(double resolution)
Downsamples each perception using a voxel grid.
Definition PointPerception.cpp:204
const PointPerceptions & get_perceptions() const
Gets a reference to the underlying perceptions container.
Definition PointPerception.hpp:222
pcl::PointCloud< pcl::PointXYZ > as_points() const
Retrieves all selected points as a single cloud.
Definition PointPerception.cpp:264
PointPerceptionsOpsView & filter(const std::vector< double > &min_bounds, const std::vector< double > &max_bounds)
Filters all point clouds by spatial bounds.
Definition PointPerception.cpp:171
const pcl::PointCloud< pcl::PointXYZ > & as_points(int idx) const
Retrieves the filtered point cloud for a specific perception.
PointPerceptionsOpsView(const PointPerceptions &perceptions)
Constructor using a constant reference to a container of perceptions.
Definition PointPerception.cpp:148
std::shared_ptr< PointPerceptionsOpsView > fuse(const std::string &target_frame) const
Fuses all perceptions into one, transforming them to a common frame.
Definition PointPerception.cpp:287
std::shared_ptr< PointPerceptionsOpsView > collapse(const std::vector< double > &collapse_dims) const
Collapses dimensions to fixed values (e.g., project onto plane).
Definition PointPerception.cpp:234
Definition RTTFBuffer.hpp:30
sensor_msgs::msg::PointCloud2 points_to_rosmsg(const pcl::PointCloud< pcl::PointXYZ > &points)
Converts a PCL point cloud to a sensor_msgs::msg::PointCloud2 message.
Definition PointPerception.cpp:140
sensor_msgs::msg::PointCloud2 perception_to_rosmsg(const PointPerception &perception)
Converts a PointPerception to a sensor_msgs::msg::PointCloud2 message.
Definition PointPerception.cpp:130
void convert(const sensor_msgs::msg::LaserScan &scan, pcl::PointCloud< pcl::PointXYZ > &pc)
Converts a LaserScan message into a point cloud.
Definition PointPerception.cpp:98
std::vector< std::shared_ptr< PointPerception > > PointPerceptions
Alias for a vector of pointers to PointPerception objects.
Definition PointPerception.hpp:140
PointPerceptions get_point_perceptions(std::vector< PerceptionPtr > &perceptionptr)
Definition PointPerception.cpp:333
Definition PointPerception.hpp:56
Hash function for VoxelKey.
Definition PointPerception.hpp:169
std::size_t operator()(const VoxelKey &key) const
Definition PointPerception.hpp:170
Represents a discrete 3D voxel index for downsampling.
Definition PointPerception.hpp:156
int y
Definition PointPerception.hpp:157
int z
Definition PointPerception.hpp:157
int x
Definition PointPerception.hpp:157
bool operator==(const VoxelKey &other) const
Equality comparison operator.
Definition PointPerception.hpp:160
std::size_t operator()(const std::tuple< int, int, int > &key) const
Definition PointPerception.hpp:62