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