IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 19, 2005, 9:53:13 AM (21 years ago)
Author:
drobbin
Message:

Made changes to poly struct (psMaskType) and spline fxns (unsigned int's)

File:
1 edited

Legend:

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

    r4991 r5066  
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.120 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2005-09-11 22:18:40 $
     9*  @version $Revision: 1.121 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2005-09-19 19:53:13 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    162162outer coefficients of the Chebyshev polynomials.
    163163 *****************************************************************************/
    164 static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
     164static psPolynomial1D **createChebyshevPolys(unsigned int maxChebyPoly)
    165165{
    166166    PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
     
    169169
    170170    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
    171     for (psS32 i = 0; i < maxChebyPoly; i++) {
     171    for (unsigned int i = 0; i < maxChebyPoly; i++) {
    172172        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
    173173    }
     
    191191    } else {
    192192        // XXX: Code this.
    193         printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
     193        printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
    194194    }
    195195
     
    200200    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
    201201 *****************************************************************************/
    202 static psF64 ordPolynomial1DEval(psF64 x, const psPolynomial1D* poly)
    203 {
    204     psS32 loop_x = 0;
     202static psF64 ordPolynomial1DEval(psF64 x,
     203                                 const psPolynomial1D* poly)
     204{
     205    unsigned int loop_x = 0;
    205206    psF64 polySum = 0.0;
    206207    psF64 xSum = 1.0;
     
    209210            "---- Calling ordPolynomial1DEval(%lf)\n", x);
    210211    psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    211             "Polynomial order is %d\n", poly->n);
     212            "Polynomial order is %u\n", poly->n);
    212213    for (loop_x = 0; loop_x < poly->n; loop_x++) {
    213214        psTrace(".psLib.dataManip.psPolynomial.ordPolynomial1DEval", 4,
    214                 "Polynomial coeff[%d] is %lf\n", loop_x, poly->coeff[loop_x]);
     215                "Polynomial coeff[%u] is %lf\n", loop_x, poly->coeff[loop_x]);
    215216    }
    216217
     
    230231// XXX: How does the mask vector effect Crenshaw's formula?
    231232// XXX: We assume that x is scaled between -1.0 and 1.0;
    232 static psF64 chebPolynomial1DEval(psF64 x, const psPolynomial1D* poly)
     233static psF64 chebPolynomial1DEval(psF64 x,
     234                                  const psPolynomial1D* poly)
    233235{
    234236    PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
    235237    // XXX: Create a macro for this in psConstants.h
    236238    if (poly->n < 1) {
    237         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", poly->n);
     239        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %u.", poly->n);
    238240        return(NAN);
    239241    }
    240242    psVector *d;
    241     psS32 n = poly->n;
    242     psS32 i;
     243    unsigned int n = poly->n;
     244    unsigned int i;
    243245    psF64 tmp = 0.0;
    244246
     
    318320    PS_ASSERT_POLY_NON_NULL(poly, NAN);
    319321
    320     psS32 loop_x = 0;
    321     psS32 loop_y = 0;
     322    unsigned int loop_x = 0;
     323    unsigned int loop_y = 0;
    322324    psF64 polySum = 0.0;
    323325    psF64 xSum = 1.0;
     
    338340}
    339341
    340 static psF64 chebPolynomial2DEval(psF64 x, psF64 y, const psPolynomial2D* poly)
     342static psF64 chebPolynomial2DEval(psF64 x,
     343                                  psF64 y,
     344                                  const psPolynomial2D* poly)
    341345{
    342346    PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
     
    344348    PS_ASSERT_POLY_NON_NULL(poly, NAN);
    345349
    346     psS32 loop_x = 0;
    347     psS32 loop_y = 0;
    348     psS32 i = 0;
     350    unsigned int loop_x = 0;
     351    unsigned int loop_y = 0;
     352    unsigned int i = 0;
    349353    psF64 polySum = 0.0;
    350354    psPolynomial1D* *chebPolys = NULL;
    351     psS32 maxChebyPoly = 0;
     355    unsigned int maxChebyPoly = 0;
    352356
    353357    // Determine how many Chebyshev polynomials
     
    375379}
    376380
    377 static psF64 ordPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly)
    378 {
    379     psS32 loop_x = 0;
    380     psS32 loop_y = 0;
    381     psS32 loop_z = 0;
     381static psF64 ordPolynomial3DEval(psF64 x,
     382                                 psF64 y,
     383                                 psF64 z,
     384                                 const psPolynomial3D* poly)
     385{
     386    unsigned int loop_x = 0;
     387    unsigned int loop_y = 0;
     388    unsigned int loop_z = 0;
    382389    psF64 polySum = 0.0;
    383390    psF64 xSum = 1.0;
     
    403410}
    404411
    405 static psF64 chebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly)
     412static psF64 chebPolynomial3DEval(psF64 x,
     413                                  psF64 y,
     414                                  psF64 z,
     415                                  const psPolynomial3D* poly)
    406416{
    407417    PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
    408418    PS_ASSERT_DOUBLE_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
    409419    PS_ASSERT_DOUBLE_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
    410     psS32 loop_x = 0;
    411     psS32 loop_y = 0;
    412     psS32 loop_z = 0;
    413     psS32 i = 0;
     420    unsigned int loop_x = 0;
     421    unsigned int loop_y = 0;
     422    unsigned int loop_z = 0;
     423    unsigned int i = 0;
    414424    psF64 polySum = 0.0;
    415425    psPolynomial1D* *chebPolys = NULL;
    416     psS32 maxChebyPoly = 0;
     426    unsigned int maxChebyPoly = 0;
    417427
    418428    // Determine how many Chebyshev polynomials
     
    447457}
    448458
    449 static psF64 ordPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly)
    450 {
    451     psS32 loop_x = 0;
    452     psS32 loop_y = 0;
    453     psS32 loop_z = 0;
    454     psS32 loop_t = 0;
     459static psF64 ordPolynomial4DEval(psF64 x,
     460                                 psF64 y,
     461                                 psF64 z,
     462                                 psF64 t,
     463                                 const psPolynomial4D* poly)
     464{
     465    unsigned int loop_x = 0;
     466    unsigned int loop_y = 0;
     467    unsigned int loop_z = 0;
     468    unsigned int loop_t = 0;
    455469    psF64 polySum = 0.0;
    456470    psF64 xSum = 1.0;
     
    481495}
    482496
    483 static psF64 chebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly)
     497static psF64 chebPolynomial4DEval(psF64 x,
     498                                  psF64 y,
     499                                  psF64 z,
     500                                  psF64 t,
     501                                  const psPolynomial4D* poly)
    484502{
    485503    PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
     
    487505    PS_ASSERT_DOUBLE_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
    488506    PS_ASSERT_DOUBLE_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
    489     psS32 loop_x = 0;
    490     psS32 loop_y = 0;
    491     psS32 loop_z = 0;
    492     psS32 loop_t = 0;
    493     psS32 i = 0;
     507    unsigned int loop_x = 0;
     508    unsigned int loop_y = 0;
     509    unsigned int loop_z = 0;
     510    unsigned int loop_t = 0;
     511    unsigned int i = 0;
    494512    psF64 polySum = 0.0;
    495513    psPolynomial1D* *chebPolys = NULL;
    496     psS32 maxChebyPoly = 0;
     514    unsigned int maxChebyPoly = 0;
    497515
    498516    // Determine how many Chebyshev polynomials
     
    542560    evaluated Gaussian is: \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
    543561 *****************************************************************************/
    544 float psGaussian(float x, float mean, float sigma, bool normal)
     562float psGaussian(float x,
     563                 float mean,
     564                 float sigma,
     565                 bool normal)
    545566{
    546567    psF32 tmp = 1.0;
     
    568589 *****************************************************************************/
    569590#define PS_XXX_GAUSSIAN_SEED 1995
    570 psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts)
     591psVector* p_psGaussianDev(psF32 mean,
     592                          psF32 sigma,
     593                          unsigned int Npts)
    571594{
    572595    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
     
    575598    psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, PS_XXX_GAUSSIAN_SEED);
    576599    psVector* gauss = psVectorAlloc(Npts, PS_TYPE_F32);
    577     for (psS32 i = 0; i < Npts; i++) {
     600    for (unsigned int i = 0; i < Npts; i++) {
    578601        gauss->data.F32[i] = mean + p_psRandomGaussian(r, sigma);
    579602    }
     
    586609    This routine must allocate memory for the polynomial structures.
    587610 *****************************************************************************/
    588 psPolynomial1D* psPolynomial1DAlloc(int n,
     611psPolynomial1D* psPolynomial1DAlloc(unsigned int n,
    589612                                    psPolynomialType type)
    590613{
    591614    PS_ASSERT_INT_POSITIVE(n, NULL);
    592615
    593     int i = 0;
     616    unsigned int i = 0;
    594617    psPolynomial1D* newPoly = NULL;
    595618
     
    601624    newPoly->coeff = psAlloc(n * sizeof(psF64));
    602625    newPoly->coeffErr = psAlloc(n * sizeof(psF64));
    603     newPoly->mask = (char *)psAlloc(n * sizeof(char));
     626    newPoly->mask = (psMaskType *)psAlloc(n * sizeof(psMaskType));
    604627    for (i = 0; i < n; i++) {
    605628        newPoly->coeff[i] = 0.0;
     
    611634}
    612635
    613 psPolynomial2D* psPolynomial2DAlloc( int nX,  int nY,
     636psPolynomial2D* psPolynomial2DAlloc( unsigned int nX,
     637                                     unsigned int nY,
    614638                                     psPolynomialType type)
    615639{
     
    617641    PS_ASSERT_INT_POSITIVE(nY, NULL);
    618642
    619     int x = 0;
    620     int y = 0;
     643    unsigned int x = 0;
     644    unsigned int y = 0;
    621645    psPolynomial2D* newPoly = NULL;
    622646
     
    630654    newPoly->coeff = psAlloc(nX * sizeof(psF64 *));
    631655    newPoly->coeffErr = psAlloc(nX * sizeof(psF64 *));
    632     newPoly->mask = (char **)psAlloc(nX * sizeof(char *));
     656    newPoly->mask = (psMaskType **)psAlloc(nX * sizeof(psMaskType *));
    633657    for (x = 0; x < nX; x++) {
    634658        newPoly->coeff[x] = psAlloc(nY * sizeof(psF64));
    635659        newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64));
    636         newPoly->mask[x] = (char *)psAlloc(nY * sizeof(char));
     660        newPoly->mask[x] = (psMaskType *)psAlloc(nY * sizeof(psMaskType));
    637661    }
    638662    for (x = 0; x < nX; x++) {
     
    647671}
    648672
    649 psPolynomial3D* psPolynomial3DAlloc( int nX,  int nY,  int nZ,
     673psPolynomial3D* psPolynomial3DAlloc( unsigned int nX,
     674                                     unsigned int nY,
     675                                     unsigned int nZ,
    650676                                     psPolynomialType type)
    651677{
     
    654680    PS_ASSERT_INT_POSITIVE(nZ, NULL);
    655681
    656     psS32 x = 0;
    657     psS32 y = 0;
    658     psS32 z = 0;
     682    unsigned int x = 0;
     683    unsigned int y = 0;
     684    unsigned int z = 0;
    659685    psPolynomial3D* newPoly = NULL;
    660686
     
    669695    newPoly->coeff = psAlloc(nX * sizeof(psF64 **));
    670696    newPoly->coeffErr = psAlloc(nX * sizeof(psF64 **));
    671     newPoly->mask = (char ***)psAlloc(nX * sizeof(char **));
     697    newPoly->mask = (psMaskType ***)psAlloc(nX * sizeof(psMaskType **));
    672698    for (x = 0; x < nX; x++) {
    673699        newPoly->coeff[x] = psAlloc(nY * sizeof(psF64 *));
    674700        newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64 *));
    675         newPoly->mask[x] = (char **)psAlloc(nY * sizeof(char *));
     701        newPoly->mask[x] = (psMaskType **)psAlloc(nY * sizeof(psMaskType *));
    676702        for (y = 0; y < nY; y++) {
    677703            newPoly->coeff[x][y] = psAlloc(nZ * sizeof(psF64));
    678704            newPoly->coeffErr[x][y] = psAlloc(nZ * sizeof(psF64));
    679             newPoly->mask[x][y] = (char *)psAlloc(nZ * sizeof(char));
     705            newPoly->mask[x][y] = (psMaskType *)psAlloc(nZ * sizeof(psMaskType));
    680706        }
    681707    }
     
    693719}
    694720
    695 psPolynomial4D* psPolynomial4DAlloc( int nX,  int nY,  int nZ,  int nT,
     721psPolynomial4D* psPolynomial4DAlloc( unsigned int nX,
     722                                     unsigned int nY,
     723                                     unsigned int nZ,
     724                                     unsigned int nT,
    696725                                     psPolynomialType type)
    697726{
     
    701730    PS_ASSERT_INT_POSITIVE(nT, NULL);
    702731
    703     psS32 x = 0;
    704     psS32 y = 0;
    705     psS32 z = 0;
    706     psS32 t = 0;
     732    unsigned int x = 0;
     733    unsigned int y = 0;
     734    unsigned int z = 0;
     735    unsigned int t = 0;
    707736    psPolynomial4D* newPoly = NULL;
    708737
     
    718747    newPoly->coeff = psAlloc(nX * sizeof(psF64 ***));
    719748    newPoly->coeffErr = psAlloc(nX * sizeof(psF64 ***));
    720     newPoly->mask = (char ****)psAlloc(nX * sizeof(char ***));
     749    newPoly->mask = (psMaskType ****)psAlloc(nX * sizeof(psMaskType ***));
    721750    for (x = 0; x < nX; x++) {
    722751        newPoly->coeff[x] = psAlloc(nY * sizeof(psF64 **));
    723752        newPoly->coeffErr[x] = psAlloc(nY * sizeof(psF64 **));
    724         newPoly->mask[x] = (char ***)psAlloc(nY * sizeof(char **));
     753        newPoly->mask[x] = (psMaskType ***)psAlloc(nY * sizeof(psMaskType **));
    725754        for (y = 0; y < nY; y++) {
    726755            newPoly->coeff[x][y] = psAlloc(nZ * sizeof(psF64 *));
    727756            newPoly->coeffErr[x][y] = psAlloc(nZ * sizeof(psF64 *));
    728             newPoly->mask[x][y] = (char **)psAlloc(nZ * sizeof(char *));
     757            newPoly->mask[x][y] = (psMaskType **)psAlloc(nZ * sizeof(psMaskType *));
    729758            for (z = 0; z < nZ; z++) {
    730759                newPoly->coeff[x][y][z] = psAlloc(nT * sizeof(psF64));
    731760                newPoly->coeffErr[x][y][z] = psAlloc(nT * sizeof(psF64));
    732                 newPoly->mask[x][y][z] = (char *)psAlloc(nT * sizeof(char));
     761                newPoly->mask[x][y][z] = (psMaskType *)psAlloc(nT * sizeof(psMaskType));
    733762            }
    734763        }
     
    749778}
    750779
    751 psF64 psPolynomial1DEval(const psPolynomial1D* poly, psF64 x)
     780psF64 psPolynomial1DEval(const psPolynomial1D* poly,
     781                         psF64 x)
    752782{
    753783    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    775805
    776806    tmp = psVectorAlloc(x->n, PS_TYPE_F64);
    777     for (psS32 i=0;i<x->n;i++) {
     807    for (unsigned int i=0;i<x->n;i++) {
    778808        tmp->data.F64[i] = psPolynomial1DEval(poly, x->data.F64[i]);
    779809    }
     
    782812}
    783813
    784 psF64 psPolynomial2DEval(const psPolynomial2D* poly, psF64 x, psF64 y)
     814psF64 psPolynomial2DEval(const psPolynomial2D* poly,
     815                         psF64 x,
     816                         psF64 y)
    785817{
    786818    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    810842
    811843    psVector *tmp;
    812     psS32 vecLen=x->n;
     844    unsigned int vecLen=x->n;
    813845
    814846    // Determine the length of the output vector to by the minimum of the x,y vectors
     
    821853
    822854    // Evaluate the polynomial at the specified points
    823     for (psS32 i=0; i<vecLen; i++) {
     855    for (unsigned int i=0; i<vecLen; i++) {
    824856        tmp->data.F64[i] = psPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]);
    825857    }
     
    829861}
    830862
    831 psF64 psPolynomial3DEval(const psPolynomial3D* poly, psF64 x, psF64 y, psF64 z)
     863psF64 psPolynomial3DEval(const psPolynomial3D* poly,
     864                         psF64 x,
     865                         psF64 y,
     866                         psF64 z)
    832867{
    833868    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    860895
    861896    psVector *tmp;
    862     psS32 vecLen=x->n;
     897    unsigned int vecLen=x->n;
    863898
    864899    // Determine the length of output vector from min of the input vectors
     
    874909
    875910    // Evaluate polynomial
    876     for (psS32 i = 0; i < vecLen; i++) {
     911    for (unsigned int i = 0; i < vecLen; i++) {
    877912        tmp->data.F64[i] = psPolynomial3DEval(poly,
    878913                                              x->data.F64[i],
     
    885920}
    886921
    887 psF64 psPolynomial4DEval(const psPolynomial4D* poly, psF64 x, psF64 y, psF64 z, psF64 t)
     922psF64 psPolynomial4DEval(const psPolynomial4D* poly,
     923                         psF64 x,
     924                         psF64 y,
     925                         psF64 z,
     926                         psF64 t)
    888927{
    889928    PS_ASSERT_POLY_NON_NULL(poly, NAN);
     
    918957
    919958    psVector *tmp;
    920     psS32 vecLen=x->n;
     959    unsigned int vecLen=x->n;
    921960
    922961    // Determine output vector size from min of input vectors
     
    935974
    936975    // Evaluate polynomial
    937     for (psS32 i = 0; i < vecLen; i++) {
     976    for (unsigned int i = 0; i < vecLen; i++) {
    938977        tmp->data.F64[i] = psPolynomial4DEval(poly,
    939978                                              x->data.F64[i],
Note: See TracChangeset for help on using the changeset viewer.