Diffstat (limited to 'inputmethods/handwriting/qimpenstroke.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/handwriting/qimpenstroke.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/inputmethods/handwriting/qimpenstroke.cpp b/inputmethods/handwriting/qimpenstroke.cpp index 3567d6d..14e435a 100644 --- a/inputmethods/handwriting/qimpenstroke.cpp +++ b/inputmethods/handwriting/qimpenstroke.cpp | |||
@@ -19,16 +19,17 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qtl.h> | 22 | #include <qtl.h> |
23 | #include <math.h> | 23 | #include <math.h> |
24 | #include <limits.h> | 24 | #include <limits.h> |
25 | #include <qdatastream.h> | 25 | #include <qdatastream.h> |
26 | #include "qimpenstroke.h" | 26 | #include "qimpenstroke.h" |
27 | #include "opie2/odebug.h" | ||
27 | 28 | ||
28 | #define QIMPEN_CORRELATION_POINTS 25 | 29 | #define QIMPEN_CORRELATION_POINTS 25 |
29 | //#define DEBUG_QIMPEN | 30 | //#define DEBUG_QIMPEN |
30 | 31 | ||
31 | /*! | 32 | /*! |
32 | \class QIMPenStroke qimpenstroke.h | 33 | \class QIMPenStroke qimpenstroke.h |
33 | 34 | ||
34 | Handles a single stroke. Can calculate closeness of match to | 35 | Handles a single stroke. Can calculate closeness of match to |
@@ -44,17 +45,17 @@ QIMPenStroke::QIMPenStroke( const QIMPenStroke &st ) | |||
44 | startPoint = st.startPoint; | 45 | startPoint = st.startPoint; |
45 | lastPoint = st.lastPoint; | 46 | lastPoint = st.lastPoint; |
46 | links = st.links.copy(); | 47 | links = st.links.copy(); |
47 | } | 48 | } |
48 | 49 | ||
49 | QIMPenStroke &QIMPenStroke::operator=( const QIMPenStroke &s ) | 50 | QIMPenStroke &QIMPenStroke::operator=( const QIMPenStroke &s ) |
50 | { | 51 | { |
51 | clear(); | 52 | clear(); |
52 | //qDebug( "copy strokes %d", s.links.count() ); | 53 | //odebug << "copy strokes " << s.links.count() << oendl; |
53 | startPoint = s.startPoint; | 54 | startPoint = s.startPoint; |
54 | lastPoint = s.lastPoint; | 55 | lastPoint = s.lastPoint; |
55 | links = s.links.copy(); | 56 | links = s.links.copy(); |
56 | 57 | ||
57 | return *this; | 58 | return *this; |
58 | } | 59 | } |
59 | 60 | ||
60 | void QIMPenStroke::clear() | 61 | void QIMPenStroke::clear() |
@@ -144,17 +145,17 @@ void QIMPenStroke::endInput() | |||
144 | if ( links.count() < 3 ) { | 145 | if ( links.count() < 3 ) { |
145 | QIMPenGlyphLink gl; | 146 | QIMPenGlyphLink gl; |
146 | links.resize(1); | 147 | links.resize(1); |
147 | gl.dx = 1; | 148 | gl.dx = 1; |
148 | gl.dy = 0; | 149 | gl.dy = 0; |
149 | links[0] = gl; | 150 | links[0] = gl; |
150 | } | 151 | } |
151 | 152 | ||
152 | //qDebug("Points: %d", links.count() ); | 153 | //odebug << "Points: " << links.count() << oendl; |
153 | } | 154 | } |
154 | 155 | ||
155 | /*! | 156 | /*! |
156 | Return an indicator of the closeness of this stroke to \a pen. | 157 | Return an indicator of the closeness of this stroke to \a pen. |
157 | Lower value is better. | 158 | Lower value is better. |
158 | */ | 159 | */ |
159 | unsigned int QIMPenStroke::match( QIMPenStroke *pen ) | 160 | unsigned int QIMPenStroke::match( QIMPenStroke *pen ) |
160 | { | 161 | { |
@@ -164,17 +165,17 @@ unsigned int QIMPenStroke::match( QIMPenStroke *pen ) | |||
164 | lratio = (links.count()+2) / (pen->links.count()+2); | 165 | lratio = (links.count()+2) / (pen->links.count()+2); |
165 | else | 166 | else |
166 | lratio = (pen->links.count()+2) / (links.count()+2); | 167 | lratio = (pen->links.count()+2) / (links.count()+2); |
167 | 168 | ||
168 | lratio -= 1.0; | 169 | lratio -= 1.0; |
169 | 170 | ||
170 | if ( lratio > 2.0 ) { | 171 | if ( lratio > 2.0 ) { |
171 | #ifdef DEBUG_QIMPEN | 172 | #ifdef DEBUG_QIMPEN |
172 | qDebug( "stroke length too different" ); | 173 | odebug << "stroke length too different" << oendl; |
173 | #endif | 174 | #endif |
174 | return 400000; | 175 | return 400000; |
175 | } | 176 | } |
176 | 177 | ||
177 | createSignatures(); | 178 | createSignatures(); |
178 | pen->createSignatures(); | 179 | pen->createSignatures(); |
179 | 180 | ||
180 | // Starting point offset | 181 | // Starting point offset |
@@ -210,49 +211,49 @@ unsigned int QIMPenStroke::match( QIMPenStroke *pen ) | |||
210 | QArray<int> base = createBase( tsig, 2 ); | 211 | QArray<int> base = createBase( tsig, 2 ); |
211 | for ( int i = 0; i < 4; i++ ) { | 212 | for ( int i = 0; i < 4; i++ ) { |
212 | int e = calcError( base, pen->tsig, i, TRUE ); | 213 | int e = calcError( base, pen->tsig, i, TRUE ); |
213 | if ( e < err1 ) | 214 | if ( e < err1 ) |
214 | err1 = e; | 215 | err1 = e; |
215 | } | 216 | } |
216 | if ( err1 > 40 ) { // no need for more matching | 217 | if ( err1 > 40 ) { // no need for more matching |
217 | #ifdef DEBUG_QIMPEN | 218 | #ifdef DEBUG_QIMPEN |
218 | qDebug( "tsig too great: %d", err1 ); | 219 | odebug << "tsig too great: " << err1 << oendl; |
219 | #endif | 220 | #endif |
220 | return 400000; | 221 | return 400000; |
221 | } | 222 | } |
222 | 223 | ||
223 | // maybe a sliding window is worthwhile for these too. | 224 | // maybe a sliding window is worthwhile for these too. |
224 | err2 = calcError( dsig, pen->dsig, 0, FALSE ); | 225 | err2 = calcError( dsig, pen->dsig, 0, FALSE ); |
225 | if ( err2 > 100 ) { | 226 | if ( err2 > 100 ) { |
226 | #ifdef DEBUG_QIMPEN | 227 | #ifdef DEBUG_QIMPEN |
227 | qDebug( "dsig too great: %d", err2 ); | 228 | odebug << "dsig too great: " << err2 << oendl; |
228 | #endif | 229 | #endif |
229 | return 400000; | 230 | return 400000; |
230 | } | 231 | } |
231 | 232 | ||
232 | err3 = calcError( asig, pen->asig, 0, TRUE ); | 233 | err3 = calcError( asig, pen->asig, 0, TRUE ); |
233 | if ( err3 > 60 ) { | 234 | if ( err3 > 60 ) { |
234 | #ifdef DEBUG_QIMPEN | 235 | #ifdef DEBUG_QIMPEN |
235 | qDebug( "asig too great: %d", err3 ); | 236 | odebug << "asig too great: " << err3 << oendl; |
236 | #endif | 237 | #endif |
237 | return 400000; | 238 | return 400000; |
238 | } | 239 | } |
239 | 240 | ||
240 | // Some magic numbers here - the addition reduces the weighting of | 241 | // Some magic numbers here - the addition reduces the weighting of |
241 | // the error and compensates for the different error scales. I | 242 | // the error and compensates for the different error scales. I |
242 | // consider the tangent signature to be the best indicator, so it | 243 | // consider the tangent signature to be the best indicator, so it |
243 | // has the most weight. This ain't rocket science. | 244 | // has the most weight. This ain't rocket science. |
244 | // Basically, these numbers are the tuning factors. | 245 | // Basically, these numbers are the tuning factors. |
245 | unsigned int err = (err1+1) * ( err2 + 60 ) * ( err3 + 20 ) + | 246 | unsigned int err = (err1+1) * ( err2 + 60 ) * ( err3 + 20 ) + |
246 | vdiff * 1000 + evdiff * 500 + | 247 | vdiff * 1000 + evdiff * 500 + |
247 | (unsigned int)(lratio * 5000.0); | 248 | (unsigned int)(lratio * 5000.0); |
248 | 249 | ||
249 | #ifdef DEBUG_QIMPEN | 250 | #ifdef DEBUG_QIMPEN |
250 | qDebug( "err %d ( %d, %d, %d, %d)", err, err1, err2, err3, vdiff ); | 251 | odebug << "err " << err << "( " << err1 << ", " << err2 << ", " << err3 << ", " << vdiff << oendl; |
251 | #endif | 252 | #endif |
252 | 253 | ||
253 | return err; | 254 | return err; |
254 | } | 255 | } |
255 | 256 | ||
256 | /*! | 257 | /*! |
257 | Return the bounding rect of this stroke. | 258 | Return the bounding rect of this stroke. |
258 | */ | 259 | */ |