]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/ImageFunctionFilter.hxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Algorithms / ImageFunctionFilter.hxx
diff --git a/lib/cpExtensions/Algorithms/ImageFunctionFilter.hxx b/lib/cpExtensions/Algorithms/ImageFunctionFilter.hxx
new file mode 100644 (file)
index 0000000..c96c092
--- /dev/null
@@ -0,0 +1,67 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
+#define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
+
+#include <itkMacro.h>
+#include <itkImageRegionConstIteratorWithIndex.h>
+#include <itkImageRegionIteratorWithIndex.h>
+#include <itkProgressReporter.h>
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutput, class _TFilter >
+cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
+ImageFunctionFilter( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutput, class _TFilter >
+cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
+~ImageFunctionFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutput, class _TFilter >
+void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
+BeforeThreadedGenerateData( )
+{
+  if( this->m_Function.IsNull( ) )
+    itkExceptionMacro( << "Please set a valid itk::ImageFunction" );
+  this->m_Function->SetInputImage( this->GetInput( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInput, class _TOutput, class _TFilter >
+void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
+ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
+{
+  const typename TRegion::SizeType& regionSize = region.GetSize( );
+  if( regionSize[ 0 ] == 0 )
+    return;
+  const _TInput* in = this->GetInput( );
+  _TOutput* out = this->GetOutput( 0 );
+
+  itk::ProgressReporter pr( this, threadId, region.GetNumberOfPixels( ) );
+
+  // Define the iterators
+  itk::ImageRegionConstIteratorWithIndex< TInput > iIt( in, region );
+  itk::ImageRegionIteratorWithIndex< TOutput > oIt( out, region );
+
+  iIt.GoToBegin( );
+  oIt.GoToBegin( );
+  for( ; !iIt.IsAtEnd( ) && !oIt.IsAtEnd( ); ++iIt, ++oIt )
+  {
+    oIt.Set( this->m_Function->EvaluateAtIndex( iIt.GetIndex( ) ) );
+    pr.CompletedPixel( );
+
+  } // rof
+}
+
+#endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
+
+// eof - $RCSfile$