1 #ifndef __fpa__Image__MoriRegionGrowHelper__hxx__
2 #define __fpa__Image__MoriRegionGrowHelper__hxx__
4 // -------------------------------------------------------------------------
5 template< class _TInputImage, class _TOutputImage >
6 fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
7 MoriRegionGrowHelper( )
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( );
15 this->m_Lower = -this->m_Upper;
16 typename TBinThresholdFunction::Pointer functor =
17 TBinThresholdFunction::New( );
18 this->SetGrowFunction( functor );
21 // -------------------------------------------------------------------------
22 template< class _TInputImage, class _TOutputImage >
23 fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
24 ~MoriRegionGrowHelper( )
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 bool fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
31 _ContinueGenerateData( )
33 TBinThresholdFunction* functor =
34 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
35 TPixel u = functor->GetUpper( );
37 // Update flooding data
38 this->m_Curve.push_back( TCurveData( u, this->m_ActualCount ) );
41 if( u < this->m_Upper )
44 if( u > this->m_Upper )
46 functor->SetUpper( u );
47 this->m_Queue = this->m_NextQueue;
48 while( this->m_NextQueue.size( ) > 0 )
49 this->m_NextQueue.pop( );
56 // -------------------------------------------------------------------------
57 template< class _TInputImage, class _TOutputImage >
58 void fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
59 _BeforeGenerateData( )
61 this->Superclass::_BeforeGenerateData( );
63 while( this->m_NextQueue.size( ) > 0 )
64 this->m_NextQueue.pop( );
65 this->m_OptimumThreshold = ( typename _TOutputImage::PixelType )( 0 );
66 this->m_ActualCount = 0;
67 this->m_Curve.clear( );
68 TBinThresholdFunction* functor =
69 dynamic_cast< TBinThresholdFunction* >( this->GetGrowFunction( ) );
70 functor->SetLower( this->m_Lower );
71 functor->SetUpper( this->m_Lower + this->m_Step );
74 // -------------------------------------------------------------------------
75 template< class _TInputImage, class _TOutputImage >
76 void fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
79 typedef typename _TOutputImage::PixelType _TOut;
81 this->Superclass::_AfterGenerateData( );
82 while( this->m_NextQueue.size( ) > 0 )
83 this->m_NextQueue.pop( );
85 // Find optimum threshold by dicotomy
87 unsigned long r = this->m_Curve.size( ) - 1;
88 while( ( r - l ) > 1 )
90 unsigned long m = ( r + l ) >> 1;
91 double vm = double( this->m_Curve[ m ].second );
92 double dl = vm - double( this->m_Curve[ l ].second );
93 double dr = double( this->m_Curve[ r ].second ) - vm;
100 this->m_OptimumThreshold = _TOut( ( r + l ) >> 1 );
103 // -------------------------------------------------------------------------
104 template< class _TInputImage, class _TOutputImage >
105 void fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
108 this->Superclass::_BeforeLoop( );
111 // -------------------------------------------------------------------------
112 template< class _TInputImage, class _TOutputImage >
113 void fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
116 this->Superclass::_AfterLoop( );
119 // -------------------------------------------------------------------------
120 template< class _TInputImage, class _TOutputImage >
121 bool fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
122 _UpdateValue( _TQueueNode& v, const _TQueueNode& p )
124 typedef typename _TOutputImage::PixelType _TOut;
126 bool ret = this->Superclass::_UpdateValue( v, p );
127 v.Result = _TOut( this->m_Curve.size( ) + 1 );
129 this->m_NextQueue.push( v );
133 // -------------------------------------------------------------------------
134 template< class _TInputImage, class _TOutputImage >
135 void fpa::Image::MoriRegionGrowHelper< _TInputImage, _TOutputImage >::
136 _UpdateResult( const _TQueueNode& n )
138 this->Superclass::_UpdateResult( n );
139 this->m_ActualCount += 1;
142 #endif // __fpa__Image__MoriRegionGrowHelper__hxx__