]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/RGBImageToOtherChannelsFilter.hxx
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / RGBImageToOtherChannelsFilter.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
7
8 #include <cmath>
9 #include <limits>
10 #include <vnl/vnl_math.h>
11
12 #include <itkImageRegionIterator.h>
13 #include <itkImageRegionConstIterator.h>
14
15 // -------------------------------------------------------------------------
16 template< class I, class O, class C >
17 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
18 GetChannel1( )
19 {
20   return( this->GetOutput( 0 ) );
21 }
22
23 // -------------------------------------------------------------------------
24 template< class I, class O, class C >
25 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
26 GetChannel2( )
27 {
28   return( this->GetOutput( 1 ) );
29 }
30
31 // -------------------------------------------------------------------------
32 template< class I, class O, class C >
33 O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
34 GetChannel3( )
35 {
36   return( this->GetOutput( 2 ) );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class I, class O, class C >
41 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
42 GetChannel1( ) const
43 {
44   if( this->GetNumberOfOutputs( ) > 0 )
45     return(
46       dynamic_cast< const O* >(
47         this->itk::ProcessObject::GetOutput( 0 )
48         )
49       );
50   else
51     return( NULL );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class I, class O, class C >
56 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
57 GetChannel2( ) const
58 {
59   if( this->GetNumberOfOutputs( ) > 1 )
60     return(
61       dynamic_cast< const O* >(
62         this->itk::ProcessObject::GetOutput( 1 )
63         )
64       );
65   else
66     return( NULL );
67 }
68
69 // -------------------------------------------------------------------------
70 template< class I, class O, class C >
71 const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
72 GetChannel3( ) const
73 {
74   if( this->GetNumberOfOutputs( ) > 2 )
75     return(
76       dynamic_cast< const O* >(
77         this->itk::ProcessObject::GetOutput( 2 )
78         )
79       );
80   else
81     return( NULL );
82 }
83
84 // -------------------------------------------------------------------------
85 template< class I, class O, class C >
86 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
87 GraftChannel1( O* hue )
88 {
89   this->GraftNthOutput( 0, hue );
90 }
91
92 // -------------------------------------------------------------------------
93 template< class I, class O, class C >
94 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
95 GraftChannel2( O* saturation )
96 {
97   this->GraftNthOutput( 1, saturation );
98 }
99
100 // -------------------------------------------------------------------------
101 template< class I, class O, class C >
102 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
103 GraftChannel3( O* value )
104 {
105   this->GraftNthOutput( 2, value );
106 }
107
108 // -------------------------------------------------------------------------
109 template< class I, class O, class C >
110 cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
111 RGBImageToOtherChannelsFilter( )
112   : Superclass( )
113 {
114   this->SetNumberOfRequiredInputs( 1 );
115   this->SetNumberOfRequiredOutputs( 3 );
116   for( unsigned int i = 0; i < 3; i++ )
117   {
118     typename O::Pointer o = O::New( );
119     this->SetNthOutput( i, o );
120
121   } // rof
122 }
123
124 // -------------------------------------------------------------------------
125 template< class I, class O, class C >
126 cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
127 ~RGBImageToOtherChannelsFilter( )
128 {
129 }
130
131 // -------------------------------------------------------------------------
132 template< class I, class O, class C >
133 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
134 BeforeThreadedGenerateData( )
135 {
136 }
137
138 // -------------------------------------------------------------------------
139 template< class I, class O, class C >
140 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
141 AfterThreadedGenerateData( )
142 {
143 }
144
145 // -------------------------------------------------------------------------
146 template< class I, class O, class C >
147 void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
148 ThreadedGenerateData(
149   const typename Superclass::OutputImageRegionType& region,
150   itk::ThreadIdType threadId
151   )
152 {
153   // typedef typename TInputPixel::ComponentType _TComponent;
154   typedef itk::ImageRegionConstIterator< I > _TInIt;
155   typedef itk::ImageRegionIterator< O >      _TOutIt;
156   typedef typename C::TOutPixel              _TOutPixel;
157
158   _TInIt inIt( this->GetInput( ), region );
159   _TOutIt hIt( this->GetChannel1( ), region );
160   _TOutIt sIt( this->GetChannel2( ), region );
161   _TOutIt vIt( this->GetChannel3( ), region );
162   inIt.GoToBegin( );
163   hIt.GoToBegin( );
164   sIt.GoToBegin( );
165   vIt.GoToBegin( );
166   for( ; !inIt.IsAtEnd( ); ++inIt, ++hIt, ++sIt, ++vIt )
167   {
168     _TOutPixel other = this->Converter( inIt.Get( ) );
169     hIt.Set( other[ 0 ] );
170     sIt.Set( other[ 1 ] );
171     vIt.Set( other[ 2 ] );
172
173   } // rof
174 }
175
176 #endif // __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
177
178 // eof - $RCSfile$