Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the PCD VIEWPOINT field to transform the pointcloud before publication #442

Open
wants to merge 1 commit into
base: melodic-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pcl_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class_loader_hide_library_symbols(pcl_ros_surface)
## Tools

add_executable(pcd_to_pointcloud tools/pcd_to_pointcloud.cpp)
target_link_libraries(pcd_to_pointcloud ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES})
target_link_libraries(pcd_to_pointcloud ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES} pcl_ros_tf)

add_executable(pointcloud_to_pcd tools/pointcloud_to_pcd.cpp)
target_link_libraries(pointcloud_to_pcd ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES})
Expand Down
10 changes: 9 additions & 1 deletion pcl_ros/tools/pcd_to_pointcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
// ROS core
#include <ros/ros.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/transforms.h>

#include <string>
#include <sstream>
Expand Down Expand Up @@ -123,16 +124,23 @@ class pcd_to_pointcloud {
}

bool try_load_pointcloud() {
Eigen::Vector4f origin = Eigen::Vector4f::Zero();
Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity();
pcl::PCLPointCloud2 loadedCloud;
if (file_name.empty()) {
ROS_ERROR_STREAM("Can't load pointcloud: no file name provided");
return false;
}
else if (pcl::io::loadPCDFile(file_name, cloud) < 0) {
else if (pcl::io::loadPCDFile(file_name, loadedCloud, origin, orientation) < 0) {
ROS_ERROR_STREAM("Failed to parse pointcloud from file ('" << file_name << "')");
return false;
}
pcl_conversions::moveFromPCL(loadedCloud, cloud);
// success: set frame_id appropriately
cloud.header.frame_id = frame_id;
// Ignore origin[3], PCL doesn't fill it.
Eigen::Isometry3f transform = Eigen::Translation3f {origin.head<3>()} * orientation;
pcl_ros::transformPointCloud(transform.matrix(), cloud, cloud);
return true;
}

Expand Down