20
20
#include < pcl/kdtree/kdtree_flann.h>
21
21
#include < pcl/search/kdtree.h>
22
22
#include < pcl/segmentation/segment_differences.h>
23
-
23
+ #ifdef ROS_DISTRO_GALACTIC
24
+ #include < tf2_geometry_msgs/tf2_geometry_msgs.h>
25
+ #include < tf2_sensor_msgs/tf2_sensor_msgs.h>
26
+ #else
27
+ #include < tf2_geometry_msgs/tf2_geometry_msgs.hpp>
28
+ #include < tf2_sensor_msgs/tf2_sensor_msgs.hpp>
29
+ #endif
24
30
#include < memory>
25
31
#include < string>
26
32
@@ -29,7 +35,9 @@ namespace autoware::compare_map_segmentation
29
35
30
36
VoxelBasedCompareMapFilterComponent::VoxelBasedCompareMapFilterComponent (
31
37
const rclcpp::NodeOptions & options)
32
- : Filter(" VoxelBasedCompareMapFilter" , options)
38
+ : Filter(" VoxelBasedCompareMapFilter" , options),
39
+ tf_buffer_ (this ->get_clock ()),
40
+ tf_listener_(tf_buffer_)
33
41
{
34
42
// initialize debug tool
35
43
{
@@ -62,6 +70,60 @@ VoxelBasedCompareMapFilterComponent::VoxelBasedCompareMapFilterComponent(
62
70
RCLCPP_INFO (this ->get_logger (), " tf_map_input_frame: %s" , tf_input_frame_.c_str ());
63
71
}
64
72
73
+ // TODO(badai-nguyen): Temporary Implementation: Delete this override function when autoware_utils
74
+ // refactor (https://github.com/autowarefoundation/autoware_utils/pull/50) or new
75
+ // ManagedTransformBuffer lib is deployed for autoware
76
+ void VoxelBasedCompareMapFilterComponent::input_indices_callback (
77
+ const sensor_msgs::msg::PointCloud2::ConstSharedPtr cloud, const PointIndicesConstPtr indices)
78
+ {
79
+ // If cloud is given, check if it's valid
80
+ if (!isValid (cloud)) {
81
+ RCLCPP_ERROR (this ->get_logger (), " [input_indices_callback] Invalid input!" );
82
+ return ;
83
+ }
84
+ // If indices are given, check if they are valid
85
+ if (indices && !isValid (indices)) {
86
+ RCLCPP_ERROR (this ->get_logger (), " [input_indices_callback] Invalid indices!" );
87
+ return ;
88
+ }
89
+
90
+ // Check whether the user has given a different input TF frame
91
+ tf_input_orig_frame_ = cloud->header .frame_id ;
92
+ PointCloud2ConstPtr cloud_tf;
93
+ if (cloud->header .frame_id != tf_input_frame_) {
94
+ RCLCPP_DEBUG (
95
+ this ->get_logger (), " [input_indices_callback] Transforming input dataset from %s to %s." ,
96
+ cloud->header .frame_id .c_str (), tf_input_frame_.c_str ());
97
+ // Save the original frame ID
98
+ // Convert the cloud into the different frame
99
+ PointCloud2 cloud_transformed;
100
+
101
+ try {
102
+ // Lookup the transform from input frame to "map"
103
+ geometry_msgs::msg::TransformStamped transform_stamped = tf_buffer_.lookupTransform (
104
+ tf_input_frame_, tf_input_orig_frame_, rclcpp::Time (cloud->header .stamp ),
105
+ rclcpp::Duration::from_seconds (1.0 ));
106
+
107
+ // Transform the point cloud
108
+ tf2::doTransform (*cloud, cloud_transformed, transform_stamped);
109
+ cloud_transformed.header .frame_id = tf_input_frame_; // Update frame ID to "map"
110
+ cloud_tf = std::make_shared<PointCloud2>(cloud_transformed);
111
+ } catch (tf2::TransformException & ex) {
112
+ RCLCPP_WARN (this ->get_logger (), " Could not transform point cloud: %s" , ex.what ());
113
+ cloud_tf = cloud; // Fallback to original data
114
+ }
115
+ } else {
116
+ cloud_tf = cloud;
117
+ }
118
+ // Need setInputCloud () here because we have to extract x/y/z
119
+ IndicesPtr vindices;
120
+ if (indices) {
121
+ vindices.reset (new std::vector<int >(indices->indices ));
122
+ }
123
+
124
+ computePublish (cloud_tf, vindices);
125
+ }
126
+
65
127
void VoxelBasedCompareMapFilterComponent::filter (
66
128
const PointCloud2ConstPtr & input, [[maybe_unused]] const IndicesPtr & indices,
67
129
PointCloud2 & output)
0 commit comments