My favorites
▼
|
Sign in
pymt
PyMT, a framework for making accelerated multitouch UI
Project Home
Downloads
Issues
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
59
attachment: orientationlessgesture.diff
(2.8 KB)
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
Index: gesture.py
===================================================================
--- gesture.py (revision 745)
+++ gesture.py (working copy)
@@ -24,6 +24,7 @@
__all__ = ['Gesture', 'GestureDatabase', 'GesturePoint', 'GestureStroke']
import math
+from vector import *
import pickle, base64, zlib
from cStringIO import StringIO
@@ -66,6 +67,7 @@
io = StringIO(zlib.decompress(base64.b64decode(data)))
p = pickle.Unpickler(io)
gesture = p.load()
+ gesture.isorientationless=True
return gesture
@@ -223,6 +225,7 @@
self.tolerance = Gesture.DEFAULT_TOLERANCE
else:
self.tolerance = tolerance
+ self.isorientationless = True
def _scale_gesture(self):
''' Scales down the gesture to a unit of 1 '''
@@ -295,6 +298,18 @@
stroke.normalize_stroke(stroke_samples)
self.gesture_product = self.dot_product(self)
+ def get_rigid_rotation(self, dstpts):
+ """
+ Extract the rotation to apply to a group of points to minimize the
+ distance to a second group of points. The two groups of points are
+ assumed to be centered. This is a simple version that just pick
+ an angle based on the first point of the gesture.
+ """
+ target = Vector( [dstpts.strokes[0].points[0].x, dstpts.strokes[0].points[0].y] )
+ source = Vector( [self.strokes[0].points[0].x, self.strokes[0].points[0].y] )
+ return source.angle(target)
+
+
def dot_product(self, comparison_gesture):
''' Calculates the dot product of the gesture with another gesture '''
if len(comparison_gesture.strokes) != len(self.strokes):
@@ -307,9 +322,29 @@
dot_product += my_point.x * cmp_point.x + my_point.y * cmp_point.y
return dot_product
+ def rotate( self, angle ):
+ g = Gesture()
+ for stroke in self.strokes:
+ tmp = []
+ for j in stroke.points:
+ v = Vector([j.x, j.y]).rotate(angle)
+ tmp.append( v )
+ g.add_stroke( tmp )
+ g.gesture_product = g.dot_product(g)
+ return g
+
def get_score(self, comparison_gesture):
''' Returns the matching score of the gesture against another gesture '''
+ mode = "orientationless"
if isinstance(comparison_gesture, Gesture):
+ if self.isorientationless:
+ # get orientation
+ angle = self.get_rigid_rotation( comparison_gesture )
+
+ # rotate the gesture to be in the same frame.
+ comparison_gesture = comparison_gesture.rotate( angle )
+
+ # this is the normal "orientation" code.
score = self.dot_product(comparison_gesture)
if score < 0:
return score
Powered by
Google Project Hosting