]> Creatis software - cpPlugins.git/commitdiff
New filter
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 10 Jun 2015 21:49:34 +0000 (16:49 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 10 Jun 2015 21:49:34 +0000 (16:49 -0500)
lib/cpPlugins/Extensions/Algorithms/ImageFunctorFilter.h [new file with mode: 0644]

diff --git a/lib/cpPlugins/Extensions/Algorithms/ImageFunctorFilter.h b/lib/cpPlugins/Extensions/Algorithms/ImageFunctorFilter.h
new file mode 100644 (file)
index 0000000..fee021c
--- /dev/null
@@ -0,0 +1,106 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__
+#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__
+
+#include <itkImageToImageFilter.h>
+#include <itkImageScanlineConstIterator.h>
+#include <itkImageScanlineIterator.h>
+#include <itkProgressReporter.h>
+
+namespace cpPlugins
+{
+  namespace Extensions
+  {
+    namespace Algorithms
+    {
+      /**
+       */
+      template< class I, class O, class F >
+      class ImageFunctorFilter
+        : public itk::ImageToImageFilter< I, O >
+      {
+      public:
+        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 typename O::RegionType TRegion;
+
+      public:
+        itkNewMacro( Self );
+        itkTypeMacro( ImageFunctorFilter, itkImageToImageFilter );
+
+        itkGetMacro( Functor, F );
+        itkGetConstMacro( Functor, F );
+
+      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
+          }
+
+      private:
+        // Purposely not implemented.
+        ImageFunctorFilter( const Self& );
+        void operator=( const Self& );
+
+      protected:
+        F m_Functor;
+      };
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
+
+#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTORFILTER__H__
+
+// eof - $RCSfile$