]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/ImageFunctionFilter.h
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / ImageFunctionFilter.h
index 9c0e76d3fbaec6d29d21bbdd8fd2614ca4f2f213..503f791355862e362a7e3d59fb371f708954b1a4 100644 (file)
@@ -5,10 +5,8 @@
 #ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
 #define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__
 
+#include <cpExtensions/Config.h>
 #include <itkImageToImageFilter.h>
-#include <itkImageScanlineConstIterator.h>
-#include <itkImageScanlineIterator.h>
-#include <itkProgressReporter.h>
 
 namespace cpExtensions
 {
@@ -16,73 +14,38 @@ namespace cpExtensions
   {
     /**
      */
-    template< class I, class O, class F >
+    template< class _TInput, class _TOutput, class _TFunction >
     class ImageFunctionFilter
-      : public itk::ImageToImageFilter< I, O >
+      : public itk::ImageToImageFilter< _TInput, _TOutput >
     {
     public:
-      typedef ImageFunctionFilter             Self;
-      typedef itk::ImageToImageFilter< I, O > Superclass;
-      typedef itk::SmartPointer< Self >       Pointer;
-      typedef itk::SmartPointer< const Self > ConstPointer;
+      typedef ImageFunctionFilter                          Self;
+      typedef itk::ImageToImageFilter< _TInput, _TOutput > Superclass;
+      typedef itk::SmartPointer< Self >                    Pointer;
+      typedef itk::SmartPointer< const Self >              ConstPointer;
 
-      typedef I TInputImage;
-      typedef O TOutputImage;
-      typedef F TFunction;
+      typedef _TInput    TInput;
+      typedef _TOutput   TOutput;
+      typedef _TFunction TFunction;
 
-      typedef typename O::RegionType TRegion;
+      typedef typename TOutput::RegionType TRegion;
 
     public:
       itkNewMacro( Self );
       itkTypeMacro( ImageFunctionFilter, itkImageToImageFilter );
 
-      itkGetObjectMacro( Function, F );
-      itkSetObjectMacro( Function, F );
+      itkGetObjectMacro( Function, TFunction );
+      itkSetObjectMacro( Function, TFunction );
 
     protected:
-      ImageFunctionFilter( )
-        : Superclass( )
-        {
-        }
-      virtual ~ImageFunctionFilter( )
-        {
-        }
+      ImageFunctionFilter( );
+      virtual ~ImageFunctionFilter( );
 
+      virtual void BeforeThreadedGenerateData( ) cpExtensions_OVERRIDE;
       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_Function->EvaluateAtIndex( inIt.GetIndex( ) ) );
-              ++inIt;
-              ++outIt;
-
-            } // elihw
-            inIt.NextLine( );
-            outIt.NextLine( );
-            progress.CompletedPixel( );
-
-          } // elihw
-        }
+        ) cpExtensions_OVERRIDE;
 
     private:
       // Purposely not implemented.
@@ -90,14 +53,16 @@ namespace cpExtensions
       void operator=( const Self& );
 
     protected:
-      typename F::Pointer m_Function;
+      typename TFunction::Pointer m_Function;
     };
 
   } // ecapseman
 
 } // ecapseman
 
-// TODO: #include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <cpExtensions/Algorithms/ImageFunctionFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
 
 #endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__