// ------------------------------------------------------------------------- // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ------------------------------------------------------------------------- #ifndef __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ #define __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ // ------------------------------------------------------------------------- template< class G > void cpExtensions::Algorithms::GradientFunctionBase< G >:: ResetBuffer( ) { this->m_Buffer.clear( ); } // ------------------------------------------------------------------------- template< class G > typename cpExtensions::Algorithms::GradientFunctionBase< G >:: TOutput cpExtensions::Algorithms::GradientFunctionBase< G >:: Evaluate( const TPoint& p ) const { TIndex i; this->GetInputImage( )->TransformPhysicalPointToIndex( p, i ); return( this->EvaluateAtIndex( i ) ); } // ------------------------------------------------------------------------- template< class G > typename cpExtensions::Algorithms::GradientFunctionBase< G >:: TOutput cpExtensions::Algorithms::GradientFunctionBase< G >:: EvaluateAtIndex( const TIndex& i ) const { TOutput res = TOutput( 0 ); bool computed = false; if( this->m_BufferResults ) { typename TBuffer::const_iterator bIt = this->m_Buffer.find( i ); computed = ( bIt != this->m_Buffer.end( ) ); res = ( computed )? bIt->second: res; } // fi if( !computed ) res = this->_Evaluate( i ); if( this->m_BufferResults ) this->m_Buffer[ i ] = res; return( res ); } // ------------------------------------------------------------------------- template< class G > typename cpExtensions::Algorithms::GradientFunctionBase< G >:: TOutput cpExtensions::Algorithms::GradientFunctionBase< G >:: EvaluateAtContinuousIndex( const TContIndex& i ) const { TPoint p; this->GetInputImage( )->TransformContinuousIndexToPhysicalPoint( i, p ); return( this->Evaluate( p ) ); } // ------------------------------------------------------------------------- template< class G > cpExtensions::Algorithms::GradientFunctionBase< G >:: GradientFunctionBase( ) : Superclass( ), m_BufferResults( false ) { this->m_Buffer.clear( ); } // ------------------------------------------------------------------------- template< class G > cpExtensions::Algorithms::GradientFunctionBase< G >:: ~GradientFunctionBase( ) { this->m_Buffer.clear( ); } #endif // __CPEXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ // eof - $RCSfile$