From 725b69528083e43ebc52bf76935596345c762fbb Mon Sep 17 00:00:00 2001 From: Larshg Date: Sat, 2 May 2020 22:27:58 +0200 Subject: [PATCH 1/2] Added unit test where points get removed and updatepointcloud is called on visualizer. --- test/visualization/test_visualization.cpp | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/visualization/test_visualization.cpp b/test/visualization/test_visualization.cpp index a6c4c5c6c86..007d780e2af 100644 --- a/test/visualization/test_visualization.cpp +++ b/test/visualization/test_visualization.cpp @@ -60,6 +60,36 @@ PointCloud::Ptr cloud_with_normals1 (new PointCloud); search::KdTree::Ptr tree3; search::KdTree::Ptr tree4; +pcl::PointCloud::Ptr getPointCloud(int pointNumber) { + pcl::PointCloud::Ptr cloud(new pcl::PointCloud()); + + for (int i = 0; i < pointNumber; i++) { + pcl::PointXYZRGB pt; + pt.x = (double)rand() / RAND_MAX * 10 - 5; + pt.y = (double)rand() / RAND_MAX * 10 - 5; + pt.z = (double)rand() / RAND_MAX * 10 - 5; + cloud->push_back(pt); + } + return cloud; +} + +//////////////////////////////////////////////////////////////////////////////// +TEST(PCL, PCLVisualizer_updatePointCloud) +{ + pcl::PointCloud::Ptr cloud = getPointCloud(3); + + // Setup a basic viewport window + pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer")); + pcl::visualization::PointCloudColorHandlerCustom color_green(cloud, 0, 225, 100); + viewer->addPointCloud(cloud, color_green, "sample cloud"); + + // remove points one by one) + while (!cloud->empty()) { + cloud->erase(cloud->end() - 1); + viewer->updatePointCloud(cloud, "sample cloud"); + viewer->spinOnce(100); + } +} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TEST (PCL, PCLVisualizer_camera) { From 20738c43f8624ecb506cde3969b9c1ecfe61fe92 Mon Sep 17 00:00:00 2001 From: Larshg Date: Sun, 3 May 2020 15:15:57 +0200 Subject: [PATCH 2/2] Use cloud generator --- test/visualization/test_visualization.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/test/visualization/test_visualization.cpp b/test/visualization/test_visualization.cpp index 007d780e2af..9cd48adefdd 100644 --- a/test/visualization/test_visualization.cpp +++ b/test/visualization/test_visualization.cpp @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -60,23 +61,13 @@ PointCloud::Ptr cloud_with_normals1 (new PointCloud); search::KdTree::Ptr tree3; search::KdTree::Ptr tree4; -pcl::PointCloud::Ptr getPointCloud(int pointNumber) { - pcl::PointCloud::Ptr cloud(new pcl::PointCloud()); - - for (int i = 0; i < pointNumber; i++) { - pcl::PointXYZRGB pt; - pt.x = (double)rand() / RAND_MAX * 10 - 5; - pt.y = (double)rand() / RAND_MAX * 10 - 5; - pt.z = (double)rand() / RAND_MAX * 10 - 5; - cloud->push_back(pt); - } - return cloud; -} - //////////////////////////////////////////////////////////////////////////////// TEST(PCL, PCLVisualizer_updatePointCloud) { - pcl::PointCloud::Ptr cloud = getPointCloud(3); + pcl::common::CloudGenerator > generator; + + pcl::PointCloud::Ptr cloud(new pcl::PointCloud()); + int result = generator.fill(3, 1, *cloud); // Setup a basic viewport window pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));