DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkFunctors.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Marius Staring, Stefan Klein, David Doria. 2011.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 #ifndef __itkFunctors_h
19 #define __itkFunctors_h
20 
21 #include "vnl/vnl_math.h"
22 #include "vnl/vnl_erf.h"
23 #include "itkNumericTraits.h"
24 
25 
26 namespace itk {
27 
28 namespace Functor {
29 
34 #define __FunctorOneArgumentRight(Name, Op) \
35 template< class TInput, class TArgument=TInput, class TOutput=TInput > \
36 class Name \
37 { \
38 public: \
39  bool operator!=(const Name & other) const \
40  { return m_Argument!=other.m_Argument; } \
41  bool operator==(const Name & other) const \
42  { return !( *this != other ); } \
43  inline TOutput operator()( const TInput & A ) const \
44  { \
45  return static_cast<TOutput>( A Op this->m_Argument ); \
46  } \
47  void SetArgument( TArgument arg ){ this->m_Argument = arg; } \
48  TArgument GetArgument( ) const { return this->m_Argument; } \
49 private: \
50  TArgument m_Argument; \
51 }; \
52 
53 
55 #define __FunctorOneArgumentLeft(Name, Op) \
56 template< class TInput, class TArgument=TInput, class TOutput=TInput > \
57 class Name \
58 { \
59 public: \
60  bool operator!=(const Name &) const \
61  { return m_Argument!=other.m_Argument; } \
62  bool operator==(const Name & other) const \
63  { return !( *this != other ); } \
64  inline TOutput operator()( const TInput & A ) const \
65  { \
66  return static_cast<TOutput>( this->m_Argument Op A ); \
67  } \
68  void SetArgument( TArgument arg ){ this->m_Argument = arg; }; \
69  TArgument GetArgument( ) const { return this->m_Argument; } \
70 private: \
71  TArgument m_Argument; \
72 }; \
73 
79 
82 
83 
84 template< class TInput, class TArgument=TInput, class TOutput=TInput >
85 class NLOG
86 {
87 public:
88  bool operator!=(const NLOG & other) const
89  { return m_Argument!=other.m_Argument; }
90  bool operator==(const NLOG & other) const
91  { return !( *this != other ); }
92  inline TOutput operator()( const TInput & A ) const
93  {
94  return static_cast<TOutput>( vcl_log( static_cast<double>( A ) ) / vcl_log( static_cast<double>( this->m_Argument ) ) );
95  }
96  void SetArgument( TArgument arg ){ this->m_Argument = arg; };
97  TArgument GetArgument( ) const { return this->m_Argument; }
98 private:
99  TArgument m_Argument;
100 };
101 
102 
103 
106 template< class TInput, class TArgument=TInput, class TOutput=TInput >
107 class RPOWER
108 {
109 public:
110  bool operator!=(const RPOWER & other) const
111  { return m_Argument!=other.m_Argument; }
112  bool operator==(const RPOWER & other) const
113  { return !( *this != other ); }
114  inline TOutput operator()( const TInput & A ) const
115  {
116  return static_cast<TOutput>( vcl_pow( static_cast<double>( A ), static_cast<double>( this->m_Argument ) ) );
117  }
118  void SetArgument( TArgument arg ){ this->m_Argument = arg; };
119  TArgument GetArgument( ) const { return this->m_Argument; }
120 private:
121  TArgument m_Argument;
122 };
123 
124 template< class TInput, class TArgument=TInput, class TOutput=TInput >
125 class LPOWER
126 {
127 public:
128  bool operator!=(const LPOWER & other) const
129  { return m_Argument!=other.m_Argument; }
130  bool operator==(const LPOWER & other) const
131  { return !( *this != other ); }
132  inline TOutput operator()( const TInput & A ) const
133  {
134  return static_cast<TOutput>( vcl_pow( static_cast<double>( this->m_Argument ), static_cast<double>( A ) ) );
135  }
136  void SetArgument( TArgument arg ){ this->m_Argument = arg; };
137  TArgument GetArgument( ) const { return this->m_Argument; }
138 private:
139  TArgument m_Argument;
140 };
141 
142 // NOTE: use utl::Functor when there is no m_Argument
143 
144 // [>* Funtions that don't use m_Argument. <]
145 // #define __FunctorNoArgument(Name, Func) \
146 // template< class TInput, class TOutput=TInput > \
147 // class Name \
148 // { \
149 // public: \
150 // bool operator!=(const Name &) const \
151 // { return false; } \
152 // bool operator==(const Name & other) const \
153 // { return !( *this != other ); } \
154 // inline TOutput operator()( const TInput & A ) const \
155 // { \
156 // return static_cast<TOutput>( Func(A) ); \
157 // } \
158 // }; \
159 
160 
161 // #define __FunctorNoArgument2(Name, Func, Func2) \
162 // template< class TInput, class TOutput=TInput > \
163 // class Name \
164 // { \
165 // public: \
166 // bool operator!=(const Name &) const \
167 // { return false; } \
168 // bool operator==(const Name & other) const \
169 // { return !( *this != other ); } \
170 // inline TOutput operator()( const TInput & A ) const \
171 // { \
172 // return static_cast<TOutput>( Func(Func2(A)) ); \
173 // } \
174 // }; \
175 
176 // __FunctorNoArgument(MATHSIGN, vnl_math_sgn)
177 // __FunctorNoArgument(ABSOLUTE, std::abs) // use utl::Functor::Abs
178 
179 // __FunctorNoArgument2(FLOOR, std::floor, static_cast<double>)
180 // __FunctorNoArgument2(CEIL, std::ceil, static_cast<double>)
181 // __FunctorNoArgument2(ROUND, vnl_math_rnd, static_cast<double>)
182 // __FunctorNoArgument2(SQR, vnl_math_sqr, static_cast<double>)
183 // __FunctorNoArgument2(SQRT, std::sqrt, static_cast<double>)
184 // __FunctorNoArgument2(LN, vcl_log, static_cast<double>)
185 // __FunctorNoArgument2(LOG10, vcl_log10, static_cast<double>)
186 // __FunctorNoArgument2(EXP, std::exp, static_cast<double>)
187 // __FunctorNoArgument2(SIN, std::sin, static_cast<double>)
188 // __FunctorNoArgument2(COS, std::cos, static_cast<double>)
189 // __FunctorNoArgument2(TAN, std::tan, static_cast<double>)
190 // __FunctorNoArgument2(ARCSIN,vcl_asin, static_cast<double>)
191 // __FunctorNoArgument2(ARCCOS,vcl_acos, static_cast<double>)
192 // __FunctorNoArgument2(ARCTAN,vcl_atan, static_cast<double>)
193 
194 // template< class TInput, class TOutput=TInput >
195 // class NEG
196 // {
197 // public:
198 // bool operator!=(const NEG &) const
199 // { return false; }
200 // bool operator==(const NEG & other) const
201 // { return !( *this != other ); }
202 // inline TOutput operator()( const TInput & A ) const
203 // {
204 // return static_cast<TOutput>( -A );
205 // }
206 // };
207 
210 template< class TInput, class TArgument=TInput, class TOutput=TInput >
211 class LINEAR
212 {
213 public:
214  bool operator!=(const LINEAR & other) const
215  { return m_Argument1!=other.m_Argument1 || m_Argument2!=other.m_Argument2; }
216  bool operator==(const LINEAR & other) const
217  { return !( *this != other ); }
218  inline TOutput operator()( const TInput & A ) const
219  {
220  return static_cast<TOutput>( this->m_Argument1 * A + this->m_Argument2 );
221  }
222  void SetArgument1( TArgument arg ){ this->m_Argument1 = arg; };
223  void SetArgument2( TArgument arg ){ this->m_Argument2 = arg; };
224  TArgument GetArgument1( ) const { return this->m_Argument1; }
225  TArgument GetArgument2( ) const { return this->m_Argument2; }
226 private:
227  TArgument m_Argument1;
228  TArgument m_Argument2;
229 };
230 
233 } // end namespace Functor
234 
235 
236 } // end namespace itk
237 
238 
239 
240 #endif //#ifndef __itkFunctors_h
bool operator!=(const NLOG &other) const
Definition: itkFunctors.h:88
bool operator==(const RPOWER &other) const
Definition: itkFunctors.h:112
bool operator==(const LINEAR &other) const
Definition: itkFunctors.h:216
bool operator==(const NLOG &other) const
Definition: itkFunctors.h:90
TArgument GetArgument() const
Definition: itkFunctors.h:97
TOutput operator()(const TInput &A) const
Definition: itkFunctors.h:132
void SetArgument2(TArgument arg)
Definition: itkFunctors.h:223
bool operator==(const LPOWER &other) const
Definition: itkFunctors.h:130
TArgument GetArgument2() const
Definition: itkFunctors.h:225
TArgument m_Argument
Definition: itkFunctors.h:99
void SetArgument(TArgument arg)
Definition: itkFunctors.h:96
TArgument GetArgument1() const
Definition: itkFunctors.h:224
void SetArgument(TArgument arg)
Definition: itkFunctors.h:118
TOutput operator()(const TInput &A) const
Definition: itkFunctors.h:92
TOutput operator()(const TInput &A) const
Definition: itkFunctors.h:114
bool operator!=(const RPOWER &other) const
Definition: itkFunctors.h:110
void SetArgument(TArgument arg)
Definition: itkFunctors.h:136
TArgument GetArgument() const
Definition: itkFunctors.h:137
bool operator!=(const LINEAR &other) const
Definition: itkFunctors.h:214
bool operator!=(const LPOWER &other) const
Definition: itkFunctors.h:128
TArgument GetArgument() const
Definition: itkFunctors.h:119
#define __FunctorOneArgumentRight(Name, Op)
Definition: itkFunctors.h:34
TOutput operator()(const TInput &A) const
Definition: itkFunctors.h:218
void SetArgument1(TArgument arg)
Definition: itkFunctors.h:222