IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3715


Ignore:
Timestamp:
Apr 18, 2005, 7:46:24 PM (21 years ago)
Author:
gusciora
Message:

Improved the psTransformFit() tests.

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astro/psCoord.c

    r3714 r3715  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-04-19 04:16:02 $
     12*  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-04-19 05:46:24 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9191XXX: Since thre is now a general psPlaneTransformInvert() function, we
    9292should rename this.
    93  
    94 X1, Y1 = (2, 3)
    95  
    96     X2 = 1 + 4 + 9   = 14
    97     Y2 = 4 + 10 + 18 = 32
    98  
    99 in inverse
    100  
    101 Y1 = (32 - ((5/2) * 14) - 4 + ((5)/2)) / (6 - ((15)/2));
    102 Y1 = (32 - 35 - 4 + (5/2)) / (6 - 15/2);
    103 Y1 = (-7 + (5/2)) / (12/2 - 15/2);
    104 Y1 = (-7 + (5/2)) / (-3/2);
    105 Y1 = (-14/2 + 5/2) / (-3/2);
    106 Y1 = (-9/2) / (-3/2);
    107 Y1 = (9/2) / (3/2);
    108 Y1 = 3
    109  
    110 X1 = (Y2 - ((F/C) * X2) - D + ((F*A)/C)) / (E - ((F*B)/C));
    111 X1 = (32 - ((6/3) * 14) - 4 + ((6)/3)) / (5 - ((12)/3));
    112 X1 = (32 - (2 * 14) - 4 + 2 / (5 - 4);
    113 X1 = (32 - 28 - 4 + 2) / 1;
    114 X1 = 2;
    115  
    11693 *****************************************************************************/
    11794psPlaneTransform *p_psPlaneTransformLinearInvert(psPlaneTransform *transform)
     
    128105    psF64 F = 0.0;
    129106
    130     // XXX: Test this for correctness.
    131107    A = transform->x->coeff[0][0];
    132108    if (transform->x->nX >= 2) {
     
    144120    }
    145121
    146     // XXX: Use the constructor here.
    147122    psPlaneTransform *out = psPlaneTransformAlloc(2, 2);
    148123
     
    877852                for (psS32 t2x = 0 ; t2x < trans2->nX ; t2x++) {
    878853                    for (psS32 t2y = 0 ; t2y < trans2->nY ; t2y++) {
    879                         /* VERIFY MACRO
     854                        /* Possible debug-only macro which checks these coords?
    880855                        if ((t1x+t2x) >= orderX)
    881                             printf("CRAP 1\n");
     856                            printf("BAD 1\n");
    882857                        if ((t1y+t2y) >= orderY)
    883                             printf("CRAP 2\n");
     858                            printf("BAD 2\n");
    884859                        */
    885860                        out->coeff[t1x+t2x][t1y+t2y]+= (trans1->coeff[t1x][t1y] * trans2->coeff[t2x][t2y]);
     
    10511026
    10521027    psS32 numCoords = PS_MIN(source->n, dest->n);
    1053     // This is not really necessary because of above conditionals.
    10541028    psS32 order = PS_MAX(trans->x->nX, trans->x->nY);
    10551029
  • trunk/psLib/src/astronomy/psCoord.c

    r3714 r3715  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-04-19 04:16:02 $
     12*  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-04-19 05:46:24 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    9191XXX: Since thre is now a general psPlaneTransformInvert() function, we
    9292should rename this.
    93  
    94 X1, Y1 = (2, 3)
    95  
    96     X2 = 1 + 4 + 9   = 14
    97     Y2 = 4 + 10 + 18 = 32
    98  
    99 in inverse
    100  
    101 Y1 = (32 - ((5/2) * 14) - 4 + ((5)/2)) / (6 - ((15)/2));
    102 Y1 = (32 - 35 - 4 + (5/2)) / (6 - 15/2);
    103 Y1 = (-7 + (5/2)) / (12/2 - 15/2);
    104 Y1 = (-7 + (5/2)) / (-3/2);
    105 Y1 = (-14/2 + 5/2) / (-3/2);
    106 Y1 = (-9/2) / (-3/2);
    107 Y1 = (9/2) / (3/2);
    108 Y1 = 3
    109  
    110 X1 = (Y2 - ((F/C) * X2) - D + ((F*A)/C)) / (E - ((F*B)/C));
    111 X1 = (32 - ((6/3) * 14) - 4 + ((6)/3)) / (5 - ((12)/3));
    112 X1 = (32 - (2 * 14) - 4 + 2 / (5 - 4);
    113 X1 = (32 - 28 - 4 + 2) / 1;
    114 X1 = 2;
    115  
    11693 *****************************************************************************/
    11794psPlaneTransform *p_psPlaneTransformLinearInvert(psPlaneTransform *transform)
     
    128105    psF64 F = 0.0;
    129106
    130     // XXX: Test this for correctness.
    131107    A = transform->x->coeff[0][0];
    132108    if (transform->x->nX >= 2) {
     
    144120    }
    145121
    146     // XXX: Use the constructor here.
    147122    psPlaneTransform *out = psPlaneTransformAlloc(2, 2);
    148123
     
    877852                for (psS32 t2x = 0 ; t2x < trans2->nX ; t2x++) {
    878853                    for (psS32 t2y = 0 ; t2y < trans2->nY ; t2y++) {
    879                         /* VERIFY MACRO
     854                        /* Possible debug-only macro which checks these coords?
    880855                        if ((t1x+t2x) >= orderX)
    881                             printf("CRAP 1\n");
     856                            printf("BAD 1\n");
    882857                        if ((t1y+t2y) >= orderY)
    883                             printf("CRAP 2\n");
     858                            printf("BAD 2\n");
    884859                        */
    885860                        out->coeff[t1x+t2x][t1y+t2y]+= (trans1->coeff[t1x][t1y] * trans2->coeff[t2x][t2y]);
     
    10511026
    10521027    psS32 numCoords = PS_MIN(source->n, dest->n);
    1053     // This is not really necessary because of above conditionals.
    10541028    psS32 order = PS_MAX(trans->x->nX, trans->x->nY);
    10551029
  • trunk/psLib/test/astronomy/tst_psAstrometry01.c

    r3714 r3715  
    55*  @author GLG, MHPCC
    66*
    7 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    8 *  @date $Date: 2005-04-19 04:16:02 $
     7*  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     8*  @date $Date: 2005-04-19 05:46:24 $
    99*
    1010* XXX: Must test
     
    4141                              {NULL}
    4242                          };
     43
     44#define PS_PERCENT_COMPARE(X, Y, PERCENT_FRACTION) \
     45(fabs((Y)-(X))/fabs(X) < (PERCENT_FRACTION))
     46
    4347#define RA  1.0
    4448#define DEC  2.0
     
    764768}
    765769
    766 #define NUM_DATA 100
    767 
     770
     771#define TST05_X_MIN 0.0
     772#define TST05_X_MAX 10.0
     773#define TST05_Y_MIN 0.0
     774#define TST05_Y_MAX 10.0
     775#define TST05_NUM_X 10.0
     776#define TST05_NUM_Y 10.0
     777#define TST05_X_POLY_ORDER 2
     778#define TST05_Y_POLY_ORDER 2
     779#define TST05_NUM_DATA (TST05_NUM_X * TST05_NUM_Y)
    768780/******************************************************************************
    769781XXX: This is only a rudimentary test of the psPlaneTransformFit() function.
     
    775787{
    776788    bool testStatus = true;
    777     psPlaneTransform *trans = psPlaneTransformAlloc(2, 2);
    778     psArray *src = psArrayAlloc(NUM_DATA);
    779     psArray *dst = psArrayAlloc(NUM_DATA);
     789    psPlaneTransform *trans = psPlaneTransformAlloc(TST05_X_POLY_ORDER, TST05_Y_POLY_ORDER);
     790    psPlaneTransform *transInit = psPlaneTransformAlloc(TST05_X_POLY_ORDER, TST05_Y_POLY_ORDER);
     791    psArray *src = psArrayAlloc((int) TST05_NUM_DATA);
     792    psArray *dst = psArrayAlloc((int) TST05_NUM_DATA);
    780793    bool rc;
    781794
    782     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
    783         src->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
    784         dst->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
    785         ((psVector *) src->data[i])->data.F32[0] = (psF32) i;
    786         ((psVector *) src->data[i])->data.F32[1] = (psF32) i;
    787         ((psVector *) dst->data[i])->data.F32[0] = (psF32) 2+i;
    788         ((psVector *) dst->data[i])->data.F32[1] = (psF32) 3+i;
    789     }
     795
     796    //
     797    // We set an arbitrary non-linear transformation.
     798    //
     799
     800    for (psS32 x = 0 ; x < TST05_X_POLY_ORDER ; x++) {
     801        for (psS32 y = 0 ; y < TST05_Y_POLY_ORDER ; y++) {
     802            transInit->x->coeff[x][y] = ((psF32) (random() % 1000000)) / 100000.0;
     803            transInit->y->coeff[x][y] = ((psF32) (random() % 1000000)) / 100000.0;
     804        }
     805    }
     806
     807    // okay, for now, it's linear.
     808    transInit->x->coeff[1][1] = 0.0;
     809    transInit->y->coeff[1][1] = 0.0;
     810
     811    /*
     812        //
     813        // We set an arbitrary linear transformation.
     814        //
     815        transInit->x->coeff[0][0] = 1.0;
     816        transInit->x->coeff[0][1] = 3.0;
     817        transInit->x->coeff[1][0] = 2.0;
     818        transInit->x->coeff[1][1] = 7.0;
     819        transInit->y->coeff[0][0] = 4.0;
     820        transInit->y->coeff[0][1] = 6.0;
     821        transInit->y->coeff[1][0] = 5.0;
     822        transInit->y->coeff[1][1] = 3.0;
     823    */
     824    //
     825    // We generate a grid of input data points in the x1,y1 plane, calculate the
     826    // corresponding valuesin the x2,y2 in the transformed plane, and set these to
     827    // the src and dst psVectors.
     828    //
     829    psPlane *inData = psPlaneAlloc();
     830    psPlane *outData = NULL;
     831    psS32 i = 0;
     832    for (inData->x = TST05_X_MIN ; inData->x < TST05_X_MAX ; inData->x+= (TST05_X_MAX-TST05_X_MIN)/TST05_NUM_X) {
     833        for (inData->y = TST05_Y_MIN ; inData->y < TST05_Y_MAX ; inData->y+= (TST05_Y_MAX-TST05_Y_MIN)/TST05_NUM_Y) {
     834            src->data[i] = (psPtr *) psPlaneAlloc();
     835            dst->data[i] = (psPtr *) psPlaneAlloc();
     836
     837            ((psPlane *) src->data[i])->x = inData->x;
     838            ((psPlane *) src->data[i])->y = inData->y;
     839
     840            outData = psPlaneTransformApply(NULL, transInit, inData);
     841
     842            ((psPlane *) dst->data[i])->x = outData->x;
     843            ((psPlane *) dst->data[i])->y = outData->y;
     844            psFree(outData);
     845
     846            i++;
     847        }
     848    }
     849    psFree(inData);
    790850
    791851    printf("----------------------------------------------------------------------------------\n");
     
    817877    rc = psPlaneTransformFit(trans, src, dst, 100, 100.0);
    818878    if (rc != true) {
    819         printf("TEST ERROR: psPlaneTransformFit() returned TRUE.\n");
     879        printf("TEST ERROR: psPlaneTransformFit() returned FALSE.\n");
    820880        testStatus = false;
    821881    }
    822882
     883    printf("The initial transformation was:\n");
     884    printTrans(transInit);
     885    printf("The derived transformation is:\n");
     886    printTrans(trans);
     887
     888    //
     889    // For the initial grid of input points, we transform them to output points with
     890    // the derived transformation, and verify that they are within 10%.
     891    //
     892
     893    for (psS32 i = 0 ; i < src->n ; i++) {
     894        psPlane *inData = (psPlane *) src->data[i];
     895        psPlane *outData = (psPlane *) dst->data[i];
     896        psPlane *outDataDeriv = psPlaneTransformApply(NULL, trans, inData);
     897
     898        if (!PS_PERCENT_COMPARE(outDataDeriv->x, outData->x, 0.10) ||
     899                !PS_PERCENT_COMPARE(outDataDeriv->y, outData->y, 0.10)) {
     900            printf("TEST ERROR: the derived output coords were (%f, %f) should have been (%f, %f).\n",
     901                   outDataDeriv->x, outDataDeriv->y, outData->x, outData->y);
     902            testStatus = false;
     903        }
     904        psFree(outDataDeriv);
     905    }
     906
     907    psFree(transInit);
    823908    psFree(trans);
    824909    psFree(src);
     
    886971        trans->x->coeff[0][1] = ((psF32) (random() % 1000000)) / 100000.0;
    887972        trans->x->coeff[1][0] = ((psF32) (random() % 1000000)) / 100000.0;
    888         trans->x->coeff[1][1] = 0.1;
     973        trans->x->coeff[1][1] = 0.0;
    889974        trans->y->coeff[0][0] = ((psF32) (random() % 1000000)) / 100000.0;
    890975        trans->y->coeff[0][1] = ((psF32) (random() % 1000000)) / 100000.0;
    891976        trans->y->coeff[1][0] = ((psF32) (random() % 1000000)) / 100000.0;
    892         trans->y->coeff[1][1] = 0.1;
     977        trans->y->coeff[1][1] = 0.0;
    893978
    894979        transOut = psPlaneTransformInvert(NULL, trans, myRegion, 10);
Note: See TracChangeset for help on using the changeset viewer.