Skip to content

Commit 02ca688

Browse files
author
plnegre
committed
Fix dependency for hydro compliance
1 parent dca4618 commit 02ca688

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

pointcloud_tools/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(pointcloud_tools)
33

4-
find_package(catkin REQUIRED COMPONENTS roscpp pcl_ros std_msgs sensor_msgs )
5-
find_package(PCL REQUIRED )
4+
find_package(catkin REQUIRED COMPONENTS roscpp pcl_ros std_msgs sensor_msgs nav_msgs)
5+
find_package(PCL REQUIRED)
6+
7+
find_package(Boost REQUIRED COMPONENTS signals filesystem system)
8+
include_directories(${Boost_INCLUDE_DIRS})
69

710
catkin_package()
811

912
include_directories(/usr/include/vtk-5.8 ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
1013

1114
add_executable(pointcloud_mapper src/pointcloud_mapper.cpp)
15+
add_executable(pointcloud_mapper_for_slam src/pointcloud_mapper_for_slam.cpp)
1216
add_executable(pointcloud_filtering src/pointcloud_filtering.cpp)
1317
add_executable(pcd_publisher src/pcd_publisher.cpp)
1418
add_executable(pointcloud_viewer src/pointcloud_viewer.cpp)
1519

16-
target_link_libraries(pointcloud_viewer ${PCL_LIBRARIES} ${catkin_LIBRARIES} libvtkCommon.so libvtkFiltering.so libvtkRendering.so)
20+
target_link_libraries(pointcloud_viewer ${Boost_LIBRARIES} ${PCL_LIBRARIES} ${catkin_LIBRARIES} libvtkCommon.so libvtkFiltering.so libvtkRendering.so)
1721
target_link_libraries(pcd_publisher ${PCL_LIBRARIES} ${catkin_LIBRARIES})
1822
target_link_libraries(pointcloud_mapper ${PCL_LIBRARIES} ${catkin_LIBRARIES})
23+
target_link_libraries(pointcloud_mapper_for_slam ${PCL_LIBRARIES} ${catkin_LIBRARIES})
1924
target_link_libraries(pointcloud_filtering ${PCL_LIBRARIES} ${catkin_LIBRARIES})

pointcloud_tools/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<build_depend>pcl_ros</build_depend>
1717
<build_depend>std_msgs</build_depend>
1818
<build_depend>sensor_msgs</build_depend>
19+
<build_depend>nav_msgs</build_depend>
1920
<run_depend>roscpp</run_depend>
2021
<run_depend>pcl_ros</run_depend>
2122
<run_depend>std_msgs</run_depend>
2223
<run_depend>sensor_msgs</run_depend>
24+
<run_depend>nav_msgs</run_depend>
2325

2426
<export>
2527

pointcloud_tools/src/pointcloud_viewer.cpp

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@
4242
#include <boost/thread/mutex.hpp>
4343
#include <boost/thread.hpp>
4444
// PCL includes
45+
#include <pcl/common/centroid.h>
4546
#include <pcl/point_types.h>
4647
#include <pcl_ros/point_cloud.h>
4748
#include <pcl/visualization/pcl_visualizer.h>
4849
#include <pcl/features/feature.h>
49-
#include <pcl/common/centroid.h>
50+
#include <pcl/io/pcd_io.h>
51+
#include <pcl/filters/voxel_grid.h>
52+
#include <pcl/filters/passthrough.h>
5053

5154
using pcl::visualization::PointCloudColorHandlerGenericField;
5255

@@ -59,6 +62,8 @@ typedef pcl::PointCloud<PointRGB> PointCloudRGB;
5962
sensor_msgs::PointCloud2ConstPtr cloud_, cloud_old_;
6063
boost::mutex m;
6164
bool viewer_initialized_;
65+
bool save_cloud_;
66+
std::string pcd_filename_;
6267
int counter_;
6368

6469
void cloud_cb(const sensor_msgs::PointCloud2ConstPtr& cloud)
@@ -71,6 +76,30 @@ void cloud_cb(const sensor_msgs::PointCloud2ConstPtr& cloud)
7176
m.unlock();
7277
}
7378

