load mesh function is finalized: color range is always 0-255 and RGB due to vtkPLYRea...
authorozantonkal <ozantonkal@gmail.com>
Wed, 28 Aug 2013 17:13:34 +0000 (19:13 +0200)
committerOzan Tonkal <ozantonkal@gmail.com>
Thu, 5 Sep 2013 19:03:39 +0000 (21:03 +0200)
modules/viz/src/types.cpp
modules/viz/src/widget.cpp

index 6d3e3d5898b4b267b65fdde08647315d5b15bc0f..64d6f91a1581d00ec95ef01aeea0b31c0984b350 100644 (file)
@@ -72,11 +72,12 @@ struct cv::viz::Mesh3d::loadMeshImpl
         vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
         reader->SetFileName(file.c_str());
         reader->Update();
+        
         vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput ();
+        CV_Assert(poly_data);
         
         vtkSmartPointer<vtkPoints> 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);
index ba21b67855759e7d5038e0c6e24f6e32381a9f19..485e35ed74b5cfcf4b593c6006c666d85e8c3505 100644 (file)
@@ -17,7 +17,6 @@ cv::viz::Widget cv::viz::Widget::fromPlyFile(const String &file_name)
 {
     vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New ();
     reader->SetFileName (file_name.c_str ());
-    reader->Update();
     
     vtkSmartPointer<vtkDataSet> data = reader->GetOutput();
     CV_Assert(data);