Crystal Space: csgeom/spline.h Source File (Crystal Space Public API Reference)

| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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
    00029 #include "csextern.h"
    00030
    00035 class CS_CRYSTALSPACE_EXPORT csSpline
    00036 {
    00037 protected:
    00038   int dimensions;
    00039   int num_points;
    00040   float* time_points;
    00041   float* points;
    00042   bool precalculation_valid;
    00043   int idx;
    00044
    00045 public:
    00047   csSpline (int d, int p);
    00048
    00050   virtual ~csSpline ();
    00051
    00053   int GetDimensionCount () const { return dimensions; }
    00054
    00056   int GetPointCount () const { return num_points; }
    00057
    00062   void InsertPoint (int idx);
    00063
    00067   void RemovePoint (int idx);
    00068
    00075   void SetTimeValues (float const* t);
    00076
    00080   void SetTimeValue (int idx, float t);
    00081
    00085   float const* GetTimeValues () const { return time_points; }
    00086
    00090   float GetTimeValue (int idx) const { return GetTimeValues ()[idx]; }
    00091
    00098   void SetDimensionValues (int dim, float const* d);
    00099
    00103   void SetDimensionValue (int dim, int idx, float d);
    00104
    00108   float const* GetDimensionValues (int dim) const
    00109   { return &points[dim*num_points]; }
    00110
    00114   float GetDimensionValue (int dim, int idx) const
    00115   {
    00116     float const* d = &points[dim*num_points];
    00117     return d[idx];
    00118   }
    00119
    00123   void SetIndexValues (int idx, float const* d);
    00124
    00129   float* GetIndexValues (int idx) const;
    00130
    00134   virtual void Calculate (float time) = 0;
    00135
    00139   int GetCurrentIndex () const { return idx; }
    00140
    00145   virtual float GetInterpolatedDimension (int dim) const = 0;
    00146 };
    00147
    00151 class CS_CRYSTALSPACE_EXPORT csCubicSpline : public csSpline
    00152 {
    00153 private:
    00154   bool derivatives_valid;
    00155   float* derivative_points;
    00156
    00157   // The following values are calculated by Calculate() and
    00158   // are used later by GetInterpolatedDimension().
    00159   float A, B, C, D;     // For computation of a spline value.
    00160
    00161 private:
    00162   void PrecalculateDerivatives (int dim);
    00163   void PrecalculateDerivatives ();
    00164
    00165 public:
    00167   csCubicSpline (int d, int p);
    00168
    00170   virtual ~csCubicSpline ();
    00171
    00175   virtual void Calculate (float time);
    00176
    00181   virtual float GetInterpolatedDimension (int dim) const;
    00182 };
    00183
    00187 class CS_CRYSTALSPACE_EXPORT csBSpline : public csSpline
    00188 {
    00189 private:
    00190   // The following values are calculated by Calculate() and
    00191   // are used later by GetInterpolatedDimension().
    00192   float t;
    00193
    00194 protected:
    00196   virtual float BaseFunction (int i, float t) const;
    00197
    00198 public:
    00200   csBSpline (int d, int p);
    00201
    00203   virtual ~csBSpline ();
    00204
    00208   virtual void Calculate (float time);
    00209
    00214   virtual float GetInterpolatedDimension (int dim) const;
    00215 };
    00216
    00220 class CS_CRYSTALSPACE_EXPORT csCatmullRomSpline : public csBSpline
    00221 {
    00222 protected:
    00224   virtual float BaseFunction (int i, float t) const;
    00225
    00226 public:
    00228   csCatmullRomSpline (int d, int p) : csBSpline (d, p) { }
    00229
    00231   virtual ~csCatmullRomSpline () {}
    00232
    00234   csCatmullRomSpline * Clone();
    00235 };
    00236
    00239 #endif // __CS_SPLINE_H__