IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1922


Ignore:
Timestamp:
Sep 28, 2004, 2:28:21 PM (22 years ago)
Author:
evanalst
Message:

Add additional test cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageManip.c

    r1914 r1922  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-09-28 01:24:46 $
     8 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-09-29 00:28:21 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    873873    */
    874874
    875     in = psImageAlloc(16,16,PS_TYPE_F32);
    876     meanTruth = psImageAlloc(4,4,PS_TYPE_F32);
    877     maxTruth = psImageAlloc(6,6,PS_TYPE_F32);
    878     memset(meanTruth->data.F32[0],0,sizeof(psF32)*4*4);
    879     memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6);
    880 
    881     for (int row = 0; row<16; row++) {
    882         psF32* inRow = in->data.F32[row];
    883         psF32* meanTruthRow = meanTruth->data.F32[row/4];
    884         psF32* maxTruthRow = maxTruth->data.F32[row/3];
    885         for (int col = 0; col<16; col++) {
    886             inRow[col] = row + col;
    887             meanTruthRow[col/4] += row + col;
    888             if (maxTruthRow[col/3] < row + col) {
    889                 maxTruthRow[col/3] = row+col;
    890             }
    891         }
    892     }
    893     for (int row = 0; row<4; row++) {
    894         psF32* meanTruthRow = meanTruth->data.F32[row];
    895         for (int col = 0; col<4; col++) {
    896             meanTruthRow[col] /= 16;
    897         }
    898     }
    899 
     875    #define testRebinType(DATATYPE)  \
     876    in = psImageAlloc(16,16,PS_TYPE_##DATATYPE); \
     877    meanTruth = psImageAlloc(4,4,PS_TYPE_F32); \
     878    maxTruth = psImageAlloc(6,6,PS_TYPE_F32); \
     879    memset(meanTruth->data.F32[0],0,sizeof(psF32)*4*4); \
     880    memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6); \
     881    for (int row = 0; row<16; row++) { \
     882        ps##DATATYPE* inRow = in->data.DATATYPE[row]; \
     883        psF32* meanTruthRow = meanTruth->data.F32[row/4]; \
     884        psF32* maxTruthRow = maxTruth->data.F32[row/3]; \
     885        for (int col = 0; col<16; col++) { \
     886            inRow[col] = row + col; \
     887            meanTruthRow[col/4] += row + col; \
     888            if (maxTruthRow[col/3] < row + col) { \
     889                maxTruthRow[col/3] = row+col; \
     890            } \
     891        } \
     892    } \
     893    for (int row = 0; row<4; row++) { \
     894        psF32* meanTruthRow = meanTruth->data.F32[row]; \
     895        for (int col = 0; col<4; col++) { \
     896            meanTruthRow[col] /= 16; \
     897        } \
     898    } \
     899    stats.options = PS_STAT_SAMPLE_MEAN; \
     900    out = psImageRebin(NULL,in,NULL,0,4,&stats); \
     901    if (out == NULL) { \
     902        psError(__func__,"psImageRebin returned a NULL pointer!?"); \
     903        return 1; \
     904    } \
     905    if (out->numRows != 4 || out->numCols != 4) { \
     906        psError(__func__,"psImageRebin didn't produce the proper size image " \
     907                "(%d x %d).", \
     908                out->numCols, out->numRows); \
     909        return 2; \
     910    } \
     911    for (int row = 0; row<4; row++) { \
     912        ps##DATATYPE* outRow = out->data.DATATYPE[row]; \
     913        psF32* truthRow = meanTruth->data.F32[row]; \
     914        for (int col = 0; col<4; col++) { \
     915            if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \
     916                psError(__func__,"psImageRebin didn't produce the proper mean " \
     917                        "result at (%d,%d) [%f vs %f].", \
     918                        col,row,outRow[col],truthRow[col]); \
     919                return 3; \
     920            } \
     921        } \
     922    } \
     923    stats.options = PS_STAT_MAX; \
     924    out2 = psImageRebin(out,in,NULL,0,3,&stats); \
     925    if (out != out2) { \
     926        psError(__func__,"psImageRebin didn't recycle a psImage properly!?"); \
     927        return 7; \
     928    } \
     929    if (out == NULL) { \
     930        psError(__func__,"psImageRebin returned a NULL pointer!?"); \
     931        return 4; \
     932    } \
     933    if (out->numRows != 6 || out->numCols != 6) { \
     934        psError(__func__,"psImageRebin didn't produce the proper size image " \
     935                "(%d x %d).", \
     936                out->numCols, out->numRows); \
     937        return 5; \
     938    } \
     939    for (int row = 0; row<6; row++) { \
     940        ps##DATATYPE* outRow = out->data.DATATYPE[row]; \
     941        psF32* truthRow = maxTruth->data.F32[row]; \
     942        for (int col = 0; col<6; col++) { \
     943            if (fabsf((float)outRow[col]-(float)truthRow[col]) > FLT_EPSILON) { \
     944                psError(__func__,"psImageRebin didn't produce the proper " \
     945                        "max result at (%d,%d) [%f vs %f].", \
     946                        col,row,outRow[col],truthRow[col]); \
     947                return 6; \
     948            } \
     949        } \
     950    } \
     951    psFree(in); \
     952    psFree(out); \
     953    psFree(meanTruth); \
     954    psFree(maxTruth);
     955
     956    testRebinType(F32);
     957    testRebinType(F64);
     958    testRebinType(U16);
     959    testRebinType(S8);
     960
     961    // Verify the returned psImage structure is null and program execution
     962    // doesn't stop, if the input image type is not supported.
     963    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
     964    in = psImageAlloc(16,16,PS_TYPE_U8);
    900965    stats.options = PS_STAT_SAMPLE_MEAN;
    901966    out = psImageRebin(NULL,in,NULL,0,4,&stats);
    902 
    903     if (out == NULL) {
    904         psError(__func__,"psImageRebin returned a NULL pointer!?");
    905         return 1;
    906     }
    907 
    908     if (out->numRows != 4 || out->numCols != 4) {
    909         psError(__func__,"psImageRebin didn't produce the proper size image "
    910                 "(%d x %d).",
    911                 out->numCols, out->numRows);
    912         return 2;
    913     }
    914 
    915     for (int row = 0; row<4; row++) {
    916         psF32* outRow = out->data.F32[row];
    917         psF32* truthRow = meanTruth->data.F32[row];
    918         for (int col = 0; col<4; col++) {
    919             if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
    920                 psError(__func__,"psImageRebin didn't produce the proper "
    921                         "result at (%d,%d) [%f vs %f].",
    922                         col,row,outRow[col],truthRow[col]);
    923                 return 3;
    924             }
    925         }
    926     }
    927 
    928     stats.options = PS_STAT_MAX;
    929     out2 = psImageRebin(out,in,NULL,0,3,&stats);
    930 
    931     // Verify the returned psImage structure is equal to the input parameter
    932     // out if specified.
    933     if (out != out2) {
    934         psError(__func__,"psImageRebin didn't recycle a psImage properly!?");
    935         return 7;
    936     }
    937 
    938     if (out == NULL) {
    939         psError(__func__,"psImageRebin returned a NULL pointer!?");
    940         return 4;
    941     }
    942 
    943     if (out->numRows != 6 || out->numCols != 6) {
    944         psError(__func__,"psImageRebin didn't produce the proper size image "
    945                 "(%d x %d).",
    946                 out->numCols, out->numRows);
    947         return 5;
    948     }
    949 
    950     for (int row = 0; row<6; row++) {
    951         psF32* outRow = out->data.F32[row];
    952         psF32* truthRow = maxTruth->data.F32[row];
    953         for (int col = 0; col<6; col++) {
    954             if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
    955                 psError(__func__,"psImageRebin didn't produce the proper "
    956                         "result at (%d,%d) [%f vs %f].",
    957                         col,row,outRow[col],truthRow[col]);
    958                 return 6;
    959             }
    960         }
    961     }
     967    if(out != NULL) {
     968        psError(__func__,"psImageRebin return an image eventhough the "
     969                "type is not handled.");
     970        return 14;
     971    }
     972    psFree(in);
    962973
    963974    // Verify the returned psImage structure is null and program execution
     
    974985    // Verify the returned psImage structure is null and program execution
    975986    // doesn't stop, if the input parameter scale is less than or equal to zero.
     987    in = psImageAlloc(16, 16, PS_TYPE_F32);
    976988    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
    977989    out2 = psImageRebin(NULL,in,NULL,0,0,&stats);
     
    10311043    }
    10321044
    1033 
    10341045    psFree(in);
    1035     psFree(out);
    1036     psFree(meanTruth);
    1037     psFree(maxTruth);
    10381046
    10391047    return 0;
Note: See TracChangeset for help on using the changeset viewer.