1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
8 #include <itkImageToImageFilter.h>
9 #include <itkImageScanlineConstIterator.h>
10 #include <itkImageScanlineIterator.h>
11 #include <itkProgressReporter.h>
21 template< class I, class O, class F >
22 class ImageFunctionFilter
23 : public itk::ImageToImageFilter< I, O >
26 typedef ImageFunctionFilter Self;
27 typedef itk::ImageToImageFilter< I, O > Superclass;
28 typedef itk::SmartPointer< Self > Pointer;
29 typedef itk::SmartPointer< const Self > ConstPointer;
31 typedef I TInputImage;
32 typedef O TOutputImage;
35 typedef typename O::RegionType TRegion;
39 itkTypeMacro( ImageFunctionFilter, itkImageToImageFilter );
41 itkGetObjectMacro( Function, F );
42 itkSetObjectMacro( Function, F );
45 ImageFunctionFilter( )
49 virtual ~ImageFunctionFilter( )
53 virtual void ThreadedGenerateData(
54 const TRegion& region,
55 itk::ThreadIdType threadId
58 const typename TRegion::SizeType& regionSize = region.GetSize( );
59 if( regionSize[ 0 ] == 0 )
61 const I* in = this->GetInput( );
62 O* out = this->GetOutput( 0 );
64 const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ];
65 itk::ProgressReporter progress( this, threadId, nLines );
67 // Define the iterators
68 itk::ImageScanlineConstIterator< I > inIt( in, region );
69 itk::ImageScanlineIterator< O > outIt( out, region );
73 while( !inIt.IsAtEnd( ) )
75 while( !inIt.IsAtEndOfLine( ) )
77 outIt.Set( this->m_Function->EvaluateAtIndex( inIt.GetIndex( ) ) );
84 progress.CompletedPixel( );
90 // Purposely not implemented.
91 ImageFunctionFilter( const Self& );
92 void operator=( const Self& );
95 typename F::Pointer m_Function;
104 // TODO: #include <cpPlugins/Extensions/Algorithms/ImageFunctionFilter.hxx>
106 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__