]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Mesh.hxx
MAC compilation issues solved... Now some tests please
[cpPlugins.git] / lib / cpPlugins / Interface / Mesh.hxx
index e897f617458dbf0a2ccd6758c568c72002293329..16504f095a31d9ea9ee3be828fbbf9c907a73fec 100644 (file)
@@ -1,11 +1,75 @@
 #ifndef __CPPLUGINS__INTERFACE__MESH__HXX__
 #define __CPPLUGINS__INTERFACE__MESH__HXX__
 
-#include <cpPlugins/Interface/Macros.h>
+#include <map>
 
 #include <itkMesh.h>
 #include <itkQuadEdgeMesh.h>
 
+#include <vtkSmartPointer.h>
+#include <vtkCellArray.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+
+// -------------------------------------------------------------------------
+template< class M >
+void cpPlugins::Interface::Mesh::
+_ITK_2_VTK( itk::LightObject* o )
+{
+  M* mesh = dynamic_cast< M* >( o );
+  if( mesh == NULL )
+    return;
+
+  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( M::PointDimension == 2 )
+      vpoints->SetPoint(
+        VTKId,
+        i->Value( )[ 0 ], i->Value( )[ 1 ], 0
+        );
+    else if( M::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_VTKObject = vmesh;
+  this->Modified( );
+}
+
 // -------------------------------------------------------------------------
 #define cpPlugins_Mesh_Import( N, T, D )                                \
   cpPlugins_TEMPLATE_IMPORT(                                            \
@@ -27,35 +91,6 @@ cpPlugins_Mesh_Import( QuadEdgeMesh, double, 3 );
 
 #endif // cpPlugins_Interface_EXPORTS
 
-// -------------------------------------------------------------------------
-template< class M >
-void cpPlugins::Interface::Mesh::
-SetITKMesh( itk::DataObject* object )
-{
-  std::cerr << "SetITKMesh: TODO" << std::endl;
-  std::exit( 1 );
-}
-
-// -------------------------------------------------------------------------
-template< class M >
-M* cpPlugins::Interface::Mesh::
-GetITKMesh( )
-{
-  std::cerr << "GetITKMesh: TODO" << std::endl;
-  std::exit( 1 );
-  return( NULL );
-}
-
-// -------------------------------------------------------------------------
-template< class M >
-const M* cpPlugins::Interface::Mesh::
-GetITKMesh( ) const
-{
-  std::cerr << "GetITKMesh (const): TODO" << std::endl;
-  std::exit( 1 );
-  return( NULL );
-}
-
 #endif // __CPPLUGINS__INTERFACE__MESH__HXX__
 
 // eof - $RCSfile$