Skip to content

Commit 1a5b36a

Browse files
feat(tier4_autoware_utils): add and use transformPointcloud (autowarefoundation#3359)
* feat(tier4_autoware_utils): add and use transformPointcloud Signed-off-by: Kaan Çolak <kaancolak95@gmail.com> --------- Signed-off-by: Kaan Çolak <kaancolak95@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5055ae2 commit 1a5b36a

File tree

16 files changed

+134
-12
lines changed

16 files changed

+134
-12
lines changed

common/tier4_autoware_utils/include/tier4_autoware_utils/tier4_autoware_utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
#include "tier4_autoware_utils/ros/uuid_helper.hpp"
3939
#include "tier4_autoware_utils/ros/wait_for_param.hpp"
4040
#include "tier4_autoware_utils/system/stop_watch.hpp"
41+
#include "tier4_autoware_utils/transform/transforms.hpp"
4142

4243
#endif // TIER4_AUTOWARE_UTILS__TIER4_AUTOWARE_UTILS_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2020 Tier IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef TIER4_AUTOWARE_UTILS__TRANSFORM__TRANSFORMS_HPP_
16+
#define TIER4_AUTOWARE_UTILS__TRANSFORM__TRANSFORMS_HPP_
17+
18+
#include <Eigen/Core>
19+
#include <rclcpp/rclcpp.hpp>
20+
21+
#include <pcl/common/transforms.h>
22+
#include <pcl/point_cloud.h>
23+
24+
namespace tier4_autoware_utils
25+
{
26+
template <typename PointT>
27+
void transformPointCloud(
28+
const pcl::PointCloud<PointT> & cloud_in, pcl::PointCloud<PointT> & cloud_out,
29+
const Eigen::Matrix<float, 4, 4> & transform)
30+
{
31+
if (cloud_in.empty() || cloud_in.width == 0) {
32+
RCLCPP_WARN(rclcpp::get_logger("transformPointCloud"), "input point cloud is empty!");
33+
} else {
34+
pcl::transformPointCloud(cloud_in, cloud_out, transform);
35+
}
36+
}
37+
38+
template <typename PointT>
39+
void transformPointCloud(
40+
const pcl::PointCloud<PointT> & cloud_in, pcl::PointCloud<PointT> & cloud_out,
41+
const Eigen::Affine3f & transform)
42+
{
43+
if (cloud_in.empty() || cloud_in.width == 0) {
44+
RCLCPP_WARN(rclcpp::get_logger("transformPointCloud"), "input point cloud is empty!");
45+
} else {
46+
pcl::transformPointCloud(cloud_in, cloud_out, transform);
47+
}
48+
}
49+
} // namespace tier4_autoware_utils
50+
51+
#endif // TIER4_AUTOWARE_UTILS__TRANSFORM__TRANSFORMS_HPP_

common/tier4_autoware_utils/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>diagnostic_msgs</depend>
2121
<depend>geometry_msgs</depend>
2222
<depend>libboost-dev</depend>
23+
<depend>pcl_ros</depend>
2324
<depend>rclcpp</depend>
2425
<depend>tf2</depend>
2526
<depend>tf2_geometry_msgs</depend>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2020 Tier IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "tier4_autoware_utils/transform/transforms.hpp"
16+
17+
#include <gtest/gtest.h>
18+
#include <pcl/point_cloud.h>
19+
#include <pcl/point_types.h>
20+
21+
#include <thread>
22+
23+
TEST(system, transform_point_cloud)
24+
{
25+
pcl::PointCloud<pcl::PointXYZI> cloud;
26+
cloud.push_back(pcl::PointXYZI(10.055880, -42.758892, -10.636949, 4));
27+
cloud.push_back(pcl::PointXYZI(23.282284, -29.485722, -11.468469, 5));
28+
29+
Eigen::Matrix<float, 4, 4> transform;
30+
transform << 0.834513, -0.550923, -0.008474, 89571.148438, 0.550986, 0.834372, 0.015428,
31+
42301.179688, -0.001429, -0.017543, 0.999845, -3.157415, 0.000000, 0.000000, 0.000000, 1.000000;
32+
33+
pcl::PointCloud<pcl::PointXYZI> cloud_transformed;
34+
tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform);
35+
36+
pcl::PointXYZI pt1_gt(89603.187500, 42270.878906, -13.056946, 4);
37+
38+
constexpr float float_error = 0.0001;
39+
EXPECT_NEAR(cloud_transformed[0].x, pt1_gt.x, float_error);
40+
EXPECT_NEAR(cloud_transformed[0].y, pt1_gt.y, float_error);
41+
EXPECT_NEAR(cloud_transformed[0].z, pt1_gt.z, float_error);
42+
EXPECT_EQ(cloud_transformed[0].intensity, pt1_gt.intensity);
43+
}
44+
45+
TEST(system, empty_point_cloud)
46+
{
47+
pcl::PointCloud<pcl::PointXYZI> cloud;
48+
49+
Eigen::Matrix<float, 4, 4> transform;
50+
transform << 0.834513, -0.550923, -0.008474, 89571.148438, 0.550986, 0.834372, 0.015428,
51+
42301.179688, -0.001429, -0.017543, 0.999845, -3.157415, 0.000000, 0.000000, 0.000000, 1.000000;
52+
53+
pcl::PointCloud<pcl::PointXYZI> cloud_transformed;
54+
55+
EXPECT_NO_THROW(tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform));
56+
EXPECT_NO_FATAL_FAILURE(
57+
tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform));
58+
EXPECT_EQ(cloud_transformed.size(), 0ul);
59+
}

