IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 15, 2005, 10:10:32 AM (21 years ago)
Author:
gusciora
Message:

Bug fix for psSpline, some new psConstant macros, ....

File:
1 edited

Legend:

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

    r5180 r5517  
    77*  splines.
    88*
    9 *  @version $Revision: 1.131 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2005-09-29 20:06:58 $
     9*  @version $Revision: 1.132 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2005-11-15 20:10:32 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    496496    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
    497497    PS_ASSERT_VECTOR_TYPE_F32_OR_F64(y, NULL);
     498    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(y->n, 2, NULL);
    498499    psS32 numSplines = (y->n)-1;
    499500    psTrace(__func__, 5, "numSplines is %d\n", numSplines);
     501
     502    //
     503    // Create the psSpline1D struct.
     504    //
     505    psSpline1D *spline = psSpline1DAlloc();
     506    spline->n = numSplines;
     507    spline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
     508    for (psS32 i=0;i<numSplines;i++) {
     509        spline->spline[i] = psPolynomial1DAlloc(3, PS_POLYNOMIAL_ORD);
     510    }
     511
    500512    //
    501513    // The following code ensures that xPtr and yPtr points to a psF32 psVector.
    502514    //
    503     psVector *xPtr = NULL;
     515    // XXX: When you debug, use the vector copy and create routines here:
     516    //
     517
     518    spline->knots = psVectorAlloc(y->n, PS_TYPE_F32);
    504519    if (x != NULL) {
    505520        PS_ASSERT_VECTOR_NON_NULL(x, NULL);
     521        PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL);
    506522        PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
    507         PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL);
    508         // Convert x to F32 if necessary.
    509         if (PS_TYPE_F64 == x->type.type) {
    510             xPtr = psVectorCopy(NULL, x, PS_TYPE_F32);
    511         } else if (PS_TYPE_F32 == x->type.type) {
    512             xPtr = (psVector *) x;
     523        if (x->type.type == PS_TYPE_F32) {
     524            for (psS32 i = 0 ; i < x->n ; i++) {
     525                spline->knots->data.F32[i] = x->data.F32[i];
     526            }
     527        } else if (x->type.type == PS_TYPE_F64) {
     528            for (psS32 i = 0 ; i < x->n ; i++) {
     529                spline->knots->data.F32[i] = (psF32) x->data.F64[i];
     530            }
    513531        }
    514532    } else {
    515         // Allocate an index vector for x
    516         xPtr = psVectorCreate(NULL, 0.0, (psF64) y->n, 1.0, PS_TYPE_F32);
    517     }
     533        for (psS32 i = 0 ; i < y->n ; i++) {
     534            spline->knots->data.F32[i] = (psF32) i;
     535        }
     536    }
     537    psVector *xPtr = spline->knots;
    518538
    519539    psVector *yPtr = NULL;
     
    526546
    527547    //
    528     // Create the psSpline1D struct.
    529     //
    530     psSpline1D *spline = psSpline1DAlloc();
    531     spline->n = numSplines;
    532     spline->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
    533     for (psS32 i=0;i<numSplines;i++) {
    534         spline->spline[i] = psPolynomial1DAlloc(3, PS_POLYNOMIAL_ORD);
    535     }
    536     spline->knots = psVectorCopy(NULL, xPtr, PS_TYPE_F32);
    537     //
    538548    // Generate the second derivatives at each data point.
    539549    //
     
    548558        psF32 H = xPtr->data.F32[i+1] - xPtr->data.F32[i];
    549559        if (fabs(H) <= FLT_EPSILON) {
    550             psError(PS_ERR_UNKNOWN, false, "x data points are not distinct (%d %d).\n", i, i+1);
     560            psError(PS_ERR_UNKNOWN, false, "x data points are not distinct (%d %d) (%f %f).\n",
     561                    i, i+1, xPtr->data.F32[i], xPtr->data.F32[i+1]);
    551562        }
    552563        psTrace(__func__, 6, "x data (%f - %f) (%f)\n", xPtr->data.F32[i], xPtr->data.F32[i+1], H);
     
    609620    }
    610621
    611     if ((x == NULL) || (PS_TYPE_F64 == x->type.type)) {
    612         psFree(xPtr);
    613     }
    614622    if (PS_TYPE_F64 == y->type.type) {
    615623        psFree(yPtr);
     
    618626    return(spline);
    619627}
     628
     629void PS_POLY1D_PRINT(
     630    psPolynomial1D *poly)
     631{
     632    printf("-------------- PS_POLY1D_PRINT() --------------\n");
     633    printf("poly->nX is %d\n", poly->nX);
     634    for (psS32 i = 0 ; i < (1 + poly->nX) ; i++) {
     635        printf("poly->coeff[%d] is %f\n", i, poly->coeff[i]);
     636    }
     637}
     638
     639void PS_PRINT_SPLINE2(psSpline1D *mySpline)
     640{
     641    printf("-------------- PS_PRINT_SPLINE2() --------------\n");
     642    printf("mySpline->n is %d\n", mySpline->n);
     643    for (psS32 i = 0 ; i < mySpline->n ; i++) {
     644        PS_POLY1D_PRINT(mySpline->spline[i]);
     645    }
     646    PS_VECTOR_PRINT_F32(mySpline->knots);
     647}
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
    620683
    621684
     
    650713        //
    651714        psLogMsg(__func__, PS_LOG_WARN,
    652                  "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
    653                  x, spline->knots->data.F32[0],
    654                  spline->knots->data.F32[n-1]);
     715                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
     716                 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
    655717
    656718        if (x < spline->knots->data.F32[0]) {
Note: See TracChangeset for help on using the changeset viewer.