X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FAlgorithms%2FImageFunctorFilter.h;fp=lib%2FcpExtensions%2FAlgorithms%2FImageFunctorFilter.h;h=c1a32b08df3962feea796a2c9810439c00bd98ef;hb=9947c770b79585f718013305a956cf9473a4e0b2;hp=d8a7ecac73ebebf40e0d1ffe9d8a09202fc82005;hpb=9af34b55ea1d60eef3608aede00f9ef5a16dccdf;p=cpPlugins.git diff --git a/lib/cpExtensions/Algorithms/ImageFunctorFilter.h b/lib/cpExtensions/Algorithms/ImageFunctorFilter.h index d8a7eca..c1a32b0 100644 --- a/lib/cpExtensions/Algorithms/ImageFunctorFilter.h +++ b/lib/cpExtensions/Algorithms/ImageFunctorFilter.h @@ -2,13 +2,11 @@ // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- -#ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__ -#define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__ +#ifndef __cpExtensions__Algorithms__ImageFunctorFilter__h__ +#define __cpExtensions__Algorithms__ImageFunctorFilter__h__ +#include #include -#include -#include -#include namespace cpExtensions { @@ -16,73 +14,37 @@ namespace cpExtensions { /** */ - template< class I, class O, class F > + template< class _TInputImage, class _TOutputImage > class ImageFunctorFilter : public itk::ImageToImageFilter< I, O > { public: - typedef ImageFunctorFilter Self; + typedef ImageFunctorFilter Self; typedef itk::ImageToImageFilter< I, O > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; - typedef I TInputImage; - typedef O TOutputImage; - typedef F TFunctor; + typedef _TInputImage TInputImage; + typedef _TOutputImage TOutputImage; + typedef typename TInputImage::PixelType TInputPixel; + typedef typename TOutputImage::PixelType TOutputPixel; + typedef typename TOutputImage::RegionType TRegion; - typedef typename O::RegionType TRegion; + typedef itk::FunctionBase< TInputPixel, TOutputPixel > TFunctor; public: itkNewMacro( Self ); itkTypeMacro( ImageFunctorFilter, itkImageToImageFilter ); - itkGetMacro( Functor, F ); - itkGetConstMacro( Functor, F ); + itkGetObjectMacro( Functor, TFunctor ); + itkGetConstObjectMacro( Functor, TFunctor ); + itkSetObjectMacro( Functor, TFunctor ); protected: - ImageFunctorFilter( ) - : Superclass( ) - { - } - virtual ~ImageFunctorFilter( ) - { - } - - virtual void ThreadedGenerateData( - const TRegion& region, - itk::ThreadIdType threadId - ) - { - const typename TRegion::SizeType& regionSize = region.GetSize( ); - if( regionSize[ 0 ] == 0 ) - return; - const I* in = this->GetInput( ); - O* out = this->GetOutput( 0 ); - - const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ]; - itk::ProgressReporter progress( this, threadId, nLines ); - - // Define the iterators - itk::ImageScanlineConstIterator< I > inIt( in, region ); - itk::ImageScanlineIterator< O > outIt( out, region ); - - inIt.GoToBegin( ); - outIt.GoToBegin( ); - while( !inIt.IsAtEnd( ) ) - { - while( !inIt.IsAtEndOfLine( ) ) - { - outIt.Set( this->m_Functor( inIt.Get( ) ) ); - ++inIt; - ++outIt; - - } // elihw - inIt.NextLine( ); - outIt.NextLine( ); - progress.CompletedPixel( ); - - } // elihw - } + ImageFunctorFilter( ); + virtual ~ImageFunctorFilter( ); + + virtual void ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId ) override; private: // Purposely not implemented. @@ -90,13 +52,17 @@ namespace cpExtensions void operator=( const Self& ); protected: - F m_Functor; + typename TFunctor::Pointer m_Functor; }; } // ecapseman } // ecapseman -#endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__ +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __cpExtensions__Algorithms__ImageFunctorFilter__h__ // eof - $RCSfile$