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