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