nurb_basis.c

Go to the documentation of this file.
00001 /*                    N U R B _ B A S I S . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1990-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** @addtogroup nurb */
00023 /*@{*/
00024 /** @file nurb_basis.c
00025  * Evaluate the B-Spline Basis Functions.
00026  *
00027  */
00028 
00029 /*
00030  *      N U R B _ B A S I S . C
00031  *
00032  * nurb_basis.c - Evaluate the B-Spline Basis Functions.
00033  *
00034  *
00035  * Author:  Paul R. Stay
00036  * Source
00037  *      SECAD/VLD Computing Consortium, Bldg 394
00038  *      The US Army Ballistic Research Laboratory
00039  *      Aberdeen Proving Ground, Maryland 21005
00040  *
00041  * Date: Mon June 4, 1990
00042  */
00043 #ifndef lint
00044 static const char rcs_ident[] = "$Header: /cvsroot/brlcad/brlcad/src/librt/nurb_basis.c,v 14.11 2006/09/16 02:04:25 lbutler Exp $";
00045 #endif
00046 
00047 #include "common.h"
00048 
00049 
00050 
00051 #include <stdio.h>
00052 
00053 #include "machine.h"
00054 #include "vmath.h"
00055 #include "raytrace.h"
00056 #include "nurb.h"
00057 
00058 /* This uses the traditional De Boor-Cox algorithm,
00059  *
00060  *   D[k,i] (u) =
00061  *
00062  *         U[i+n-k] - mu                        mu - U[i-1]
00063  *         ________________ D[k-1, i-1] (mu)+_________________  D[k-1,i] (mu)
00064  *         U[i+n-k] - U[i-1]                 U[i+n-k] - U[i-1]
00065  *
00066  * For U[i-1]] <= mu < U[i] where U is the knot vector, k is the order,
00067  * and i is the interval. If the denominator is zero than the term is
00068  * zero.
00069  *
00070  * Arguments -
00071  *      knts - knot vector of type (struct knot_vector *)
00072  *      interval - where the parameter mu is defined above.
00073  *      order - Order of the b-spline.
00074  *      mu -  value which the basis functions are to be evaluated.
00075  *
00076  * Returns -
00077  *      fastf_t  - a floating point value of the basis evaluation.
00078  *
00079  * Reference -
00080  *      Farin G., "Curves and Surfaces for Computer Aided Geometric Design",
00081  *      Academic Press, New York 1988.
00082  */
00083 
00084 fastf_t
00085 rt_nurb_basis_eval(register struct knot_vector *knts, int interval, int order, fastf_t mu)
00086 {
00087 
00088         register fastf_t den;
00089         register fastf_t k1;
00090         register fastf_t k2;
00091         register fastf_t k3;
00092         register fastf_t *kk = knts->knots + interval;
00093         fastf_t b1, b2;
00094 
00095         k1 = *(kk);
00096         k2 = *(kk + 1);
00097 
00098         if (order <= 1) {
00099                 if ( ( k1 <= mu) && (mu < k2))
00100                         return 1.0;
00101                 else
00102                         return 0.0;
00103         }
00104 
00105         k3 = *(kk + order);
00106 
00107         den = ( *(kk + order - 1) - k1);
00108 
00109         if ( den == 0.0)
00110                 b1 = 0.0;
00111         else
00112                 b1 = ((mu - k1) *
00113                     rt_nurb_basis_eval( knts, interval, order - 1, mu)) / den;
00114 
00115         den = ( k3 - k2);
00116 
00117         if (den == 0.0)
00118                 b2 = 0.0;
00119         else
00120                 b2 = ((k3 - mu) *
00121                     rt_nurb_basis_eval( knts, interval + 1, order - 1, mu)) / den;
00122 
00123         return (b1 + b2);
00124 }
00125 /*@}*/
00126 
00127 /*
00128  * Local Variables:
00129  * mode: C
00130  * tab-width: 8
00131  * c-basic-offset: 4
00132  * indent-tabs-mode: t
00133  * End:
00134  * ex: shiftwidth=4 tabstop=8
00135  */

Generated on Mon Sep 18 01:24:55 2006 for BRL-CAD by  doxygen 1.4.6