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 virtual void Setup (int d, int p); 00054 00056 int GetDimensionCount () const { return dimensions; } 00057 00059 int GetPointCount () const { return num_points; } 00060 00065 void InsertPoint (int idx); 00066 00070 void RemovePoint (int idx); 00071 00078 void SetTimeValues (float const* t); 00079 00083 void SetTimeValue (int idx, float t); 00084 00088 float const* GetTimeValues () const { return time_points; } 00089 00093 float GetTimeValue (int idx) const { return GetTimeValues ()[idx]; } 00094 00101 void SetDimensionValues (int dim, float const* d); 00102 00106 void SetDimensionValue (int dim, int idx, float d); 00107 00111 float const* GetDimensionValues (int dim) const 00112 { return &points[dim*num_points]; } 00113 00117 float GetDimensionValue (int dim, int idx) const 00118 { 00119 float const* d = &points[dim*num_points]; 00120 return d[idx]; 00121 } 00122 00126 void SetIndexValues (int idx, float const* d); 00127 00132 float* GetIndexValues (int idx) const; 00133 00137 virtual void Calculate (float time) = 0; 00138 00142 int GetCurrentIndex () const { return idx; } 00143 00148 virtual float GetInterpolatedDimension (int dim) const = 0; 00149 }; 00150 00154 class CS_CRYSTALSPACE_EXPORT csCubicSpline : public csSpline 00155 { 00156 private: 00157 bool derivatives_valid; 00158 float* derivative_points; 00159 00160 // The following values are calculated by Calculate() and 00161 // are used later by GetInterpolatedDimension(). 00162 float A, B, C, D; // For computation of a spline value. 00163 00164 private: 00165 void PrecalculateDerivatives (int dim); 00166 void PrecalculateDerivatives (); 00167 00168 public: 00170 csCubicSpline (int d, int p); 00171 00173 virtual ~csCubicSpline (); 00174 00175 virtual void Setup (int d, int p); 00176 00180 virtual void Calculate (float time); 00181 00186 virtual float GetInterpolatedDimension (int dim) const; 00187 }; 00188 00192 class CS_CRYSTALSPACE_EXPORT csBSpline : public csSpline 00193 { 00194 private: 00195 // The following values are calculated by Calculate() and 00196 // are used later by GetInterpolatedDimension(). 00197 float t; 00198 00199 protected: 00201 virtual float BaseFunction (int i, float t) const; 00202 00203 public: 00205 csBSpline (int d, int p); 00206 00208 virtual ~csBSpline (); 00209 00213 virtual void Calculate (float time); 00214 00219 virtual float GetInterpolatedDimension (int dim) const; 00220 }; 00221 00225 class CS_CRYSTALSPACE_EXPORT csCatmullRomSpline : public csBSpline 00226 { 00227 protected: 00229 virtual float BaseFunction (int i, float t) const; 00230 00231 public: 00233 csCatmullRomSpline (int d, int p) : csBSpline (d, p) { } 00234 00236 virtual ~csCatmullRomSpline () {} 00237 00239 csCatmullRomSpline * Clone(); 00240 }; 00241 00244 #endif // __CS_SPLINE_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1