IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2128


Ignore:
Timestamp:
Oct 14, 2004, 10:49:53 AM (22 years ago)
Author:
gusciora
Message:

SHould be the first full version of tst_pmNonLinear.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/tst_pmNonLinear.c

    r2123 r2128  
    33 *  @brief Contains the tests for pmNonLinear.c:
    44 *
     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 *
    513 *  @author GLG, MHPCC
    614 *
    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 $
    917 *
    1018 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1523#include "pmNonLinear.h"
    1624static int test00(void);
     25static int test01(void);
    1726testDescription tests[] = {
    18                               {test00, 000, "pmNonLinear", 0, false},
     27                              {test00, 000, "pmNonLinearityPolynomial", 0, false},
     28                              {test01, 000, "pmNonLinearityLookup", 0, false},
    1929                              {NULL}
    2030                          };
     
    2636}
    2737
    28 #define NUM_ROWS 32
    29 #define NUM_COLS 32
    30 int test00( void )
     38#define NUM_ROWS 8
     39#define NUM_COLS 8
     40int doNonLinearityPolynomialTest(int numCols, int numRows)
    3141{
    3242    int i;
    3343    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);
    3750    myPoly->coeff[1] = 1.0;
    3851
    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++) {
    4154            myReadout->image->data.F32[i][j] = (float) (i + j);
    4255        }
     
    4558    printPositiveTestHeader(stdout, "pmNonLinear", "Simple polynomial");
    4659    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
    4772    psFree(myReadout);
     73    psFree(myPoly);
    4874    printFooter(stdout, "pmNonLinear", "Simple polynomial", true);
    49     return 0;
     75    return(testStatus);
    5076}
    51 //This code will use the psNonLinearLookup routines.
     77
     78int 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
     90int 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
     135int 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.