]> Creatis software - cpPlugins.git/blob - lib/ivq/ITK/ThresholdFunction.hxx
090b278f1e03bc7ccf7689a827ffa75c96168004
[cpPlugins.git] / lib / ivq / ITK / ThresholdFunction.hxx
1 /* =======================================================================
2  * @author: Leonardo Florez-Valencia
3  * @email: florez-l@javeriana.edu.co
4  * =======================================================================
5  */
6
7 #ifndef __ivq__ITK__ThresholdFunction__hxx__
8 #define __ivq__ITK__ThresholdFunction__hxx__
9
10 #include <limits>
11
12 // -------------------------------------------------------------------------
13 template< class _TIn, class _TOut >
14 void ivq::ITK::ThresholdFunction< _TIn, _TOut >::
15 SetBetween( const _TIn& lower, const _TIn& upper )
16 {
17   this->SetLowerThreshold( lower );
18   this->SetUpperThreshold( upper );
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TIn, class _TOut >
23 void ivq::ITK::ThresholdFunction< _TIn, _TOut >::
24 SetBelow( const _TIn& value )
25 {
26   typedef std::numeric_limits< _TIn > _TTraits;
27   if( _TTraits::is_signed )
28     this->SetLowerThreshold( -_TTraits::max( ) );
29   else
30     this->SetLowerThreshold( _TIn( 0 ) );
31   this->SetUpperThreshold( value );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TIn, class _TOut >
36 void ivq::ITK::ThresholdFunction< _TIn, _TOut >::
37 SetAbove( const _TIn& value )
38 {
39   typedef std::numeric_limits< _TIn > _TTraits;
40   this->SetLowerThreshold( value );
41   this->SetUpperThreshold( _TTraits::max( ) );
42 }
43
44 // -------------------------------------------------------------------------
45 template< class _TIn, class _TOut >
46 _TOut ivq::ITK::ThresholdFunction< _TIn, _TOut >::
47 Evaluate( const _TIn& in ) const
48 {
49   // Check threshold
50   bool inside = false;
51   if( this->m_Strict )
52   {
53     inside  = ( this->m_LowerThreshold < in );
54     inside &= ( in < this->m_UpperThreshold );
55   }
56   else
57   {
58     inside  = ( this->m_LowerThreshold <= in );
59     inside &= ( in <= this->m_UpperThreshold );
60
61   } // fi
62
63   // Return value
64   if( inside )
65   {
66     if( this->m_Binary )
67       return( this->m_InsideValue );
68     else
69       return( _TOut( in ) );
70   }
71   else
72     return( this->m_OutsideValue );
73 }
74
75 // -------------------------------------------------------------------------
76 template< class _TIn, class _TOut >
77 ivq::ITK::ThresholdFunction< _TIn, _TOut >::
78 ThresholdFunction( )
79   : Superclass( ),
80     m_LowerThreshold( _TIn( 0 ) ),
81     m_UpperThreshold( std::numeric_limits< _TIn >::max( ) ),
82     m_Strict( false ),
83     m_Binary( false ),
84     m_InsideValue( std::numeric_limits< _TOut >::max( ) ),
85     m_OutsideValue( _TOut( 0 ) )
86 {
87 }
88
89 // -------------------------------------------------------------------------
90 template< class _TIn, class _TOut >
91 ivq::ITK::ThresholdFunction< _TIn, _TOut >::
92 ~ThresholdFunction( )
93 {
94 }
95
96 #endif // __ivq__ITK__ThresholdFunction__hxx__
97
98 // eof - $RCSfile$