IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6389


Ignore:
Timestamp:
Feb 8, 2006, 3:18:53 PM (20 years ago)
Author:
gusciora
Message:

Complete rewrite of psPlaneTransformInvert(). I now call the vectorFit
poly routines.

File:
1 edited

Legend:

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

    r6388 r6389  
    1010*  @author GLG, MHPCC
    1111*
    12 *  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-02-09 00:52:18 $
     12*  @version $Revision: 1.111 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-02-09 01:18:53 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    766766psPlaneTransformFit(trans, source, dest, nRejIter, sigmaClip)
    767767 
    768 XXX: This code ignores nRejIter and sigmaClip.
     768XXX: This code ignores nRejIter and sigmaClip.  We must call the ClipFit
     769routines instead.
    769770 *****************************************************************************/
    770771bool psPlaneTransformFit(
     
    824825    PS_ASSERT_PTR_NON_NULL(in->x, NULL);
    825826    PS_ASSERT_PTR_NON_NULL(in->y, NULL);
    826     if ((in->x->nX < 1) ||
    827             (in->x->nY < 1) ||
    828             (in->y->nX < 1) ||
    829             (in->y->nY < 1)) {
     827    PS_ASSERT_INT_LARGER_THAN(nSamples, 0, NULL);
     828
     829    // Reject a trivially non-invertible case.
     830    if ((in->x->nX < 1) || (in->x->nY < 1) || (in->y->nX < 1) || (in->y->nY < 1)) {
    830831        psLogMsg(__func__, PS_LOG_WARN, "WARNING: input transform is not invertible.");
    831832        return(NULL);
    832833    }
     834
     835    // Ensure that the input transformation is symmetrical.
     836    if ((in->x->nX != in->x->nY) || (in->y->nX != in->y->nY) || (in->x->nX != in->y->nX)) {
     837        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Input transformation must have same nX==nY.");
     838    }
     839
    833840    //
    834841    // If the transform is linear, then invert it exactly and return.
     
    839846    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(nSamples, 1, NULL);
    840847
    841     // Ensure that the input transformation is symmetrical.
    842     if ((in->x->nX != in->x->nY) ||
    843             (in->y->nX != in->y->nY) ||
    844             (in->x->nX != in->y->nX)) {
    845         psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Input transformation must have same nX==nY.");
    846     }
    847     // XXX: recode or verify after poly changes
    848     psS32 order = 1 + in->x->nX;
    849 
     848    //
     849    // Allocate a new psPlaneTransform if "out" is NULL, or has the wrong size.
     850    //
     851    psS32 order = in->x->nX;
    850852    psPlaneTransform *myPT = NULL;
    851     psPlane *inCoord = psPlaneAlloc();
    852     psPlane *outCoord = psPlaneAlloc();
    853 
    854     //
    855     // Allocate a new psPlaneTransform if "out" is NULL, or has the wrong size.
    856     //
    857853    if (out == NULL) {
    858         // XXX: Verify this (poly order/nterm change)
    859854        myPT = psPlaneTransformAlloc(order, order);
    860855    } else {
    861         // XXX: recode or verify after poly changes
    862         if (((1 + out->x->nX) == order) && ((1 + out->x->nY) == order) &&
    863                 ((1 + out->y->nX) == order) && ((1 + out->y->nX) == order)) {
     856        if ((out->x->nX == order) && (out->x->nY == order) &&
     857                (out->y->nX == order) && (out->y->nX == order)) {
    864858            myPT = out;
    865859        } else {
     
    870864
    871865    //
    872     // Copy the input transform to myPT.
    873     //
    874     for (psS32 i = 0 ; i < (1 + in->x->nX) ; i++) {
    875         for (psS32 j = 0 ; j < (1 + in->x->nY) ; j++) {
    876             myPT->x->coeff[i][j] = in->x->coeff[i][j];
    877         }
    878     }
    879     for (psS32 i = 0 ; i < (1 + in->y->nX) ; i++) {
    880         for (psS32 j = 0 ; j < (1 + in->y->nY) ; j++) {
    881             myPT->y->coeff[i][j] = in->y->coeff[i][j];
    882         }
    883     }
    884 
    885     //
    886     // Create a grid of xin,yin --> xout,yout
    887     //
    888     psArray *inData = psArrayAlloc(nSamples * nSamples);
    889     psArray *outData = psArrayAlloc(nSamples * nSamples);
    890     for (psS32 i = 0 ; i < inData->n; i++) {
    891         inData->data[i] = (psPtr *) psPlaneAlloc();
    892         outData->data[i] = (psPtr *) psPlaneAlloc();
    893     }
    894 
    895     //
    896866    // Initialize the grid.  Since we want the inverse of the transformation, the
    897867    // inCoords are written to the outData vector, and the outCoords are written
    898868    // to the inData vector.
    899869    //
     870    psVector *xIn = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64);
     871    psVector *yIn = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64);
     872    psVector *xOut = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64);
     873    psVector *yOut = psVectorAlloc(nSamples*nSamples, PS_TYPE_F64);
     874    psPlane *inCoord = psPlaneAlloc();
     875    psPlane *outCoord = psPlaneAlloc();
    900876    psS32 cnt = 0;
    901877    for (int yint = 0; yint < nSamples; yint++) {
     
    904880            inCoord->x = region.x0 + ((psF32) xint) * ((region.x1 - region.x0) / ((psF32) nSamples));
    905881            (void)psPlaneTransformApply(outCoord, in, inCoord);
    906             ((psPlane *) outData->data[cnt])->x = inCoord->x;
    907             ((psPlane *) outData->data[cnt])->y = inCoord->y;
    908             ((psPlane *) inData->data[cnt])->x = outCoord->x;
    909             ((psPlane *) inData->data[cnt])->y = outCoord->y;
    910 
     882            xOut->data.F64[cnt] = inCoord->x;
     883            yOut->data.F64[cnt] = inCoord->y;
     884            xIn->data.F64[cnt] = outCoord->x;
     885            yIn->data.F64[cnt] = outCoord->y;
    911886            cnt++;
    912887        }
    913888    }
    914     // XXX: what values should be used here?
    915     bool rc = psPlaneTransformFit(myPT, inData, outData, 10, 100.0);
     889
     890    myPT->x = psVectorFitPolynomial2D(myPT->x, NULL, 0, xOut, NULL, xIn, yIn);
     891    myPT->y = psVectorFitPolynomial2D(myPT->y, NULL, 0, yOut, NULL, xIn, yIn);
    916892
    917893    psFree(inCoord);
    918894    psFree(outCoord);
    919     psFree(inData);
    920     psFree(outData);
    921 
    922     if (rc == true) {
    923         return(myPT);
    924     } else {
    925         psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not fit a transform to coordinates.");
     895    psFree(xIn);
     896    psFree(yIn);
     897    psFree(xOut);
     898    psFree(yOut);
     899
     900    if ((myPT->x == NULL) || (myPT->y == NULL)) {
     901        psError( PS_ERR_UNKNOWN, true, "psVectorFitPolynomial2D() returned NULL: could not fit a 2-D polynomial to the data.\n");
     902        psFree(out);
    926903        return(NULL);
    927904    }
    928 }
     905
     906    return(myPT);
     907}
     908
    929909
    930910psPlane *psPlaneTransformDeriv(
Note: See TracChangeset for help on using the changeset viewer.