IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2005, 9:41:56 AM (21 years ago)
Author:
gusciora
Message:

Plane transform invert, combine, and fit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/astronomy/psAstrometry.c

    r3497 r3540  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.60 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-03-24 22:36:16 $
     10 *  @version $Revision: 1.61 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-03-29 19:41:56 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    913913
    914914
    915 
    916 
    917 
    918 /*****************************************************************************
    919 psPlaneTransformInvertHEY(out, in, region, nSamples): this is an earlier
    920 version of this function which doesnot separate the code for building and
    921 solving the matrixequations.
    922  
    923 XXX: Delete this codeonce you know the other version works.
    924  *****************************************************************************/
    925 psPlaneTransform *psPlaneTransformInvertHEY(psPlaneTransform *out,
    926         const psPlaneTransform *in,
    927         psRegion *region,
    928         int nSamples)
    929 {
    930     PS_PTR_CHECK_NULL(in, NULL);
    931     if (isProjectionLinear((psPlaneTransform *) in)) {
    932         return(invertPlaneTransform((psPlaneTransform *) in));
    933     }
    934     psPlaneTransform *myPT = NULL;
    935     psPlane *inCoord = psPlaneAlloc();
    936     psPlane *outCoord = psPlaneAlloc();
    937 
    938     PS_PTR_CHECK_NULL(region, NULL);
    939     PS_INT_COMPARE(0, nSamples, NULL);
    940 
    941     // XXX: Is this correct?
    942     psS32 order = PS_MAX(in->x->nX, in->x->nY);
    943 
    944     //
    945     // Allocate a new psPlaneTransform if "out" is NULL, or has the wrong size.
    946     //
    947     if (out == NULL) {
    948         myPT = psPlaneTransformAlloc(order, order);
    949     } else {
    950         if (!((out->x->nX == order) &&
    951                 (out->x->nY == order) &&
    952                 (out->y->nX == order) &&
    953                 (out->y->nY == order))) {
    954             psFree(out);
    955             myPT = psPlaneTransformAlloc(order, order);
    956         } else {
    957             myPT = out;
    958         }
    959     }
    960     // XXX: Initialize myPT?
    961 
    962     //
    963     // Create fake polynomial to use in evaluation
    964     //
    965     psDPolynomial2D *fakePoly = psDPolynomial2DAlloc(order, order, PS_POLYNOMIAL_ORD);
    966     for (int i = 0; i < order; i++) {
    967         for (int j = 0; j < order; j++) {
    968             fakePoly->coeff[i][j] = 1.0; // Set all coeffecients to 1
    969             fakePoly->mask[i][j] = 1; // Mask all coefficients; unmask to evaluate
    970         }
    971     }
    972 
    973     //
    974     // Create a grid of xin,yin --> xout,yout
    975     //
    976     psVector *xIn = psVectorAlloc(nSamples * nSamples, PS_TYPE_F32);
    977     psVector *yIn = psVectorAlloc(nSamples * nSamples, PS_TYPE_F32);
    978     psVector *xOut = psVectorAlloc(nSamples * nSamples, PS_TYPE_F32);
    979     psVector *yOut = psVectorAlloc(nSamples * nSamples, PS_TYPE_F32);
    980 
    981     //
    982     // Initialize the grid of points
    983     //
    984     for (int yint = 0; yint < nSamples; yint++) {
    985         inCoord->y = region->y0 + ((psF32) yint) * ((region->y1 - region->y0) / ((psF32) nSamples));
    986         for (int xint = 0; xint < nSamples; xint++) {
    987             inCoord->x = region->x0 + ((psF32) xint) * ((region->x1 - region->x0) / ((psF32) nSamples));
    988 
    989             (void)psPlaneTransformApply(outCoord, in, inCoord);
    990             xOut->data.F32[yint*nSamples + xint] = inCoord->x;
    991             yOut->data.F32[yint*nSamples + xint] = inCoord->y;
    992             xIn->data.F32[yint*nSamples + xint] = outCoord->x;
    993             yIn->data.F32[yint*nSamples + xint] = outCoord->y;
    994         }
    995     }
    996 
    997     //
    998     // Initialise the matrix and vectors
    999     //
    1000     psS32 nCoeff = order * (order + 1) / 2; // Number of polynomial coefficients
    1001     psImage *matrix = psImageAlloc(nCoeff, nCoeff, PS_TYPE_F64); // Matrix for solution
    1002     psVector *xVector = psVectorAlloc(nCoeff, PS_TYPE_F64); // Vector for solution in x
    1003     psVector *yVector = psVectorAlloc(nCoeff, PS_TYPE_F64); // Vector for solution in y
    1004     for (psS32 i = 0; i < nCoeff; i++) {
    1005         for (psS32 j = 0; j < nCoeff; j++) {
    1006             matrix->data.F64[i][j] = 0.0;
    1007         }
    1008         xVector->data.F64[i] = 0.0;
    1009         yVector->data.F64[i] = 0.0;
    1010     }
    1011 
    1012     //
    1013     // Iterate over the grid points
    1014     //
    1015     for (psS32 g = 0; g < nSamples*nSamples; g++) {
    1016         // Iterate over the polynomial coefficients, accumulating the matrix and vectors
    1017 
    1018         for (psS32 i = 0, ijIndex = 0; i < order; i++) {
    1019             for (psS32 j = 0; j < order - i; j++, ijIndex++) {
    1020 
    1021                 fakePoly->mask[i][j] = 0;
    1022                 psF64 ijPoly = psDPolynomial2DEval(fakePoly, (psF64) xIn->data.F32[g], (psF64) yIn->data.F32[g]);
    1023                 fakePoly->mask[i][j] = 1;
    1024 
    1025                 for (psS32 m = 0, mnIndex = 0; m < order; m++) {
    1026                     for (psS32 n = 0; n < order - m; n++, mnIndex++) {
    1027                         fakePoly->mask[m][n] = 0;
    1028                         psF64 mnPoly = psDPolynomial2DEval(fakePoly, (psF64) xIn->data.F32[g], (psF64) yIn->data.F32[g]);
    1029                         fakePoly->mask[m][n] = 1;
    1030 
    1031                         matrix->data.F64[ijIndex][mnIndex] += ijPoly * mnPoly;
    1032                     }
    1033                 }
    1034 
    1035                 xVector->data.F64[ijIndex] += ijPoly * (psF64)xOut->data.F32[g];
    1036                 yVector->data.F64[ijIndex] += ijPoly * (psF64)yOut->data.F32[g];
    1037             }
    1038         }
    1039     }
    1040 
    1041     //
    1042     // Solution via LU Decomposition
    1043     //
    1044     psVector *permutation = psVectorAlloc(nCoeff, PS_TYPE_F64); // Permutation vector for LU Decomposition
    1045     psImage *luMatrix = psMatrixLUD(NULL, &permutation, matrix); // LU decomposed matrix
    1046     psVector *xSolution = psMatrixLUSolve(NULL, luMatrix, xVector, permutation); // Solution in x
    1047     psVector *ySolution = psMatrixLUSolve(NULL, luMatrix, yVector, permutation); // Solution in y
    1048 
    1049     //
    1050     // Stuff coefficients into transformation
    1051     //
    1052     for (psS32 i = 0, ijIndex = 0; i < order; i++) {
    1053         for (psS32 j = 0; j < order - i; j++, ijIndex++) {
    1054             myPT->x->coeff[i][j] = xSolution->data.F64[ijIndex];
    1055             myPT->y->coeff[i][j] = ySolution->data.F64[ijIndex];
    1056         }
    1057     }
    1058 
    1059     return(myPT);
    1060 }
    1061 
    1062 
    1063915/*****************************************************************************
    1064916multiplyCoeffs(trans1, trans2): Takes two 2-D polynomials as input and
     
    1100952
    1101953/*****************************************************************************
    1102 psPlaneTransformCombineTmp(out, trans1, trans2)
     954psPlaneTransformCombine(out, trans1, trans2)
    1103955 
    1104956XXX: Much room for optimization.  Currently, we call the polyMultiply
    1105957routine far too many times.
    1106958 *****************************************************************************/
    1107 psPlaneTransform *psPlaneTransformCombineTmp(psPlaneTransform *out,
     959psPlaneTransform *psPlaneTransformCombine(psPlaneTransform *out,
    1108960        const psPlaneTransform *trans1,
    1109961        const psPlaneTransform *trans2)
     
    12401092
    12411093/*****************************************************************************
    1242 psPlaneTranformFitTmp(trans, source, dest, nRejIter, sigmaClip)
     1094psPlaneTranformFit(trans, source, dest, nRejIter, sigmaClip)
    12431095 
    12441096XXX: What about nRejIter?  Iterations?
    12451097XXX: Use static vectors for internal data.
    12461098 *****************************************************************************/
    1247 bool psPlaneTranformFitTmp(psPlaneTransform *trans,
    1248                            const psArray *source,
    1249                            const psArray *dest,
    1250                            int nRejIter,
    1251                            float sigmaClip)
     1099bool psPlaneTranformFit(psPlaneTransform *trans,
     1100                        const psArray *source,
     1101                        const psArray *dest,
     1102                        int nRejIter,
     1103                        float sigmaClip)
    12521104{
    12531105    PS_PTR_CHECK_NULL(trans, NULL);
     
    13601212
    13611213/*****************************************************************************
    1362 psPlaneTransformInvertTmp(out, in, region, nSamples)
     1214psPlaneTransformInvert(out, in, region, nSamples)
    13631215 
    13641216// XXX: Use static data structures.
    13651217 *****************************************************************************/
    1366 psPlaneTransform *psPlaneTransformInvertTmp(psPlaneTransform *out,
     1218psPlaneTransform *psPlaneTransformInvert(psPlaneTransform *out,
    13671219        const psPlaneTransform *in,
    13681220        psRegion *region,
     
    14481300        }
    14491301    }
    1450     bool rc = psPlaneTranformFitTmp(myPT, inData, outData, 10, 100.0);
     1302    bool rc = psPlaneTranformFit(myPT, inData, outData, 10, 100.0);
    14511303
    14521304    psFree(inCoord);
Note: See TracChangeset for help on using the changeset viewer.