From 663e093a7a84156a1e6a3457ef9e5ac49e617a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Agostinho?= Date: Sat, 29 Sep 2018 13:06:58 +0200 Subject: [PATCH 1/2] Cleanup ply files after ply_mesh_io test completion. --- test/io/test_ply_mesh_io.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/io/test_ply_mesh_io.cpp b/test/io/test_ply_mesh_io.cpp index f16da63ae5a..0bb613e901f 100644 --- a/test/io/test_ply_mesh_io.cpp +++ b/test/io/test_ply_mesh_io.cpp @@ -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) @@ -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"); } /* ---[ */ From 85e73ecf0958f8d43c1dcf062642c7c0eaaa2ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Agostinho?= Date: Sat, 29 Sep 2018 13:08:01 +0200 Subject: [PATCH 2/2] vtk2mesh: Add parsing support to the new RGBA scalar field added in vtk8. --- io/src/vtk_lib_io.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/io/src/vtk_lib_io.cpp b/io/src/vtk_lib_io.cpp index cc537c15d4e..92a880a7877 100644 --- a/io/src/vtk_lib_io.cpp +++ b/io/src/vtk_lib_io.cpp @@ -288,17 +288,21 @@ pcl::io::vtk2mesh (const vtkSmartPointer& 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::Ptr rgb_cloud (new pcl::PointCloud ()); rgb_cloud->points.resize (nr_points); @@ -306,13 +310,15 @@ pcl::io::vtk2mesh (const vtkSmartPointer& poly_data, pcl::PolygonMe 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;