IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 10, 2004, 10:00:22 AM (22 years ago)
Author:
harman
Message:

Added support for psF32 types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psMatrix04.c

    r2392 r2686  
    1010 *     E)  Attempt to use null input image argument
    1111 *     F)  Attempt to use null input float argument
    12  * 
     12 *
    1313 *  @author  Ross Harman, MHPCC
    1414 *
    15  *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
    16  *  @date  $Date: 2004-11-22 21:00:21 $
     15 *  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
     16 *  @date  $Date: 2004-12-10 19:59:49 $
    1717 *
    1818 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "psTest.h"
    2424
    25 #define PRINT_MATRIX(IMAGE)                         \
    26 for(psS32 i=IMAGE->numRows-1; i>-1; i--) {            \
    27     for(psS32 j=0; j<IMAGE->numCols; j++) {           \
    28         printf("%f ", IMAGE->data.F64[i][j]);       \
    29     }                                               \
    30     printf("\n");                                   \
     25
     26#define TOLERANCE 0.000001
     27
     28#define CHECK_MATRIX(IMAGE)                                                                                  \
     29for(psU32 i=0; i<IMAGE->numRows; i++) {                                                                  \
     30    for(psU32 j=0; j<IMAGE->numCols; j++) {                                                              \
     31        if(IMAGE->type.type == PS_TYPE_F64) {                                                            \
     32            if(fabs(IMAGE->data.F64[i][j]-truthMatrix[i][j]) > TOLERANCE) {                              \
     33                printf("Matrix values at element %d, %d don't agree %lf vs %lf\n", i, j,                 \
     34                       IMAGE->data.F64[i][j], truthMatrix[i][j]);                                        \
     35            }                                                                                            \
     36        } else if(IMAGE->type.type == PS_TYPE_F32){                                                      \
     37            if(fabs(IMAGE->data.F32[i][j]-truthMatrix[i][j]) > TOLERANCE) {                              \
     38                printf("Matrix values at element %d, %d don't agree %f vs %lf\n", i, j,                  \
     39                       IMAGE->data.F32[i][j], truthMatrix[i][j]);                                        \
     40            }                                                                                            \
     41        }                                                                                                \
     42    }                                                                                                    \
    3143}
    3244
     45#define CHECK_VALUE(VALUE)                                                                                   \
     46if(fabs(VALUE-truthValue) > TOLERANCE) {                                                                     \
     47    printf("Values don't agree %lf vs %lf\n", VALUE, truthValue);                                            \
     48}
    3349
    34 psS32 main(psS32 argc,
    35            char* argv[])
     50psS32 main(psS32 argc, char* argv[])
    3651{
    3752    float det = 0.0f;
     
    4055    psImage *inImage = NULL;
    4156    psImage *tempImage = NULL;
     57    psImage *outImage32 = NULL;
     58    psImage *inImage32 = NULL;
     59    psImage *tempImage32 = NULL;
     60
     61    double truthMatrix[3][3] = {{4.0000000, -4.333333, -2.333333},
     62                                {-1.000000,  1.666667,  0.666667},
     63                                {-1.000000,  0.666667,  0.666667}};
     64    double truthValue = 3.0;
    4265
    4366
     
    5578    inImage->data.F64[2][1] =  5;
    5679    inImage->data.F64[2][2] =  7;
    57     PRINT_MATRIX(inImage);
     80
     81    outImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32);
     82    inImage32 = (psImage*)psImageAlloc(3, 3, PS_TYPE_F32);
     83    inImage32->data.F32[0][0] =  2;
     84    inImage32->data.F32[0][1] =  4;
     85    inImage32->data.F32[0][2] =  3;
     86    inImage32->data.F32[1][0] =  0;
     87    inImage32->data.F32[1][1] =  1;
     88    inImage32->data.F32[1][2] = -1;
     89    inImage32->data.F32[2][0] =  3;
     90    inImage32->data.F32[2][1] =  5;
     91    inImage32->data.F32[2][2] =  7;
    5892    printFooter(stdout, "psMatrix", "Create input and output images", true);
    5993
     
    6397    tempImage = outImage;
    6498    outImage = psMatrixInvert(outImage, inImage, &det);
    65     PRINT_MATRIX(outImage);
    66     printf("\ndet = %f\n", det);
     99    CHECK_MATRIX(outImage);
     100    CHECK_VALUE(det);
    67101    if(outImage->type.dimen != PS_DIMEN_IMAGE) {
    68102        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
    69     } else
    70         if(outImage != tempImage) {
    71             printf("Error: Return pointer not equal to output argument pointer\n");
    72         }
     103    } else if(outImage != tempImage) {
     104        printf("Error: Return pointer not equal to output argument pointer\n");
     105    }
     106    det = 0.0f;
     107    tempImage32 = outImage32;
     108    outImage32 = psMatrixInvert(outImage32, inImage32, &det);
     109    CHECK_MATRIX(outImage32);
     110    CHECK_VALUE(det);
     111    if(outImage32->type.dimen != PS_DIMEN_IMAGE) {
     112        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     113    } else if(outImage32 != tempImage32) {
     114        printf("Error: Return pointer not equal to output argument pointer\n");
     115    }
    73116    printFooter(stdout, "psMatrix", "Invert matrix and calculate determinant", true);
    74117
     
    77120    printPositiveTestHeader(stdout, "psMatrix", "Calculate determinant only");
    78121    det2 = psMatrixDeterminant(inImage);
    79     printf("det = %f\n", *det2);
     122    CHECK_VALUE(*det2);
     123    psFree(det2);
     124    det2 = psMatrixDeterminant(inImage32);
     125    CHECK_VALUE(*det2);
     126    psFree(det2);
    80127    printFooter(stdout, "psMatrix", "Calculate determinant only", true);
    81128
     
    85132    psFree(outImage);
    86133    psFree(inImage);
    87     psFree(det2);
     134    psFree(outImage32);
     135    psFree(inImage32);
    88136    if(psMemCheckLeaks(0, NULL, stdout, false) != 0 ) {
    89137        psError(PS_ERR_UNKNOWN,true,"Memory leaks detected.");
Note: See TracChangeset for help on using the changeset viewer.