#ifndef __CPM__VTK__POLYDATATOMESHFILTER__HXX__ #define __CPM__VTK__POLYDATATOMESHFILTER__HXx__ #include #include // ------------------------------------------------------------------------- template< class M > const vtkPolyData* cpm::VTK::PolyDataToMeshFilter< M >:: GetInput( ) const { return( this->m_Input ); } // ------------------------------------------------------------------------- template< class M > void cpm::VTK::PolyDataToMeshFilter< M >:: SetInput( const vtkPolyData* input ) { if( this->m_Input != input ) { this->m_Input = input; this->Modified( ); } // fi } // ------------------------------------------------------------------------- template< class M > cpm::VTK::PolyDataToMeshFilter< M >:: PolyDataToMeshFilter( ) : Superclass( ), m_Input( NULL ) { } // ------------------------------------------------------------------------- template< class M > cpm::VTK::PolyDataToMeshFilter< M >:: ~PolyDataToMeshFilter( ) { } // ------------------------------------------------------------------------- template< class M > void cpm::VTK::PolyDataToMeshFilter< M >:: GenerateData( ) { typedef typename M::PixelType _TScalar; typedef itk::PolygonCell< typename M::CellType > _TPolygonCell; vtkPolyData* in = const_cast< vtkPolyData* >( this->m_Input ); typename M::Pointer out = this->GetOutput( ); out->Initialize( ); if( in == NULL ) return; // Assign points double vpnt[ 3 ]; typename M::PointType ipnt; for( unsigned long pId = 0; pId < in->GetNumberOfPoints( ); ++pId ) { in->GetPoint( pId, vpnt ); ipnt.Fill( _TScalar( 0 ) ); if( M::PointDimension > 0 ) ipnt[ 0 ] = _TScalar( vpnt[ 0 ] ); if( M::PointDimension > 1 ) ipnt[ 1 ] = _TScalar( vpnt[ 1 ] ); if( M::PointDimension > 2 ) ipnt[ 2 ] = _TScalar( vpnt[ 2 ] ); out->SetPoint( pId, ipnt ); } // rof // Assign cells for( unsigned long cId = 0; cId < in->GetNumberOfCells( ); ++cId ) { vtkCell* vcell = in->GetCell( cId ); unsigned int nPoints = vcell->GetNumberOfPoints( ); if( 2 < nPoints ) { // Add a face typename M::CellAutoPointer cell; _TPolygonCell* face = new _TPolygonCell( ); for( unsigned int k = 0; k < nPoints; ++k ) face->AddPointId( vcell->GetPointId( k ) ); cell.TakeOwnership( face ); out->SetCell( out->GetNumberOfCells( ), cell ); } // fi } // rof } #endif // __CPM__VTK__POLYDATATOMESHFILTER__HXX__ // eof - $RCSfile$