const rampage:) added next2 to curve code
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index e80ada5..bb1e7fa 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -48,15 +48,15 @@ class ftPoint
ftPoint()
: x(0), y(0), z(0){}
- ftPoint( float X, float Y, float Z)
+ ftPoint( const float X, const float Y, const float Z)
: x(X), y(Y), z(Z){}
- friend bool operator == (const ftPoint &a, const ftPoint &b)
+ friend bool operator == (const ftPoint &a, const ftPoint &b)
{
return((a.x == b.x) && (a.y == b.y) && (a.z == b.z));
}
- friend bool operator != (const ftPoint &a, const ftPoint &b)
+ friend bool operator != (const ftPoint &a, const ftPoint &b)
{
return((a.x != b.x) || (a.y != b.y) || (a.z != b.z));
}
@@ -74,7 +74,7 @@ class FTContour
FTContour();
~FTContour();
- void AddPoint( int x, int y);
+ void AddPoint( const int x, const int y);
int size() const { return pointList.size();}
@@ -107,23 +107,21 @@ class FTVectoriser
private:
// methods
- int Conic( int index, int first, int last);
- int Cubic( int index, int first, int last);
- void deCasteljau( GLfloat t, int n);
- void evaluateCurve( int n);
+ int Conic( const int index, const int first, const int last);
+ int Cubic( const int index, const int first, const int last);
+ void deCasteljau( const float t, const int n);
+ void evaluateCurve( const int n);
// attributes
- vector< FTContour*> contourList;
- float ctrlPtArray[4][2]; // Magic numbers
+ vector< const FTContour*> contourList;
FTContour* contour;
FT_Outline ftOutline;
// Magic numbers -- #define MAX_DEG 4
- float bValues[4][4][2]; //3D array storing values
- //of de Casteljau algorithm.
-
+ float bValues[4][4][2]; //3D array storing values of de Casteljau algorithm.
+ float ctrlPtArray[4][2]; // Magic numbers
};
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 6f20f1a..3896eed 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -1,5 +1,3 @@
-#include "gl.h"
-
#include "FTVectoriser.h"
#include "FTGL.h"
@@ -16,12 +14,12 @@ FTContour::~FTContour()
}
-void FTContour::AddPoint( int x, int y)
+void FTContour::AddPoint( const int x, const int y)
{
ftPoint point( static_cast<float>( x), static_cast<float>( y), 0.0);
// Eliminate duplicate points.
- if( ( pointList[pointList.size() - 1] != point) || pointList[0] != point)
+ if( ( pointList[pointList.size() - 1] != point) && pointList[0] != point)
{
pointList.push_back( point);
}
@@ -29,13 +27,11 @@ void FTContour::AddPoint( int x, int y)
// De Casteljau algorithm supplied by Jed Soane
-void FTVectoriser::deCasteljau( float t, int n)
+void FTVectoriser::deCasteljau( const float t, const int n)
{
- int i, k;
-
//Calculating successive b(i)'s using de Casteljau algorithm.
- for ( i = 1; i <= n; i++)
- for (k = 0; k <= (n - i); k++)
+ for( int i = 1; i <= n; i++)
+ for( int k = 0; k <= (n - i); k++)
{
bValues[i][k][0] = (1 - t) * bValues[i - 1][k][0] + t * bValues[i - 1][k + 1][0];
bValues[i][k][1] = (1 - t) * bValues[i - 1][k][1] + t * bValues[i - 1][k + 1][1];
@@ -46,20 +42,20 @@ void FTVectoriser::deCasteljau( float t, int n)
}
-void FTVectoriser::evaluateCurve( int n)
+// De Casteljau algorithm supplied by Jed Soane
+void FTVectoriser::evaluateCurve( const int n)
{
- int m, i; //loop counters
- float t; //parameter for curve point calc. [0.0, 1.0]
- float stepSize = 0.2;
-
// setting the b(0) equal to the control points
- for (i = 0; i <= n; i++)
+ for( int i = 0; i <= n; i++)
{
bValues[0][i][0] = ctrlPtArray[i][0];
bValues[0][i][1] = ctrlPtArray[i][1];
} //end for(i..)
- for (m = 0; m <= (1 / stepSize); m++)
+ float t; //parameter for curve point calc. [0.0, 1.0]
+ const float stepSize = 0.2; // FIXME variable
+
+ for( int m = 0; m <= (1 / stepSize); m++)
{
t = m * stepSize;
deCasteljau( t, n); //calls to evaluate point on curve att.
@@ -67,7 +63,9 @@ void FTVectoriser::evaluateCurve( int n)
}
-FTVectoriser::FTVectoriser( FT_Glyph glyph)
+FTVectoriser::FTVectoriser( const FT_Glyph glyph)
+: contourFlag(0),
+ contour(0)
{
FT_OutlineGlyph outline = (FT_OutlineGlyph)glyph;
ftOutline = outline->outline;
@@ -101,19 +99,18 @@ int FTVectoriser::points()
bool FTVectoriser::Ingest()
{
- if ( ( ftOutline.n_contours < 1) || ( ftOutline.n_points < 1))
+ if ( ( ftOutline.n_contours < 1) || ( ftOutline.n_points < 3)) //FIXME check this
return false;
short first = 0;
- short cont = ftOutline.n_contours;
+ short last;
+ const short cont = ftOutline.n_contours;
for( short c = 0; c < cont; ++c)
{
contour = new FTContour;
-
contourFlag = ftOutline.flags;
-
- short last = ftOutline.contours[c];
+ last = ftOutline.contours[c];
for( short p = first; p <= last; ++p)
{
@@ -132,16 +129,14 @@ bool FTVectoriser::Ingest()
}
contourList.push_back( contour);
-
first = last + 1;
}
return true;
-
}
-int FTVectoriser::Conic( int index, int first, int last)
+int FTVectoriser::Conic( const int index, const int first, const int last)
{
int next = index + 1;
int prev = index - 1;
@@ -155,7 +150,7 @@ int FTVectoriser::Conic( int index, int first, int last)
if( ftOutline.tags[next] != FT_Curve_Tag_Conic)
{
ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
- ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
+ ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
ctrlPtArray[2][0] = ftOutline.points[next].x; ctrlPtArray[2][1] = ftOutline.points[next].y;
evaluateCurve( 2);
@@ -163,29 +158,25 @@ int FTVectoriser::Conic( int index, int first, int last)
}
else
{
+ int next2 = next + 1;
+ if( next == last)
+ next2 = first;
+
//create a phantom point
float x = ( ftOutline.points[index].x + ftOutline.points[next].x) / 2;
float y = ( ftOutline.points[index].y + ftOutline.points[next].y) / 2;
// process first curve
ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
- ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
- ctrlPtArray[2][0] = x; ctrlPtArray[2][1] = y;
+ ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
+ ctrlPtArray[2][0] = x; ctrlPtArray[2][1] = y;
evaluateCurve( 2);
// process second curve
- ctrlPtArray[0][0] = x; ctrlPtArray[0][1] = y;
- ctrlPtArray[1][0] = ftOutline.points[next].x; ctrlPtArray[1][1] = ftOutline.points[next].y;
-
- if( index != last -1)
- {
- ctrlPtArray[2][0] = ftOutline.points[index+2].x; ctrlPtArray[2][1] = ftOutline.points[index+2].y;
- }
- else
- {
- ctrlPtArray[2][0] = ftOutline.points[first].x; ctrlPtArray[2][1] = ftOutline.points[first].y;
- }
+ ctrlPtArray[0][0] = x; ctrlPtArray[0][1] = y;
+ ctrlPtArray[1][0] = ftOutline.points[next].x; ctrlPtArray[1][1] = ftOutline.points[next].y;
+ ctrlPtArray[2][0] = ftOutline.points[next2].x; ctrlPtArray[2][1] = ftOutline.points[next2].y;
evaluateCurve( 2);
return 2;
@@ -193,7 +184,7 @@ int FTVectoriser::Conic( int index, int first, int last)
}
-int FTVectoriser::Cubic( int index, int first, int last)
+int FTVectoriser::Cubic( const int index, const int first, const int last)
{
int next = index + 1;
int prev = index - 1;
@@ -201,20 +192,19 @@ int FTVectoriser::Cubic( int index, int first, int last)
if( index == last)
next = first;
+ int next2 = next + 1;
+
+ if( next == last)
+ next2 = first;
+
if( index == first)
prev = last;
- ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
+ ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
ctrlPtArray[2][0] = ftOutline.points[next].x; ctrlPtArray[2][1] = ftOutline.points[next].y;
- if( index != last -1)
- {
- ctrlPtArray[3][0] = ftOutline.points[index+2].x; ctrlPtArray[3][1] = ftOutline.points[index+2].y;
- }
- else
- {
- ctrlPtArray[3][0] = ftOutline.points[first].x; ctrlPtArray[3][1] = ftOutline.points[first].y;
- }
+ ctrlPtArray[3][0] = ftOutline.points[next2].x; ctrlPtArray[3][1] = ftOutline.points[next2].y;
+
evaluateCurve( 3);
return 2;
}
@@ -226,13 +216,13 @@ void FTVectoriser::Output( double* data)
for( int c= 0; c < contours(); ++c)
{
- FTContour* contour = contourList[c];
+ const FTContour* contour = contourList[c];
for( int p = 0; p < contour->size(); ++p)
{
data[i] = static_cast<double>(contour->pointList[p].x / 64.0f); // is 64 correct?
data[i + 1] = static_cast<double>(contour->pointList[p].y / 64.0f);
- data[i + 2] = static_cast<double>(contour->pointList[p].z / 64.0f);
+ data[i + 2] = 0.0; // static_cast<double>(contour->pointList[p].z / 64.0f);
i += 3;
}
}