00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_Spline__
00022 #define __UT_Spline__
00023
00024 #include "UT_API.h"
00025 #include "UT_Color.h"
00026 #include <SYS/SYS_Types.h>
00027
00028 typedef enum {
00029
00030 UT_SPLINE_CONSTANT,
00031 UT_SPLINE_LINEAR,
00032 UT_SPLINE_CATMULL_ROM,
00033 UT_SPLINE_MONOTONECUBIC,
00034
00035
00036
00037
00038
00039
00040 UT_SPLINE_LINEAR_SOLVE,
00041 } UT_SPLINE_BASIS;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 class UT_API UT_Spline {
00052 public:
00053 UT_Spline();
00054 ~UT_Spline();
00055
00056
00057 UT_SPLINE_BASIS getGlobalBasis() const { return myGlobalBasis; }
00058 int getVectorSize() const { return myVectorSize; }
00059 int getKnotLength() const { return myKnotLength; }
00060 fpreal64 getTension() const { return myTension; }
00061
00062 void setGlobalBasis(UT_SPLINE_BASIS b)
00063 { myGlobalBasis = b; }
00064
00065
00066
00067 void setSize(int nkeys, int vector_size);
00068
00069
00070 void setTension(fpreal64 t);
00071
00072
00073
00074
00075 void setValue(int key, const fpreal32 *value, int size);
00076 void setValue(int key, const fpreal64 *value, int size);
00077
00078
00079
00080
00081 void setBasis(int key, UT_SPLINE_BASIS b);
00082
00083
00084
00085
00086
00087
00088 bool evaluate(fpreal t, fpreal32 *result, int size,
00089 UT_ColorType interp_space) const;
00090 bool evaluate(fpreal t, fpreal64 *result, int size,
00091 UT_ColorType interp_space) const;
00092
00093
00094
00095
00096
00097
00098
00099 bool evaluateMulti(fpreal t, fpreal32 *result, int n,
00100 UT_ColorType interp_space) const;
00101 bool evaluateMulti(fpreal t, fpreal64 *result, int n,
00102 UT_ColorType interp_space) const;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 static fpreal64 getMonotoneSlopeFC(fpreal64 v_cur, fpreal64 t_cur,
00114 fpreal64 v_prev, fpreal64 t_prev,
00115 fpreal64 v_next, fpreal64 t_next);
00116
00117
00118
00119
00120
00121
00122 static fpreal64 getMonotoneSlopePA(fpreal64 v_cur, fpreal64 t_cur,
00123 fpreal64 v_prev, fpreal64 t_prev,
00124 fpreal64 v_next, fpreal64 t_next);
00125
00126
00127
00128
00129
00130 template <typename T>
00131 static T evalCubic(T kt, T dt, T iv, T im, T ov, T om)
00132 {
00133 T x0 = iv;
00134 T x1 = im*dt;
00135 T x3 = 2*(iv - ov) + (im + om)*dt;
00136 T x2 = ov - iv - im*dt - x3;
00137 return x0 + kt*(x1 + kt*(x2 + kt*x3));
00138 }
00139
00140 private:
00141 UT_Spline(const UT_Spline ©);
00142 UT_Spline &operator =(const UT_Spline ©);
00143
00144 private:
00145 void grow(int size);
00146 int getInterp(fpreal t, int knots[], fpreal weights[]);
00147
00148 int64 getSizeOfValues() const
00149 { return myKnotLength*myVectorSize*sizeof(fpreal64); }
00150 int64 getSizeOfBases() const
00151 { return myKnotLength*sizeof(UT_SPLINE_BASIS); }
00152
00153 template <typename T>
00154 inline void combineKeys(T *result, int vector_size,
00155 fpreal64 weights[], int indices[],
00156 int num_indices,
00157 UT_ColorType interp_space) const;
00158
00159 template <typename T>
00160 inline void evalMonotoneCubic(fpreal t, T *result,
00161 int n, UT_ColorType interp_space,
00162 bool do_multi) const;
00163
00164 template <typename T>
00165 inline void setValueInternal(int key, const T *value, int size);
00166
00167 template <typename T>
00168 inline bool evaluateInternal(fpreal t, T *result, int size,
00169 UT_ColorType interp_space) const;
00170
00171 template <typename T>
00172 inline bool evaluateMultiInternal(fpreal t, T *result, int n,
00173 UT_ColorType interp_space) const;
00174
00175 fpreal64 *myValues;
00176 UT_SPLINE_BASIS *myBases;
00177 fpreal64 myTension;
00178 int myVectorSize;
00179 int myKnotLength;
00180 UT_SPLINE_BASIS myGlobalBasis;
00181 };
00182
00183 #endif