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

[Visualizer] Fix crashes and exceptions in updatePointCloud() #4017

Merged
merged 2 commits into from
May 8, 2020
Merged
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
23 changes: 23 additions & 0 deletions test/visualization/test_visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <pcl/test/gtest.h>

#include <pcl/common/generate.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/features/normal_3d.h>
Expand All @@ -60,6 +61,28 @@ PointCloud<PointNormal>::Ptr cloud_with_normals1 (new PointCloud<PointNormal>);
search::KdTree<PointXYZ>::Ptr tree3;
search::KdTree<PointNormal>::Ptr tree4;

// Test that updatepointcloud works when removing points. Ie. modifying vtk data structure to reflect modified pointcloud
// See #4001 and #3452 for previously undetected error.
////////////////////////////////////////////////////////////////////////////////
TEST(PCL, PCLVisualizer_updatePointCloud)
larshg marked this conversation as resolved.
Show resolved Hide resolved
{
pcl::common::CloudGenerator<pcl::PointXYZRGB, pcl::common::UniformGenerator<float> > generator;

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
int result = generator.fill(3, 1, *cloud);

// Setup a basic viewport window
pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> color_green(cloud, 0, 225, 100);
viewer->addPointCloud<pcl::PointXYZRGB>(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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl

// Set the cells and the vertices
vertices->SetCells (nr_points, cells);
// Set the cell count explicitly as the array doesn't get modified enough so the above method updates accordingly. See #4001 and #3452
vertices->SetNumberOfCells(nr_points);

// Get the colors from the handler
bool has_colors = false;
Expand Down