]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/ImageFunctionFilter.hxx
c96c0928ab36c3ef7a25e0839d0f359407c16a9a
[cpPlugins.git] / lib / cpExtensions / Algorithms / ImageFunctionFilter.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
7
8 #include <itkMacro.h>
9 #include <itkImageRegionConstIteratorWithIndex.h>
10 #include <itkImageRegionIteratorWithIndex.h>
11 #include <itkProgressReporter.h>
12
13 // -------------------------------------------------------------------------
14 template< class _TInput, class _TOutput, class _TFilter >
15 cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
16 ImageFunctionFilter( )
17   : Superclass( )
18 {
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TInput, class _TOutput, class _TFilter >
23 cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
24 ~ImageFunctionFilter( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TInput, class _TOutput, class _TFilter >
30 void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
31 BeforeThreadedGenerateData( )
32 {
33   if( this->m_Function.IsNull( ) )
34     itkExceptionMacro( << "Please set a valid itk::ImageFunction" );
35   this->m_Function->SetInputImage( this->GetInput( ) );
36 }
37
38 // -------------------------------------------------------------------------
39 template< class _TInput, class _TOutput, class _TFilter >
40 void cpExtensions::Algorithms::ImageFunctionFilter< _TInput, _TOutput, _TFilter >::
41 ThreadedGenerateData( const TRegion& region, itk::ThreadIdType threadId )
42 {
43   const typename TRegion::SizeType& regionSize = region.GetSize( );
44   if( regionSize[ 0 ] == 0 )
45     return;
46   const _TInput* in = this->GetInput( );
47   _TOutput* out = this->GetOutput( 0 );
48
49   itk::ProgressReporter pr( this, threadId, region.GetNumberOfPixels( ) );
50
51   // Define the iterators
52   itk::ImageRegionConstIteratorWithIndex< TInput > iIt( in, region );
53   itk::ImageRegionIteratorWithIndex< TOutput > oIt( out, region );
54
55   iIt.GoToBegin( );
56   oIt.GoToBegin( );
57   for( ; !iIt.IsAtEnd( ) && !oIt.IsAtEnd( ); ++iIt, ++oIt )
58   {
59     oIt.Set( this->m_Function->EvaluateAtIndex( iIt.GetIndex( ) ) );
60     pr.CompletedPixel( );
61
62   } // rof
63 }
64
65 #endif // __CPEXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__HXX__
66
67 // eof - $RCSfile$