#include <cpPlugins/DataObjects/Mesh.h>
+#include <cpPlugins/DataObjects/Mesh_Demanglers.h>
+
+#include <itkMesh.h>
+#include <itkLineCell.h>
+#include <itkTriangleCell.h>
+#include <itkPolygonCell.h>
#include <vtkPolyData.h>
// -------------------------------------------------------------------------
SetITK( itk::LightObject* o )
{
this->Superclass::SetITK( o );
- bool s = false;
- cpPlugins_Demangle_Meshes_Dims( o, _ITK_2_VTK );
+ cpPlugins_Demangle_Mesh_Meshes_1( o, _ITK_2_VTK, 2 )
+ cpPlugins_Demangle_Mesh_Meshes_1( o, _ITK_2_VTK, 3 )
+ {
+ this->m_VTK = NULL;
+
+ } // fi
+ this->Modified( );
}
// -------------------------------------------------------------------------
{
}
+// -------------------------------------------------------------------------
+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( );
+}
+
// eof - $RCSfile$