]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/ImageFunctorFilter.hxx
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / ImageFunctorFilter.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
6 #define __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
7
8 #include <itkImageScanlineConstIterator.h>
9 #include <itkImageScanlineIterator.h>
10 #include <itkProgressReporter.h>
11
12 // -------------------------------------------------------------------------
13 template< class _TInputImage, class _TOutputImage >
14 cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
15 ImageFunctorFilter( )
16   : Superclass( )
17 {
18 }
19
20 // -------------------------------------------------------------------------
21 template< class _TInputImage, class _TOutputImage >
22 cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
23 ~ImageFunctorFilter( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 template< class _TInputImage, class _TOutputImage >
29 void
30 cpExtensions::Algorithms::ImageFunctorFilter< _TInputImage, _TOutputImage >::
31 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
32 {
33   // Configure data for this thread
34   const typename TRegion::SizeType& regionSize = region.GetSize( );
35   if( regionSize[ 0 ] == 0 )
36     return;
37   const TInputImage* in = this->GetInput( );
38   TOutputImage* out = this->GetOutput( 0 );
39   const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ];
40   itk::ProgressReporter progress( this, threadId, nLines );
41
42   // Iterate over this region
43   itk::ImageScanlineConstIterator< TInputImage > iIt( in, region );
44   itk::ImageScanlineIterator< TOutputImage > oIt( out, region );
45   iIt.GoToBegin( );
46   oIt.GoToBegin( );
47   while( !iIt.IsAtEnd( ) )
48   {
49     while( !iIt.IsAtEndOfLine( ) )
50     {
51       oIt.Set( this->m_Functor->Evaluate( iIt.Get( ) ) );
52       ++iIt;
53       ++oIt;
54
55     } // elihw
56     iIt.NextLine( );
57     oIt.NextLine( );
58     progress.CompletedPixel( );
59
60   } // elihw
61 }
62
63 #endif // __cpExtensions__Algorithms__ImageFunctorFilter__hxx__
64
65 // eof - $RCSfile$