18 #ifndef __itkUnaryFunctorLookUpTable_h 19 #define __itkUnaryFunctorLookUpTable_h 33 template <
class TFunctor >
57 itkSetMacro(VariableMax,
double);
58 itkGetMacro(VariableMax,
double);
60 itkSetMacro(VariableMin,
double);
61 itkGetMacro(VariableMin,
double);
63 itkSetMacro(NumberOfBins,
int);
64 itkGetMacro(NumberOfBins,
int);
66 itkGetMacro(Table, STDVectorPointer);
76 utlGlobalException(m_VariableMax<=m_VariableMin,
"m_VariableMax should be larger than m_VariableMin");
77 m_Table = STDVectorPointer(
new STDVectorType(m_NumberOfBins+1));
78 m_Delta = (m_VariableMax-m_VariableMin)/(
double)m_NumberOfBins;
79 m_DeltaInv = 1.0/m_Delta;
81 for (
int i=0; i<= m_NumberOfBins; i++)
82 (*m_Table)[i] = this->m_Functor( m_Delta*i + m_VariableMin );
87 return m_Table->size();
92 return m_NumberOfBins>0 && m_Table->size()==m_NumberOfBins+1;
98 if (var<=m_VariableMin)
100 if (var>=m_VariableMax)
101 return m_Table->back();
103 double xDouble = (var-m_VariableMin)*m_DeltaInv;
104 int x = (int) std::floor(xDouble);
105 return (*m_Table)[x] + ((*m_Table)[x+1]-(*m_Table)[x])*(xDouble-x);
110 m_Table(new STDVectorType())
122 Superclass::PrintSelf(os, indent);
123 PrintVar4(
true, m_VariableMax, m_VariableMin, m_NumberOfBins, m_Delta, os<<indent);
124 for (
int i=0; i<= m_NumberOfBins; i++)
125 utlPrintVar3(
true, i, m_Delta*i+m_VariableMin, (*m_Table)[i]);
130 typename LightObject::Pointer loPtr = Superclass::InternalClone();
131 typename Self::Pointer rval =
dynamic_cast<Self *
>(loPtr.GetPointer());
134 itkExceptionMacro(<<
"downcast to type " << this->GetNameOfClass()<<
" failed.");
136 rval->m_VariableMax = m_VariableMax;
137 rval->m_VariableMin = m_VariableMin;
138 rval->m_Delta = m_Delta;
139 rval->m_DeltaInv = m_DeltaInv;
140 rval->m_NumberOfBins = m_NumberOfBins;
142 rval->m_Table = m_Table;
160 void operator=(
const Self&);
std::vector< double > STDVectorType
Superclass::FunctorValueType FunctorValueType
use UnaryFunctorLookUpTable to accelerate evaluation of functions.
#define utlPrintVar3(cond, var1, var2, var3)
FunctorValueType GetFunctionValue(const ParametersType &var)
Superclass::ParametersType ParametersType
UnaryFunctorLookUpTable()
SmartPointer< const Self > ConstPointer
Superclass::STDVectorType STDVectorType
void Initialize() ITK_OVERRIDE
Superclass::FunctorType FunctorType
LightObject::Pointer InternalClone() const ITK_OVERRIDE
bool IsTableBuilt() const
#define utlGlobalException(cond, expout)
UnaryFunctorLookUpTable Self
SmartPointer< Self > Pointer
~UnaryFunctorLookUpTable()
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
FunctorTableBase< TFunctor, double, double > Superclass
Superclass::STDVectorPointer STDVectorPointer
unsigned long GetTableSize() const
#define PrintVar4(cond, var1, var2, var3, var4, os)
use FunctorTableBase to accelerate evaluation of functions.