IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 9, 2006, 4:19:56 AM (20 years ago)
Author:
magnier
Message:

adding psPolynomial2DRecycle, psPolynomial2DCopy, psPolynomial2D_dX, psPolynomial2D_dY

File:
1 edited

Legend:

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

    r9730 r10598  
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.152 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2006-10-24 22:52:56 $
     9*  @version $Revision: 1.153 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2006-12-09 14:19:56 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    636636
    637637    return(newPoly);
     638}
     639
     640// XXX add 1D, 3D, 4D versions
     641bool psPolynomial2DRecycle(psPolynomial2D *poly,
     642                           psPolynomialType type,
     643                           unsigned int nX,
     644                           unsigned int nY)
     645{
     646    PS_ASSERT_INT_NONNEGATIVE(nX, NULL);
     647    PS_ASSERT_INT_NONNEGATIVE(nY, NULL);
     648
     649    bool match = true;
     650    match &= (poly->type == type);
     651    match &= (poly->nX == type);
     652    match &= (poly->nY == type);
     653
     654    if (!match) {
     655        for (int i = 0; i < poly->nX + 1; i++) {
     656            psFree (poly->coeff[i]);
     657            psFree (poly->coeffErr[i]);
     658            psFree (poly->mask[i]);
     659        }
     660        psFree (poly->coeff);
     661        psFree (poly->coeffErr);
     662        psFree (poly->mask);
     663
     664        poly->type = type;
     665        poly->nX = nX;
     666        poly->nY = nY;
     667
     668        poly->coeff = psAlloc((1 + nX) * sizeof(psF64 *));
     669        poly->coeffErr = psAlloc((1 + nX) * sizeof(psF64 *));
     670        poly->mask = (psMaskType **)psAlloc((1 + nX) * sizeof(psMaskType *));
     671        for (int i = 0; i < (1 + nX); i++) {
     672            poly->coeff[i] = psAlloc((1 + nY) * sizeof(psF64));
     673            poly->coeffErr[i] = psAlloc((1 + nY) * sizeof(psF64));
     674            poly->mask[i] = (psMaskType *)psAlloc((1 + nY) * sizeof(psMaskType));
     675        }
     676    }
     677    for (int i = 0; i < (1 + nX); i++) {
     678        for (int j = 0; j < (1 + nY); j++) {
     679            poly->coeff[i][j] = 0.0;
     680            poly->coeffErr[i][j] = 0.0;
     681            poly->mask[i][j] = 0;
     682        }
     683    }
     684    return(true);
     685}
     686
     687// XXX add 1D, 3D, 4D versions
     688psPolynomial2D *psPolynomial2DCopy(psPolynomial2D *out,
     689                                   psPolynomial2D *poly)
     690{
     691    if (out == NULL) {
     692        psPolynomial2DAlloc (poly->type, poly->nX, poly->nY);
     693    } else {
     694        psPolynomial2DRecycle (out, poly->type, poly->nX, poly->nY);
     695    }
     696
     697    for (int i = 0; i < (1 + poly->nX); i++) {
     698        for (int j = 0; j < (1 + poly->nY); j++) {
     699            out->coeff[i][j] = poly->coeff[i][j] = 0.0;
     700            out->coeffErr[i][j] = poly->coeffErr[i][j] = 0.0;
     701            out->mask[i][j] = poly->mask[i][j] = 0;
     702        }
     703    }
     704    return(out);
    638705}
    639706
Note: See TracChangeset for help on using the changeset viewer.