1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__
10 #include <vnl/vnl_math.h>
12 #include <itkImageRegionIterator.h>
13 #include <itkImageRegionConstIterator.h>
15 // -------------------------------------------------------------------------
16 template< class I, class O, class C >
18 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
21 return( this->GetOutput( 0 ) );
24 // -------------------------------------------------------------------------
25 template< class I, class O, class C >
27 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
30 return( this->GetOutput( 1 ) );
33 // -------------------------------------------------------------------------
34 template< class I, class O, class C >
36 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
39 return( this->GetOutput( 2 ) );
42 // -------------------------------------------------------------------------
43 template< class I, class O, class C >
45 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
48 if( this->GetNumberOfOutputs( ) > 0 )
50 dynamic_cast< const O* >(
51 this->itk::ProcessObject::GetOutput( 0 )
58 // -------------------------------------------------------------------------
59 template< class I, class O, class C >
61 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
64 if( this->GetNumberOfOutputs( ) > 1 )
66 dynamic_cast< const O* >(
67 this->itk::ProcessObject::GetOutput( 1 )
74 // -------------------------------------------------------------------------
75 template< class I, class O, class C >
77 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
80 if( this->GetNumberOfOutputs( ) > 2 )
82 dynamic_cast< const O* >(
83 this->itk::ProcessObject::GetOutput( 2 )
90 // -------------------------------------------------------------------------
91 template< class I, class O, class C >
93 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
94 GraftChannel1( O* hue )
96 this->GraftNthOutput( 0, hue );
99 // -------------------------------------------------------------------------
100 template< class I, class O, class C >
102 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
103 GraftChannel2( O* saturation )
105 this->GraftNthOutput( 1, saturation );
108 // -------------------------------------------------------------------------
109 template< class I, class O, class C >
111 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
112 GraftChannel3( O* value )
114 this->GraftNthOutput( 2, value );
117 // -------------------------------------------------------------------------
118 template< class I, class O, class C >
119 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
120 RGBImageToOtherChannelsFilter( )
123 this->SetNumberOfRequiredInputs( 1 );
124 this->SetNumberOfRequiredOutputs( 3 );
125 for( unsigned int i = 0; i < 3; i++ )
127 typename O::Pointer o = O::New( );
128 this->SetNthOutput( i, o );
133 // -------------------------------------------------------------------------
134 template< class I, class O, class C >
135 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
136 ~RGBImageToOtherChannelsFilter( )
140 // -------------------------------------------------------------------------
141 template< class I, class O, class C >
143 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
144 BeforeThreadedGenerateData( )
148 // -------------------------------------------------------------------------
149 template< class I, class O, class C >
151 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
152 AfterThreadedGenerateData( )
156 // -------------------------------------------------------------------------
157 template< class I, class O, class C >
159 cpPlugins::Extensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >::
160 ThreadedGenerateData(
161 const typename Superclass::OutputImageRegionType& region,
162 itk::ThreadIdType threadId
165 // typedef typename TInputPixel::ComponentType _TComponent;
166 typedef itk::ImageRegionConstIterator< I > _TInIt;
167 typedef itk::ImageRegionIterator< O > _TOutIt;
168 typedef typename C::TOutPixel _TOutPixel;
170 _TInIt inIt( this->GetInput( ), region );
171 _TOutIt hIt( this->GetChannel1( ), region );
172 _TOutIt sIt( this->GetChannel2( ), region );
173 _TOutIt vIt( this->GetChannel3( ), region );
178 for( ; !inIt.IsAtEnd( ); ++inIt, ++hIt, ++sIt, ++vIt )
180 _TOutPixel other = this->Converter( inIt.Get( ) );
181 hIt.Set( other[ 0 ] );
182 sIt.Set( other[ 1 ] );
183 vIt.Set( other[ 2 ] );
188 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__