#include #include #include #define ITK_MANUAL_INSTANTIATION #include #include // ------------------------------------------------------------------------- std::string cpPlugins::Interface::PolyLineParametricPath:: GetClassName( ) const { return( "cpPlugins::Interface::PolyLineParametricPath" ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::PolyLineParametricPath:: SetRealDataObject( itk::DataObject* dobj, itk::DataObject* ref_image ) { typedef itk::PolyLineParametricPath< 2 > _T2; typedef itk::PolyLineParametricPath< 3 > _T3; this->Superclass::SetRealDataObject( dobj ); if( ref_image != NULL ) { if( dynamic_cast< _T2* >( dobj ) != NULL ) this->_VTK< 2 >( ref_image ); else if( dynamic_cast< _T3* >( dobj ) != NULL ) this->_VTK< 3 >( ref_image ); } // fi } // ------------------------------------------------------------------------- cpPlugins::Interface::PolyLineParametricPath:: PolyLineParametricPath( ) : Superclass( ) { this->m_PolyData = vtkSmartPointer< vtkPolyData >::New( ); } // ------------------------------------------------------------------------- cpPlugins::Interface::PolyLineParametricPath:: ~PolyLineParametricPath( ) { } // ------------------------------------------------------------------------- template< unsigned int D > void cpPlugins::Interface::PolyLineParametricPath:: _VTK( itk::DataObject* ref_image ) { typedef itk::PolyLineParametricPath< D > _TPath; typedef typename _TPath::VertexListType _TVertices; typedef typename _TPath::ContinuousIndexType _TIndex; typedef itk::ImageBase< D > _TImage; typedef typename _TImage::PointType _TPoint; _TPath* path = dynamic_cast< _TPath* >( this->m_RealDataObject.GetPointer( ) ); if( path == NULL ) return; const _TVertices* vertices = path->GetVertexList( ); if( vertices == NULL ) return; const _TImage* image = dynamic_cast< const _TImage* >( ref_image ); vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints >::New( ); vtkSmartPointer< vtkCellArray > lines = vtkSmartPointer< vtkCellArray >::New( ); double x, y, z; for( unsigned int i = 0; i < vertices->Size( ); ++i ) { _TIndex idx = vertices->GetElement( i ); if( image != NULL ) { _TPoint pnt; image->TransformContinuousIndexToPhysicalPoint( idx, pnt ); x = double( pnt[ 0 ] ); y = double( pnt[ 1 ] ); z = ( D >= 3 )? double( pnt[ 2 ] ): double( 0 ); } else { x = double( idx[ 0 ] ); y = double( idx[ 1 ] ); z = ( D >= 3 )? double( idx[ 2 ] ): double( 0 ); } // fi points->InsertNextPoint( x, y, z ); if( i > 0 ) { lines->InsertNextCell( 2 ); lines->InsertCellPoint( i - 1 ); lines->InsertCellPoint( i ); } // fi } // rof this->m_PolyData->SetPoints( points ); this->m_PolyData->SetLines( lines ); } // eof - $RCSfile$