]> Creatis software - cpPlugins.git/blob - lib/ivq/ITK/CPRImageFilter.hxx
...
[cpPlugins.git] / lib / ivq / ITK / CPRImageFilter.hxx
1 /* =======================================================================
2  * @author: Leonardo Florez-Valencia
3  * @email: florez-l@javeriana.edu.co
4  * =======================================================================
5  */
6
7 #ifndef __ivq__ITK__CPRImageFilter__hxx__
8 #define __ivq__ITK__CPRImageFilter__hxx__
9
10 #include <itkMinimumMaximumImageCalculator.h>
11
12 // -------------------------------------------------------------------------
13 template< class _TImage, class _TCurve >
14 _TCurve* ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
15 GetCurve( )
16 {
17   return(
18     dynamic_cast< _TCurve* >( this->itk::ProcessObject::GetInput( 1 ) )
19     );
20 }
21
22 // -------------------------------------------------------------------------
23 template< class _TImage, class _TCurve >
24 const _TCurve* ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
25 GetCurve( ) const
26 {
27   return(
28     dynamic_cast< const _TCurve* >( this->itk::ProcessObject::GetInput( 1 ) )
29     );
30 }
31
32 // -------------------------------------------------------------------------
33 template< class _TImage, class _TCurve >
34 void ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
35 SetCurve( _TCurve* curve )
36 {
37   this->itk::ProcessObject::SetNthInput( 1, curve );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class _TImage, class _TCurve >
42 ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
43 CPRImageFilter( )
44   : Superclass( ),
45     m_SliceRadius( 0 )
46 {
47   this->Superclass::SetNumberOfRequiredInputs( 2 );
48 }
49
50 // -------------------------------------------------------------------------
51 template< class _TImage, class _TCurve >
52 ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
53 ~CPRImageFilter( )
54 {
55 }
56
57 // -------------------------------------------------------------------------
58 template< class _TImage, class _TCurve >
59 void ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
60 GenerateOutputInformation( )
61 {
62 }
63
64 // -------------------------------------------------------------------------
65 template< class _TImage, class _TCurve >
66 void ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
67 GenerateInputRequestedRegion( )
68 {
69   TImage* input = const_cast< TImage* >( this->GetInput( ) );
70   if( input != NULL )
71     input->SetRequestedRegionToLargestPossibleRegion( );
72 }
73
74 // -------------------------------------------------------------------------
75 template< class _TImage, class _TCurve >
76 void ivq::ITK::CPRImageFilter< _TImage, _TCurve >::
77 GenerateData( )
78 {
79   typedef itk::MinimumMaximumImageCalculator< _TImage > _TMinMax;
80
81   const _TImage* input = this->GetInput( );
82   const _TCurve* curve = this->GetCurve( );
83   _TImage* output = this->GetOutput( );
84
85   // Compute image intensity range
86   typename _TMinMax::Pointer minmax = _TMinMax::New( );
87   minmax->SetImage( input );
88   minmax->Compute( );
89
90   // Main loop
91   this->m_Join = TJoinFilter::New( );
92   this->m_Slicers.clear( );
93   unsigned long N = curve->GetNumberOfPoints( );
94   double len = 0;
95   typename _TCurve::TPoint p, q;
96   for( unsigned long n = 0; n < N; ++n )
97   {
98     p = curve->GetPoint( n );
99     if( n > 0 )
100       len += p.EuclideanDistanceTo( q );
101     q = p;
102
103     // Prepare slicer
104     typename TSlicer::Pointer slicer = TSlicer::New( );
105     slicer->SetInput( input );
106     slicer->SetDefaultValue( minmax->GetMinimum( ) );
107     slicer->SpacingFromMinimumOn( );
108     if( this->m_Interpolator.IsNotNull( ) )
109       slicer->SetInterpolator( this->m_Interpolator );
110     slicer->SizeFromMaximumOff( );
111     if( this->m_SliceRadius > double( 0 ) )
112     {
113       slicer->SizeFromMinimumOff( );
114       slicer->SetSize( this->m_SliceRadius );
115     }
116     else
117       slicer->SizeFromMinimumOn( );
118     slicer->SetTranslation( p );
119     slicer->SetRotation( curve->GetFrame( n ) );
120     slicer->Update( );
121
122     this->m_Join->SetInput( n, slicer->GetOutput( ) );
123     this->m_Slicers.push_back( slicer );
124
125   } // rof
126   this->m_Join->SetSpacing( len / double( N ) );
127   this->m_Join->Update( );
128   this->GetOutput( )->Graft( this->m_Join->GetOutput( ) );
129 }
130
131 #endif // __ivq__ITK__CPRImageFilter__hxx__
132
133 // eof - $RCSfile$