localization/ndt_scan_matcher/include/ndt_scan_matcher/map_update_module.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <rclcpp/rclcpp.hpp>
2424
#include <tier4_autoware_utils/ros/marker_helper.hpp>
25+
#include <tier4_autoware_utils/transform/transforms.hpp>
2526

2627
#include <autoware_map_msgs/srv/get_differential_point_cloud_map.hpp>
2728
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>

localization/ndt_scan_matcher/include/ndt_scan_matcher/pose_initialization_module.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <rclcpp/rclcpp.hpp>
2424
#include <tier4_autoware_utils/ros/marker_helper.hpp>
25+
#include <tier4_autoware_utils/transform/transforms.hpp>
2526

2627
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
2728
#include <tier4_localization_msgs/srv/pose_with_covariance_stamped.hpp>

localization/ndt_scan_matcher/src/map_update_module.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ geometry_msgs::msg::PoseWithCovarianceStamped MapUpdateModule::align_using_monte
260260
ndt_monte_carlo_initial_pose_marker_pub_->publish(marker_array);
261261

262262
auto sensor_points_mapTF_ptr = std::make_shared<pcl::PointCloud<PointSource>>();
263-
pcl::transformPointCloud(*ndt_ptr->getInputSource(), *sensor_points_mapTF_ptr, ndt_result.pose);
263+
tier4_autoware_utils::transformPointCloud(
264+
*ndt_ptr->getInputSource(), *sensor_points_mapTF_ptr, ndt_result.pose);
264265
publish_point_cloud(initial_pose_with_cov.header.stamp, map_frame_, sensor_points_mapTF_ptr);
265266
}
266267

localization/ndt_scan_matcher/src/ndt_scan_matcher_core.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ndt_scan_matcher/util_func.hpp"
2121

2222
#include <tier4_autoware_utils/geometry/geometry.hpp>
23+
#include <tier4_autoware_utils/transform/transforms.hpp>
2324

2425
#include <pcl_conversions/pcl_conversions.h>
2526

