IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 23, 2006, 12:25:31 PM (20 years ago)
Author:
gusciora
Message:

Misc code cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psPolynomial.c

    r6101 r6186  
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-01-21 02:43:31 $
     9*  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-01-23 22:25:31 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1414*  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
    1515*
    16 *  XXX: In the various polyAlloc(n) functions, n is really the order of the
    17 *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
    1816*/
    1917/*****************************************************************************/
     
    154152
    155153/*****************************************************************************
    156 createChebyshevPolys(n): this routine takes as input the required order n,
     154p_psCreateChebyshevPolys(n): this routine takes as input the required order n,
    157155and returns as output as a pointer to an array of n psPolynomial1D
    158156structures, corresponding to the first n Chebyshev polynomials.
     
    162160outer coefficients of the Chebyshev polynomials.
    163161 
    164 XXX: From the poly nOrder/nTerm changem the maxChebyPoly here is still nTerms,
    165 not nOrder.
    166162 *****************************************************************************/
    167 psPolynomial1D **createChebyshevPolys(psS32 numPolys)
     163psPolynomial1D **p_psCreateChebyshevPolys(psS32 numPolys)
    168164{
    169165    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL);
     
    202198}
    203199
    204 /*
    205 static psPolynomial1D **createChebyshevPolysOld(psS32 maxChebyPoly)
    206 {
    207     PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
    208  
    209     psPolynomial1D **chebPolys = NULL;
    210  
    211     chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
    212     for (psS32 i = 0; i < maxChebyPoly; i++) {
    213         chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
    214     }
    215  
    216     // Create the Chebyshev polynomials.
    217     // Polynomial i has i-th order.
    218     chebPolys[0]->coeff[0] = 1;
    219  
    220     // XXX: Bug 296
    221     if (maxChebyPoly > 1) {
    222         chebPolys[1]->coeff[1] = 1;
    223  
    224         for (psS32 i = 2; i < maxChebyPoly; i++) {
    225             for (psS32 j = 0; j < chebPolys[i - 1]->nX; j++) {
    226                 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
    227             }
    228             for (psS32 j = 0; j < chebPolys[i - 2]->nX; j++) {
    229                 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
    230             }
    231         }
    232     } else {
    233         // XXX: Code this.
    234         printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    235     }
    236  
    237     return (chebPolys);
    238 }
    239 */
    240200
    241201/*****************************************************************************
    242202    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
    243203 *****************************************************************************/
    244 static psF64 ordPolynomial1DEval(psF64 x,
    245                                  const psPolynomial1D* poly)
     204static psF64 ordPolynomial1DEval(
     205    psF64 x,
     206    const psPolynomial1D* poly)
    246207{
    247208    unsigned int loop_x = 0;
     
    249210    psF64 xSum = 1.0;
    250211
    251     psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    252             "---- Calling ordPolynomial1DEval(%lf)\n", x);
    253     psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    254             "Polynomial order is %u\n", poly->nX);
     212    psTrace(__func__, 4, "---- %s() begin ----\n", __func__);
     213    psTrace(__func__, 4, "Polynomial order is %u\n", poly->nX);
    255214    for (loop_x = 0; loop_x < poly->nX+1; loop_x++) {
    256         psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    257                 "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]);
     215        psTrace(__func__, 4, "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]);
    258216    }
    259217
     
    262220            // XXX: If you set the tracelevel to 10 here, and later set the tracelevel to
    263221            // 2 or higher in the test code, you get seg faults.
    264             psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 8,
     222            psTrace(__func__, 8,
    265223                    "polysum+= sum*coeff [%lf+= (%lf * %lf)\n", polySum, xSum, poly->coeff[loop_x]);
    266224            polySum += xSum * poly->coeff[loop_x];
     
    269227    }
    270228
     229    psTrace(__func__, 4, "---- %s() end ----\n", __func__);
    271230    return(polySum);
    272231}
     
    284243    psVector *d;
    285244
    286     // XXX: n should be nTerms here (for clarity).  Or get rid of the variable.
    287245    unsigned int nTerms = 1 + poly->nX;
    288246    unsigned int i;
     
    338296    } else {
    339297        // This is old code that does not use Clenshaw's formula.  Get rid of it.
    340         psPolynomial1D **chebPolys = createChebyshevPolys(1 + poly->nX);
     298        psPolynomial1D **chebPolys = p_psCreateChebyshevPolys(1 + poly->nX);
    341299
    342300        tmp = 0.0;
     
    402360        maxChebyPoly = poly->nY;
    403361    }
    404     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     362    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    405363
    406364    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    476434        maxChebyPoly = poly->nZ;
    477435    }
    478     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     436    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    479437
    480438    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    567525        maxChebyPoly = poly->nT;
    568526    }
    569     // XXX: Add 1 since createChebyshevPolys() takes nTerms, not nOrder.
    570     chebPolys = createChebyshevPolys(maxChebyPoly + 1);
     527    // Add 1 since p_psCreateChebyshevPolys() takes nTerms, not nOrder.
     528    chebPolys = p_psCreateChebyshevPolys(maxChebyPoly + 1);
    571529
    572530    for (loop_x = 0; loop_x < (1 + poly->nX); loop_x++) {
     
    648606/*****************************************************************************
    649607    This routine must allocate memory for the polynomial structures.
    650     XXX: replaces nterms variables with nOrder.  Lots of potential for bugs
    651          here.  Probably should create separately named private variables
    652          in these functions.
    653608 *****************************************************************************/
    654 psPolynomial1D* psPolynomial1DAlloc(unsigned int n,
    655                                     psPolynomialType type)
     609psPolynomial1D* psPolynomial1DAlloc(
     610    unsigned int n,
     611    psPolynomialType type)
    656612{
    657613    PS_ASSERT_INT_NONNEGATIVE(n, NULL);
    658 
    659     unsigned int i = 0;
    660     psPolynomial1D* newPoly = NULL;
    661 
    662     newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
     614    psU32 nOrder = n;
     615    psPolynomial1D *newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
    663616    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
    664617
    665618    newPoly->type = type;
    666     newPoly->nX = n;
     619    newPoly->nX = nOrder;
    667620    newPoly->p_min = NAN;
    668621    newPoly->p_max = NAN;
    669     newPoly->coeff = psAlloc((n + 1) * sizeof(psF64));
    670     newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64));
    671     newPoly->mask = (psMaskType *)psAlloc((n + 1) * sizeof(psMaskType));
    672     for (i = 0; i < (n + 1); i++) {
     622    newPoly->coeff = psAlloc((nOrder + 1) * sizeof(psF64));
     623    newPoly->coeffErr = psAlloc((nOrder + 1) * sizeof(psF64));
     624    newPoly->mask = (psMaskType *)psAlloc((nOrder + 1) * sizeof(psMaskType));
     625    for (psU32 i = 0; i < (nOrder + 1); i++) {
    673626        newPoly->coeff[i] = 0.0;
    674627        newPoly->coeffErr[i] = 0.0;
     
    967920// XXX: The output of this routine is always psF64 while 1D and 2D are
    968921// dependent on the input vectors.
    969 psVector *psPolynomial3DEvalVector(const psPolynomial3D *poly,
    970                                    const psVector *x,
    971                                    const psVector *y,
    972                                    const psVector *z)
    973 
     922psVector *psPolynomial3DEvalVector(
     923    const psPolynomial3D *poly,
     924    const psVector *x,
     925    const psVector *y,
     926    const psVector *z)
    974927{
    975928    PS_ASSERT_POLY_NON_NULL(poly, NULL);
     
    1036989}
    1037990
    1038 psF64 psPolynomial4DEval(const psPolynomial4D* poly,
    1039                          psF64 x,
    1040                          psF64 y,
    1041                          psF64 z,
    1042                          psF64 t)
     991psF64 psPolynomial4DEval(
     992    const psPolynomial4D* poly,
     993    psF64 x,
     994    psF64 y,
     995    psF64 z,
     996    psF64 t)
    1043997{
    1044998    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    10561010}
    10571011
    1058 psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly,
    1059                                    const psVector *x,
    1060                                    const psVector *y,
    1061                                    const psVector *z,
    1062                                    const psVector *t)
     1012psVector *psPolynomial4DEvalVector(
     1013    const psPolynomial4D *poly,
     1014    const psVector *x,
     1015    const psVector *y,
     1016    const psVector *z,
     1017    const psVector *t)
    10631018{
    10641019    PS_ASSERT_POLY_NON_NULL(poly, NULL);
Note: See TracChangeset for help on using the changeset viewer.