1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
6 #define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
8 #include <itkImageToImageFilter.h>
9 #include <itkImageScanlineConstIterator.h>
10 #include <itkImageScanlineIterator.h>
11 #include <itkProgressReporter.h>
13 namespace cpExtensions
19 template< class I, class O, class F >
20 class ImageFunctionFilter
21 : public itk::ImageToImageFilter< I, O >
24 typedef ImageFunctionFilter Self;
25 typedef itk::ImageToImageFilter< I, O > Superclass;
26 typedef itk::SmartPointer< Self > Pointer;
27 typedef itk::SmartPointer< const Self > ConstPointer;
29 typedef I TInputImage;
30 typedef O TOutputImage;
33 typedef typename O::RegionType TRegion;
37 itkTypeMacro( ImageFunctionFilter, itkImageToImageFilter );
39 itkGetObjectMacro( Function, F );
40 itkSetObjectMacro( Function, F );
43 ImageFunctionFilter( )
47 virtual ~ImageFunctionFilter( )
51 virtual void ThreadedGenerateData(
52 const TRegion& region,
53 itk::ThreadIdType threadId
56 const typename TRegion::SizeType& regionSize = region.GetSize( );
57 if( regionSize[ 0 ] == 0 )
59 const I* in = this->GetInput( );
60 O* out = this->GetOutput( 0 );
62 const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ];
63 itk::ProgressReporter progress( this, threadId, nLines );
65 // Define the iterators
66 itk::ImageScanlineConstIterator< I > inIt( in, region );
67 itk::ImageScanlineIterator< O > outIt( out, region );
71 while( !inIt.IsAtEnd( ) )
73 while( !inIt.IsAtEndOfLine( ) )
75 outIt.Set( this->m_Function->EvaluateAtIndex( inIt.GetIndex( ) ) );
82 progress.CompletedPixel( );
88 // Purposely not implemented.
89 ImageFunctionFilter( const Self& );
90 void operator=( const Self& );
93 typename F::Pointer m_Function;
100 #ifndef ITK_MANUAL_INSTANTIATION
101 // TODO: #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
102 #endif // ITK_MANUAL_INSTANTIATION
104 #endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__