Skip to content

Small optimizations and fixes in PCLVisualizer #2112

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

Merged
merged 5 commits into from
Dec 18, 2017
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
56 changes: 30 additions & 26 deletions visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ pcl::visualization::PCLVisualizer::convertPointCloudToVTKPolyData (
float *data = (static_cast<vtkFloatArray*> (points->GetData ()))->GetPointer (0);

// Set the points
vtkIdType ptr = 0;
if (cloud->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i)
memcpy (&data[i * 3], &cloud->points[i].x, 12); // sizeof (float) * 3
for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3)
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
}
else
{
Expand All @@ -261,7 +262,7 @@ pcl::visualization::PCLVisualizer::convertPointCloudToVTKPolyData (
!pcl_isfinite (cloud->points[i].z))
continue;

memcpy (&data[j * 3], &cloud->points[i].x, 12); // sizeof (float) * 3
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
j++;
}
nr_points = j;
Expand Down Expand Up @@ -600,7 +601,9 @@ pcl::visualization::PCLVisualizer::addSphere (const PointT &center, double radiu
actor->GetProperty ()->SetRepresentationToSurface ();
actor->GetProperty ()->SetInterpolationToFlat ();
actor->GetProperty ()->SetColor (r, g, b);
#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
actor->GetMapper ()->ImmediateModeRenderingOn ();
#endif
actor->GetMapper ()->StaticOn ();
actor->GetMapper ()->ScalarVisibilityOff ();
actor->GetMapper ()->Update ();
Expand Down Expand Up @@ -1516,7 +1519,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
double minmax[2];
minmax[0] = std::numeric_limits<double>::min ();
minmax[1] = std::numeric_limits<double>::max ();
#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff ();
#endif
am_it->second.actor->GetMapper ()->SetScalarRange (minmax);

// Update the mapper
Expand Down Expand Up @@ -1552,7 +1557,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
double minmax[2];
minmax[0] = std::numeric_limits<double>::min ();
minmax[1] = std::numeric_limits<double>::max ();
#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff ();
#endif
am_it->second.actor->GetMapper ()->SetScalarRange (minmax);

// Update the mapper
Expand Down Expand Up @@ -1590,12 +1597,12 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
// Get a pointer to the beginning of the data array
float *data = (static_cast<vtkFloatArray*> (points->GetData ()))->GetPointer (0);

int pts = 0;
vtkIdType pts = 0;
// If the dataset is dense (no NaNs)
if (cloud->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i, pts += 3)
memcpy (&data[pts], &cloud->points[i].x, 12); // sizeof (float) * 3
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[pts]);
}
else
{
Expand All @@ -1605,8 +1612,7 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
// Check if the point is invalid
if (!isFinite (cloud->points[i]))
continue;

memcpy (&data[pts], &cloud->points[i].x, 12); // sizeof (float) * 3
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[pts]);
pts += 3;
j++;
}
Expand All @@ -1627,8 +1633,9 @@ pcl::visualization::PCLVisualizer::updatePointCloud (const typename pcl::PointCl
scalars->GetRange (minmax);
// Update the data
polydata->GetPointData ()->SetScalars (scalars);

#if VTK_RENDERING_BACKEND_OPENGL_VERSION < 2
am_it->second.actor->GetMapper ()->ImmediateModeRenderingOff ();
#endif
am_it->second.actor->GetMapper ()->SetScalarRange (minmax);

// Update the mapper
Expand Down Expand Up @@ -1668,17 +1675,16 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
colors = vtkSmartPointer<vtkUnsignedCharArray>::New ();
colors->SetNumberOfComponents (3);
colors->SetName ("Colors");

pcl::RGB rgb_data;
uint32_t offset = fields[rgb_idx].offset;
for (size_t i = 0; i < cloud->size (); ++i)
{
if (!isFinite (cloud->points[i]))
continue;
memcpy (&rgb_data, reinterpret_cast<const char*> (&cloud->points[i]) + fields[rgb_idx].offset, sizeof (pcl::RGB));
const pcl::RGB* const rgb_data = reinterpret_cast<const pcl::RGB*>(reinterpret_cast<const char*> (&cloud->points[i]) + offset);
unsigned char color[3];
color[0] = rgb_data.r;
color[1] = rgb_data.g;
color[2] = rgb_data.b;
color[0] = rgb_data->r;
color[1] = rgb_data->g;
color[2] = rgb_data->b;
colors->InsertNextTupleValue (color);
}
}
Expand All @@ -1692,13 +1698,13 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
// Get a pointer to the beginning of the data array
float *data = static_cast<vtkFloatArray*> (points->GetData ())->GetPointer (0);

int ptr = 0;
vtkIdType ptr = 0;
std::vector<int> lookup;
// If the dataset is dense (no NaNs)
if (cloud->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3)
memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3);
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
}
else
{
Expand All @@ -1711,7 +1717,7 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
continue;

lookup[i] = static_cast<int> (j);
memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3);
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
j++;
ptr += 3;
}
Expand Down Expand Up @@ -1851,7 +1857,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
if (cloud->is_dense)
{
for (vtkIdType i = 0; i < nr_points; ++i, ptr += 3)
memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3);
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
}
else
{
Expand All @@ -1864,7 +1870,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
continue;

lookup [i] = static_cast<int> (j);
memcpy (&data[ptr], &cloud->points[i].x, sizeof (float) * 3);
std::copy (&cloud->points[i].x, &cloud->points[i].x + 3, &data[ptr]);
j++;
ptr += 3;
}
Expand All @@ -1883,19 +1889,17 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
rgb_idx = pcl::getFieldIndex (*cloud, "rgba", fields);
if (rgb_idx != -1 && colors)
{
pcl::RGB rgb_data;
int j = 0;
uint32_t offset = fields[rgb_idx].offset;
for (size_t i = 0; i < cloud->size (); ++i)
{
if (!isFinite (cloud->points[i]))
continue;
memcpy (&rgb_data,
reinterpret_cast<const char*> (&cloud->points[i]) + fields[rgb_idx].offset,
sizeof (pcl::RGB));
const pcl::RGB* const rgb_data = reinterpret_cast<const pcl::RGB*>(reinterpret_cast<const char*> (&cloud->points[i]) + offset);
unsigned char color[3];
color[0] = rgb_data.r;
color[1] = rgb_data.g;
color[2] = rgb_data.b;
color[0] = rgb_data->r;
color[1] = rgb_data->g;
color[2] = rgb_data->b;
colors->SetTupleValue (j++, color);
}
}
Expand Down
3 changes: 2 additions & 1 deletion visualization/include/pcl/visualization/pcl_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ namespace pcl
*/
PCLVisualizer (const std::string &name = "", const bool create_interactor = true);

/** \brief PCL Visualizer constructor.
/** \brief PCL Visualizer constructor. It looks through the passed argv arguments to find the "-cam *.cam" argument.
* If the search failed, the name for cam file is calculated with boost uuid. If there is no such file, camera is not initilalized.
* \param[in] argc
* \param[in] argv
* \param[in] name the window name (empty by default)
Expand Down
Loading