]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/PolyLineParametricPath.cxx
...
[cpPlugins.git] / lib / cpPlugins / Interface / PolyLineParametricPath.cxx
1 #include <cpPlugins/Interface/PolyLineParametricPath.h>
2
3 #include <vtkCellArray.h>
4 #include <vtkPoints.h>
5
6 #define ITK_MANUAL_INSTANTIATION
7 #include <itkPolyLineParametricPath.h>
8 #include <itkImageBase.h>
9
10 // -------------------------------------------------------------------------
11 std::string cpPlugins::Interface::PolyLineParametricPath::
12 GetClassName( ) const
13 {
14   return( "cpPlugins::Interface::PolyLineParametricPath" );
15 }
16
17 // -------------------------------------------------------------------------
18 void cpPlugins::Interface::PolyLineParametricPath::
19 SetRealDataObject( itk::DataObject* dobj, itk::DataObject* ref_image )
20 {
21   typedef itk::PolyLineParametricPath< 2 > _T2;
22   typedef itk::PolyLineParametricPath< 3 > _T3;
23
24   this->Superclass::SetRealDataObject( dobj );
25
26   if( ref_image != NULL )
27   {
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 );
32
33   } // fi
34 }
35
36 // -------------------------------------------------------------------------
37 cpPlugins::Interface::PolyLineParametricPath::
38 PolyLineParametricPath( )
39   : Superclass( )
40 {
41   this->m_PolyData = vtkSmartPointer< vtkPolyData >::New( );
42 }
43
44 // -------------------------------------------------------------------------
45 cpPlugins::Interface::PolyLineParametricPath::
46 ~PolyLineParametricPath( )
47 {
48 }
49
50 // -------------------------------------------------------------------------
51 template< unsigned int D >
52 void cpPlugins::Interface::PolyLineParametricPath::
53 _VTK( itk::DataObject* ref_image )
54 {
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;
60
61   _TPath* path =
62     dynamic_cast< _TPath* >( this->m_RealDataObject.GetPointer( ) );
63   if( path == NULL )
64     return;
65   const _TVertices* vertices = path->GetVertexList( );
66   if( vertices == NULL )
67     return;
68   const _TImage* image = dynamic_cast< const _TImage* >( ref_image );
69
70   vtkSmartPointer< vtkPoints > points =
71     vtkSmartPointer< vtkPoints >::New( );
72   vtkSmartPointer< vtkCellArray > lines =
73     vtkSmartPointer< vtkCellArray >::New( );
74   double x, y, z;
75   for( unsigned int i = 0; i < vertices->Size( ); ++i )
76   {
77     _TIndex idx = vertices->GetElement( i );
78     if( image != NULL )
79     {
80       _TPoint pnt;
81       image->TransformContinuousIndexToPhysicalPoint( idx, pnt );
82       x = double( pnt[ 0 ] );
83       y = double( pnt[ 1 ] );
84       z = ( D >= 3 )? double( pnt[ 2 ] ): double( 0 );
85     }
86     else
87     {
88       x = double( idx[ 0 ] );
89       y = double( idx[ 1 ] );
90       z = ( D >= 3 )? double( idx[ 2 ] ): double( 0 );
91
92     } // fi
93     points->InsertNextPoint( x, y, z );
94     if( i > 0 )
95     {
96       lines->InsertNextCell( 2 );
97       lines->InsertCellPoint( i - 1 );
98       lines->InsertCellPoint( i );
99
100     } // fi
101     
102   } // rof
103   this->m_PolyData->SetPoints( points );
104   this->m_PolyData->SetLines( lines );
105 }
106
107 // eof - $RCSfile$