#include <cpPlugins/Interface/Mesh.h>
+#include <itkMesh.h>
+#include <itkLineCell.h>
+#include <itkTriangleCell.h>
+#include <itkPolygonCell.h>
+
#include <vtkPolyData.h>
// -------------------------------------------------------------------------
void cpPlugins::Interface::Mesh::
-SetVTK( vtkObject* mesh )
+SetVTK( vtkObject* object )
{
- if( dynamic_cast< vtkPolyData* >( mesh ) != NULL )
- this->m_VTKObject = mesh;
- else
- this->m_VTKObject = NULL;
- this->m_Mapper = NULL;
- this->m_Actor = NULL;
- this->Modified( );
-}
+ 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;
-// -------------------------------------------------------------------------
-void cpPlugins::Interface::Mesh::
-CreateVTKActor( )
-{
- vtkPolyData* pd = this->GetVTK< vtkPolyData >( );
- if(
- pd != NULL &&
- (
- this->m_Mapper.GetPointer( ) == NULL ||
- this->m_Actor.GetPointer( ) == NULL
- )
- )
+ vtkPolyData* mesh = dynamic_cast< vtkPolyData* >( object );
+ if( mesh == NULL )
{
- double range[ 2 ];
- pd->GetScalarRange( range );
+ this->m_ITKObject = NULL;
+ this->Modified( );
+ return;
- this->m_Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
- this->m_Stripper = vtkSmartPointer< vtkStripper >::New( );
- this->m_Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
- this->m_Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
+ } // fi
- this->m_Normals->SetInputData( pd );
- this->m_Normals->SetFeatureAngle( 60.0 );
- this->m_Stripper->SetInputConnection( this->m_Normals->GetOutputPort( ) );
- this->m_Mapper->SetInputConnection( this->m_Stripper->GetOutputPort( ) );
- this->m_Mapper->UseLookupTableScalarRangeOff( );
- this->m_Mapper->SetScalarRange(
- range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
- );
- this->m_Actor->SetMapper( this->m_Mapper );
- this->m_Actor->DeferLODConstructionOff( );
- this->Modified( );
+ if( this->m_VTKObject.GetPointer( ) != mesh )
+ {
+ this->m_VTKObject = mesh;
- /*
- TODO: vtkQuadricLODActor : AllocatedRenderTime
- */
+ // 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 );
- } // fi
-}
+ } // rof
-// -------------------------------------------------------------------------
-vtkActor* cpPlugins::Interface::Mesh::
-GetVTKActor( )
-{
- return( this->m_Actor );
-}
+ // 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 );
-// -------------------------------------------------------------------------
-const vtkActor* cpPlugins::Interface::Mesh::
-GetVTKActor( ) const
-{
- return( this->m_Actor );
-}
+ } // fi
+ imesh->SetCell( imesh->GetNumberOfCells( ), icell );
+
+ } // rof
+
+ this->m_ITKObject = imesh;
+ this->Modified( );
+ } // fi
+}
// -------------------------------------------------------------------------
cpPlugins::Interface::Mesh::
Mesh( )
- : Superclass( ),
- m_Mapper( NULL ),
- m_Actor( NULL )
+ : Superclass( )
{
}