1 #include <cpPlugins/Interface/PolyLineParametricPath.h>
3 #include <vtkCellArray.h>
6 #define ITK_MANUAL_INSTANTIATION
7 #include <itkPolyLineParametricPath.h>
8 #include <itkImageBase.h>
10 // -------------------------------------------------------------------------
11 std::string cpPlugins::Interface::PolyLineParametricPath::
14 return( "cpPlugins::Interface::PolyLineParametricPath" );
17 // -------------------------------------------------------------------------
18 void cpPlugins::Interface::PolyLineParametricPath::
19 SetRealDataObject( itk::DataObject* dobj, itk::DataObject* ref_image )
21 typedef itk::PolyLineParametricPath< 2 > _T2;
22 typedef itk::PolyLineParametricPath< 3 > _T3;
24 this->Superclass::SetRealDataObject( dobj );
26 if( ref_image != NULL )
28 if( dynamic_cast< _T2* >( dobj ) != NULL )
29 this->_VTK< 2 >( ref_image );
30 else if( dynamic_cast< _T3* >( dobj ) != NULL )
31 this->_VTK< 3 >( ref_image );
36 // -------------------------------------------------------------------------
37 cpPlugins::Interface::PolyLineParametricPath::
38 PolyLineParametricPath( )
41 this->m_PolyData = vtkSmartPointer< vtkPolyData >::New( );
44 // -------------------------------------------------------------------------
45 cpPlugins::Interface::PolyLineParametricPath::
46 ~PolyLineParametricPath( )
50 // -------------------------------------------------------------------------
51 template< unsigned int D >
52 void cpPlugins::Interface::PolyLineParametricPath::
53 _VTK( itk::DataObject* ref_image )
55 typedef itk::PolyLineParametricPath< D > _TPath;
56 typedef typename _TPath::VertexListType _TVertices;
57 typedef typename _TPath::ContinuousIndexType _TIndex;
58 typedef itk::ImageBase< D > _TImage;
59 typedef typename _TImage::PointType _TPoint;
62 dynamic_cast< _TPath* >( this->m_RealDataObject.GetPointer( ) );
65 const _TVertices* vertices = path->GetVertexList( );
66 if( vertices == NULL )
68 const _TImage* image = dynamic_cast< const _TImage* >( ref_image );
70 vtkSmartPointer< vtkPoints > points =
71 vtkSmartPointer< vtkPoints >::New( );
72 vtkSmartPointer< vtkCellArray > lines =
73 vtkSmartPointer< vtkCellArray >::New( );
75 for( unsigned int i = 0; i < vertices->Size( ); ++i )
77 _TIndex idx = vertices->GetElement( i );
81 image->TransformContinuousIndexToPhysicalPoint( idx, pnt );
82 x = double( pnt[ 0 ] );
83 y = double( pnt[ 1 ] );
84 z = ( D >= 3 )? double( pnt[ 2 ] ): double( 0 );
88 x = double( idx[ 0 ] );
89 y = double( idx[ 1 ] );
90 z = ( D >= 3 )? double( idx[ 2 ] ): double( 0 );
93 points->InsertNextPoint( x, y, z );
96 lines->InsertNextCell( 2 );
97 lines->InsertCellPoint( i - 1 );
98 lines->InsertCellPoint( i );
103 this->m_PolyData->SetPoints( points );
104 this->m_PolyData->SetLines( lines );