Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

BSpline.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 //
00003 // BSpline.h: interface for the BSplineBase class.
00004 //
00006 /*
00007  * Copyright (c) 1998,1999
00008  * University Corporation for Atmospheric Research, UCAR
00009  *
00010  * Permission to use, copy, modify, distribute and sell this software and
00011  * its documentation for any purpose is hereby granted without fee,
00012  * provided that the above copyright notice appear in all copies and that
00013  * both that copyright notice and this permission notice appear in
00014  * supporting documentation.  UCAR makes no representations about the
00015  * suitability of this software for any purpose.  It is provided "as is"
00016  * without express or implied warranty.
00017  * 
00018  * Note from the author:
00019  *
00020  * Where possible, you are encouraged to follow the GNU General Public
00021  * License, or at least the spirit of the license, for the distribution and
00022  * licensing of this software and any derived works.  See
00023  * http://www.gnu.org/copyleft/gpl.html.
00024  */
00025 
00026 #ifndef _BSPLINEBASE_IFACE_ID
00027 #define _BSPLINEBASE_IFACE_ID "$Id: BSpline.h,v 1.21 2005/05/27 21:16:23 granger Exp $"
00028 
00040 #if WIN32
00041 # ifndef BSPLINE_DLL_
00042 #  define BSPLINE_DLL_ __declspec(dllimport)
00043 # endif
00044 #else
00045 # define BSPLINE_DLL_
00046 #endif /* WIN32 */
00047 
00048 
00049 template <class T> class BSpline;
00050 
00051 /*
00052  * Opaque member structure to hide the matrix implementation.
00053  */
00054 template <class T> struct BSplineBaseP;
00055 
00187 template <class T> 
00188 class BSPLINE_DLL_ BSplineBase  
00189 {
00190 public:
00191     // Datum type
00192     typedef T datum_type;
00193 
00195     static const char *ImplVersion();
00196 
00198     static const char *IfaceVersion();
00199         
00205     static bool Debug (int on = -1);
00206 
00210     enum BoundaryConditionTypes
00211     {
00213         BC_ZERO_ENDPOINTS = 0,
00215         BC_ZERO_FIRST = 1,
00217         BC_ZERO_SECOND = 2
00218     };
00219 
00220 public:
00221 
00228     BSplineBase (const T *x, int nx, 
00229                  double wl, int bc_type = BC_ZERO_SECOND,
00230                  int num_nodes = 0);
00231 
00233     BSplineBase (const BSplineBase &);
00234 
00260     bool setDomain (const T *x, int nx, double wl, 
00261                     int bc_type = BC_ZERO_SECOND,
00262                     int num_nodes = 0);
00263 
00271     BSpline<T> *apply (const T *y);
00272 
00278     const T *nodes (int *nnodes);
00279 
00283     int nNodes () { return M+1; }
00284 
00288     int nX () { return NX; }
00289 
00291     T Xmin () { return xmin; }
00292 
00294     T Xmax () { return xmin + (M * DX); }
00295 
00300     double Alpha (double wavelength);
00301 
00305     double Alpha () { return alpha; }
00306 
00315     bool ok () { return OK; }
00316 
00317     virtual ~BSplineBase();
00318 
00319 protected:
00320 
00321     typedef BSplineBaseP<T> Base;
00322 
00323     // Provided
00324     double waveLength;  // Cutoff wavelength (l sub c)
00325     int NX;
00326     int K;      // Degree of derivative constraint (currently fixed at 2)
00327     int BC;                     // Boundary conditions type (0,1,2)
00328 
00329     // Derived
00330     T xmax;
00331     T xmin;
00332     int M;                      // Number of intervals (M+1 nodes)
00333     double DX;                  // Interval length in same units as X
00334     double alpha;
00335     bool OK;
00336     Base *base;                 // Hide more complicated state members
00337                                 // from the public interface.
00338 
00339     bool Setup (int num_nodes = 0);
00340     void calculateQ ();
00341     double qDelta (int m1, int m2);
00342     double Beta (int m);
00343     void addP ();
00344     bool factor ();
00345     double Basis (int m, T x);
00346     double DBasis (int m, T x);
00347 
00348     static const double BoundaryConditions[3][4];
00349     static const double PI;
00350 
00351     double Ratiod (int&, double &, double &);
00352 };
00353 
00354 
00355 template <class T> struct BSplineP;
00356 
00357 
00363 template <class T>
00364 class BSPLINE_DLL_ BSpline : public BSplineBase<T>
00365 {
00366 public:
00390     BSpline (const T *x, int nx,                /* independent variable */
00391              const T *y,                        /* dependent values @ ea X */
00392              double wl,                         /* cutoff wavelength */
00393              int bc_type = BSplineBase<T>::BC_ZERO_SECOND,
00394              int num_nodes = 0);
00395 
00400     BSpline (BSplineBase<T> &base, const T *y);
00401 
00409     bool solve (const T *y);
00410 
00419     const T *curve (int *nx = 0);
00420 
00425     T evaluate (T x);
00426 
00431     T slope (T x);
00432 
00437     T coefficient (int n);
00438 
00439     virtual ~BSpline();
00440 
00441     using BSplineBase<T>::Debug;
00442 
00443 protected:
00444 
00445     using BSplineBase<T>::OK;
00446     using BSplineBase<T>::M;
00447     using BSplineBase<T>::NX;
00448     using BSplineBase<T>::DX;
00449     using BSplineBase<T>::base;
00450     using BSplineBase<T>::xmin;
00451     using BSplineBase<T>::xmax;
00452 
00453     // Our hidden state structure
00454     BSplineP<T> *s;
00455     T mean;                     // Fit without mean and add it in later
00456 
00457 };
00458 
00459 #endif // !defined _BSPLINEBASE_IFACE_ID

Generated on Tue May 31 13:21:37 2005 for BSpline Library by  doxygen 1.4.2