load mesh function is finalized: color range is always 0-255 and RGB due to vtkPLYReader limitations

This commit is contained in:
ozantonkal 2013-08-28 19:13:34 +02:00 committed by Ozan Tonkal
parent e4b13f2ef0
commit 8007e07ad2
2 changed files with 6 additions and 14 deletions

View File

@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New(); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName(file.c_str()); reader->SetFileName(file.c_str());
reader->Update(); reader->Update();
vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput (); vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput ();
CV_Assert(poly_data);
vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints (); vtkSmartPointer<vtkPoints> mesh_points = poly_data->GetPoints ();
vtkIdType nr_points = mesh_points->GetNumberOfPoints (); vtkIdType nr_points = mesh_points->GetNumberOfPoints ();
//vtkIdType nr_polygons = poly_data->GetNumberOfPolys ();
mesh.cloud.create(1, nr_points, CV_32FC3); mesh.cloud.create(1, nr_points, CV_32FC3);
@ -89,18 +90,10 @@ struct cv::viz::Mesh3d::loadMeshImpl
} }
// Then the color information, if any // Then the color information, if any
vtkUnsignedCharArray* poly_colors = NULL; vtkUnsignedCharArray* poly_colors = 0;
if (poly_data->GetPointData() != NULL) if (poly_data->GetPointData())
poly_colors = vtkUnsignedCharArray::SafeDownCast (poly_data->GetPointData ()->GetScalars ("Colors")); poly_colors = vtkUnsignedCharArray::SafeDownCast(poly_data->GetPointData()->GetScalars());
// 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
if (poly_colors && (poly_colors->GetNumberOfComponents () == 3)) if (poly_colors && (poly_colors->GetNumberOfComponents () == 3))
{ {
mesh.colors.create(1, nr_points, CV_8UC3); mesh.colors.create(1, nr_points, CV_8UC3);

View File

@ -17,7 +17,6 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
{ {
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New (); vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New ();
reader->SetFileName (file_name.c_str ()); reader->SetFileName (file_name.c_str ());
reader->Update();
vtkSmartPointer<vtkDataSet> data = reader->GetOutput(); vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
CV_Assert(data); CV_Assert(data);