DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkFunctorTableBase.h
Go to the documentation of this file.
1 
19 #ifndef __itkFunctorTableBase_h
20 #define __itkFunctorTableBase_h
21 
22 #include "itkObject.h"
23 #include "itkObjectFactory.h"
24 #include "utlSTDHeaders.h"
25 #include "utlCoreMacro.h"
26 
27 namespace itk
28 {
29 
37 template < class TFunctor, class TParameters, class TFunctorValue >
38 class ITK_EXPORT FunctorTableBase
39  : public Object
40 {
41 public:
44  typedef Object Superclass;
45  typedef SmartPointer<Self> Pointer;
46  typedef SmartPointer<const Self> ConstPointer;
47 
49  itkNewMacro(Self);
50 
52  itkTypeMacro( FunctorTableBase, Object );
53 
54  typedef TParameters ParametersType;
55  typedef TFunctor FunctorType;
56  typedef TFunctorValue FunctorValueType;
57 
58  typedef std::vector<double> STDVectorType;
59  typedef utl_shared_ptr<STDVectorType > STDVectorPointer;
60 
61 
66  FunctorType & GetFunctor() { return m_Functor; }
67  const FunctorType & GetFunctor() const { return m_Functor; }
68 
75  void SetFunctor(const FunctorType & functor)
76  {
77  if ( m_Functor != functor )
78  {
79  m_Functor = functor;
80  this->Modified();
81  }
82  }
83 
84  virtual void Initialize()
85  {
86  }
87 
88  void BuildTable()
89  {
90  }
91 
92  unsigned long GetTableSize() const
93  {
94  return -1;
95  }
96 
97  bool IsTableBuilt() const
98  {
99  return false;
100  }
101 
103  FunctorValueType GetFunctionValue ( const ParametersType& param)
104  {
105  return m_Functor(param);
106  }
107 
108 protected:
109  FunctorTableBase() : Superclass()
110  {
111  }
112  virtual ~FunctorTableBase() {};
113 
114  // void PrintSelf(std::ostream& os, Indent indent) const
115  // {
116  // Superclass::PrintSelf(os, indent);
117  // }
118 
119  typename LightObject::Pointer InternalClone() const ITK_OVERRIDE
120  {
121  typename LightObject::Pointer loPtr = Superclass::InternalClone();
122  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
123  if(rval.IsNull())
124  {
125  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
126  }
127  rval->m_Functor = m_Functor;
128  return loPtr;
129  }
130 
131  FunctorType m_Functor;
132 
133 private:
134  FunctorTableBase(const Self&); //purposely not implemented
135  void operator=(const Self&); //purposely not implemented
136 
137 };
138 
139 
140 }
141 
142 
143 #endif
144 
std::vector< double > STDVectorType
LightObject::Pointer InternalClone() const ITK_OVERRIDE
const FunctorType & GetFunctor() const
FunctorValueType GetFunctionValue(const ParametersType &param)
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
SmartPointer< Self > Pointer
unsigned long GetTableSize() const
TFunctorValue FunctorValueType
SmartPointer< const Self > ConstPointer
void SetFunctor(const FunctorType &functor)
macros for utlCore
FunctorType & GetFunctor()
utl_shared_ptr< STDVectorType > STDVectorPointer
use FunctorTableBase to accelerate evaluation of functions.