Changeset 15985 for trunk/psModules/test/objects/tap_pmModel.c
- Timestamp:
- Jan 2, 2008, 10:45:23 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/test/objects/tap_pmModel.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/objects/tap_pmModel.c
r15726 r15985 5 5 #include "tap.h" 6 6 #include "pstap.h" 7 /* STATUS: 8 All functions are tested. However... 9 10 The source code for pmModelAddWithOffset() and pmModelSubWithOffset() is 11 almost exactly the same as the source code for pmModelAdd() and 12 pmModelSub(). We do not test them here. 13 */ 7 14 8 15 #define MISC_NUM 32 … … 15 22 #define NUM_ROWS 8 16 23 #define NUM_COLS 16 24 #define TEST_FLOATS_EQUAL(X, Y) (abs(X - Y) < 0.01) 17 25 18 26 /****************************************************************************** … … 42 50 psLogSetLevel(PS_LOG_INFO); 43 51 psTraceSetLevel("err", ERR_TRACE_LEVEL); 44 plan_tests( 1);52 plan_tests(53); 45 53 46 54 // ---------------------------------------------------------------------- … … 142 150 // ---------------------------------------------------------------------- 143 151 // pmModelEval() tests 144 // psF32 pmModelEval(pmModel *model, psImage *image, psS32 col, psS32 row)145 152 // call pmModelEval() with NULL input pmModel parameter 146 153 { … … 201 208 202 209 210 /* XXX: This seems to have disappeared from pmModel.h 203 211 // ---------------------------------------------------------------------- 204 212 // pmModelEvalWithOffset() tests 205 // psF32 pmModelEvalWithOffset WithOffset(pmModel *model, psImage *image,213 // psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, 206 214 // psS32 col, psS32 row, int dx, int dy) 207 215 // call pmModelEvalWithOffset() with NULL input pmModel parameter … … 220 228 221 229 222 // psF32 pmModelEvalWithOffset WithOffset(pmModel *model, psImage *image,230 // psF32 pmModelEvalWithOffset(pmModel *model, psImage *image, 223 231 // psS32 col, psS32 row, int dx, int dy) 224 232 // call pmModelEvalWithOffset() with NULL input psImage parameter … … 262 270 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 263 271 } 272 */ 273 274 275 // ---------------------------------------------------------------------- 276 // pmModelAdd() tests 277 // call pmModelAdd() with bad input parameters 278 { 279 psMemId id = psMemGetId(); 280 psImage *img = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 281 psImage *imgS32 = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_S32); 282 psImage *mask = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_U8); 283 for (int i = 0 ; i < NUM_ROWS ; i++) { 284 for (int j = 0 ; j < NUM_COLS ; j++) { 285 img->data.F32[i][j] = 0.0; 286 mask->data.U8[i][j] = 0; 287 } 288 } 289 pmModel *model = pmModelAlloc(pmModelClassGetType("PS_MODEL_GAUSS")); 290 psF32 *PAR = model->params->data.F32; 291 PAR[PM_PAR_XPOS] = (float) (NUM_COLS/2); 292 PAR[PM_PAR_YPOS] = (float) (NUM_ROWS/2); 293 PAR[PM_PAR_SXX] = 1.0; 294 PAR[PM_PAR_SYY] = 1.0; 295 296 // NULL psImage input parameter 297 bool rc = pmModelAdd(NULL, mask, model, PM_MODEL_OP_FUNC, 1); 298 ok(rc == false, "pmModelAdd() returned FALSE with NULL psImage input parameter"); 299 300 // NULL pmModel input parameter 301 rc = pmModelAdd(img, mask, NULL, PM_MODEL_OP_FUNC, 1); 302 ok(rc == false, "pmModelAdd() returned FALSE with NULL pmModel input parameter"); 303 304 // Incorrect type psImage input parameter 305 rc = pmModelAdd(imgS32, mask, model, PM_MODEL_OP_FUNC, 1); 306 ok(rc == false, "pmModelAdd() returned FALSE with Incorrect type psImage input parameter"); 307 308 psFree(img); 309 psFree(imgS32); 310 psFree(mask); 311 psFree(model); 312 pmModelClassCleanup(); 313 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 314 } 315 316 317 // call pmModelAdd() with acceptable parameters 318 // We only test with a single Gaussian model, with no residuals or masks. 319 // For completeness, additional tests should be added. 320 { 321 psMemId id = psMemGetId(); 322 psImage *img = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 323 psImage *mask = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_U8); 324 for (int i = 0 ; i < NUM_ROWS ; i++) { 325 for (int j = 0 ; j < NUM_COLS ; j++) { 326 img->data.F32[i][j] = 0.0; 327 mask->data.U8[i][j] = 0; 328 } 329 } 330 pmModel *model = pmModelAlloc(pmModelClassGetType("PS_MODEL_GAUSS")); 331 psF32 *PAR = model->params->data.F32; 332 PAR[PM_PAR_I0] = 5.0; 333 PAR[PM_PAR_XPOS] = 0.0; 334 PAR[PM_PAR_YPOS] = 0.0; 335 PAR[PM_PAR_XPOS] = (float) (NUM_COLS/2); 336 PAR[PM_PAR_YPOS] = (float) (NUM_ROWS/2); 337 PAR[PM_PAR_SXX] = 10.0; 338 PAR[PM_PAR_SYY] = 10.0; 339 340 bool rc = pmModelAdd(img, mask, model, PM_MODEL_OP_FUNC, 1); 341 ok(rc == true, "pmModelAdd() returned TRUE with acceptable input parameters"); 342 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 343 bool errorFlag = false; 344 for (int i = 0 ; i < NUM_ROWS ; i++) { 345 for (int j = 0 ; j < NUM_COLS ; j++) { 346 x->data.F32[0] = (float) j; 347 x->data.F32[1] = (float) i; 348 psF32 modF = model->modelFunc (NULL, model->params, x); 349 psF32 imgF = img->data.F32[i][j]; 350 if (!TEST_FLOATS_EQUAL(modF, imgF)) { 351 diag("ERROR: img[%d][%d] is %.2f, should be %.2f\n", i, j, img->data.F32[i][j], modF); 352 errorFlag = true; 353 } 354 } 355 } 356 ok(!errorFlag, "pmModelAdd() set the image pixels correctly"); 357 psFree(x); 358 psFree(img); 359 psFree(mask); 360 psFree(model); 361 pmModelClassCleanup(); 362 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 363 } 364 365 366 // ---------------------------------------------------------------------- 367 // pmModelSub() tests 368 // call pmModelSub() with bad input parameters 369 { 370 psMemId id = psMemGetId(); 371 psImage *img = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 372 psImage *imgS32 = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_S32); 373 psImage *mask = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_U8); 374 for (int i = 0 ; i < NUM_ROWS ; i++) { 375 for (int j = 0 ; j < NUM_COLS ; j++) { 376 img->data.F32[i][j] = 0.0; 377 mask->data.U8[i][j] = 0; 378 } 379 } 380 pmModel *model = pmModelAlloc(pmModelClassGetType("PS_MODEL_GAUSS")); 381 psF32 *PAR = model->params->data.F32; 382 PAR[PM_PAR_XPOS] = (float) (NUM_COLS/2); 383 PAR[PM_PAR_YPOS] = (float) (NUM_ROWS/2); 384 PAR[PM_PAR_SXX] = 1.0; 385 PAR[PM_PAR_SYY] = 1.0; 386 387 // NULL psImage input parameter 388 bool rc = pmModelSub(NULL, mask, model, PM_MODEL_OP_FUNC, 1); 389 ok(rc == false, "pmModelSub() returned FALSE with NULL psImage input parameter"); 390 391 // NULL pmModel input parameter 392 rc = pmModelSub(img, mask, NULL, PM_MODEL_OP_FUNC, 1); 393 ok(rc == false, "pmModelSub() returned FALSE with NULL pmModel input parameter"); 394 395 // Incorrect type psImage input parameter 396 rc = pmModelSub(imgS32, mask, model, PM_MODEL_OP_FUNC, 1); 397 ok(rc == false, "pmModelSub() returned FALSE with Incorrect type psImage input parameter"); 398 399 psFree(img); 400 psFree(imgS32); 401 psFree(mask); 402 psFree(model); 403 pmModelClassCleanup(); 404 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 405 } 406 407 408 // call pmModelSub() with acceptable parameters 409 // We only test with a single Gaussian model, with no residuals or masks. 410 // For completeness, additional tests should be added. 411 { 412 psMemId id = psMemGetId(); 413 psImage *img = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 414 psImage *mask = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_U8); 415 for (int i = 0 ; i < NUM_ROWS ; i++) { 416 for (int j = 0 ; j < NUM_COLS ; j++) { 417 img->data.F32[i][j] = 0.0; 418 mask->data.U8[i][j] = 0; 419 } 420 } 421 pmModel *model = pmModelAlloc(pmModelClassGetType("PS_MODEL_GAUSS")); 422 psF32 *PAR = model->params->data.F32; 423 PAR[PM_PAR_I0] = 5.0; 424 PAR[PM_PAR_XPOS] = 0.0; 425 PAR[PM_PAR_YPOS] = 0.0; 426 PAR[PM_PAR_XPOS] = (float) (NUM_COLS/2); 427 PAR[PM_PAR_YPOS] = (float) (NUM_ROWS/2); 428 PAR[PM_PAR_SXX] = 10.0; 429 PAR[PM_PAR_SYY] = 10.0; 430 431 bool rc = pmModelSub(img, mask, model, PM_MODEL_OP_FUNC, 1); 432 ok(rc == true, "pmModelSub() returned TRUE with acceptable input parameters"); 433 psVector *x = psVectorAlloc(2, PS_TYPE_F32); 434 bool errorFlag = false; 435 for (int i = 0 ; i < NUM_ROWS ; i++) { 436 for (int j = 0 ; j < NUM_COLS ; j++) { 437 x->data.F32[0] = (float) j; 438 x->data.F32[1] = (float) i; 439 psF32 modF = model->modelFunc (NULL, model->params, x); 440 psF32 imgF = img->data.F32[i][j]; 441 if (!TEST_FLOATS_EQUAL(modF, -imgF)) { 442 diag("ERROR: img[%d][%d] is %.2f, should be %.2f\n", i, j, img->data.F32[i][j], modF); 443 errorFlag = true; 444 } 445 } 446 } 447 ok(!errorFlag, "pmModelSub() set the image pixels correctly"); 448 psFree(x); 449 psFree(img); 450 psFree(mask); 451 psFree(model); 452 pmModelClassCleanup(); 453 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 454 } 455 456 // XXX: The source code for pmModelAddWithOffset() and pmModelSubWithOffset() is 457 // almost exactly the same as the source code for pmModelAdd() and pmModelSub(). 458 // We do not test them here. 264 459 } 265 460
Note:
See TracChangeset
for help on using the changeset viewer.
