report.tex 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. \documentclass[twoside,openright]{uva-bachelor-thesis}
  2. \usepackage[english]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{hyperref,graphicx,float,tikz}
  5. \usetikzlibrary{shapes,arrows}
  6. % Link colors
  7. \hypersetup{colorlinks=true,linkcolor=black,urlcolor=blue,citecolor=DarkGreen}
  8. % Title Page
  9. \title{A generic architecture for the detection of multi-touch gestures}
  10. \author{Taddeüs Kroes}
  11. \supervisors{Dr. Robert G. Belleman (UvA)}
  12. \signedby{Dr. Robert G. Belleman (UvA)}
  13. \begin{document}
  14. % Title page
  15. \maketitle
  16. \begin{abstract}
  17. % TODO
  18. \end{abstract}
  19. % Set paragraph indentation
  20. \parindent 0pt
  21. \parskip 1.5ex plus 0.5ex minus 0.2ex
  22. % Table of contant on separate page
  23. \tableofcontents
  24. \chapter{Introduction}
  25. % Ruwe probleemstelling
  26. Multi-touch interaction is becoming increasingly common, mostly due to the wide
  27. use of touch screens in phones and tablets. When programming applications using
  28. this method of interaction, the programmer needs an abstraction of the raw data
  29. provided by the touch driver of the device. This abstraction exists in several
  30. multi-touch application frameworks like Nokia's
  31. Qt\footnote{\url{http://qt.nokia.com/}}. However, applications that do not use
  32. these frameworks have no access to their multi-touch events.
  33. % Aanleiding
  34. This problem was observed during an attempt to create a multi-touch
  35. ``interactor'' class for the Visualization Toolkit \cite[VTK]{VTK}. Because VTK
  36. provides the application framework here, it is undesirable to use an entire
  37. framework like Qt simultaneously only for its multi-touch support.
  38. % Ruw doel
  39. The goal of this project is to define a generic multi-touch event triggering
  40. architecture. To test the definition, a reference implementation is written in
  41. Python.
  42. \section{Definition of the problem}
  43. % Hoofdvraag
  44. The goal of this thesis is to a create generic architecture for a
  45. multi-touch event triggering mechanism for use in multi-touch applications.
  46. % Deelvragen
  47. To design such an architecture properly, the following questions are relevant:
  48. \begin{itemize}
  49. \item What is the input of the architecture? Different touch drivers
  50. have different API's. To be able to support different drivers
  51. (which is highly desirable), there should be a translation from the
  52. driver API to a fixed input format.
  53. \item How can extendability be accomplished? The set of supported
  54. events should not be limited to a single implementation, but an
  55. application should be able to define its own custom events.
  56. \item How can the architecture be used by different programming
  57. languages? A generic architecture should not be limited to be used
  58. in only one language.
  59. \item Can events be shared with multiple processes at the same time?
  60. For example, a network implementation could run as a service
  61. instead of within a single application, triggering events in any
  62. application that needs them.
  63. % FIXME: gaan we nog wat doen met onderstaand?
  64. %\item Is performance an issue? For example, an event loop with rotation
  65. % detection could swallow up more processing resources than desired.
  66. %\item How can the architecture be integrated in a VTK interactor?
  67. \end{itemize}
  68. % Afbakening
  69. The scope of this thesis includes the design of a generic multi-touch
  70. triggering architecture, a reference implementation of this design, and its
  71. integration into a test case application. To be successful, the design
  72. should allow for extensions to be added to any implementation.
  73. The reference implementation is a Proof of Concept that translates TUIO
  74. events to some simple touch gestures that are used by a VTK interactor.
  75. Being a Proof of Concept, the reference implementation itself does not
  76. necessarily need to meet all the requirements of the design.
  77. \section{Structure of this document}
  78. % TODO: pas als thesis af is
  79. \chapter{Related work}
  80. \section{Gesture and Activity Recognition Toolkit}
  81. The Gesture and Activity Recognition Toolkit (GART) \cite{GART} is a
  82. toolkit for the development of gesture-based applications. The toolkit
  83. states that the best way to classify gestures is to use machine learning.
  84. The programmer trains a program to recognize using the machine learning
  85. library from the toolkit. The toolkit contains a callback-mechanism that
  86. the programmer uses to execute custom code when a gesture is recognized.
  87. Though multi-touch input is not directly supported by the toolkit, the
  88. level of abstraction does allow for it to be implemented in the form of a
  89. ``touch'' sensor.
  90. The reason to use machine learning is the statement that gesture detection
  91. ``is likely to become increasingly complex and unmanageable'' when using a
  92. set of predefined rules to detect whether some sensor input can be seen as
  93. a specific gesture. This statement is not necessarily true. If the
  94. programmer is given a way to separate the detection of different types of
  95. gestures and flexibility in rule definitions, over-complexity can be
  96. avoided.
  97. % oplossing: trackers. bijv. TapTracker, TransformationTracker gescheiden
  98. \section{Gesture recognition software for Windows 7}
  99. % TODO
  100. The online article \cite{win7touch} presents a Windows 7 application,
  101. written in Microsofts .NET. The application shows detected gestures in a
  102. canvas. Gesture trackers keep track of stylus locations to detect specific
  103. gestures. The event types required to track a touch stylus are ``stylus
  104. down'', ``stylus move'' and ``stylus up'' events. A
  105. \texttt{GestureTrackerManager} object dispatches these events to gesture
  106. trackers. The application supports a limited number of pre-defined
  107. gestures.
  108. An important observation in this application is that different gestures are
  109. detected by different gesture trackers, thus separating gesture detection
  110. code into maintainable parts.
  111. \section{Processing implementation of simple gestures in Android}
  112. An implementation of a detection architecture for some simple multi-touch
  113. gestures (tap, double tap, rotation, pinch and drag) using
  114. Processing\footnote{Processing is a Java-based development environment with
  115. an export possibility for Android. See also \url{http://processing.org/.}}
  116. can be found found in a forum on the Processing website
  117. \cite{processingMT}. The implementation is fairly simple, but it yields
  118. some very appealing results. The detection logic of all gestures is
  119. combined in a single class. This does not allow for extendability, because
  120. the complexity of this class would increase to an undesirable level (as
  121. predicted by the GART article \cite{GART}). However, the detection logic
  122. itself is partially re-used in the reference implementation of the
  123. generic gesture detection architecture.
  124. \section{Analysis}
  125. \chapter{Problem analysis}
  126. % testimplementatie met taps, rotatie en pinch. Hieruit bleek:
  127. % - dat er verschillende manieren zijn om bijv. "rotatie" te
  128. % detecteren, (en dat daartussen onderscheid moet kunnen worden
  129. % gemaakt)
  130. % - dat detectie van verschillende soorten gestures moet kunnen
  131. % worden gescheiden, anders wordt het een chaos.
  132. % - Er zijn een aantal keuzes gemaakt bij het ontwerpen van de gestures,
  133. % bijv dat rotatie ALLE vingers gebruikt voor het centroid. Het is
  134. % wellicht in een ander programma nodig om maar 1 hand te gebruiken, en
  135. % dus punten dicht bij elkaar te kiezen (oplossing: windows).
  136. % Tekenprogramma dat huidige points + centroid tekent en waarmee
  137. % transformatie kan worden getest Link naar appendix "supported events"
  138. % Proof of Concept: VTK interactor
  139. \section{Introduction}
  140. % TODO
  141. TODO: doel v/h experiment
  142. To test multi-touch interaction properly, a multi-touch device is required.
  143. The University of Amsterdam (UvA) has provided access to a multi-touch
  144. table from PQlabs. The table uses the TUIO protocol \cite{TUIO} to
  145. communicate touch events. See appendix \ref{app:tuio} for details regarding
  146. the TUIO protocol.
  147. \section{Experimenting with TUIO and event bindings}
  148. \label{sec:experimental-draw}
  149. When designing a software library, its API should be understandable and
  150. easy to use for programmers. To find out the basic requirements of the API
  151. to be usable, an experimental program has been written based on the
  152. Processing code from \cite{processingMT}. The program receives TUIO events
  153. and translates them to point \emph{down}, \emph{move} and \emph{up} events.
  154. These events are then interpreted to be (double or single) \emph{tap},
  155. \emph{rotation} or \emph{pinch} gestures. A simple drawing program then
  156. draws the current state to the screen using the PyGame library. The output
  157. of the program can be seen in figure \ref{fig:draw}.
  158. \begin{figure}[H]
  159. \center
  160. \label{fig:draw}
  161. \includegraphics[scale=0.4]{data/experimental_draw.png}
  162. \caption{Output of the experimental drawing program. It draws the touch
  163. points and their centroid on the screen (the centroid is used
  164. as center point for rotation and pinch detection). It also
  165. draws a green rectangle which responds to rotation and pinch
  166. events.}
  167. \end{figure}
  168. One of the first observations is the fact that TUIO's \texttt{SET} messages
  169. use the TUIO coordinate system, as described in appendix \ref{app:tuio}.
  170. The test program multiplies these with its own dimensions, thus showing the
  171. entire screen in its window. Also, the implementation only works using the
  172. TUIO protocol. Other drivers are not supported.
  173. Though using relatively simple math, the rotation and pinch events work
  174. surprisingly well. Both rotation and pinch use the centroid of all touch
  175. points. A \emph{rotation} gesture uses the difference in angle relative to
  176. the centroid of all touch points, and \emph{pinch} uses the difference in
  177. distance. Both values are normalized using division by the number of touch
  178. points. A pinch event contains a scale factor, and therefore uses a
  179. division of the current by the previous average distance to the centroid.
  180. There is a flaw in this implementation. Since the centroid is calculated
  181. using all current touch points, there cannot be two or more rotation or
  182. pinch gestures simultaneously. On a large multi-touch table, it is
  183. desirable to support interaction with multiple hands, or multiple persons,
  184. at the same time. This kind of application-specific requirements should be
  185. defined in the application itself, whereas the experimental implementation
  186. defines detection algorithms based on its test program.
  187. Also, the different detection algorithms are all implemented in the same
  188. file, making it complex to read or debug, and difficult to extend.
  189. \section{Summary of observations}
  190. \label{sec:observations}
  191. \begin{itemize}
  192. \item The TUIO protocol uses a distinctive coordinate system and set of
  193. messages.
  194. \item Touch events occur outside of the application window.
  195. \item Gestures that use multiple touch points are using all touch
  196. points (not a subset of them).
  197. \item Code complexity increases when detection algorithms are added.
  198. \item A multi-touch application can have very specific requirements for
  199. gestures.
  200. \end{itemize}
  201. % -------
  202. % Results
  203. % -------
  204. \chapter{Design}
  205. \section{Requirements}
  206. \label{sec:requirements}
  207. From the observations in section \ref{sec:observations}, a number of
  208. requirements can be specified for the design of the event mechanism:
  209. \begin{itemize}
  210. % vertalen driver-specifieke events naar algemeen formaat
  211. \item To be able to support multiple input drivers, there must be a
  212. translation from driver-specific messages to some common format
  213. that can be used in gesture detection algorithms.
  214. % events toewijzen aan GUI window (windows)
  215. \item An application GUI window should be able to receive only events
  216. occurring within that window, and not outside of it.
  217. % scheiden groepen touchpoints voor verschillende gestures (windows)
  218. \item To support multiple objects that are performing different
  219. gestures at the same time, the architecture must be able to perform
  220. gesture detection on a subset of the active touch points.
  221. % scheiden van detectiecode voor verschillende gesture types
  222. \item To avoid an increase in code complexity when adding new detection
  223. algorithms, detection code of different gesture types must be
  224. separated.
  225. % extendability
  226. \item The architecture should allow for extension with new detection
  227. algorithms to be added to an implementation. This enables a
  228. programmer to define custom gestures for an application.
  229. \end{itemize}
  230. \section{Components}
  231. Based on the requirements from section \ref{sec:requirements}, a design
  232. for the architecture has been created. The design consists of a number
  233. of components, each having a specific set of tasks.
  234. \subsection{Event server}
  235. % vertaling driver naar point down, move, up
  236. % vertaling naar schermpixelcoordinaten
  237. % TUIO in reference implementation
  238. The \emph{event server} is an abstraction for driver-specific server
  239. implementations, such as a TUIO server. It receives driver-specific
  240. messages and tanslates these to a common set of events and a common
  241. coordinate system.
  242. A minimal example of a common set of events is $\{point\_down,
  243. point\_move, point\_up\}$. This is the set used by the reference
  244. implementation. Respectively, these events represent an object being
  245. placed on the screen, moving along the surface of the screen, and being
  246. released from the screen.
  247. A more extended set could also contain the same three events for an
  248. object touching the screen. However, a object can also have a
  249. rotational property, like the ``fiducials'' type in the TUIO protocol.
  250. This results in $\{point\_down, point\_move, point\_up, object\_down,
  251. object\_move, object\_up,\\object\_rotate\}$.
  252. % TODO: is dit handig? point_down/object_down op 1 of andere manier samenvoegen?
  253. An important note here, is that similar events triggered by different
  254. event servers must have the same event type and parameters. In other
  255. words, the output of the event servers should be determined by the
  256. gesture servers (not the contrary).
  257. The output of an event server implementation should also use a common
  258. coordinate system, that is the coordinate system used by the gesture
  259. server. For example, the reference implementation uses screen
  260. coordinates in pixels, where (0, 0) is the upper left corner and
  261. (\emph{screen width}, \emph{screen height}) the lower right corner of
  262. the screen.
  263. The abstract class definition of the event server should provide some
  264. functionality to detect which driver-specific event server
  265. implementation should be used.
  266. \subsection{Gesture trackers}
  267. Like \cite[the .NET implementation]{win7touch}, the architecture uses a
  268. \emph{gesture tracker} to detect if a sequence of events forms a
  269. particular gesture. A gesture tracker detects and triggers events for a
  270. limited set of gesture types, given a set of touch points. If one group
  271. of touch points is assigned to one tracker and another group to another
  272. tracker, multiple gestures can be detected at the same time. For the
  273. assignment of different groups of touch points to different gesture
  274. trackers, the architecture uses so-called \emph{windows}. These are
  275. described in the next section.
  276. % event binding/triggering
  277. A gesture tracker triggers a gesture event by executing a callback.
  278. Callbacks are ``bound'' to a tracker by the application. Because
  279. multiple gesture types can have very similar detection algorithm, a
  280. tracker can detect multiple different types of gestures. For instance,
  281. the rotation and pinch gestures from the experimental program in
  282. section \ref{sec:experimental-draw} both use the centroid of all touch
  283. points.
  284. If no callback is bound for a particular gesture type, no detection of
  285. that type is needed. A tracker implementation can use this knowledge
  286. for code optimization.
  287. % scheiding algoritmiek
  288. A tracker implementation defines the gesture types it can trigger, and
  289. the detection algorithms to trigger them. Consequently, detection
  290. algorithms can be separated in different trackers. Different
  291. trackers can be saved in different files, reducing the complexity of
  292. the code in a single file. \\
  293. % extendability
  294. Because a tracker defines its own set of gesture types, the application
  295. developer can define application-specific trackers (by extending a base
  296. \texttt{GestureTracker} class, for example). In fact, any built-in
  297. gesture trackers of an implementation are also created this way. This
  298. allows for a plugin-like way of programming, which is very desirable if
  299. someone would want to build a library of gesture trackers. Such a
  300. library can easy be extended by others.
  301. \subsection{Windows}
  302. A \emph{window} represents a subset of the entire screen surface. The
  303. goal of a window is to restrict the detection of certain gestures to
  304. certain areas. A window contains a list of touch points, and a list of
  305. trackers. A gesture server (defined in the next section) assigns touch
  306. points to a window, but the window itself defines functionality to
  307. check whether a touch point is inside the window. This way, new windows
  308. can be defined to fit over any 2D object used by the application.
  309. The first and most obvious use of a window is to restrict touch events
  310. to a single application window. However, the use of windows can be used
  311. in a lot more powerful way.
  312. For example, an application contains an image with a transparent
  313. background that can be dragged around. The user can only drag the image
  314. by touching its foreground. To accomplish this, the application
  315. programmer can define a window type that uses a bitmap to determine
  316. whether a touch point is on the visible image surface. The tracker
  317. which detects drag gestures is then bound to this window, limiting the
  318. occurence of drag events to the image surface.
  319. % toewijzen even aan deel v/h scherm:
  320. % TUIO coördinaten zijn over het hele scherm en van 0.0 tot 1.0, dus
  321. % moeten worden vertaald naar pixelcoördinaten binnen een ``window''
  322. % TODO
  323. \subsection{Gesture server}
  324. % luistert naar point down, move, up
  325. The \emph{gesture server} delegates events from the event server to the
  326. set of windows that contain the touch points related to the events.
  327. % toewijzing point (down) aan window(s)
  328. The gesture server contains a list of windows. When the event server
  329. triggers an event, the gesture server ``asks'' each window whether it
  330. contains the related touch point. If so, the window updates its gesture
  331. trackers, which can then trigger gestures.
  332. \section{Diagram of component relations}
  333. \begin{figure}[H]
  334. \input{data/diagram}
  335. % TODO: caption
  336. \end{figure}
  337. \section{Example usage}
  338. This section describes an example that illustrates the communication
  339. between different components. The example application listens to tap events
  340. in a GUI window.
  341. \begin{verbatim}
  342. # Create a gesture server that will be started later
  343. server = new GestureServer object
  344. # Add a new window to the server, representing the GUI
  345. window = new Window object
  346. set window position and size to that of GUIO window
  347. add window to server
  348. # Define a handler that must be triggered when a tap gesture is detected
  349. begin function handler(gesture)
  350. # Do something
  351. end function
  352. # Create a tracker that detects tap gestures
  353. tracker = new TapTracker object # Where TapTracker is an implementation of
  354. # abstract Tracker
  355. add tracker tot window
  356. bind handler to tracker.tap
  357. # If the GUI toolkit allows it, bind window movement and resize handlers
  358. # that alter the position size and sieze of the window object
  359. # Start the gesture server (which in turn starts a driver-specific event
  360. # server)
  361. start server
  362. \end{verbatim}
  363. \section{\emph{hier moet een conslusie komen die de componenten aansluit op de requirements(?)}}
  364. % TODO
  365. %
  366. %\section{Network protocol}
  367. % TODO
  368. % ZeroMQ gebruiken voor communicatie tussen meerdere processen (in
  369. % verschillende talen)
  370. \chapter{Reference implementation}
  371. % TODO
  372. % alleen window.contains op point down, niet move/up
  373. \chapter{Integration in VTK}
  374. \section{The Visualization Toolkit}
  375. \label{sec:vtk}
  376. % TODO
  377. % VTK heeft eigen pipeline, architectuur moet daarnaast draaien
  378. % VTK interactor
  379. %\chapter{Conclusions}
  380. % TODO
  381. % Windows zijn een manier om globale events toe te wijzen aan vensters
  382. % Trackers zijn een effectieve manier om gebaren te detecteren
  383. % Trackers zijn uitbreidbaar door object-orientatie
  384. \chapter{Suggestions for future work}
  385. % TODO
  386. % Network protocol (ZeroMQ) voor meerdere talen en simultane processen
  387. % Hierij ook: extra laag die gesture windows aanmaakt die corresponderen met window manager
  388. % State machine
  389. % Window in boomstructuur voor efficientie
  390. \bibliographystyle{plain}
  391. \bibliography{report}{}
  392. \appendix
  393. \chapter{The TUIO protocol}
  394. \label{app:tuio}
  395. The TUIO protocol \cite{TUIO} defines a way to geometrically describe tangible
  396. objects, such as fingers or objects on a multi-touch table. Object information
  397. is sent to the TUIO UDP port (3333 by default).
  398. For efficiency reasons, the TUIO protocol is encoded using the Open Sound
  399. Control \cite[OSC]{OSC} format. An OSC server/client implementation is
  400. available for Python: pyOSC \cite{pyOSC}.
  401. A Python implementation of the TUIO protocol also exists: pyTUIO \cite{pyTUIO}.
  402. However, the execution of an example script yields an error regarding Python's
  403. built-in \texttt{socket} library. Therefore, the reference implementation uses
  404. the pyOSC package to receive TUIO messages.
  405. The two most important message types of the protocol are ALIVE and SET
  406. messages. An ALIVE message contains the list of session id's that are currently
  407. ``active'', which in the case of multi-touch a table means that they are
  408. touching the screen. A SET message provides geometric information of a session
  409. id, such as position, velocity and acceleration.
  410. Each session id represents an object. The only type of objects on the
  411. multi-touch table are what the TUIO protocol calls ``2DCur'', which is a (x, y)
  412. position on the screen.
  413. ALIVE messages can be used to determine when an object touches and releases the
  414. screen. For example, if a session id was in the previous message but not in the
  415. current, The object it represents has been lifted from the screen.
  416. SET provide information about movement. In the case of simple (x, y) positions,
  417. only the movement vector of the position itself can be calculated. For more
  418. complex objects such as fiducials, arguments like rotational position is also
  419. included.
  420. ALIVE and SET messages can be combined to create ``point down'', ``point move''
  421. and ``point up'' events (as used by the \cite[.NET application]{win7touch}).
  422. TUIO coordinates range from $0.0$ to $1.0$, with $(0.0, 0.0)$ being the left
  423. top corner of the screen and $(1.0, 1.0)$ the right bottom corner. To focus
  424. events within a window, a translation to window coordinates is required in the
  425. client application, as stated by the online specification
  426. \cite{TUIO_specification}:
  427. \begin{quote}
  428. In order to compute the X and Y coordinates for the 2D profiles a TUIO
  429. tracker implementation needs to divide these values by the actual sensor
  430. dimension, while a TUIO client implementation consequently can scale these
  431. values back to the actual screen dimension.
  432. \end{quote}
  433. \end{document}