]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/ImageFunctorFilter.hxx
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / ImageFunctorFilter.hxx
diff --git a/lib/cpExtensions/Algorithms/ImageFunctorFilter.hxx b/lib/cpExtensions/Algorithms/ImageFunctorFilter.hxx
new file mode 100644 (file)
index 0000000..73777da
--- /dev/null
@@ -0,0 +1,65 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
+#define __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
+
+#include <itkImageScanlineConstIterator.h>
+#include <itkImageScanlineIterator.h>
+#include <itkProgressReporter.h>
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
+ImageFunctorFilter( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
+~ImageFunctorFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+void
+cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
+ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
+{
+  // Configure data for this thread
+  const typename TRegion::SizeType& regionSize = region.GetSize( );
+  if( regionSize[ 0 ] == 0 )
+    return;
+  const TInputImage* in = this->GetInput( );
+  TOutputImage* out = this->GetOutput( 0 );
+  const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ];
+  itk::ProgressReporter progress( this, threadId, nLines );
+
+  // Iterate over this region
+  itk::ImageScanlineConstIterator< TInputImage > iIt( in, region );
+  itk::ImageScanlineIterator< TOutputImage > oIt( out, region );
+  iIt.GoToBegin( );
+  oIt.GoToBegin( );
+  while( !iIt.IsAtEnd( ) )
+  {
+    while( !iIt.IsAtEndOfLine( ) )
+    {
+      oIt.Set( this->m_Functor->Evaluate( iIt.Get( ) ) );
+      ++iIt;
+      ++oIt;
+
+    } // elihw
+    iIt.NextLine( );
+    oIt.NextLine( );
+    progress.CompletedPixel( );
+
+  } // elihw
+}
+
+#endif // __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
+
+// eof - $RCSfile$