00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __UT_FitCubic_H__
00022 #define __UT_FitCubic_H__
00023
00024
00025 #include "UT_API.h"
00026 #include "UT_Vector2.h"
00027 typedef UT_Vector2 cubicCurve[4];
00028
00029 class UT_Interrupt;
00030
00031
00032
00033
00034 class UT_API utCubicSpan {
00035
00036 public:
00037
00038 UT_Vector2 point[3];
00039 int isLinear;
00040 class utCubicSpan *next;
00041 };
00042
00043 enum utFitType
00044 {
00045 UT_FIT_BEZIER = 0,
00046 UT_FIT_CUBIC = 1
00047
00048 };
00049
00050 enum utCurveType
00051 {
00052 UT_FIT_CURVES = 0,
00053 UT_FIT_POLYS = 1,
00054 UT_FIT_BOTH = 2
00055 };
00056
00057 class UT_API UT_FitCubic {
00058
00059 public:
00060
00061 UT_FitCubic();
00062 ~UT_FitCubic();
00063
00064 int fitCurve(UT_Vector2 *d, int nPts, int closed, fpreal error2,
00065 bool preserveExtrema);
00066
00067 const utCubicSpan *getFirstSpan(void) const
00068 { return myHead; }
00069
00070 int numSpans(void) const
00071 { return myNSpans; }
00072
00073 int containsCurve(void)
00074 { return myContainsCurve; }
00075
00076 void setCurveType(utCurveType type)
00077 { myCurveType = type; }
00078
00079 void setType(utFitType type)
00080 { myFitType = type; }
00081
00082 static UT_Vector2 calcCubic(UT_Vector2 *V, fpreal t);
00083
00084 private:
00085
00086 int myContainsCurve;
00087 fpreal myError2;
00088 utCubicSpan *myHead;
00089
00090 void destroySolution(void);
00091
00092
00093 utCubicSpan *appendCurve(cubicCurve fcurve, int islinear);
00094
00095
00096 int fitLine(UT_Vector2 *d, int first, int last,
00097 utCubicSpan **head, utCubicSpan **tail,
00098 int recurse);
00099
00100 int fitCubic(UT_Vector2 *d, int f, int l,UT_Vector2 tHat1,
00101 UT_Vector2 tHat2,
00102 utCubicSpan **head, utCubicSpan **tail,
00103 bool preserveExtrema, UT_Interrupt *boss);
00104
00105 UT_Vector2 computeCenterTangent(UT_Vector2 *d, int center);
00106
00107 float *reparameterize(UT_Vector2 *d, int first, int last,
00108 float *u, cubicCurve fcurve);
00109
00110 fpreal newtonRaphsonRootFind(cubicCurve Q, UT_Vector2 P, fpreal u);
00111
00112 UT_Vector2 calcBezier2(UT_Vector2 *V, fpreal t);
00113 UT_Vector2 calcBezier3(UT_Vector2 *V, fpreal t);
00114
00115
00116 fpreal computeBezierError(UT_Vector2 *d, int first, int last,
00117 cubicCurve fcurve, float *u, int *splitPoint);
00118
00119 fpreal computeCubicError(UT_Vector2 *d, int first, int last,
00120 cubicCurve fcurve, int *splitPoint,
00121 bool preserveExtrema);
00122
00123 fpreal computeLineError(UT_Vector2 *d, int first, int last,
00124 cubicCurve fcurve, float *u, int *splitPoint);
00125
00126 float *chordLengthParameterize(UT_Vector2 *d,int f,int l);
00127
00128 void generateBezier(UT_Vector2 *d, int first, int last,
00129 float *uPrime, UT_Vector2 tHat1,
00130 UT_Vector2 tHat2, cubicCurve fcurve);
00131
00132 void simpleCurve(UT_Vector2 *d, int first, int last,
00133 UT_Vector2 tHat1, UT_Vector2 tHat2,
00134 cubicCurve rcurve);
00135
00136 void findCorner(UT_Vector2 *d, int first, int last,
00137 int *splitPoint);
00138
00139 int isSeamCorner(UT_Vector2 *d, int last);
00140
00141
00142
00143
00144 fpreal BEZ_MULT_0(fpreal u)
00145 {
00146 fpreal tmp = 1.0F - u;
00147 return (tmp * tmp * tmp);
00148 }
00149
00150 fpreal BEZ_MULT_1(fpreal u)
00151 {
00152 fpreal tmp = 1.0F - u;
00153 return (3.0F * u * (tmp * tmp));
00154 }
00155
00156 fpreal BEZ_MULT_2(fpreal u)
00157 {
00158 fpreal tmp = 1.0F - u;
00159 return (3.0F * u * u * tmp);
00160 }
00161
00162 fpreal BEZ_MULT_3(fpreal u)
00163 {
00164 return (u * u * u);
00165
00166 }
00167
00168 int myNumPoints;
00169 int myClosed;
00170 int myNSpans;
00171
00172 utFitType myFitType;
00173 utCurveType myCurveType;
00174
00175
00176 };
00177
00178 #endif
00179