#include <cpPlugins/Interface/Mesh.h>
-#include <vtkPolyData.h>
-
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Mesh::
-SetVTKMesh( vtkPolyData* mesh )
-{
- this->m_VTKObject = mesh;
- this->Modified( );
-}
-
-// -------------------------------------------------------------------------
-vtkPolyData* cpPlugins::Interface::Mesh::
-GetVTKMesh( )
-{
- return( dynamic_cast< vtkPolyData* >( this->m_VTKObject.GetPointer( ) ) );
-}
-
-// -------------------------------------------------------------------------
-const vtkPolyData* cpPlugins::Interface::Mesh::
-GetVTKMesh( ) const
-{
- return(
- dynamic_cast< const vtkPolyData* >( this->m_VTKObject.GetPointer( ) )
- );
-}
+#include <itkMesh.h>
+#include <itkLineCell.h>
+#include <itkTriangleCell.h>
+#include <itkPolygonCell.h>
-/*
-void cpPlugins::Interface::Mesh::
-SetITKDataObject( itk::DataObject* o )
-{
- // TODO: conversion!!!
- std::cout << "Mesh: SetITKDataObject " << std::endl;
- std::exit( 1 );
-}
+#include <vtkPolyData.h>
// -------------------------------------------------------------------------
void cpPlugins::Interface::Mesh::
-SetVTKDataObject( vtkDataObject* o )
+SetVTK( vtkObject* object )
{
- if( dynamic_cast< vtkPolyData* >( o ) != NULL )
+ typedef itk::Mesh< double, 3 > _TMesh;
+ typedef _TMesh::CellType _TCell;
+ typedef _TCell::CellAutoPointer _TCellAutoPointer;
+ typedef itk::LineCell< _TCell > _TLine;
+ typedef itk::TriangleCell< _TCell > _TTriangle;
+ typedef itk::PolygonCell< _TCell > _TPolygon;
+
+ vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( object );
+ if( mesh == NULL )
{
- this->m_VTKObject = o;
+ this->m_ITKObject = NULL;
+ this->Modified( );
+ return;
- // TODO: conversion!!!
- }
- else
- this->m_VTKObject = NULL;
-}
-
-// -------------------------------------------------------------------------
-vtkPolyData* cpPlugins::Interface::Mesh::
-GetVTKPolyData( )
-{
- return( dynamic_cast< vtkPolyData* >( this->m_VTKObject.GetPointer( ) ) );
-}
+ } // fi
-// -------------------------------------------------------------------------
-const vtkPolyData* cpPlugins::Interface::Mesh::
-GetVTKPolyData( ) const
-{
- return(
- dynamic_cast< const vtkPolyData* >( this->m_VTKObject.GetPointer( ) )
- );
+ if( this->m_VTKObject.GetPointer( ) != mesh )
+ {
+ this->m_VTKObject = mesh;
+
+ // Copy points
+ _TMesh::Pointer imesh = _TMesh::New( );
+ double point[ 3 ];
+ for( long i = 0; i < mesh->GetNumberOfPoints( ); ++i )
+ {
+ mesh->GetPoint( i, point );
+ _TMesh::PointType ipoint;
+ ipoint[ 0 ] = point[ 0 ];
+ ipoint[ 1 ] = point[ 1 ];
+ ipoint[ 2 ] = point[ 2 ];
+ imesh->SetPoint( i, ipoint );
+
+ } // rof
+
+ // Copy cells
+ for( long i = 0; i < mesh->GetNumberOfCells( ); ++i )
+ {
+ 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 )
+ {
+ _TPolygon* polygon = new _TPolygon( );
+ for( long j = 0; j < nPoints; ++j )
+ polygon->AddPointId( cell->GetPointId( j ) );
+ icell.TakeOwnership( polygon );
+
+ } // fi
+ imesh->SetCell( imesh->GetNumberOfCells( ), icell );
+
+ } // rof
+
+ this->m_ITKObject = imesh;
+ this->Modified( );
+
+ } // fi
}
-*/
-
// -------------------------------------------------------------------------
cpPlugins::Interface::Mesh::
Mesh( )
: Superclass( )
{
- this->m_ClassName = "cpPlugins::Interface::Mesh";
- this->m_ClassCategory = "BasicObject";
}
// -------------------------------------------------------------------------
{
}
-// -------------------------------------------------------------------------
-/* TODO
-template< unsigned int D >
-void cpPlugins::Interface::Mesh::
-_ITK_2_VTK_0( itk::DataObject* o )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class P, unsigned int D >
-void cpPlugins::Interface::Mesh::
-_ITK_2_VTK_1( itk::DataObject* o )
-{
-}
-
-// -------------------------------------------------------------------------
-template< unsigned int D >
-void cpPlugins::Interface::Mesh::
-_VTK_2_ITK_0( itk::DataObject* o )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class P, unsigned int D >
-void cpPlugins::Interface::Mesh::
-_VTK_2_ITK_1( itk::DataObject* o )
-{
-}
-*/
-
// eof - $RCSfile$