From 8007e07ad2ded72132f8a15e71e28519ffd540d1 Mon Sep 17 00:00:00 2001 From: ozantonkal Date: Wed, 28 Aug 2013 19:13:34 +0200 Subject: [PATCH] load mesh function is finalized: color range is always 0-255 and RGB due to vtkPLYReader limitations --- modules/viz/src/types.cpp | 19 ++++++------------- modules/viz/src/widget.cpp | 1 - 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index 6d3e3d589..64d6f91a1 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName(file.c_str()); reader->Update(); + vtkSmartPointer poly_data = reader->GetOutput (); + CV_Assert(poly_data); vtkSmartPointer mesh_points = poly_data->GetPoints (); vtkIdType nr_points = mesh_points->GetNumberOfPoints (); - //vtkIdType nr_polygons = poly_data->GetNumberOfPolys (); mesh.cloud.create(1, nr_points, CV_32FC3); @@ -89,18 +90,10 @@ struct cv::viz::Mesh3d::loadMeshImpl } // 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")); - - if (!poly_colors && poly_data->GetPointData () != NULL) - poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("RGB")); - - // TODO: currently only handles rgb values with 3 components + vtkUnsignedCharArray* poly_colors = 0; + if (poly_data->GetPointData()) + poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars()); + if (poly_colors && (poly_colors->GetNumberOfComponents () == 3)) { mesh.colors.create(1, nr_points, CV_8UC3); diff --git a/modules/viz/src/widget.cpp b/modules/viz/src/widget.cpp index ba21b6785..485e35ed7 100644 --- a/modules/viz/src/widget.cpp +++ b/modules/viz/src/widget.cpp @@ -17,7 +17,6 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name) { vtkSmartPointer reader = vtkSmartPointer::New (); reader->SetFileName (file_name.c_str ()); - reader->Update(); vtkSmartPointer data = reader->GetOutput(); CV_Assert(data);