46
46
#include < pcl/console/parse.h>
47
47
#include < pcl/io/pcd_io.h>
48
48
#include < pcl/visualization/pcl_visualizer.h>
49
+ #include < pcl/visualization/point_cloud_color_handlers.h>
49
50
50
51
// PCL other
51
52
#include < pcl/filters/passthrough.h>
@@ -114,13 +115,6 @@ keyboardEventOccurred (const pcl::visualization::KeyboardEvent& event_arg,
114
115
115
116
// / ***** Prototypes ***** ///
116
117
117
- /* * \brief Fill vector with random colors
118
- * \param[in] label_colors_arg Vector to be filled.
119
- * \param[in] nr_labels_arg The number of random colors which will be drawn */
120
- void
121
- drawColors (std::vector<uint32_t >& label_colors_arg,
122
- const uint nr_labels_arg);
123
-
124
118
/* * \brief Displays info text in the specified PCLVisualizer
125
119
* \param[in] viewer_arg The PCLVisualizer to modify */
126
120
void
@@ -324,7 +318,6 @@ LCCPSegmentation Parameters: \n\
324
318
325
319
// / Get the cloud of supervoxel centroid with normals and the colored cloud with supervoxel coloring (this is used for visulization)
326
320
pcl::PointCloud<pcl::PointNormal>::Ptr sv_centroid_normal_cloud = pcl::SupervoxelClustering<PointT>::makeSupervoxelNormalCloud (supervoxel_clusters);
327
- pcl::PointCloud<pcl::PointXYZRGBA>::Ptr sv_colored_cloud = super.getColoredCloud (); // This is also used for supervoxel output
328
321
329
322
// / The Main Step: Perform LCCPSegmentation
330
323
@@ -343,29 +336,15 @@ LCCPSegmentation Parameters: \n\
343
336
}
344
337
345
338
PCL_INFO (" Interpolation voxel cloud -> input cloud and relabeling\n " );
346
- pcl::PointCloud<pcl::PointXYZL>::Ptr segment_labeled_cloud = super.getLabeledCloud ();
347
- lccp.relabelCloud (segment_labeled_cloud);
339
+ pcl::PointCloud<pcl::PointXYZL>::Ptr sv_labeled_cloud = super.getLabeledCloud ();
340
+ pcl::PointCloud<pcl::PointXYZL>::Ptr lccp_labeled_cloud = sv_labeled_cloud->makeShared ();
341
+ lccp.relabelCloud (lccp_labeled_cloud);
348
342
SuperVoxelAdjacencyList sv_adjacency_list;
349
343
lccp.getSVAdjacencyList (sv_adjacency_list); // Needed for visualization
350
344
351
345
// / Creating Colored Clouds and Output
352
- pcl::PointCloud<PointT>::Ptr recolored_cloud_ptr (input_cloud_ptr->makeShared ());
353
- if (segment_labeled_cloud->size () == input_cloud_ptr->size ())
346
+ if (lccp_labeled_cloud->size () == input_cloud_ptr->size ())
354
347
{
355
- PCL_INFO (" Coloring cloud\n " );
356
- std::vector<uint32_t > label_colors;
357
- drawColors (label_colors, supervoxel_clusters.size ());
358
-
359
- /* NOTE: segment_labeled_cloud was produced by getLabeledCloud (), which performs an interpolation to the input cloud.
360
- Thus, segment_labeled_cloud and the input cloud should have the same size and points with the same ID should correspond to one another. */
361
-
362
- for (int pointID = 0 ; pointID < segment_labeled_cloud->size (); ++pointID)
363
- {
364
- PointT& search_point = recolored_cloud_ptr->points [pointID];
365
- pcl::PointXYZL& label_point = segment_labeled_cloud->points [pointID];
366
- search_point.rgba = label_colors[label_point.label ];
367
- }
368
-
369
348
if (output_specified)
370
349
{
371
350
PCL_INFO (" Saving output\n " );
@@ -374,12 +353,12 @@ LCCPSegmentation Parameters: \n\
374
353
if (hasField (input_pointcloud2, " label" ))
375
354
PCL_WARN (" Input cloud already has a label field. It will be overwritten by the lccp segmentation output.\n " );
376
355
pcl::PCLPointCloud2 output_label_cloud2, output_concat_cloud2;
377
- pcl::toPCLPointCloud2 (*segment_labeled_cloud , output_label_cloud2);
356
+ pcl::toPCLPointCloud2 (*lccp_labeled_cloud , output_label_cloud2);
378
357
pcl::concatenateFields (input_pointcloud2, output_label_cloud2, output_concat_cloud2);
379
358
pcl::io::savePCDFile (outputname + " _out.pcd" , output_concat_cloud2, Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), save_binary_pcd);
380
359
}
381
360
else
382
- pcl::io::savePCDFile (outputname + " _out.pcd" , *segment_labeled_cloud , save_binary_pcd);
361
+ pcl::io::savePCDFile (outputname + " _out.pcd" , *lccp_labeled_cloud , save_binary_pcd);
383
362
384
363
if (sv_output_specified)
385
364
{
@@ -448,18 +427,16 @@ LCCPSegmentation Parameters: \n\
448
427
pcl::PointXYZRGBA vert_curr = supervoxel->centroid_ ;
449
428
450
429
451
- const uint32_t sv_neighbor_label = sv_adjacency_list[*itr_neighbor];
430
+ const uint32_t sv_neighbor_label = sv_adjacency_list[*itr_neighbor];
452
431
pcl::Supervoxel<PointT>::Ptr supervoxel_neigh = supervoxel_clusters.at (sv_neighbor_label);
453
432
pcl::PointXYZRGBA vert_neigh = supervoxel_neigh->centroid_ ;
454
-
455
433
456
434
points->InsertNextPoint (vert_curr.data );
457
- points->InsertNextPoint (vert_neigh.data );
458
-
435
+ points->InsertNextPoint (vert_neigh.data );
459
436
460
- // Add the points to the dataset
461
- vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New ();
462
- polyLine->GetPointIds ()->SetNumberOfIds (2 );
437
+ // Add the points to the dataset
438
+ vtkSmartPointer<vtkPolyLine> polyLine = vtkSmartPointer<vtkPolyLine>::New ();
439
+ polyLine->GetPointIds ()->SetNumberOfIds (2 );
463
440
polyLine->GetPointIds ()->SetId (0 ,points->GetNumberOfPoints ()-2 );
464
441
polyLine->GetPointIds ()->SetId (1 ,points->GetNumberOfPoints ()-1 );
465
442
cells->InsertNextCell (polyLine);
@@ -474,10 +451,10 @@ LCCPSegmentation Parameters: \n\
474
451
// / END: Calculate visualization of adjacency graph
475
452
476
453
// / Configure Visualizer
477
- boost::shared_ptr< pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer (" 3D Viewer" ));
454
+ pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer (" 3D Viewer" ));
478
455
viewer->setBackgroundColor (0 , 0 , 0 );
479
456
viewer->registerKeyboardCallback (keyboardEventOccurred, 0 );
480
- viewer->addPointCloud (recolored_cloud_ptr , " maincloud" );
457
+ viewer->addPointCloud (lccp_labeled_cloud , " maincloud" );
481
458
482
459
// / Visualization Loop
483
460
PCL_INFO (" Loading viewer\n " );
@@ -486,7 +463,7 @@ LCCPSegmentation Parameters: \n\
486
463
viewer->spinOnce (100 );
487
464
488
465
// / Show Segmentation or Supervoxels
489
- viewer->updatePointCloud ( (show_supervoxels) ? sv_colored_cloud : recolored_cloud_ptr , " maincloud" );
466
+ viewer->updatePointCloud ( (show_supervoxels) ? sv_labeled_cloud : lccp_labeled_cloud , " maincloud" );
490
467
491
468
// / Show Normals
492
469
if (normals_changed)
@@ -531,27 +508,6 @@ LCCPSegmentation Parameters: \n\
531
508
532
509
// / -------------------------| Definitions of helper functions|-------------------------
533
510
534
- void
535
- drawColors (std::vector<uint32_t >& label_colors_arg,
536
- const uint nr_labels_arg)
537
- {
538
- // Create colors for coloring segments
539
- const uint32_t max_label = 1.1 * nr_labels_arg; // 10% error margin..
540
- label_colors_arg.clear ();
541
- label_colors_arg.reserve (max_label);
542
- // NOTE First label pushed back can be used for errors
543
- label_colors_arg.push_back (static_cast <uint32_t > (0 ) << 16 | static_cast <uint32_t > (0 ) << 8 | static_cast <uint32_t > (0 ));
544
-
545
- srand (static_cast <unsigned int > (time (0 )));
546
- for (size_t i_label = 0 ; i_label < max_label; i_label++)
547
- {
548
- uint8_t r = static_cast <uint8_t > ( (rand () % 256 ));
549
- uint8_t g = static_cast <uint8_t > ( (rand () % 256 ));
550
- uint8_t b = static_cast <uint8_t > ( (rand () % 256 ));
551
- label_colors_arg.push_back (static_cast <uint32_t > (r) << 16 | static_cast <uint32_t > (g) << 8 | static_cast <uint32_t > (b));
552
- }
553
- }
554
-
555
511
void
556
512
printText (boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer_arg)
557
513
{
0 commit comments