]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.hxx
...
[cpPlugins.git] / lib / cpPlugins / Extensions / Algorithms / GradientFunctionBase.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__
7
8 // -------------------------------------------------------------------------
9 template< class G >
10 void cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
11 ResetBuffer( )
12 {
13   this->m_Buffer.clear( );
14 }
15
16 // -------------------------------------------------------------------------
17 template< class G >
18 typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
19 TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
20 Evaluate( const TPoint& p ) const
21 {
22   TIndex i;
23   this->GetInputImage( )->TransformPhysicalPointToIndex( p, i );
24   return( this->EvaluateAtIndex( i ) );
25 }
26
27 // -------------------------------------------------------------------------
28 template< class G >
29 typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
30 TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
31 EvaluateAtIndex( const TIndex& i ) const
32 {
33   TOutput res = TOutput( 0 );
34   bool computed = false;
35   if( this->m_BufferResults )
36   {
37     typename TBuffer::const_iterator bIt = this->m_Buffer.find( i );
38     computed = ( bIt != this->m_Buffer.end( ) );
39     res = ( computed )? bIt->second: res;
40
41   } // fi
42
43   if( !computed )
44     res = this->_Evaluate( i );
45
46   if( this->m_BufferResults )
47     this->m_Buffer[ i ] = res;
48   return( res );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class G >
53 typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
54 TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
55 EvaluateAtContinuousIndex( const TContIndex& i ) const
56 {
57   TPoint p;
58   this->GetInputImage( )->TransformContinuousIndexToPhysicalPoint( i, p );
59   return( this->Evaluate( p ) );
60 }
61
62 // -------------------------------------------------------------------------
63 template< class G >
64 cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
65 GradientFunctionBase( )
66   : Superclass( ),
67     m_BufferResults( false )
68 {
69   this->m_Buffer.clear( );
70 }
71
72 // -------------------------------------------------------------------------
73 template< class G >
74 cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >::
75 ~GradientFunctionBase( )
76 {
77   this->m_Buffer.clear( );
78 }
79
80 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__
81
82 // eof - $RCSfile$