79+
PointCloudRGB::Ptr filter(PointCloudRGB::Ptr cloud, double voxel_size)
80+
{
81+
PointCloudRGB::Ptr cloud_filtered_ptr(new PointCloudRGB);
82+
83+
// Downsampling using voxel grid
84+
pcl::VoxelGrid<PointRGB> grid_;
85+
PointCloudRGB::Ptr cloud_downsampled_ptr(new PointCloudRGB);
86+
87+
grid_.setLeafSize(voxel_size,
88+
voxel_size,
89+
voxel_size);
90+
grid_.setDownsampleAllData(true);
91+
grid_.setInputCloud(cloud);
92+
grid_.filter(*cloud_downsampled_ptr);
93+
94+
return cloud_downsampled_ptr;
95+
}
96+
97+
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent& event, void* nothing)
98+
{
99+
if (event.getKeySym() == "space" && event.keyDown())
100+
save_cloud_ = true;
101+
}
102+
74103
void updateVisualization()
75104
{
76105
PointCloud cloud_xyz;
@@ -80,13 +109,15 @@ void updateVisualization()
80109

81110
ros::WallDuration d(0.01);
82111
bool rgb = false;
112+
//std::vector<sensor_msgs::PointField> fields;
83113
std::vector<pcl::PCLPointField> fields;
84114

85115
// Create the visualizer
86116
pcl::visualization::PCLVisualizer viewer("Point Cloud Viewer");
87117

88118
// Add a coordinate system to screen
89119
viewer.addCoordinateSystem(0.1);
120+
viewer.registerKeyboardCallback(&keyboardEventOccurred);
90121

91122
while(true)
92123
{
@@ -127,25 +158,35 @@ void updateVisualization()
127158
// Initialize the camera view
128159
if(!viewer_initialized_)
129160
{
130-
computeMeanAndCovarianceMatrix(cloud_xyz_rgb, covariance_matrix, xyz_centroid);
161+
pcl::computeMeanAndCovarianceMatrix(cloud_xyz_rgb, covariance_matrix, xyz_centroid);
131162
viewer.initCameraParameters();
132163
viewer.setCameraPosition(xyz_centroid(0), xyz_centroid(1), xyz_centroid(2)+3.0, 0, -1, 0);
133164
ROS_INFO_STREAM("[PointCloudViewer:] Point cloud viewer camera initialized in: [" <<
134165
xyz_centroid(0) << ", " << xyz_centroid(1) << ", " << xyz_centroid(2)+3.0 << "]");
135166
viewer_initialized_ = true;
136167
}
137-
138168
// Show the point cloud
139169
pcl::visualization::PointCloudColorHandlerRGBField<PointRGB> color_handler(
140170
cloud_xyz_rgb.makeShared());
141171
viewer.addPointCloud(cloud_xyz_rgb.makeShared(), color_handler, "cloud");
172+
173+
// Save pcd
174+
if (save_cloud_ && cloud_xyz_rgb.size() > 0)
175+
{
176+
if (pcl::io::savePCDFile(pcd_filename_, cloud_xyz_rgb) == 0)
177+
ROS_INFO_STREAM("[PointCloudViewer:] Pointcloud saved into: " << pcd_filename_);
178+
else
179+
ROS_ERROR_STREAM("[PointCloudViewer:] Problem saving " << pcd_filename_.c_str());
180+
save_cloud_ = false;
181+
}
182+
142183
}
143184
else
144185
{
145186
// Initialize the camera view
146187
if(!viewer_initialized_)
147188
{
148-
computeMeanAndCovarianceMatrix(cloud_xyz_rgb, covariance_matrix, xyz_centroid);
189+
pcl::computeMeanAndCovarianceMatrix(cloud_xyz_rgb, covariance_matrix, xyz_centroid);
149190
viewer.initCameraParameters();
150191
viewer.setCameraPosition(xyz_centroid(0), xyz_centroid(1), xyz_centroid(2)+3.0, 0, -1, 0);
151192
ROS_INFO_STREAM("[PointCloudViewer:] Point cloud viewer camera initialized in: [" <<
@@ -170,8 +211,17 @@ void updateVisualization()
170211
pcl::visualization::PointCloudColorHandlerCustom<Point> color_handler(
171212
cloud_xyz.makeShared(), 255, 0, 255);
172213
}
173-
174214
viewer.addPointCloud(cloud_xyz.makeShared(), color_handler, "cloud");
215+
216+
// Save pcd
217+
if (save_cloud_ && cloud_xyz.size() > 0)
218+
{
219+
if (pcl::io::savePCDFile(pcd_filename_, cloud_xyz) == 0)
220+
ROS_INFO_STREAM("[PointCloudViewer:] Pointcloud saved into: " << pcd_filename_);
221+
else
222+
ROS_ERROR_STREAM("[PointCloudViewer:] Problem saving " << pcd_filename_.c_str());
223+
save_cloud_ = false;
224+
}
175225
}
176226

177227
counter_++;
@@ -188,9 +238,14 @@ int main(int argc, char** argv)
188238
{
189239
ros::init(argc, argv, "pointcloud_viewer", ros::init_options::NoSigintHandler);
190240
ros::NodeHandle nh;
241+
ros::NodeHandle nh_priv("~");
191242
viewer_initialized_ = false;
243+
save_cloud_ = false;
192244
counter_ = 0;
193245

246+
// Read parameters
247+
nh_priv.param("pcd_filename", pcd_filename_, std::string("pointcloud_file.pcd"));
248+
194249
// Create a ROS subscriber
195250
ros::Subscriber sub = nh.subscribe("input", 30, cloud_cb);
196251

0 commit comments

Comments
 (0)