/usr/include/crystalspace-2.0/csgeom/spline.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | /*
Copyright (C) 2001 by Jorrit Tyberghein
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_SPLINE_H__
#define __CS_SPLINE_H__
/**\file
* Splines.
*/
/**
* \addtogroup geom_utils
* @{ */
#include "csextern.h"
/**
* A spline superclass.
* This spline can control several dimensions at once.
*/
class CS_CRYSTALSPACE_EXPORT csSpline
{
protected:
int dimensions;
int num_points;
float* time_points;
float* points;
bool precalculation_valid;
int idx;
public:
/// Create a spline with d dimensions and p points.
csSpline (int d, int p);
/// Destroy the spline.
virtual ~csSpline ();
/// Change the setup of the spline.
virtual void Setup (int d, int p);
/// Get the number of dimensions.
int GetDimensionCount () const { return dimensions; }
/// Get the number of points.
int GetPointCount () const { return num_points; }
/**
* Insert a point after some index. If index == -1 add a point before all
* others.
*/
void InsertPoint (int idx);
/**
* Remove a point at the index.
*/
void RemovePoint (int idx);
/**
* Set the time values. 't' should point to an array containing
* 'num_points' values. These values typically start with 0 and end
* with 1. Other values are also possible the but the values should
* rise. The given array is copied.
*/
void SetTimeValues (float const* t);
/**
* Set one time point.
*/
void SetTimeValue (int idx, float t);
/**
* Get the time values.
*/
float const* GetTimeValues () const { return time_points; }
/**
* Get one time point.
*/
float GetTimeValue (int idx) const { return GetTimeValues ()[idx]; }
/**
* Set the values for some dimension.
* 'd' should point to an array containing 'num_points' values.
* These are the values that will be interpolated. The given
* array is copied.
*/
void SetDimensionValues (int dim, float const* d);
/**
* Set a value for some dimension.
*/
void SetDimensionValue (int dim, int idx, float d);
/**
* Get the values for some dimension.
*/
float const* GetDimensionValues (int dim) const
{ return &points[dim*num_points]; }
/**
* Get the value for some dimension.
*/
float GetDimensionValue (int dim, int idx) const
{
float const* d = &points[dim*num_points];
return d[idx];
}
/**
* Sets the values of the control point at index idx.
*/
void SetIndexValues (int idx, float const* d);
/**
* Gets the values of the control point at index idx. Caller is responsible
* for invoking `delete[]' on returned array when no longer needed.
*/
float* GetIndexValues (int idx) const;
/**
* Calculate internal values for this spline given some time value.
*/
virtual void Calculate (float time) = 0;
/**
* Get the index of the current point we are in (valid after Calculate()).
*/
int GetCurrentIndex () const { return idx; }
/**
* After calling Calculate() you can use this to fetch the value of
* some dimension.
*/
virtual float GetInterpolatedDimension (int dim) const = 0;
};
/**
* A cubic spline.
*/
class CS_CRYSTALSPACE_EXPORT csCubicSpline : public csSpline
{
private:
bool derivatives_valid;
float* derivative_points;
// The following values are calculated by Calculate() and
// are used later by GetInterpolatedDimension().
float A, B, C, D; // For computation of a spline value.
private:
void PrecalculateDerivatives (int dim);
void PrecalculateDerivatives ();
public:
/// Create a cubic spline with d dimensions and p points.
csCubicSpline (int d, int p);
/// Destroy the spline.
virtual ~csCubicSpline ();
virtual void Setup (int d, int p);
/**
* Calculate internal values for this spline given some time value.
*/
virtual void Calculate (float time);
/**
* After calling Calculate() you can use this to fetch the value of
* some dimension.
*/
virtual float GetInterpolatedDimension (int dim) const;
};
/**
* A B-spline.
*/
class CS_CRYSTALSPACE_EXPORT csBSpline : public csSpline
{
private:
// The following values are calculated by Calculate() and
// are used later by GetInterpolatedDimension().
float t;
protected:
/// Base function for a cubic B-spline (i=-2..1).
virtual float BaseFunction (int i, float t) const;
public:
/// Create a B-spline with d dimensions and p points.
csBSpline (int d, int p);
/// Destroy the spline.
virtual ~csBSpline ();
/**
* Calculate internal values for this spline given some time value.
*/
virtual void Calculate (float time);
/**
* After calling Calculate() you can use this to fetch the value of
* some dimension.
*/
virtual float GetInterpolatedDimension (int dim) const;
};
/**
* A CatmullRom spline.
*/
class CS_CRYSTALSPACE_EXPORT csCatmullRomSpline : public csBSpline
{
protected:
/// Base function for a cubic CatmullRom spline (i=-2..1).
virtual float BaseFunction (int i, float t) const;
public:
/// Create a CatmullRom spline with d dimensions and p points.
csCatmullRomSpline (int d, int p) : csBSpline (d, p) { }
/// Destroy the spline.
virtual ~csCatmullRomSpline () {}
/// Clones the spline
csCatmullRomSpline * Clone();
};
/** @} */
#endif // __CS_SPLINE_H__
|