]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/ParallelImageMean.hxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Algorithms / ParallelImageMean.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__PARALLELIMAGEMEAN__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__PARALLELIMAGEMEAN__HXX__
7
8 #include <itkImageRegionConstIterator.h>
9
10 // -------------------------------------------------------------------------
11 template< class I >
12 cpExtensions::Algorithms::ParallelImageMean< I >::
13 ParallelImageMean( )
14   : Superclass( )
15 {
16 }
17
18 // -------------------------------------------------------------------------
19 template< class I >
20 cpExtensions::Algorithms::ParallelImageMean< I >::
21 ~ParallelImageMean( )
22 {
23 }
24
25 // -------------------------------------------------------------------------
26 template< class I >
27 void cpExtensions::Algorithms::ParallelImageMean< I >::
28 BeforeThreadedExecution( )
29 {
30   this->m_Mean.SetSize( _TPixelTraits::GetLength( ) );
31   this->m_Mean.Fill( double( 0 ) );
32   this->m_N = 0;
33 }
34
35 // -------------------------------------------------------------------------
36 template< class I >
37 void cpExtensions::Algorithms::ParallelImageMean< I >::
38 ThreadedExecution( const DomainType& region, const itk::ThreadIdType id )
39 {
40   itk::ImageRegionConstIterator< I > i( this->m_Associate, region );
41   for( i.GoToBegin( ); !i.IsAtEnd( ); ++i )
42   {
43     for( unsigned int d = 0; d < _TPixelTraits::GetLength( ); ++d )
44     {
45       this->m_Mean.SetElement(
46         d, this->m_Mean.GetElement( d ) + double( i.Get( )[ d ] )
47         );
48       this->m_N++;
49
50     } // rof
51
52   } // rof
53 }
54
55 // -------------------------------------------------------------------------
56 template< class I >
57 void cpExtensions::Algorithms::ParallelImageMean< I >::
58 AfterThreadedExecution( )
59 {
60   this->m_Mean /= double( this->m_N );
61 }
62
63 #endif // __CPEXTENSIONS__ALGORITHMS__PARALLELIMAGEMEAN__HXX__
64
65 // eof - $RCSfile$