]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
0cb1b66598aa225f33799855c44a4435ed376a20
[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 }
33
34 // -------------------------------------------------------------------------
35 template< class I >
36 fpa::Image::RegionGrowWithMultipleThresholds< I >::
37 ~RegionGrowWithMultipleThresholds( )
38 {
39 }
40
41 // -------------------------------------------------------------------------
42 template< class I >
43 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
44 _BeforeMainLoop( )
45 {
46   const I* img = this->GetInput( );
47
48   this->ClearMembershipFunctions( );
49   typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
50   TPixel min_thr = *tIt;
51   for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt )
52   {
53     typename TFunction::Pointer function = TFunction::New( );
54     function->SetInputImage( img );
55     function->SetLowerThreshold( min_thr );
56     function->SetUpperThreshold( *tIt );
57     this->AddMembershipFunction( function );
58
59   } // rof
60
61   this->Superclass::_BeforeMainLoop( );
62 }
63
64 // -------------------------------------------------------------------------
65 template< class I >
66 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
67 _AfterLoop( )
68 {
69   if( this->m_ActualFunction != this->m_Functions.end( ) )
70   {
71     TFunction* f =
72       dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
73     // std::cout << f->GetUpperThreshold( ) << " " << this->m_Marks.size( ) << std::endl;
74
75   } // fi
76   this->Superclass::_AfterLoop( );
77 }
78
79 // -------------------------------------------------------------------------
80 template< class I >
81 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
82 _AfterMainLoop( )
83 {
84   this->Superclass::_AfterMainLoop( );
85 }
86
87 // -------------------------------------------------------------------------
88 template< class I >
89 bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
90 _UpdateResult( _TNode& n )
91 {
92   #error ACA VOY -> explicar esto!!!! cambiar salida por una especie de curva de nivel
93   bool ret = this->Superclass::_UpdateResult( n );
94   if( this->m_ActualFunction != this->m_Functions.end( ) )
95   {
96     TFunction* f =
97       dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
98     this->GetOutput( )->SetPixel( n.Vertex, f->GetUpperThreshold( ) );
99
100   } // fi
101   return( ret );
102 }
103 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
104
105 // eof - $RCSfile$