report.tex 24 KB

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