CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csgeom/spline.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2001 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_SPLINE_H__
00020 #define __CS_SPLINE_H__
00021 
00028 #include "csextern.h"
00029 
00034 class CS_CSGEOM_EXPORT csSpline
00035 {
00036 protected:
00037   int dimensions;
00038   int num_points;
00039   float* time_points;
00040   float* points;
00041   bool precalculation_valid;
00042   int idx;
00043 
00044 public:
00046   csSpline (int d, int p);
00047 
00049   virtual ~csSpline ();
00050 
00052   int GetDimensionCount () const { return dimensions; }
00053 
00055   int GetPointCount () const { return num_points; }
00056 
00061   void InsertPoint (int idx);
00062 
00066   void RemovePoint (int idx);
00067 
00074   void SetTimeValues (float const* t);
00075 
00079   void SetTimeValue (int idx, float t);
00080 
00084   float const* GetTimeValues () const { return time_points; }
00085 
00089   float GetTimeValue (int idx) const { return GetTimeValues ()[idx]; }
00090 
00097   void SetDimensionValues (int dim, float const* d);
00098 
00102   void SetDimensionValue (int dim, int idx, float d);
00103 
00107   float const* GetDimensionValues (int dim) const
00108   { return &points[dim*num_points]; }
00109 
00113   float GetDimensionValue (int dim, int idx) const
00114   {
00115     float const* d = &points[dim*num_points];
00116     return d[idx];
00117   }
00118 
00122   void SetIndexValues (int idx, float const* d);
00123   
00128   float* GetIndexValues (int idx) const;
00129   
00133   virtual void Calculate (float time) = 0;
00134 
00138   int GetCurrentIndex () const { return idx; }
00139 
00144   virtual float GetInterpolatedDimension (int dim) const = 0;
00145 };
00146 
00150 class CS_CSGEOM_EXPORT csCubicSpline : public csSpline
00151 {
00152 private:
00153   bool derivatives_valid;
00154   float* derivative_points;
00155 
00156   // The following values are calculated by Calculate() and
00157   // are used later by GetInterpolatedDimension().
00158   float A, B, C, D;     // For computation of a spline value.
00159 
00160 private:
00161   void PrecalculateDerivatives (int dim);
00162   void PrecalculateDerivatives ();
00163 
00164 public:
00166   csCubicSpline (int d, int p);
00167 
00169   virtual ~csCubicSpline ();
00170 
00174   virtual void Calculate (float time);
00175 
00180   virtual float GetInterpolatedDimension (int dim) const;
00181 };
00182 
00186 class CS_CSGEOM_EXPORT csBSpline : public csSpline
00187 {
00188 private:
00189   // The following values are calculated by Calculate() and
00190   // are used later by GetInterpolatedDimension().
00191   float t;
00192 
00193 protected:
00195   virtual float BaseFunction (int i, float t) const;
00196 
00197 public:
00199   csBSpline (int d, int p);
00200 
00202   virtual ~csBSpline ();
00203 
00207   virtual void Calculate (float time);
00208 
00213   virtual float GetInterpolatedDimension (int dim) const;
00214 };
00215 
00219 class CS_CSGEOM_EXPORT csCatmullRomSpline : public csBSpline
00220 {
00221 protected:
00223   virtual float BaseFunction (int i, float t) const;
00224 
00225 public:
00227   csCatmullRomSpline (int d, int p) : csBSpline (d, p) { }
00228 
00230   virtual ~csCatmullRomSpline () {}
00231 };
00232 
00235 #endif // __CS_SPLINE_H__

Generated for Crystal Space by doxygen 1.2.18