#ifndef __cpPlugins__DataObjects__Mesh__hxx__ #define __cpPlugins__DataObjects__Mesh__hxx__ // TODO: #include #include #include #include #include // ------------------------------------------------------------------------- template< class _TMesh > void cpPlugins::DataObjects::Mesh:: _ITK_2_VTK( _TMesh* mesh ) { long numPoints = mesh->GetNumberOfPoints( ); if( numPoints == 0 ) return; vtkSmartPointer< vtkPoints > vpoints = vtkSmartPointer< vtkPoints >::New( ); vpoints->SetNumberOfPoints( numPoints ); auto points = mesh->GetPoints( ); // Copy points vtkIdType VTKId = 0; std::map< vtkIdType, long > IndexMap; for( auto i = points->Begin( ); i != points->End( ); ++i, VTKId++ ) { IndexMap[ VTKId ] = i->Index( ); if( _TMesh::PointDimension == 2 ) vpoints->SetPoint( VTKId, i->Value( )[ 0 ], i->Value( )[ 1 ], 0 ); else if( _TMesh::PointDimension == 3 ) vpoints->SetPoint( VTKId, i->Value( )[ 0 ], i->Value( )[ 1 ], i->Value( )[ 2 ] ); } // rof // Copy cells vtkSmartPointer< vtkCellArray > vcells = vtkSmartPointer< vtkCellArray >::New( ); auto cells = mesh->GetCells( ); for( auto j = cells->Begin( ); j != cells->End( ); ++j ) { auto cell = j->Value( ); vcells->InsertNextCell( cell->GetNumberOfPoints( ) ); for( auto k = cell->PointIdsBegin( ); k != cell->PointIdsEnd( ); ++k ) vcells->InsertCellPoint( IndexMap[ *k ] ); } // rof // Final assignations vtkSmartPointer< vtkPolyData > vmesh = vtkSmartPointer< vtkPolyData >::New( ); vmesh->SetPoints( vpoints ); vmesh->SetPolys( vcells ); this->m_VTK = vmesh; this->Modified( ); } #endif // __cpPlugins__DataObjects__Mesh__hxx__ // eof - $RCSfile$