]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/MoriRegionGrow.hxx
3b06e41cdd463dce08115f3e6cdf7eb8011442a8
[FrontAlgorithms.git] / lib / fpa / Image / MoriRegionGrow.hxx
1 #ifndef __fpa__Image__MoriRegionGrow__hxx__
2 #define __fpa__Image__MoriRegionGrow__hxx__
3
4 // -------------------------------------------------------------------------
5 template< class _TInputImage, class _TOutputImage >
6 fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
7 MoriRegionGrow( )
8   : Superclass( ),
9     m_Step( TPixel( 1 ) )
10 {
11   this->m_Upper = std::numeric_limits< TPixel >::max( );
12   if( std::numeric_limits< TPixel >::is_integer )
13     this->m_Lower = std::numeric_limits< TPixel >::min( );
14   else
15     this->m_Lower = -this->m_Upper;
16   typename TBinThresholdFunction::Pointer functor =
17     TBinThresholdFunction::New( );
18   this->SetGrowFunction( functor );
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TInputImage, class _TOutputImage >
23 fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
24 ~MoriRegionGrow( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
31 _ContinueGenerateData( )
32 {
33   TBinThresholdFunction* functor =
34     dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
35   TPixel u = functor->GetUpper( );
36
37   std::cout << long( u ) << " " << this->m_ActualCount << std::endl;
38
39   if( u < this->m_Upper )
40   {
41     u += this->m_Step;
42     if( u > this->m_Upper )
43       u = this->m_Upper;
44     functor->SetUpper( u );
45     this->m_Queue = this->m_NextQueue;
46     while( this->m_NextQueue.size( ) > 0 )
47       this->m_NextQueue.pop( );
48     return( true );
49   }
50   else
51     return( false );
52 }
53
54 // -------------------------------------------------------------------------
55 template< class _TInputImage, class _TOutputImage >
56 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
57 _BeforeGenerateData( )
58 {
59   this->Superclass::_BeforeGenerateData( );
60
61   while( this->m_NextQueue.size( ) > 0 )
62     this->m_NextQueue.pop( );
63   this->m_ActualCount = 0;
64   TBinThresholdFunction* functor =
65     dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
66   functor->SetLower( this->m_Lower );
67   functor->SetUpper( this->m_Lower + this->m_Step );
68 }
69
70 // -------------------------------------------------------------------------
71 template< class _TInputImage, class _TOutputImage >
72 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
73 _AfterGenerateData( )
74 {
75   this->Superclass::_AfterGenerateData( );
76   while( this->m_NextQueue.size( ) > 0 )
77     this->m_NextQueue.pop( );
78 }
79
80 // -------------------------------------------------------------------------
81 template< class _TInputImage, class _TOutputImage >
82 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
83 _BeforeLoop( )
84 {
85   this->Superclass::_BeforeLoop( );
86 }
87
88 // -------------------------------------------------------------------------
89 template< class _TInputImage, class _TOutputImage >
90 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
91 _AfterLoop( )
92 {
93   this->Superclass::_AfterLoop( );
94 }
95
96 // -------------------------------------------------------------------------
97 template< class _TInputImage, class _TOutputImage >
98 bool fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
99 _UpdateValue( _TQueueNode& v, const _TQueueNode& p )
100 {
101   bool ret = this->Superclass::_UpdateValue( v, p );
102   if( !ret )
103   {
104     v.Result = this->m_InsideValue;
105     this->m_NextQueue.push( v );
106
107   } // fi
108   return( ret );
109 }
110
111 // -------------------------------------------------------------------------
112 template< class _TInputImage, class _TOutputImage >
113 void fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage >::
114 _UpdateResult( const _TQueueNode& n )
115 {
116   this->Superclass::_UpdateResult( n );
117   this->m_ActualCount += 1;
118 }
119
120 #endif // __fpa__Image__MoriRegionGrow__hxx__
121
122 // eof - $RCSfile$