]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 18 May 2016 00:14:35 +0000 (19:14 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 18 May 2016 00:14:35 +0000 (19:14 -0500)
lib/cpPlugins/Mesh.cxx

index 216f3b3ac9cf61b4300789d920d2cb3c21d6dfa0..054b71ae1b1f17e0f7cfac129f12556613b2b3e0 100644 (file)
@@ -57,33 +57,49 @@ SetVTK( vtkObjectBase* o )
     } // rof
 
     // Copy cells
-    for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
+    vtkCellArray* arrays[ 4 ];
+    arrays[ 0 ] = mesh->GetLines( );
+    arrays[ 1 ] = mesh->GetPolys( );
+    arrays[ 2 ] = NULL; // TODO: mesh->GetStrips( );
+    arrays[ 3 ] = mesh->GetVerts( );
+
+    for( unsigned int c = 0; c < 4; c++ )
     {
-      auto cell = mesh->GetCell( i );
-      long nPoints = cell->GetNumberOfPoints( );
-      _TCellAutoPointer icell;
-      if( nPoints == 2 )
-      {
-        icell.TakeOwnership( new _TLine );
-        icell->SetPointId( 0, cell->GetPointId( 0 ) );
-        icell->SetPointId( 1, cell->GetPointId( 1 ) );
-      }
-      else if( nPoints == 3 )
-      {
-        icell.TakeOwnership( new _TTriangle );
-        icell->SetPointId( 0, cell->GetPointId( 0 ) );
-        icell->SetPointId( 1, cell->GetPointId( 1 ) );
-        icell->SetPointId( 2, cell->GetPointId( 2 ) );
-      }
-      else if( nPoints > 3 )
+      if( arrays[ c ] != NULL )
       {
-        _TPolygon* polygon = new _TPolygon( );
-        for( long j = 0; j < nPoints; ++j )
-          polygon->AddPointId( cell->GetPointId( j ) );
-        icell.TakeOwnership( polygon );
+        vtkSmartPointer< vtkIdList > ids =
+          vtkSmartPointer< vtkIdList >::New( );
+        arrays[ c ]->InitTraversal( );
+        while( arrays[ c ]->GetNextCell( ids ) == 1 )
+        {
+          long nPoints = ids->GetNumberOfIds( );
+          _TCellAutoPointer icell;
+          if( nPoints == 2 )
+          {
+            icell.TakeOwnership( new _TLine );
+            icell->SetPointId( 0, ids->GetId( 0 ) );
+            icell->SetPointId( 1, ids->GetId( 1 ) );
+          }
+          else if( nPoints == 3 )
+          {
+            icell.TakeOwnership( new _TTriangle );
+            icell->SetPointId( 0, ids->GetId( 0 ) );
+            icell->SetPointId( 1, ids->GetId( 1 ) );
+            icell->SetPointId( 2, ids->GetId( 2 ) );
+          }
+          else if( nPoints > 3 )
+          {
+            _TPolygon* polygon = new _TPolygon( );
+            for( long j = 0; j < nPoints; ++j )
+              polygon->AddPointId( ids->GetId( j ) );
+            icell.TakeOwnership( polygon );
+
+          } // fi
+          imesh->SetCell( imesh->GetNumberOfCells( ), icell );
+
+        } // elihw
 
       } // fi
-      imesh->SetCell( imesh->GetNumberOfCells( ), icell );
 
     } // rof
     this->m_ITKObject = imesh;