IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 16, 2006, 2:56:48 PM (20 years ago)
Author:
gusciora
Message:

* empty log message *

File:
1 edited

Legend:

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

    r6305 r6437  
    66*  This file contains the routines that allocate, free, and evaluate splines.
    77*
    8 *  @version $Revision: 1.135 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2006-02-02 21:09:08 $
     8*  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2006-02-17 00:56:48 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    101101 
    102102The first and second derivatives at the endpoints were previously undefined in
    103 the SDR.  From bugzilla #???, they are required to be 0.0, impementing natural
     103the SDR.  From bugzilla #???, they are required to be 0.0, implementing natural
    104104splines.
    105105 
     
    228228    // The following code ensures that xPtr and yPtr points to a psF32 psVector.
    229229    //
    230     // XXX: When you debug, use the vector copy and create routines here:
     230    // XXX: Use the vector copy and create routines here:
    231231    //
    232232
     
    345345/*****************************************************************************
    346346psSpline1DEval(): this routine takes an existing spline of arbitrary order
    347 and an independent x value.  Each determines which spline that x corresponds
     347and an independent x value.  It determines which spline that x corresponds
    348348to by doing a bracket disection on the knots of the spline data structure
    349349(vectorBinDisectF32()).  Then it evaluates the spline at that x location
     
    360360    float x)
    361361{
    362     psTrace(__func__, 3, "---- %s(%f) begin ----\n", __func__, x);
     362    psTrace(__func__, 3, "---- %s() begin ----\n", __func__);
    363363    PS_ASSERT_PTR_NON_NULL(spline, NAN);
    364364    PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
     
    366366
    367367    psS32 n = spline->n;
     368    if ((x < spline->knots->data.F32[0]) || (x > spline->knots->data.F32[n-1])) {
     369        // If x is outside the range of spline->knots, generate a warning
     370        // message, then return the left, or right, endpoint.
     371        psLogMsg(__func__, PS_LOG_WARN,
     372                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
     373                 x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
     374
     375        psS32 binNum = (x < spline->knots->data.F32[0]) ? 0 : n-1;
     376        psTrace(__func__, 3, "---- %s() end ----\n", __func__);
     377        return(psPolynomial1DEval(spline->spline[binNum], x));
     378    }
     379
    368380    psScalar tmpScalar;
    369381    tmpScalar.type.type = PS_TYPE_F32;
    370382    tmpScalar.data.F32 = x;
    371383    psS32 binNum = p_psVectorBinDisect(spline->knots, &tmpScalar);
    372 
    373384    if (binNum < 0) {
    374         //
    375         // If x is outside the range of spline->knots, generate a warning
    376         // message, then return the left, or right, endpoint.
    377         //
    378         psLogMsg(__func__, PS_LOG_WARN,
    379                  "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f) (%d).",
    380                  x, spline->knots->data.F32[0], spline->knots->data.F32[n-1], n);
    381 
    382         if (x < spline->knots->data.F32[0]) {
    383             psF32 rcF32 = psPolynomial1DEval(spline->spline[0], x);
    384             psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    385             return(rcF32);
    386         } else if (x > spline->knots->data.F32[n-1]) {
    387             psF32 rcF32 = psPolynomial1DEval(spline->spline[n-1], x);
    388             psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    389             return(rcF32);
    390         }
    391     }
    392 
    393     psF32 rcF32 = psPolynomial1DEval(spline->spline[binNum], x);
    394     psTrace(__func__, 3, "---- %s(%f) end ----\n", __func__, rcF32);
    395     return(rcF32);
     385        psError(PS_ERR_UNKNOWN, false, "Could not perform bin dissection on spline->knots.\n");
     386        return(NAN);
     387    }
     388
     389    psTrace(__func__, 3, "---- %s() end ----\n", __func__);
     390    return(psPolynomial1DEval(spline->spline[binNum], x));
    396391}
    397392
Note: See TracChangeset for help on using the changeset viewer.