Changeset 2128
- Timestamp:
- Oct 14, 2004, 10:49:53 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/psModules/test/tst_pmNonLinear.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/tst_pmNonLinear.c
r2123 r2128 3 3 * @brief Contains the tests for pmNonLinear.c: 4 4 * 5 * test00: This code will create a simple polynomial, and call 6 * pmNonLinearityPolynomial() for a variety of image sizes [(1, 1), (1, 7 * N), (N, 1), (N, N)]. 8 * 9 * test01: This code will create simple table lookup vectors, and call 10 * pmNonLinearityPolynomial() for a variety of image sizes [(1, 1), (1, 11 * N), (N, 1), (N, N)]. 12 * 5 13 * @author GLG, MHPCC 6 14 * 7 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $8 * @date $Date: 2004-10-14 18:31:32$15 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2004-10-14 20:49:53 $ 9 17 * 10 18 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 15 23 #include "pmNonLinear.h" 16 24 static int test00(void); 25 static int test01(void); 17 26 testDescription tests[] = { 18 {test00, 000, "pmNonLinear", 0, false}, 27 {test00, 000, "pmNonLinearityPolynomial", 0, false}, 28 {test01, 000, "pmNonLinearityLookup", 0, false}, 19 29 {NULL} 20 30 }; … … 26 36 } 27 37 28 #define NUM_ROWS 3229 #define NUM_COLS 3230 int test00( void)38 #define NUM_ROWS 8 39 #define NUM_COLS 8 40 int doNonLinearityPolynomialTest(int numCols, int numRows) 31 41 { 32 42 int i; 33 43 int j; 34 psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 35 psReadout *myReadout = psReadoutAlloc(NUM_COLS, NUM_ROWS, myImage); 36 psPolynomial1D *myPoly = psPolynomial1DAlloc(1, PS_POLYNOMIAL_ORD); 44 float actual; 45 float expect; 46 int testStatus = 0; 47 psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); 48 psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage); 49 psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD); 37 50 myPoly->coeff[1] = 1.0; 38 51 39 for (i=0;i< NUM_ROWS;i++) {40 for (j=0;j< NUM_COLS;j++) {52 for (i=0;i<numRows;i++) { 53 for (j=0;j<numCols;j++) { 41 54 myReadout->image->data.F32[i][j] = (float) (i + j); 42 55 } … … 45 58 printPositiveTestHeader(stdout, "pmNonLinear", "Simple polynomial"); 46 59 myReadout = pmNonLinearityPolynomial(myReadout, myPoly); 60 for (i=0;i<numRows;i++) { 61 for (j=0;j<numCols;j++) { 62 expect = psPolynomial1DEval((float) (i + j), myPoly); 63 actual = myReadout->image->data.F32[i][j]; 64 if (FLT_EPSILON < fabs(expect - actual)) { 65 printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 66 testStatus = 1; 67 } 68 } 69 } 70 71 47 72 psFree(myReadout); 73 psFree(myPoly); 48 74 printFooter(stdout, "pmNonLinear", "Simple polynomial", true); 49 return 0;75 return(testStatus); 50 76 } 51 //This code will use the psNonLinearLookup routines. 77 78 int test00( void ) 79 { 80 int testStatus = 0; 81 82 testStatus |= doNonLinearityPolynomialTest(1, 1); 83 testStatus |= doNonLinearityPolynomialTest(NUM_COLS, 1); 84 testStatus |= doNonLinearityPolynomialTest(1, NUM_ROWS); 85 testStatus |= doNonLinearityPolynomialTest(NUM_COLS, NUM_ROWS); 86 87 return(testStatus); 88 } 89 90 int doNonLinearityLookupTest(int numCols, int numRows) 91 { 92 int i; 93 int j; 94 float actual; 95 float expect; 96 int testStatus = 0; 97 int tableSize = PS_MAX(numCols, numRows)*2; 98 psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); 99 psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage); 100 psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32); 101 psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32); 102 103 for (i=0;i<numRows;i++) { 104 for (j=0;j<numCols;j++) { 105 myReadout->image->data.F32[i][j] = (float) (i + j); 106 } 107 } 108 109 for (i=0;i<tableSize;i++) { 110 in->data.F32[i] = (float) i; 111 out->data.F32[i] = (float) (2 * i); 112 } 113 114 printPositiveTestHeader(stdout, "pmNonLinear", "Simple polynomial"); 115 myReadout = pmNonLinearityLookup(myReadout, in, out); 116 for (i=0;i<numRows;i++) { 117 for (j=0;j<numCols;j++) { 118 expect = (float) (2 * (i + j)); 119 actual = myReadout->image->data.F32[i][j]; 120 if (FLT_EPSILON < fabs(expect - actual)) { 121 printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 122 testStatus = 1; 123 } 124 } 125 } 126 127 128 psFree(myReadout); 129 psFree(in); 130 psFree(out); 131 printFooter(stdout, "pmNonLinear", "Simple polynomial", true); 132 return(testStatus); 133 } 134 135 int test01( void ) 136 { 137 int testStatus = 0; 138 139 testStatus |= doNonLinearityLookupTest(1, 1); 140 testStatus |= doNonLinearityLookupTest(NUM_COLS, 1); 141 testStatus |= doNonLinearityLookupTest(1, NUM_ROWS); 142 testStatus |= doNonLinearityLookupTest (NUM_COLS, NUM_ROWS); 143 144 return(testStatus); 145 }
Note:
See TracChangeset
for help on using the changeset viewer.
