]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
Filter updated
[FrontAlgorithms.git] / lib / fpa / Image / RegionGrowWithMultipleThresholds.hxx
1 #ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
2 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
3
4 #include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
5
6 // -------------------------------------------------------------------------
7 template< class I >
8 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
9 AddThreshold( const TPixel& v )
10 {
11   this->m_Histogram[ v ] = 0;
12
13   /* TODO
14      typedef
15      fpa::Image::Functors::RegionGrowThresholdFunction< I >
16      TFunction;
17      TFunction* function =
18      dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
19      if( function != NULL )
20      {
21      function->SetLowerThreshold( this->m_Histogram.begin( )->first );
22      function->SetUpperThreshold( this->m_Histogram.rbegin( )->first );
23
24      } // fi
25   */
26   this->Modified( );
27 }
28
29 // -------------------------------------------------------------------------
30 template< class I >
31 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
32 AddThresholds( const TPixel& t0, const TPixel& t1, const unsigned int& s )
33 {
34   double o = ( double( t1 ) - double( t0 ) ) / ( double( s ) - double( 1 ) );
35   for( unsigned int i = 0; i < s; i++ )
36     this->AddThreshold( TPixel( ( double( i ) * o ) + double( t0 ) ) );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class I >
41 fpa::Image::RegionGrowWithMultipleThresholds< I >::
42 RegionGrowWithMultipleThresholds( )
43   : Superclass( ),
44     m_DerivativeThreshold( double( 3 ) )
45 {
46   typedef
47     fpa::Image::Functors::RegionGrowThresholdFunction< I >
48     TFunction;
49   typename TFunction::Pointer function = TFunction::New( );
50   this->SetMembershipFunction( function );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class I >
55 fpa::Image::RegionGrowWithMultipleThresholds< I >::
56 ~RegionGrowWithMultipleThresholds( )
57 {
58 }
59
60 // -------------------------------------------------------------------------
61 template< class I >
62 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
63 _UpdateResult( _TNode& n )
64 {
65   bool ret = this->Superclass::_UpdateResult( n );
66
67   if( ret )
68   {
69     TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
70
71     typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
72     while( hIt != this->m_Histogram.rend( ) )
73     {
74       if( v <= hIt->first )
75       {
76         hIt->second += 1;
77         hIt++;
78       }
79       else
80         hIt = this->m_Histogram.rend( );
81
82     } // elihw
83     this->GetOutput( )->SetPixel( n.Vertex, v );
84
85   } // fi
86   return( ret );
87 }
88
89 // -------------------------------------------------------------------------
90 template< class I >
91 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
92 _AfterLoop( )
93 {
94   /*
95     typename THistogram::iterator prevIt = this->m_Histogram.begin( );
96     typename THistogram::iterator currIt = prevIt; currIt++;
97     typename THistogram::iterator nextIt = currIt; nextIt++;
98     double prev_d1 = double( 0 );
99     for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
100     {
101     double d1 = double( nextIt->second ) - double( prevIt->second );
102     d1 /= double( nextIt->first ) - double( prevIt->first );
103
104     std::cout
105     << currIt->first  << " "
106     << currIt->second << " "
107     << d1 << " "
108     << ( d1 - prev_d1 ) << std::endl;
109
110     prev_d1 = d1;
111
112     } // rof
113   */
114
115   /*
116     double prev = double( 0 );
117     while( hIt != this->m_Histogram.end( ) )
118     {
119     double curr = double( hIt->second );
120     double deri = curr - prev;
121
122     if( hIt != this->m_Histogram.begin( ) )
123     std::cout << hIt->first << " " << curr << " " << deri << std::endl;
124
125     prev = curr;
126     hIt++;
127
128     } // rof
129   */
130   this->Superclass::_AfterLoop( );
131 }
132
133 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
134
135 // eof - $RCSfile$