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