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

vtk2mesh: Add parsing support to the new RGBA scalar field added in vtk8 #2492

Merged
merged 2 commits into from
Sep 29, 2018
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
28 changes: 17 additions & 11 deletions io/src/vtk_lib_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,31 +288,37 @@ pcl::io::vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data, pcl::PolygonMe
// Then the color information, if any
vtkUnsignedCharArray* poly_colors = NULL;
if (poly_data->GetPointData() != NULL)
{
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("Colors"));

// some applications do not save the name of scalars (including PCL's native vtk_io)
if (!poly_colors && poly_data->GetPointData () != NULL)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("scalars"));
// some applications do not save the name of scalars (including PCL's native vtk_io)
if (!poly_colors)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("scalars"));

if (!poly_colors)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGB"));

if (!poly_colors && poly_data->GetPointData () != NULL)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGB"));
if (!poly_colors)
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGBA"));
}

// TODO: currently only handles rgb values with 3 components
if (poly_colors && (poly_colors->GetNumberOfComponents () == 3))
if (poly_colors && (poly_colors->GetNumberOfComponents () == 3 || poly_colors->GetNumberOfComponents () == 4))
{
pcl::PointCloud<pcl::RGB>::Ptr rgb_cloud (new pcl::PointCloud<pcl::RGB> ());
rgb_cloud->points.resize (nr_points);
rgb_cloud->width = static_cast<uint32_t> (rgb_cloud->points.size ());
rgb_cloud->height = 1;
rgb_cloud->is_dense = true;

unsigned char point_color[3];
unsigned char point_color[4] = {0, 0, 0, 255};
for (vtkIdType i = 0; i < mesh_points->GetNumberOfPoints (); i++)
{
poly_colors->GetTupleValue (i, &point_color[0]);
rgb_cloud->points[i].r = point_color[0];
rgb_cloud->points[i].g = point_color[1];
rgb_cloud->points[i].b = point_color[2];
// individual component copy due to different memory layout
(*rgb_cloud)[i].r = point_color[0];
(*rgb_cloud)[i].g = point_color[1];
(*rgb_cloud)[i].b = point_color[2];
(*rgb_cloud)[i].a = point_color[3];
}

pcl::PCLPointCloud2 rgb_cloud2;
Expand Down
8 changes: 8 additions & 0 deletions test/io/test_ply_mesh_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ TEST (PCL, PLYPolygonMeshIO)
EXPECT_EQ (mesh_binary_pcl.polygons[i].vertices[j], mesh.polygons[i].vertices[j]);
}
}

remove ("test_mesh_ascii.ply");
remove ("test_mesh_binary.ply");
}

TEST (PCL, PLYPolygonMeshColoredIO)
Expand Down Expand Up @@ -276,6 +279,11 @@ TEST (PCL, PLYPolygonMeshColoredIO)
EXPECT_EQ (mesh_rgba_binary_pcl.polygons[i].vertices[j], mesh.polygons[i].vertices[j]);
}
}

remove ("test_mesh_rgb_ascii.ply");
remove ("test_mesh_rgba_ascii.ply");
remove ("test_mesh_rgb_binary.ply");
remove ("test_mesh_rgba_binary.ply");
}

/* ---[ */
Expand Down