// ------------------------------------------------------------------------- // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- #ifndef __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__ #define __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__ #include #include #include #include #include // ------------------------------------------------------------------------- template< class I, class O, class C > O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel1( ) { return( this->GetOutput( 0 ) ); } // ------------------------------------------------------------------------- template< class I, class O, class C > O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel2( ) { return( this->GetOutput( 1 ) ); } // ------------------------------------------------------------------------- template< class I, class O, class C > O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel3( ) { return( this->GetOutput( 2 ) ); } // ------------------------------------------------------------------------- template< class I, class O, class C > const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel1( ) const { if( this->GetNumberOfOutputs( ) > 0 ) return( dynamic_cast< const O* >( this->itk::ProcessObject::GetOutput( 0 ) ) ); else return( NULL ); } // ------------------------------------------------------------------------- template< class I, class O, class C > const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel2( ) const { if( this->GetNumberOfOutputs( ) > 1 ) return( dynamic_cast< const O* >( this->itk::ProcessObject::GetOutput( 1 ) ) ); else return( NULL ); } // ------------------------------------------------------------------------- template< class I, class O, class C > const O* cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GetChannel3( ) const { if( this->GetNumberOfOutputs( ) > 2 ) return( dynamic_cast< const O* >( this->itk::ProcessObject::GetOutput( 2 ) ) ); else return( NULL ); } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GraftChannel1( O* hue ) { this->GraftNthOutput( 0, hue ); } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GraftChannel2( O* saturation ) { this->GraftNthOutput( 1, saturation ); } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: GraftChannel3( O* value ) { this->GraftNthOutput( 2, value ); } // ------------------------------------------------------------------------- template< class I, class O, class C > cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: RGBImageToOtherChannelsFilter( ) : Superclass( ) { this->SetNumberOfRequiredInputs( 1 ); this->SetNumberOfRequiredOutputs( 3 ); for( unsigned int i = 0; i < 3; i++ ) { typename O::Pointer o = O::New( ); this->SetNthOutput( i, o ); } // rof } // ------------------------------------------------------------------------- template< class I, class O, class C > cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: ~RGBImageToOtherChannelsFilter( ) { } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: BeforeThreadedGenerateData( ) { } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: AfterThreadedGenerateData( ) { } // ------------------------------------------------------------------------- template< class I, class O, class C > void cpExtensions::Algorithms::RGBImageToOtherChannelsFilter< I, O, C >:: ThreadedGenerateData( const typename Superclass::OutputImageRegionType& region, itk::ThreadIdType threadId ) { // typedef typename TInputPixel::ComponentType _TComponent; typedef itk::ImageRegionConstIterator< I > _TInIt; typedef itk::ImageRegionIterator< O > _TOutIt; typedef typename C::TOutPixel _TOutPixel; _TInIt inIt( this->GetInput( ), region ); _TOutIt hIt( this->GetChannel1( ), region ); _TOutIt sIt( this->GetChannel2( ), region ); _TOutIt vIt( this->GetChannel3( ), region ); inIt.GoToBegin( ); hIt.GoToBegin( ); sIt.GoToBegin( ); vIt.GoToBegin( ); for( ; !inIt.IsAtEnd( ); ++inIt, ++hIt, ++sIt, ++vIt ) { _TOutPixel other = this->Converter( inIt.Get( ) ); hIt.Set( other[ 0 ] ); sIt.Set( other[ 1 ] ); vIt.Set( other[ 2 ] ); } // rof } #endif // __CPEXTENSIONS__ALGORITHMS__RGBIMAGETOOTHERCHANNELSFILTER__HXX__ // eof - $RCSfile$