00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef PS_POLYNOMIAL_H
00017 #define PS_POLYNOMIAL_H
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <stdbool.h>
00024 #include <float.h>
00025 #include <math.h>
00026
00027 #include "psVector.h"
00028 #include "psScalar.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 float psGaussian(
00039 float x,
00040 float mean,
00041 float sigma,
00042 bool normal
00043 );
00044
00045
00046
00047
00048
00049 typedef enum {
00050 PS_POLYNOMIAL_ORD,
00051 PS_POLYNOMIAL_CHEB
00052 }
00053 psPolynomialType;
00054
00055
00056 typedef struct
00057 {
00058 psPolynomialType type;
00059 unsigned int nX;
00060 psF64 *coeff;
00061 psF64 *coeffErr;
00062 psMaskType *mask;
00063 }
00064 psPolynomial1D;
00065
00066
00067 typedef struct
00068 {
00069 psPolynomialType type;
00070 unsigned int nX;
00071 unsigned int nY;
00072 psF64 **coeff;
00073 psF64 **coeffErr;
00074 psMaskType **mask;
00075 }
00076 psPolynomial2D;
00077
00078
00079 typedef struct
00080 {
00081 psPolynomialType type;
00082 unsigned int nX;
00083 unsigned int nY;
00084 unsigned int nZ;
00085 psF64 ***coeff;
00086 psF64 ***coeffErr;
00087 psMaskType ***mask;
00088 }
00089 psPolynomial3D;
00090
00091
00092 typedef struct
00093 {
00094 psPolynomialType type;
00095 unsigned int nX;
00096 unsigned int nY;
00097 unsigned int nZ;
00098 unsigned int nT;
00099 psF64 ****coeff;
00100 psF64 ****coeffErr;
00101 psMaskType ****mask;
00102 }
00103 psPolynomial4D;
00104
00105
00106
00107
00108
00109
00110 psPolynomial1D* psPolynomial1DAlloc(
00111 psPolynomialType type,
00112 unsigned int nX
00113 );
00114
00115
00116
00117
00118
00119 psPolynomial2D* psPolynomial2DAlloc(
00120 psPolynomialType type,
00121 unsigned int nX,
00122 unsigned int nY
00123 );
00124
00125
00126
00127
00128
00129 psPolynomial3D* psPolynomial3DAlloc(
00130 psPolynomialType type,
00131 unsigned int nX,
00132 unsigned int nY,
00133 unsigned int nZ
00134 );
00135
00136
00137
00138
00139
00140 psPolynomial4D* psPolynomial4DAlloc(
00141 psPolynomialType type,
00142 unsigned int nX,
00143 unsigned int nY,
00144 unsigned int nZ,
00145 unsigned int nT
00146 );
00147
00148 bool psPolynomial2DRecycle(psPolynomial2D *poly,
00149 psPolynomialType type,
00150 unsigned int nX,
00151 unsigned int nY);
00152
00153 psPolynomial2D *psPolynomial2DCopy(psPolynomial2D *out,
00154 psPolynomial2D *poly);
00155
00156
00157
00158
00159
00160 psF64 psPolynomial1DEval(
00161 const psPolynomial1D* poly,
00162 psF64 x
00163 );
00164
00165
00166
00167
00168
00169 psF64 psPolynomial2DEval(
00170 const psPolynomial2D* poly,
00171 psF64 x,
00172 psF64 y
00173 );
00174
00175
00176
00177
00178
00179 psF64 psPolynomial3DEval(
00180 const psPolynomial3D* poly,
00181 psF64 x,
00182 psF64 y,
00183 psF64 z
00184 );
00185
00186
00187
00188
00189
00190 psF64 psPolynomial4DEval(
00191 const psPolynomial4D* poly,
00192 psF64 x,
00193 psF64 y,
00194 psF64 z,
00195 psF64 t
00196 );
00197
00198
00199
00200
00201
00202 psVector *psPolynomial1DEvalVector(
00203 const psPolynomial1D *poly,
00204 const psVector *x
00205 );
00206
00207
00208
00209
00210
00211 psVector *psPolynomial2DEvalVector(
00212 const psPolynomial2D *poly,
00213 const psVector *x,
00214 const psVector *y
00215 );
00216
00217
00218
00219
00220
00221 psVector *psPolynomial3DEvalVector(
00222 const psPolynomial3D *poly,
00223 const psVector *x,
00224 const psVector *y,
00225 const psVector *z
00226 );
00227
00228
00229
00230
00231
00232 psVector *psPolynomial4DEvalVector(
00233 const psPolynomial4D *poly,
00234 const psVector *x,
00235 const psVector *y,
00236 const psVector *z,
00237 const psVector *t
00238 );
00239
00240
00241
00242
00243
00244
00245
00246 bool psMemCheckPolynomial1D(
00247 psPtr ptr
00248 );
00249
00250
00251
00252
00253
00254
00255
00256 bool psMemCheckPolynomial2D(
00257 psPtr ptr
00258 );
00259
00260
00261
00262
00263
00264
00265
00266 bool psMemCheckPolynomial3D(
00267 psPtr ptr
00268 );
00269
00270
00271
00272
00273
00274
00275
00276 bool psMemCheckPolynomial4D(
00277 psPtr ptr
00278 );
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 psPolynomial1D **p_psCreateChebyshevPolys(
00289 psS32 numPolys
00290 );
00291
00292 typedef struct
00293 {
00294 int n;
00295 psPolynomial1D **chebyPolys;
00296
00297 }
00298 p_chebyPolys;
00299
00300
00301
00302
00303
00304 #define PS_ASSERT_POLY1D(NAME, RVAL) \
00305 if (false == psMemCheckPolynomial1D(NAME)) { \
00306 psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00307 "Unallowable operation: argument %s is not a psPolynomial1D struct.\n",\
00308 #NAME); \
00309 return(RVAL); \
00310 } \
00311
00312 #define PS_ASSERT_POLY_NON_NULL(NAME, RVAL) \
00313 if ((NAME) == NULL || (NAME)->coeff == NULL) { \
00314 psError(PS_ERR_BAD_PARAMETER_NULL, true, \
00315 "Unallowable operation: polynomial %s or its coeffs is NULL.", \
00316 #NAME); \
00317 return(RVAL); \
00318 } \
00319
00320 #define PS_ASSERT_POLY_TYPE(NAME, TYPE, RVAL) \
00321 if ((NAME)->type != TYPE) { \
00322 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00323 "Unallowable operation: polynomial %s has wrong type.", #NAME); \
00324 return(RVAL); \
00325 } \
00326
00327 #define PS_ASSERT_POLY_VALID_TYPE(TYPE, RVAL) \
00328 if ((TYPE != PS_POLYNOMIAL_ORD) && \
00329 (TYPE != PS_POLYNOMIAL_CHEB)) { \
00330 psError(PS_ERR_BAD_PARAMETER_TYPE, true, \
00331 "Unallowable operation: invalid type %d for polynomial", TYPE); \
00332 return(RVAL); \
00333 } \
00334
00335 #define PS_POLY_PRINT_1D(NAME) \
00336 printf("Poly %s: (nX) is (%d)\n", #NAME, NAME->nX);\
00337 for (psS32 i = 0 ; i < NAME->nX+1 ; i++) {\
00338 printf("%s->coeff[%d] is %f\n", #NAME, i, NAME->coeff[i]); \
00339 }\
00340
00341 #define PS_POLY_PRINT_2D(NAME) \
00342 printf("Poly %s: (nX, nY) is (%d, %d)\n", #NAME, NAME->nX, NAME->nY);\
00343 for (psS32 i = 0 ; i < NAME->nX+1 ; i++) {\
00344 for (psS32 j = 0 ; j < NAME->nY+1 ; j++) {\
00345 printf("%s->coeff[%d][%d] is %f\n", #NAME, i, j, NAME->coeff[i][j]); \
00346 }\
00347 }\
00348
00349
00350 #endif // #ifndef PS_POLYNOMIAL_H