1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
9 #include <itkImageRegionConstIteratorWithIndex.h>
10 #include <itkImageRegionIteratorWithIndex.h>
11 #include <itkProgressReporter.h>
13 // -------------------------------------------------------------------------
14 template< class _TInput, class _TOutput, class _TFilter >
15 cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
16 ImageFunctionFilter( )
21 // -------------------------------------------------------------------------
22 template< class _TInput, class _TOutput, class _TFilter >
23 cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
24 ~ImageFunctionFilter( )
28 // -------------------------------------------------------------------------
29 template< class _TInput, class _TOutput, class _TFilter >
30 void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
31 BeforeThreadedGenerateData( )
33 if( this->m_Function.IsNull( ) )
34 itkExceptionMacro( << "Please set a valid itk::ImageFunction" );
35 this->m_Function->SetInputImage( this->GetInput( ) );
38 // -------------------------------------------------------------------------
39 template< class _TInput, class _TOutput, class _TFilter >
40 void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
41 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
43 const typename TRegion::SizeType& regionSize = region.GetSize( );
44 if( regionSize[ 0 ] == 0 )
46 const _TInput* in = this->GetInput( );
47 _TOutput* out = this->GetOutput( 0 );
49 itk::ProgressReporter pr( this, threadId, region.GetNumberOfPixels( ) );
51 // Define the iterators
52 itk::ImageRegionConstIteratorWithIndex< TInput > iIt( in, region );
53 itk::ImageRegionIteratorWithIndex< TOutput > oIt( out, region );
57 for( ; !iIt.IsAtEnd( ) && !oIt.IsAtEnd( ); ++iIt, ++oIt )
59 oIt.Set( this->m_Function->EvaluateAtIndex( iIt.GetIndex( ) ) );
65 #endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__