Skip to content

Commit cf14c0d

Browse files
committed
fixed bug with XYZ clouds
1 parent 0a1671f commit cf14c0d

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

pointcloud_tools/src/pointcloud_viewer.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ PointCloudRGB cloud_xyz_rgb_;
7171
void cloud_cb(const sensor_msgs::PointCloud2ConstPtr& cloud)
7272
{
7373
m_.lock ();
74-
ROS_INFO_STREAM("Pointcloud viewer has received a pointcloud.");
74+
ROS_INFO_STREAM("[PointCloudViewer:] Pointcloud received.");
7575
cloud_ = cloud;
7676
m_.unlock();
7777
}
7878

7979
void keyboardEventOccurred(const pcl::visualization::KeyboardEvent& event, void* nothing)
8080
{
8181
if (event.getKeySym() == "space" && event.keyDown()) {
82-
ROS_INFO("Saving pointcloud, please wait...");
82+
ROS_INFO("[PointCloudViewer:] Saving pointcloud, please wait...");
8383
save_cloud_ = true;
8484
}
8585
}
@@ -156,23 +156,14 @@ void updateVisualization()
156156
// Initialize the camera view
157157
if(!viewer_initialized_)
158158
{
159-
pcl::computeMeanAndCovarianceMatrix(cloud_xyz_rgb_, covariance_matrix, xyz_centroid);
159+
pcl::computeMeanAndCovarianceMatrix(cloud_xyz_, covariance_matrix, xyz_centroid);
160160
viewer.initCameraParameters();
161161
viewer.setCameraPosition(xyz_centroid(0), xyz_centroid(1), xyz_centroid(2)+3.0, 0, -1, 0);
162162
ROS_INFO_STREAM("[PointCloudViewer:] Point cloud viewer camera initialized in: [" <<
163163
xyz_centroid(0) << ", " << xyz_centroid(1) << ", " << xyz_centroid(2)+3.0 << "]");
164164
viewer_initialized_ = true;
165165
}
166166

167-
// Some xyz_rgb point clouds have incorrect rgb field. Detect and convert to xyz.
168-
if(pcl::getFieldIndex(cloud_xyz_rgb_, "rgb", fields) != -1)
169-
{
170-
if(cloud_xyz_rgb_.points[0].rgb == 0)
171-
{
172-
pcl::copyPointCloud(cloud_xyz_rgb_, cloud_xyz_);
173-
}
174-
}
175-
176167
// Show the xyz point cloud
177168
PointCloudColorHandlerGenericField<Point> color_handler (cloud_xyz_.makeShared(), "z");
178169
if (!color_handler.isCapable ())
@@ -211,15 +202,15 @@ void saveCallback(const ros::WallTimerEvent&)
211202
}
212203
}
213204

214-
void sigIntHandler(int sig)
215-
{
216-
exit(0);
217-
}
205+
// void sigIntHandler(int sig)
206+
// {
207+
// exit(0);
208+
// }
218209

219210
/* ---[ */
220211
int main(int argc, char** argv)
221212
{
222-
ros::init(argc, argv, "pointcloud_viewer", ros::init_options::NoSigintHandler);
213+
ros::init(argc, argv, "pointcloud_viewer");//, ros::init_options::NoSigintHandler);
223214
ros::NodeHandle nh;
224215
ros::NodeHandle nh_priv("~");
225216
viewer_initialized_ = false;
@@ -232,9 +223,9 @@ int main(int argc, char** argv)
232223
// Create a ROS subscriber
233224
ros::Subscriber sub = nh.subscribe("input", 30, cloud_cb);
234225

235-
ROS_INFO("Subscribing to %s for PointCloud2 messages...", nh.resolveName ("input").c_str ());
226+
ROS_INFO("[PointCloudViewer:] Subscribing to %s for PointCloud2 messages...", nh.resolveName ("input").c_str ());
236227

237-
signal(SIGINT, sigIntHandler);
228+
// signal(SIGINT, sigIntHandler);
238229
boost::thread visualization_thread(&updateVisualization);
239230
save_timer_ = nh.createWallTimer(ros::WallDuration(1), &saveCallback);
240231

0 commit comments

Comments
 (0)