00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __cmtkPolynomial_h_included_
00033 #define __cmtkPolynomial_h_included_
00034
00035 #include <cmtkconfig.h>
00036
00037 namespace
00038 cmtk
00039 {
00040
00047 template<unsigned int NDegree,class TRealType=double>
00048 class Polynomial
00049 {
00050 public:
00052 typedef Polynomial<NDegree,TRealType> Self;
00053
00055 typedef TRealType RealValueType;
00056
00058 enum { NumberOfMonomials = 0 };
00059
00061 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00062 {
00063 return 0.0;
00064 }
00065
00070 static void EvaluateAllMonomials( TRealType *const mvec, const TRealType x, const TRealType y, const TRealType z )
00071 {
00072 }
00073 };
00074
00076 template<class TRealType>
00077 class Polynomial<0,TRealType>
00078 {
00079 public:
00081 typedef Polynomial<0,TRealType> Self;
00082
00084 typedef TRealType RealValueType;
00085
00087 enum { NumberOfMonomials = 0 };
00088
00090 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00091 {
00092 return 0.0;
00093 }
00094
00099 static void EvaluateAllMonomials( TRealType *const, const TRealType, const TRealType, const TRealType ) {}
00100 };
00101
00103 template<class TRealType>
00104 class Polynomial<1,TRealType>
00105 {
00106 public:
00108 typedef Polynomial<1,TRealType> Self;
00109
00111 typedef TRealType RealValueType;
00112
00114 enum { NumberOfMonomials = 3 };
00115
00117 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00118 {
00119 switch ( idx )
00120 {
00121 case 0 : return x;
00122 case 1 : return y;
00123 case 2 : return z;
00124 }
00125 return 0.0;
00126 }
00127
00132 static void EvaluateAllMonomials( TRealType *const mvec, const TRealType x, const TRealType y, const TRealType z )
00133 {
00134 mvec[0] = x;
00135 mvec[1] = y;
00136 mvec[2] = z;
00137 }
00138 };
00139
00141 template<class TRealType>
00142 class Polynomial<2,TRealType>
00143 {
00144 public:
00146 typedef Polynomial<2,TRealType> Self;
00147
00149 typedef TRealType RealValueType;
00150
00152 enum { NumberOfMonomials = 9 };
00153
00155 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00156 {
00157 switch ( idx )
00158 {
00159 case 0 : return x;
00160 case 1 : return y;
00161 case 2 : return z;
00162
00163 case 3 : return x*x;
00164 case 4 : return x*y;
00165 case 5 : return x*z;
00166 case 6 : return y*y;
00167 case 7 : return y*z;
00168 case 8 : return z*z;
00169 }
00170 return 0.0;
00171 }
00172
00177 static void EvaluateAllMonomials( TRealType *const mvec, const TRealType x, const TRealType y, const TRealType z )
00178 {
00179 Polynomial<1,TRealType>::EvaluateAllMonomials( mvec, x, y, z );
00180 mvec[3] = mvec[0]*x;
00181 mvec[4] = mvec[0]*y;
00182 mvec[5] = mvec[0]*z;
00183 mvec[6] = mvec[1]*y;
00184 mvec[7] = mvec[1]*z;
00185 mvec[8] = mvec[2]*z;
00186 }
00187 };
00188
00190 template<class TRealType>
00191 class Polynomial<3,TRealType>
00192 {
00193 public:
00195 typedef Polynomial<3,TRealType> Self;
00196
00198 typedef TRealType RealValueType;
00199
00201 enum { NumberOfMonomials = 19 };
00202
00204 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00205 {
00206 switch ( idx )
00207 {
00208 case 0 : return x;
00209 case 1 : return y;
00210 case 2 : return z;
00211
00212 case 3 : return x*x;
00213 case 4 : return x*y;
00214 case 5 : return x*z;
00215 case 6 : return y*y;
00216 case 7 : return y*z;
00217 case 8 : return z*z;
00218
00219 case 9 : return x*x*x;
00220 case 10 : return x*x*y;
00221 case 11 : return x*x*z;
00222 case 12 : return x*y*y;
00223 case 13 : return x*y*z;
00224 case 14 : return x*z*z;
00225 case 15 : return y*y*y;
00226 case 16 : return y*y*z;
00227 case 17 : return y*z*z;
00228 case 18 : return z*z*z;
00229 }
00230 return 0.0;
00231 }
00232
00237 static void EvaluateAllMonomials( TRealType *const mvec, const TRealType x, const TRealType y, const TRealType z )
00238 {
00239 Polynomial<2,TRealType>::EvaluateAllMonomials( mvec, x, y, z );
00240
00241 mvec[9] = mvec[3]*x;
00242 mvec[10] = mvec[3]*y;
00243 mvec[11] = mvec[3]*z;
00244
00245 mvec[12] = mvec[4]*y;
00246 mvec[13] = mvec[4]*z;
00247
00248 mvec[14] = mvec[5]*z;
00249
00250 mvec[15] = mvec[6]*y;
00251 mvec[16] = mvec[6]*z;
00252
00253 mvec[17] = mvec[7]*z;
00254 mvec[18] = mvec[8]*z;
00255 }
00256 };
00257
00259 template<class TRealType>
00260 class Polynomial<4,TRealType>
00261 {
00262 public:
00264 typedef Polynomial<4,TRealType> Self;
00265
00267 typedef TRealType RealValueType;
00268
00270 enum { NumberOfMonomials = 34 };
00271
00273 static TRealType EvaluateMonomialAt( const size_t idx, const TRealType x, const TRealType y, const TRealType z )
00274 {
00275 switch ( idx )
00276 {
00277 case 0 : return x;
00278 case 1 : return y;
00279 case 2 : return z;
00280
00281 case 3 : return x*x;
00282 case 4 : return x*y;
00283 case 5 : return x*z;
00284 case 6 : return y*y;
00285 case 7 : return y*z;
00286 case 8 : return z*z;
00287
00288 case 9 : return x*x*x;
00289 case 10 : return x*x*y;
00290 case 11 : return x*x*z;
00291 case 12 : return x*y*y;
00292 case 13 : return x*y*z;
00293 case 14 : return x*z*z;
00294 case 15 : return y*y*y;
00295 case 16 : return y*y*z;
00296 case 17 : return y*z*z;
00297 case 18 : return z*z*z;
00298
00299 case 19 : return x*x*x*x;
00300 case 20 : return x*x*x*y;
00301 case 21 : return x*x*x*z;
00302 case 22 : return x*x*y*y;
00303 case 23 : return x*x*y*z;
00304 case 24 : return x*x*z*z;
00305 case 25 : return x*y*y*y;
00306 case 26 : return x*y*y*z;
00307 case 27 : return x*y*z*z;
00308 case 28 : return x*z*z*z;
00309
00310 case 29 : return y*y*y*y;
00311 case 30 : return y*y*y*z;
00312 case 31 : return y*y*z*z;
00313 case 32 : return y*z*z*z;
00314 case 33 : return z*z*z*z;
00315 }
00316 return 0.0;
00317 }
00318
00323 static void EvaluateAllMonomials( TRealType *const mvec, const TRealType x, const TRealType y, const TRealType z )
00324 {
00325 Polynomial<3,TRealType>::EvaluateAllMonomials( mvec, x, y, z );
00326
00327 mvec[19] = mvec[9] * x;
00328 mvec[20] = mvec[9] * y;
00329 mvec[21] = mvec[9] * z;
00330 mvec[22] = mvec[10] * y;
00331 mvec[23] = mvec[10] * z;
00332 mvec[24] = mvec[11] * z;
00333 mvec[25] = mvec[12] * y;
00334 mvec[26] = mvec[12] * z;
00335 mvec[27] = mvec[13] * z;
00336 mvec[28] = mvec[14] * z;
00337 mvec[29] = mvec[15] * y;
00338 mvec[30] = mvec[15] * z;
00339 mvec[31] = mvec[16] * z;
00340 mvec[32] = mvec[17] * z;
00341 mvec[33] = mvec[18] * z;
00342 }
00343 };
00344
00346
00347 }
00348
00349 #endif // #ifndef __cmtkPolynomial_h_included_
00350