@@ -437,7 +438,7 @@ void NDTScanMatcher::callback_sensor_points(
437438

438439
pcl::shared_ptr<pcl::PointCloud<PointSource>> sensor_points_mapTF_ptr(
439440
new pcl::PointCloud<PointSource>);
440-
pcl::transformPointCloud(
441+
tier4_autoware_utils::transformPointCloud(
441442
*sensor_points_baselinkTF_ptr, *sensor_points_mapTF_ptr, ndt_result.pose);
442443
publish_point_cloud(sensor_ros_time, map_frame_, sensor_points_mapTF_ptr);
443444

@@ -495,7 +496,7 @@ void NDTScanMatcher::transform_sensor_measurement(
495496
tier4_autoware_utils::transform2pose(*TF_target_to_source_ptr);
496497
const Eigen::Matrix4f base_to_sensor_matrix =
497498
pose_to_matrix4f(target_to_source_pose_stamped.pose);
498-
pcl::transformPointCloud(
499+
tier4_autoware_utils::transformPointCloud(
499500
*sensor_points_input_ptr, *sensor_points_output_ptr, base_to_sensor_matrix);
500501
}
501502

localization/ndt_scan_matcher/src/pose_initialization_module.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ geometry_msgs::msg::PoseWithCovarianceStamped PoseInitializationModule::align_us
111111
ndt_monte_carlo_initial_pose_marker_pub_->publish(marker_array);
112112

113113
auto sensor_points_mapTF_ptr = std::make_shared<pcl::PointCloud<PointSource>>();
114-
pcl::transformPointCloud(*ndt_ptr->getInputSource(), *sensor_points_mapTF_ptr, ndt_result.pose);
114+
tier4_autoware_utils::transformPointCloud(
115+
*ndt_ptr->getInputSource(), *sensor_points_mapTF_ptr, ndt_result.pose);
115116
publish_point_cloud(initial_pose_with_cov.header.stamp, map_frame_, sensor_points_mapTF_ptr);
116117
}
117118

perception/lidar_apollo_instance_segmentation/include/lidar_apollo_instance_segmentation/detector.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <cuda_utils/stream_unique_ptr.hpp>
2424
#include <tensorrt_common/tensorrt_common.hpp>
2525
#include <tf2_eigen/tf2_eigen.hpp>
26+
#include <tier4_autoware_utils/transform/transforms.hpp>
2627

27-
#include <pcl/common/transforms.h>
2828
#include <tf2_ros/buffer_interface.h>
2929
#include <tf2_ros/transform_listener.h>
3030

perception/lidar_apollo_instance_segmentation/src/detector.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool LidarApolloInstanceSegmentation::transformCloud(
8383
target_frame_, input.header.frame_id, input.header.stamp, std::chrono::milliseconds(500));
8484
Eigen::Matrix4f affine_matrix =
8585
tf2::transformToEigen(transform_stamped.transform).matrix().cast<float>();
86-
pcl::transformPointCloud(pcl_input, pcl_transformed_cloud, affine_matrix);
86+
tier4_autoware_utils::transformPointCloud(pcl_input, pcl_transformed_cloud, affine_matrix);
8787
transformed_cloud.header.frame_id = target_frame_;
8888
pcl_transformed_cloud.header.frame_id = target_frame_;
8989
} catch (tf2::TransformException & ex) {
@@ -98,7 +98,8 @@ bool LidarApolloInstanceSegmentation::transformCloud(
9898
pcl::PointCloud<pcl::PointXYZI> pointcloud_with_z_offset;
9999
Eigen::Affine3f z_up_translation(Eigen::Translation3f(0, 0, z_offset));
100100
Eigen::Matrix4f z_up_transform = z_up_translation.matrix();
101-
pcl::transformPointCloud(pcl_transformed_cloud, pcl_transformed_cloud, z_up_transform);
101+
tier4_autoware_utils::transformPointCloud(
102+
pcl_transformed_cloud, pcl_transformed_cloud, z_up_transform);
102103

103104
pcl::toROSMsg(pcl_transformed_cloud, transformed_cloud);
104105

perception/lidar_apollo_segmentation_tvm/src/lidar_apollo_segmentation_tvm.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ void ApolloLidarSegmentation::transformCloud(
145145
tf_buffer_->lookupTransform(target_frame_, input.header.frame_id, time_point);
146146
Eigen::Matrix4f affine_matrix =
147147
tf2::transformToEigen(transform_stamped.transform).matrix().cast<float>();
148-
pcl::transformPointCloud(in_cluster, transformed_cloud_cluster, affine_matrix);
148+
tier4_autoware_utils::transformPointCloud(
149+
in_cluster, transformed_cloud_cluster, affine_matrix);
149150
transformed_cloud_cluster.header.frame_id = target_frame_;
150151
} else {
151152
transformed_cloud_cluster = in_cluster;
@@ -155,7 +156,7 @@ void ApolloLidarSegmentation::transformCloud(
155156
if (z_offset != 0) {
156157
Eigen::Affine3f z_up_translation(Eigen::Translation3f(0, 0, z_offset));
157158
Eigen::Matrix4f z_up_transform = z_up_translation.matrix();
158-
pcl::transformPointCloud(
159+
tier4_autoware_utils::transformPointCloud(
159160
transformed_cloud_cluster, transformed_cloud_cluster, z_up_transform);
160161
}
161162

planning/behavior_velocity_planner/src/node.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void BehaviorVelocityPlannerNode::onNoGroundPointCloud(
270270
Eigen::Affine3f affine = tf2::transformToEigen(transform.transform).cast<float>();
271271
pcl::PointCloud<pcl::PointXYZ>::Ptr pc_transformed(new pcl::PointCloud<pcl::PointXYZ>);
272272
if (!pc.empty()) {
273-
pcl::transformPointCloud(pc, *pc_transformed, affine);
273+
tier4_autoware_utils::transformPointCloud(pc, *pc_transformed, affine);
274274
}
275275

276276
{

planning/behavior_velocity_planner/src/scene_module/run_out/dynamic_obstacle.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ pcl::PointCloud<pcl::PointXYZ> transformPointCloud(
252252
pcl::PointCloud<pcl::PointXYZ> pointcloud_pcl;
253253
pcl::fromROSMsg(input_pointcloud, pointcloud_pcl);
254254
pcl::PointCloud<pcl::PointXYZ> pointcloud_pcl_transformed;
255-
pcl::transformPointCloud(pointcloud_pcl, pointcloud_pcl_transformed, transform_matrix);
255+
tier4_autoware_utils::transformPointCloud(
256+
pointcloud_pcl, pointcloud_pcl_transformed, transform_matrix);
256257

257258
return pointcloud_pcl_transformed;
258259
}

planning/surround_obstacle_checker/include/surround_obstacle_checker/node.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <motion_utils/motion_utils.hpp>
2121
#include <rclcpp/rclcpp.hpp>
2222
#include <tier4_autoware_utils/tier4_autoware_utils.hpp>
23+
#include <tier4_autoware_utils/transform/transforms.hpp>
2324
#include <vehicle_info_util/vehicle_info_util.hpp>
2425

2526
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>

planning/surround_obstacle_checker/src/node.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ boost::optional<Obstacle> SurroundObstacleCheckerNode::getNearestObstacleByPoint
346346
Eigen::Affine3f isometry = tf2::transformToEigen(transform_stamped.get().transform).cast<float>();
347347
pcl::PointCloud<pcl::PointXYZ> transformed_pointcloud;
348348
pcl::fromROSMsg(*pointcloud_ptr_, transformed_pointcloud);
349-
pcl::transformPointCloud(transformed_pointcloud, transformed_pointcloud, isometry);
349+
tier4_autoware_utils::transformPointCloud(
350+
transformed_pointcloud, transformed_pointcloud, isometry);
350351

351352
const auto ego_polygon = createSelfPolygon(vehicle_info_);
352353

0 commit comments

Comments
 (0)