IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3710


Ignore:
Timestamp:
Apr 18, 2005, 3:22:23 PM (21 years ago)
Author:
gusciora
Message:

The psTransformCombine() tests were significantly modified. They now
more fully test a wider range of input transforms and data.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/astronomy/tst_psAstrometry01.c

    r3707 r3710  
    11/** @file  tst_psAstrometry01.c
    22*
    3 *  @brief The code in this file will test the code in psAstrometry.[ch]
     3*  @brief This code will test the code in psAstrometry.[ch]
    44*
    55*  @author GLG, MHPCC
    66*
    7 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    8 *  @date $Date: 2005-04-18 23:55:29 $
     7*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     8*  @date $Date: 2005-04-19 01:22:23 $
    99*
    1010* XXX: Must test
     
    571571}
    572572
     573
    573574/******************************************************************************
    574 XXX: This is only a rudimentary test of the psPlaneTransformCombine()
    575 function.  It tests a few NULL input parameter conditions.  Then, it combines
    576 two very simply functions and prints the result to the screen.  No values are
    577 checked.
    578  
    579 // XXX: This function must verify the outputs of the combined functions.
    580  
    581 // XXX: Must do: Run thru several combinations of random parameters, then pipe
    582    random x/y values thru both trans1+trans2, as well as the combined function
    583    and verify the output.
     575TEST04: The strategy behind test04() is to generate a pair of transforms t1
     576and t2 with a wide variety of sizes for the x/y components of the x/y
     577transforms, then set the coefficients of t1/t2 to arbitray values, then
     578generate a new transform t3 via psPlaneTransformCombine() function.  Then, for
     579several arbitrary input plane coordinates, we tarnsform them via the new
     580transform t3, as well as individually via t1 then t2, and verify that they
     581produce identical output coordinates.
     582 *****************************************************************************/
     583// These macros determine the number of x/y test points which will be x-formed.
     584#define TST04_X_MIN 0.0
     585#define TST04_X_MAX 10.0
     586#define TST04_Y_MIN 0.0
     587#define TST04_Y_MAX 10.0
     588#define TST04_NUM 5.0
     589// These macros define the max sizes of the various input transforms.
     590#define TST04_T1_X_X 6
     591#define TST04_T1_X_Y 3
     592#define TST04_T1_Y_X 3
     593#define TST04_T1_Y_Y 3
     594#define TST04_T2_X_X 3
     595#define TST04_T2_X_Y 3
     596#define TST04_T2_Y_X 3
     597#define TST04_T2_Y_Y 3
     598/******************************************************************************
     599tstTransforms(t1, t2, t3): this function generates a set of arbitrary x/y
     600coordinates, then transforms them into output coordinates via the t3
     601transform, as well as the t1 followed by the t2 transform.  It verifies the
     602output coordinates are identical and returns TRUE if so.  Otherwise, it prints
     603an error message and returns FALSE.
     604 *****************************************************************************/
     605bool tstTransforms(psPlaneTransform *t1, psPlaneTransform *t2, psPlaneTransform *t3)
     606{
     607    bool testStatus = true;
     608    psPlane *in = psPlaneAlloc();
     609    in->xErr = 0.0;
     610    in->yErr = 0.0;
     611
     612    for (in->x = TST04_X_MIN ;
     613            in->x <= TST04_X_MAX ;
     614            in->x+= (TST04_X_MAX-TST04_X_MIN) / TST04_NUM) {
     615        for (in->y = TST04_Y_MIN ; in->y <= TST04_Y_MAX ; in->y+= (TST04_Y_MAX-TST04_Y_MIN) / TST04_NUM) {
     616            // Apply the t1/t2 transforms individually to the in coords.
     617            psPlane *mid = psPlaneTransformApply(NULL, t1, in);
     618            if (mid == NULL) {
     619                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
     620                psFree(in);
     621                return(false);
     622            }
     623
     624            psPlane *outT1T2 = psPlaneTransformApply(NULL, t2, mid);
     625            if (outT1T2 == NULL) {
     626                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
     627                psFree(mid);
     628                return(false);
     629            }
     630
     631            // Apply the t3 transforms individually to the in coords.
     632            psPlane *outT3 = psPlaneTransformApply(NULL, t3, in);
     633            if (outT3 == NULL) {
     634                printf("TEST ERROR: intermediate psPlane coords are NULL.\n");
     635                psFree(mid);
     636                psFree(outT1T2);
     637                return(false);
     638            }
     639
     640            // Verify that the results are identical.
     641            if (fabs(outT3->x - outT1T2->x) > FLT_EPSILON) {
     642                printf("TEST ERROR: x is %f, should be %f\n", outT3->x, outT1T2->x);
     643                testStatus = false;
     644            }
     645            if (fabs(outT3->y - outT1T2->y) > FLT_EPSILON) {
     646                printf("TEST ERROR: y is %f, should be %f\n", outT3->y, outT1T2->y);
     647                testStatus = false;
     648            }
     649            psFree(mid);
     650            psFree(outT1T2);
     651            psFree(outT3);
     652        }
     653    }
     654
     655    psFree(in);
     656    return(testStatus);
     657}
     658
     659/******************************************************************************
     660setCoeffs(t1, t2): this function sets the coefficients of the t1 and t2
     661transforms to somewhat arbitrary values.
     662 *****************************************************************************/
     663int setCoeffs(psPlaneTransform *t1, psPlaneTransform *t2)
     664{
     665    for (psS32 t1xx = 0 ; t1xx < t1->x->nX ; t1xx++) {
     666        for (psS32 t1xy = 0 ; t1xy < t1->x->nY ; t1xy++) {
     667            t1->x->coeff[t1xx][t1xy] = (psF32) (t1xx + t1xy);
     668        }
     669    }
     670
     671    for (psS32 t1yx = 0 ; t1yx < t1->y->nX ; t1yx++) {
     672        for (psS32 t1yy = 0 ; t1yy < t1->y->nY ; t1yy++) {
     673            t1->y->coeff[t1yx][t1yy] = (psF32) (t1yx + t1yy - 10);
     674        }
     675    }
     676    for (psS32 t2xx = 0 ; t2xx < t2->x->nX ; t2xx++) {
     677        for (psS32 t2xy = 0 ; t2xy < t2->x->nY ; t2xy++) {
     678            t2->x->coeff[t2xx][t2xy] = (psF32) (2 + (t2xx * t2xy));
     679        }
     680    }
     681    for (psS32 t2yx = 0 ; t2yx < t2->y->nX ; t2yx++) {
     682        for (psS32 t2yy = 0 ; t2yy < t2->y->nY ; t2yy++) {
     683            t2->y->coeff[t2yx][t2yy] = (psF32) (3 - t2yx + t2yy);
     684        }
     685    }
     686
     687    return(0);
     688}
     689
     690/******************************************************************************
     691test04(): We test psPlaneTransformCombine() with a wariety of input
     692transforms, as well as input coordinates, as well as erroneous input
     693parameters.
    584694 *****************************************************************************/
    585695psS32 test4( void )
    586696{
    587697    bool testStatus = true;
     698
     699
     700    //
     701    // Create a variety of input input transforms, then test them.
     702    //
     703    for (psS32 t1xx = 1 ; t1xx < TST04_T1_X_X ; t1xx++) {
     704        for (psS32 t1xy = 1 ; t1xy < TST04_T1_X_Y ; t1xy++) {
     705            for (psS32 t1yx = 1 ; t1yx < TST04_T1_Y_X ; t1yx++) {
     706                for (psS32 t1yy = 1 ; t1yy < TST04_T1_Y_Y ; t1yy++) {
     707                    for (psS32 t2xx = 1 ; t2xx < TST04_T2_X_X ; t2xx++) {
     708                        for (psS32 t2xy = 1 ; t2xy < TST04_T2_X_Y ; t2xy++) {
     709                            for (psS32 t2yx = 1 ; t2yx < TST04_T2_Y_X ; t2yx++) {
     710                                for (psS32 t2yy = 1 ; t2yy < TST04_T2_Y_Y ; t2yy++) {
     711                                    psPlaneTransform *trans1 = psPlaneTransformAlloc(PS_MAX(t1xx, t1yx), PS_MAX(t1xy, t1yy));
     712                                    psPlaneTransform *trans2 = psPlaneTransformAlloc(PS_MAX(t2xx, t2yx), PS_MAX(t2xy, t2yy));
     713                                    psPlaneTransform *trans3 = NULL;
     714                                    setCoeffs(trans1, trans2);
     715                                    trans3 = psPlaneTransformCombine(NULL, trans1, trans2);
     716
     717                                    if (trans3 == NULL) {
     718                                        printf("TEST ERROR: psPlaneTransformCombine() returned NULL/\n");
     719                                        testStatus = false;
     720                                    } else {
     721                                        testStatus = tstTransforms(trans1, trans2, trans3);
     722                                    }
     723                                    psFree(trans1);
     724                                    psFree(trans2);
     725                                    psFree(trans3);
     726                                }
     727                            }
     728                        }
     729                    }
     730                }
     731            }
     732        }
     733    }
     734
     735
     736    //
     737    // Test erroneous input parameter combinations
     738    //
    588739    psPlaneTransform *trans1 = psPlaneTransformAlloc(2, 2);
    589740    psPlaneTransform *trans2 = psPlaneTransformAlloc(2, 2);
    590741    psPlaneTransform *trans3 = NULL;
    591 
    592     printf("trans1: x = x+y, y = x+y\n");
    593     trans1->x->coeff[0][0] = 0.0;
    594     trans1->x->coeff[0][1] = 1.0;
    595     trans1->x->coeff[1][0] = 1.0;
    596     trans1->x->coeff[1][1] = 0;
    597     trans1->y->coeff[0][0] = 0.0;
    598     trans1->y->coeff[0][1] = 1.0;
    599     trans1->y->coeff[1][0] = 1.0;
    600     trans1->y->coeff[1][1] = 0;
    601     printTrans(trans1);
    602 
    603     printf("trans2: x = x+y, y = x+y\n");
    604     trans2->x->coeff[0][0] = 0.0;
    605     trans2->x->coeff[0][1] = 1.0;
    606     trans2->x->coeff[1][0] = 1.0;
    607     trans2->x->coeff[1][1] = 0;
    608     trans2->y->coeff[0][0] = 0.0;
    609     trans2->y->coeff[0][1] = 1.0;
    610     trans2->y->coeff[1][0] = 1.0;
    611     trans2->y->coeff[1][1] = 0;
    612     printTrans(trans2);
    613 
    614     printf("trans2: x = xy, y = xy\n");
    615     trans2->x->coeff[0][0] = 0.0;
    616     trans2->x->coeff[0][1] = 0.0;
    617     trans2->x->coeff[1][0] = 0.0;
    618     trans2->x->coeff[1][1] = 1.0;
    619     trans2->y->coeff[0][0] = 0.0;
    620     trans2->y->coeff[0][1] = 0.0;
    621     trans2->y->coeff[1][0] = 0.0;
    622     trans2->y->coeff[1][1] = 1.0;
    623     printTrans(trans2);
    624742
    625743    printf("----------------------------------------------------------------------------------\n");
     
    641759    }
    642760
    643 
    644     printf("----------------------------------------------------------------------------------\n");
    645     printf("Calling psPlaneTransformCombine with acceptable data.\n");
    646     trans3 = psPlaneTransformCombine(NULL, trans1, trans2);
    647     if (trans3 == NULL) {
    648         printf("TEST ERROR: psPlaneTransformCombine() returned a NULL psPlaneTransform.\n");
    649         testStatus = false;
    650         psFree(trans3);
    651     }
    652     printf("trans3: \n");
    653     printTrans(trans3);
    654 
    655761    psFree(trans1);
    656762    psFree(trans2);
    657     psFree(trans3);
    658 
    659763    return(!testStatus);
    660764}
Note: See TracChangeset for help on using the changeset viewer.