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

Fix rendering of pointclouds in PCLVisualizer #4067

Merged
merged 1 commit into from
May 9, 2020
Merged
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
Fix rendering of points.
  • Loading branch information
larshg committed May 8, 2020
commit c2675cdd8b2ed5686e3af0174a724b6caae0e5d0
48 changes: 23 additions & 25 deletions visualization/src/point_cloud_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,56 +686,54 @@ pcl::visualization::PointCloudGeometryHandler<pcl::PCLPointCloud2>::getGeometry

vtkSmartPointer<vtkFloatArray> data = vtkSmartPointer<vtkFloatArray>::New ();
data->SetNumberOfComponents (3);

vtkIdType nr_points = cloud_->width * cloud_->height;

if (!data->Resize(nr_points))
{
PCL_ERROR("[point_cloud_handlers::getGeometry] Failed to allocate space for points in VTK array.");
throw std::bad_alloc();
}


// Add all points
float dim;
vtkIdType j = 0; // true point index
std::vector<float> pts (nr_points * 3);
int point_offset = 0;

// If the dataset has no invalid values, just copy all of them
if (cloud_->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i, point_offset+=cloud_->point_step)
{
// Copy the value at the specified field
memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_x_idx_].offset], sizeof (float));
pts[i * 3 + 0] = dim;
const float* ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_x_idx_].offset]);
data->InsertNextValue(*ptr);

memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_y_idx_].offset], sizeof (float));
pts[i * 3 + 1] = dim;
ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_y_idx_].offset]);
data->InsertNextValue(*ptr);

memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_z_idx_].offset], sizeof (float));
pts[i * 3 + 2] = dim;
ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_z_idx_].offset]);
data->InsertNextValue(*ptr);
}
data->SetArray (&pts[0], nr_points * 3, 0);
points->SetData (data);
}
else
{
for (vtkIdType i = 0; i < nr_points; ++i, point_offset+=cloud_->point_step)
{
// Copy the value at the specified field
memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_x_idx_].offset], sizeof (float));
if (!std::isfinite (dim))
const float* ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_x_idx_].offset]);
if (!std::isfinite (*ptr))
continue;
pts[j * 3 + 0] = dim;
data->InsertNextValue(*ptr);

memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_y_idx_].offset], sizeof (float));
if (!std::isfinite (dim))
ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_y_idx_].offset]);
if (!std::isfinite (*ptr))
continue;
pts[j * 3 + 1] = dim;
data->InsertNextValue(*ptr);

memcpy (&dim, &cloud_->data[point_offset + cloud_->fields[field_z_idx_].offset], sizeof (float));
if (!std::isfinite (dim))
ptr = reinterpret_cast<const float*>(&cloud_->data[point_offset + cloud_->fields[field_z_idx_].offset]);
if (!std::isfinite (*ptr))
continue;
pts[j * 3 + 2] = dim;

// Set j and increment
j++;
data->InsertNextValue(*ptr);
}
data->SetArray (&pts[0], j * 3, 0);
points->SetData (data);
}
}
Expand Down