report.tex 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. \documentclass[twoside,openright]{uva-bachelor-thesis}
  2. \usepackage[english]{babel}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{hyperref,graphicx,tikz,subfigure,float}
  5. % Link colors
  6. \hypersetup{colorlinks=true,linkcolor=black,urlcolor=blue,citecolor=DarkGreen}
  7. % Title Page
  8. \title{A generic architecture for gesture-based interaction}
  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. Applications that use complex gesture-based interaction need to translate
  17. primitive messages from low-level device drivers to complex, high-level
  18. gestures, and map these gestures to elements in an application. This report
  19. presents a generic architecture for the detection of complex gestures in an
  20. application. The architecture translates device driver messages to a common
  21. set of ``events''. The events are then delegated to a tree of ``event
  22. areas'', which are used to separate groups of events and assign these
  23. groups to an element in the application. Gesture detection is performed on
  24. a group of events assigned to an event area, using detection units called
  25. ``gesture tackers''. An implementation of the architecture as a daemon
  26. process would be capable of serving gestures to multiple applications at
  27. the same time. A reference implementation and two test case applications
  28. have been created to test the effectiveness of the architecture design.
  29. \end{abstract}
  30. % Set paragraph indentation
  31. \parindent 0pt
  32. \parskip 1.5ex plus 0.5ex minus 0.2ex
  33. % Table of content on separate page
  34. \tableofcontents
  35. \chapter{Introduction}
  36. \label{chapter:introduction}
  37. Surface-touch devices have evolved from pen-based tablets to single-touch
  38. trackpads, to multi-touch devices like smartphones and tablets. Multi-touch
  39. devices enable a user to interact with software using hand gestures, making the
  40. interaction more expressive and intuitive. These gestures are more complex than
  41. primitive ``click'' or ``tap'' events that are used by single-touch devices.
  42. Some examples of more complex gestures are ``pinch''\footnote{A ``pinch''
  43. gesture is formed by performing a pinching movement with multiple fingers on a
  44. multi-touch surface. Pinch gestures are often used to zoom in or out on an
  45. object.} and ``flick''\footnote{A ``flick'' gesture is the act of grabbing an
  46. object and throwing it in a direction on a touch surface, giving it momentum to
  47. move for some time after the hand releases the surface.} gestures.
  48. The complexity of gestures is not limited to navigation in smartphones. Some
  49. multi-touch devices are already capable of recognizing objects touching the
  50. screen \cite[Microsoft Surface]{mssurface}. In the near future, touch screens
  51. will possibly be extended or even replaced with in-air interaction (Microsoft's
  52. Kinect \cite{kinect} and the Leap \cite{leap}).
  53. The interaction devices mentioned above generate primitive events. In the case
  54. of surface-touch devices, these are \emph{down}, \emph{move} and \emph{up}
  55. events. Application programmers who want to incorporate complex, intuitive
  56. gestures in their application face the challenge of interpreting these
  57. primitive events as gestures. With the increasing complexity of gestures, the
  58. complexity of the logic required to detect these gestures increases as well.
  59. This challenge limits, or even deters the application developer to use complex
  60. gestures in an application.
  61. The main question in this research project is whether a generic architecture
  62. for the detection of complex interaction gestures can be designed, with the
  63. capability of managing the complexity of gesture detection logic. The ultimate
  64. goal would be to create an implementation of this architecture that can be
  65. extended to support a wide range of complex gestures. With the existence of
  66. such an implementation, application developers do not need to reinvent gesture
  67. detection for every new gesture-based application.
  68. \section{Structure of this document}
  69. The scope of this thesis is limited to the detection of gestures on
  70. multi-touch surface devices. It presents a design for a generic gesture
  71. detection architecture for use in multi-touch based applications. A
  72. reference implementation of this design is used in some test case
  73. applications, whose goal is to test the effectiveness of the design and
  74. detect its shortcomings.
  75. Chapter \ref{chapter:related} describes related work that inspired a design
  76. for the architecture. The design is presented in chapter
  77. \ref{chapter:design}. Sections \ref{sec:multipledrivers} to
  78. \ref{sec:daemon} define requirements for the architecture, and introduce
  79. architecture components that meet these requirements. Section
  80. \ref{sec:example} then shows the use of the architecture in an example
  81. application. Chapter \ref{chapter:testapps} presents a reference
  82. implementation of the architecture, an two test case applications that show
  83. the practical use of its components as presented in chapter
  84. \ref{chapter:design}. Finally, some suggestions for future research on the
  85. subject are given in chapter \ref{chapter:futurework}.
  86. \chapter{Related work}
  87. \label{chapter:related}
  88. % TODO: herstructureren
  89. \section{Existing application frameworks}
  90. Application frameworks for surface-touch devices, such as Nokia's Qt
  91. \cite{qt}, do already include the detection of commonly used gestures like
  92. \emph{pinch} gestures. However, this detection logic is dependent on the
  93. application framework. Consequently, an application developer who wants to
  94. use multi-touch interaction in an application is forced to use an
  95. application framework that includes support for multi-touch gestures.
  96. Moreover, the set of supported gestures is limited by the application
  97. framework of choice. To incorporate a custom event in an application, the
  98. application developer needs to extend the framework. This requires
  99. extensive knowledge of the framework's architecture. Also, if the same
  100. gesture is needed in another application that is based on another
  101. framework, the detection logic has to be translated for use in that
  102. framework.
  103. \section{Gesture and Activity Recognition Toolkit}
  104. The Gesture and Activity Recognition Toolkit (GART) \cite{GART} is a
  105. toolkit for the development of gesture-based applications. The toolkit
  106. states that the best way to classify gestures is to use machine learning.
  107. The programmer trains a program to recognize using the machine learning
  108. library from the toolkit. The toolkit contains a callback mechanism that
  109. the programmer uses to execute custom code when a gesture is recognized.
  110. Though multi-touch input is not directly supported by the toolkit, the
  111. level of abstraction does allow for it to be implemented in the form of a
  112. ``touch'' sensor.
  113. The reason to use machine learning is the statement that gesture detection
  114. ``is likely to become increasingly complex and unmanageable'' when using a
  115. set of predefined rules to detect whether some sensor input can be seen as
  116. a specific gesture. This statement is not necessarily true. If the
  117. programmer is given a way to separate the detection of different types of
  118. gestures and flexibility in rule definitions, over-complexity can be
  119. avoided.
  120. \section{Gesture recognition implementation for Windows 7}
  121. The online article \cite{win7touch} presents a Windows 7 application,
  122. written in Microsofts .NET. The application shows detected gestures in a
  123. canvas. Gesture trackers keep track of stylus locations to detect specific
  124. gestures. The event types required to track a touch stylus are ``stylus
  125. down'', ``stylus move'' and ``stylus up'' events. A
  126. \texttt{GestureTrackerManager} object dispatches these events to gesture
  127. trackers. The application supports a limited number of pre-defined
  128. gestures.
  129. An important observation in this application is that different gestures are
  130. detected by different gesture trackers, thus separating gesture detection
  131. code into maintainable parts.
  132. \section{Analysis of related work}
  133. The simple Processing implementation of multi-touch events provides most of
  134. the functionality that can be found in existing multi-touch applications.
  135. In fact, many applications for mobile phones and tablets only use tap and
  136. scroll events. For this category of applications, using machine learning
  137. seems excessive. Though the representation of a gesture using a feature
  138. vector in a machine learning algorithm is a generic and formal way to
  139. define a gesture, a programmer-friendly architecture should also support
  140. simple, ``hard-coded'' detection code. A way to separate different pieces
  141. of gesture detection code, thus keeping a code library manageable and
  142. extendable, is to user different gesture trackers.
  143. \chapter{Design}
  144. \label{chapter:design}
  145. % Diagrams are defined in a separate file
  146. \input{data/diagrams}
  147. \section{Introduction}
  148. Application frameworks are a necessity when it comes to fast,
  149. cross-platform development. A generic architecture design should aim to be
  150. compatible with existing frameworks, and provide a way to detect and extend
  151. gestures independent of the framework. An application framework is written
  152. in a specific programming language. To support multiple frameworks and
  153. programming languages, the architecture should be accessible for
  154. applications using a language-independent method of communication. This
  155. intention leads towards the concept of a dedicated gesture detection
  156. application that serves gestures to multiple applications at the same time.
  157. This chapter describes a design for such an architecture. The architecture
  158. is represented as diagram of relations between different components.
  159. Sections \ref{sec:multipledrivers} to \ref{sec:daemon} define requirements
  160. for the architecture, and extend the diagram with components that meet
  161. these requirements. Section \ref{sec:example} describes an example usage of
  162. the architecture in an application.
  163. The input of the architecture comes from a multi-touch device driver.
  164. The task of the architecture is to translate this input to multi-touch
  165. gestures that are used by an application, as illustrated in figure
  166. \ref{fig:basicdiagram}. In the course of this chapter, the diagram is
  167. extended with the different components of the architecture.
  168. \basicdiagram
  169. \section{Supporting multiple drivers}
  170. \label{sec:multipledrivers}
  171. The TUIO protocol \cite{TUIO} is an example of a driver that can be used by
  172. multi-touch devices. TUIO uses ALIVE- and SET-messages to communicate
  173. low-level touch events (see appendix \ref{app:tuio} for more details).
  174. These messages are specific to the API of the TUIO protocol. Other drivers
  175. may use different messages types. To support more than one driver in the
  176. architecture, there must be some translation from driver-specific messages
  177. to a common format for primitive touch events. After all, the gesture
  178. detection logic in a ``generic'' architecture should not be implemented
  179. based on driver-specific messages. The event types in this format should be
  180. chosen so that multiple drivers can trigger the same events. If each
  181. supported driver would add its own set of event types to the common format,
  182. the purpose of it being ``common'' would be defeated.
  183. A minimal expectation for a touch device driver is that it detects simple
  184. touch points, with a ``point'' being an object at an $(x, y)$ position on
  185. the touch surface. This yields a basic set of events: $\{point\_down,
  186. point\_move, point\_up\}$.
  187. The TUIO protocol supports fiducials\footnote{A fiducial is a pattern used
  188. by some touch devices to identify objects.}, which also have a rotational
  189. property. This results in a more extended set: $\{point\_down, point\_move,
  190. point\_up, object\_down, object\_move, object\_up,\\ object\_rotate\}$.
  191. Due to their generic nature, the use of these events is not limited to the
  192. TUIO protocol. Another driver that can keep apart rotated objects from
  193. simple touch points could also trigger them.
  194. The component that translates driver-specific messages to common events,
  195. will be called the \emph{event driver}. The event driver runs in a loop,
  196. receiving and analyzing driver messages. When a sequence of messages is
  197. analyzed as an event, the event driver delegates the event to other
  198. components in the architecture for translation to gestures. This
  199. communication flow is illustrated in figure \ref{fig:driverdiagram}.
  200. \driverdiagram
  201. Support for a touch driver can be added by adding an event driver
  202. implementation. The choice of event driver implementation that is used in an
  203. application is dependent on the driver support of the touch device being
  204. used.
  205. Because driver implementations have a common output format in the form of
  206. events, multiple event drivers can run at the same time (see figure
  207. \ref{fig:multipledrivers}). This design feature allows low-level events
  208. from multiple devices to be aggregated into high-level gestures.
  209. \multipledriversdiagram
  210. \section{Restricting events to a screen area}
  211. \label{sec:areas}
  212. % TODO: in introduction: gestures zijn opgebouwd uit meerdere primitieven
  213. Touch input devices are unaware of the graphical input
  214. widgets\footnote{``Widget'' is a name commonly used to identify an element
  215. of a graphical user interface (GUI).} rendered by an application, and
  216. therefore generate events that simply identify the screen location at which
  217. an event takes place. User interfaces of applications that do not run in
  218. full screen modus are contained in a window. Events which occur outside the
  219. application window should not be handled by the program in most cases.
  220. What's more, widget within the application window itself should be able to
  221. respond to different gestures. E.g. a button widget may respond to a
  222. ``tap'' gesture to be activated, whereas the application window responds to
  223. a ``pinch'' gesture to be resized. In order to be able to direct a gesture
  224. to a particular widget in an application, a gesture must be restricted to
  225. the area of the screen covered by that widget. An important question is if
  226. the architecture should offer a solution to this problem, or leave the task
  227. of assigning gestures to application widgets to the application developer.
  228. If the architecture does not provide a solution, the ``Event analysis''
  229. component in figure \ref{fig:multipledrivers} receives all events that
  230. occur on the screen surface. The gesture detection logic thus uses all
  231. events as input to detect a gesture. This leaves no possibility for a
  232. gesture to occur at multiple screen positions at the same time. The problem
  233. is illustrated in figure \ref{fig:ex1}, where two widgets on the screen can
  234. be rotated independently. The rotation detection component that detects
  235. rotation gestures receives all four fingers as input. If the two groups of
  236. finger events are not separated by cluster detection, only one rotation
  237. event will occur.
  238. \examplefigureone
  239. A gesture detection component could perform a heuristic way of cluster
  240. detection based on the distance between events. However, this method cannot
  241. guarantee that a cluster of events corresponds with a particular
  242. application widget. In short, a gesture detection component is difficult to
  243. implement without awareness of the location of application widgets.
  244. Secondly, the application developer still needs to direct gestures to a
  245. particular widget manually. This requires geometric calculations in the
  246. application logic, which is a tedious and error-prone task for the
  247. developer.
  248. A better solution is to group events that occur inside the area covered by
  249. a widget, before passing them on to a gesture detection component.
  250. Different gesture detection components can then detect gestures
  251. simultaneously, based on different sets of input events. An area of the
  252. screen surface will be represented by an \emph{event area}. An event area
  253. filters input events based on their location, and then delegates events to
  254. gesture detection components that are assigned to the event area. Events
  255. which are located outside the event area are not delegated to its gesture
  256. detection components.
  257. In the example of figure \ref{fig:ex1}, the two rotatable widgets can be
  258. represented by two event areas, each having a different rotation detection
  259. component.
  260. \subsection*{Callback mechanism}
  261. When a gesture is detected by a gesture detection component, it must be
  262. handled by the client application. A common way to handle events in an
  263. application is a ``callback'' mechanism: the application developer binds a
  264. function to an event, that is called when the event occurs. Because of the
  265. familiarity of this concept with developers, the architecture uses a
  266. callback mechanism to handle gestures in an application. Callback handlers
  267. are bound to event areas, since events areas controls the grouping of
  268. events and thus the occurrence of gestures in an area of the screen.
  269. Figure \ref{fig:areadiagram} shows the position of areas in the
  270. architecture.
  271. \areadiagram
  272. %Note that the boundaries of an area are only used to group events, not
  273. %gestures. A gesture could occur outside the area that contains its
  274. %originating events, as illustrated by the example in figure \ref{fig:ex2}.
  275. %\examplefiguretwo
  276. A remark must be made about the use of event areas to assign events to the
  277. detection of some gesture. The concept of an event area is based on the
  278. assumption that the set or originating events that form a particular
  279. gesture, can be determined based exclusively on the location of the events.
  280. This is a reasonable assumption for simple touch objects whose only
  281. parameter is a position, such as a pen or a human finger. However, more
  282. complex touch objects can have additional parameters, such as rotational
  283. orientation or color. An even more generic concept is the \emph{event
  284. filter}, which detects whether an event should be assigned to a particular
  285. gesture detection component based on all available parameters. This level
  286. of abstraction provides additional methods of interaction. For example, a
  287. camera-based multi-touch surface could make a distinction between gestures
  288. performed with a blue gloved hand, and gestures performed with a green
  289. gloved hand.
  290. As mentioned in the introduction chapter [\ref{chapter:introduction}], the
  291. scope of this thesis is limited to multi-touch surface based devices, for
  292. which the \emph{event area} concept suffices. Section \ref{sec:eventfilter}
  293. explores the possibility of event areas to be replaced with event filters.
  294. \subsection{Area tree}
  295. \label{sec:tree}
  296. The most simple usage of event areas in the architecture would be a list of
  297. event areas. When the event driver delegates an event, it is accepted by
  298. each event area that contains the event coordinates.
  299. If the architecture were to be used in combination with an application
  300. framework like GTK \cite{GTK}, each GTK widget that responds to gestures
  301. should have a mirroring event area that synchronizes its location with that
  302. of the widget. Consider a panel with five buttons that all listen to a
  303. ``tap'' event. If the location of the panel changes as a result of movement
  304. of the application window, the positions of all buttons have to be updated
  305. too.
  306. This process is simplified by the arrangement of event areas in a tree
  307. structure. A root event area represents the panel, containing five other
  308. event areas which are positioned relative to the root area. The relative
  309. positions do not need to be updated when the panel area changes its
  310. position. GUI frameworks, like GTK, use this kind of tree structure to
  311. manage graphical widgets.
  312. If the GUI toolkit provides an API for requesting the position and size of
  313. a widget, a recommended first step when developing an application is to
  314. create some subclass of the area that automatically synchronizes with the
  315. position of a widget from the GUI framework.
  316. \subsection{Event propagation}
  317. \label{sec:eventpropagation}
  318. Another problem occurs when event areas overlap, as shown by figure
  319. \ref{fig:eventpropagation}. When the white square is rotated, the gray
  320. square should keep its current orientation. This means that events that are
  321. used for rotation of the white square, should not be used for rotation of
  322. the gray square. The use of event areas alone does not provide a solution
  323. here, since both the gray and the white event area accept an event that
  324. occurs within the white square.
  325. The problem described above is a common problem in GUI applications, and
  326. there is a common solution (used by GTK \cite{gtkeventpropagation}, among
  327. others). An event is passed to an ``event handler''. If the handler returns
  328. \texttt{true}, the event is considered ``handled'' and is not
  329. ``propagated'' to other widgets.
  330. Applied to the example of the rotating squares, the rotation detection
  331. component of the white square should stop the propagation of events to the
  332. event area of the gray square. This is illustrated in figure
  333. \ref{fig:eventpropagation}.
  334. In the example, rotation of the white square has priority over rotation of
  335. the gray square because the white area is the widget actually being touched
  336. at the screen surface. In general, events should be delegated to event
  337. areas according to the order in which the event areas are positioned over
  338. each other. The tree structure in which event areas are arranged, is an
  339. ideal tool to determine the order in which an event is delegated. Event
  340. areas in deeper layers of the tree are positioned on top of their parent.
  341. An object touching the screen is essentially touching the deepest event
  342. area in the tree that contains the triggered event. That event area should
  343. be the first to delegate the event to its gesture detection components, and
  344. then propagate the event up in the tree to its ancestors. A gesture
  345. detection component can stop the propagation of the event.
  346. An additional type of event propagation is ``immediate propagation'', which
  347. indicates propagation of an event from one gesture detection component to
  348. another. This is applicable when an event area uses more than one gesture
  349. detection component. One of the components can stop the immediate
  350. propagation of an event, so that the event is not passed to the next
  351. gesture detection component, nor to the ancestors of the event area.
  352. When regular propagation is stopped, the event is propagated to other
  353. gesture detection components first, before actually being stopped.
  354. \eventpropagationfigure
  355. \newpage
  356. \section{Detecting gestures from events}
  357. \label{sec:gesture-detection}
  358. The low-level events that are grouped by an event area must be translated
  359. to high-level gestures in some way. Simple gestures, such as a tap or the
  360. dragging of an element using one finger, are easy to detect by comparing
  361. the positions of sequential $point\_down$ and $point\_move$ events. More
  362. complex gestures, like the writing of a character from the alphabet,
  363. require more advanced detection algorithms.
  364. A way to detect these complex gestures based on a sequence of input events,
  365. is with the use of machine learning methods, such as the Hidden Markov
  366. Models \footnote{A Hidden Markov Model (HMM) is a statistical model without
  367. a memory, it can be used to detect gestures based on the current input
  368. state alone.} used for sign language detection by
  369. \cite{conf/gw/RigollKE97}. A sequence of input states can be mapped to a
  370. feature vector that is recognized as a particular gesture with a certain
  371. probability. An advantage of using machine learning with respect to an
  372. imperative programming style is that complex gestures can be described
  373. without the use of explicit detection logic. For example, the detection of
  374. the character `A' being written on the screen is difficult to implement
  375. using an imperative programming style, while a trained machine learning
  376. system can produce a match with relative ease.
  377. Sequences of events that are triggered by a multi-touch based surfaces are
  378. often of a manageable complexity. An imperative programming style is
  379. sufficient to detect many common gestures, like rotation and dragging. The
  380. imperative programming style is also familiar and understandable for a wide
  381. range of application developers. Therefore, the architecture should support
  382. an imperative style of gesture detection. A problem with an imperative
  383. programming style is that the explicit detection of different gestures
  384. requires different gesture detection components. If these components are
  385. not managed well, the detection logic is prone to become chaotic and
  386. over-complex.
  387. To manage complexity and support multiple styles of gesture detection
  388. logic, the architecture has adopted the tracker-based design as described
  389. by \cite{win7touch}. Different detection components are wrapped in separate
  390. gesture tracking units, or \emph{gesture trackers}. The input of a gesture
  391. tracker is provided by an event area in the form of events. Each gesture
  392. detection component is wrapped in a gesture tracker with a fixed type of
  393. input and output. Internally, the gesture tracker can adopt any programming
  394. style. A character recognition component can use an HMM, whereas a tap
  395. detection component defines a simple function that compares event
  396. coordinates.
  397. \trackerdiagram
  398. When a gesture tracker detects a gesture, this gesture is triggered in the
  399. corresponding event area. The event area then calls the callbacks which are
  400. bound to the gesture type by the application. Figure
  401. \ref{fig:trackerdiagram} shows the position of gesture trackers in the
  402. architecture.
  403. The use of gesture trackers as small detection units provides extendability
  404. of the architecture. A developer can write a custom gesture tracker and
  405. register it in the architecture. The tracker can use any type of detection
  406. logic internally, as long as it translates events to gestures.
  407. An example of a possible gesture tracker implementation is a
  408. ``transformation tracker'' that detects rotation, scaling and translation
  409. gestures.
  410. \section{Serving multiple applications}
  411. \label{sec:daemon}
  412. The design of the architecture is essentially complete with the components
  413. specified in this chapter. However, one specification has not yet been
  414. discussed: the ability to address the architecture using a method of
  415. communication independent of the application's programming language.
  416. If the architecture and a gesture-based application are written in the same
  417. language, the main loop of the architecture can run in a separate thread of
  418. the application. If the application is written in a different language, the
  419. architecture has to run in a separate process. Since the application needs
  420. to respond to gestures that are triggered by the architecture, there must
  421. be a communication layer between the separate processes.
  422. A common and efficient way of communication between two separate processes
  423. is through the use of a network protocol. In this particular case, the
  424. architecture can run as a daemon\footnote{``daemon'' is a name Unix uses to
  425. indicate that a process runs as a background process.} process, listening
  426. to driver messages and triggering gestures in registered applications.
  427. \vspace{-0.3em}
  428. \daemondiagram
  429. An advantage of a daemon setup is that it can serve multiple applications
  430. at the same time. Alternatively, each application that uses gesture
  431. interaction would start its own instance of the architecture in a separate
  432. process, which would be less efficient.
  433. \section{Example usage}
  434. \label{sec:example}
  435. This section describes an extended example to illustrate the data flow of
  436. the architecture. The example application listens to tap events on a button
  437. within an application window. The window also contains a draggable circle.
  438. The application window can be resized using \emph{pinch} gestures. Figure
  439. \ref{fig:examplediagram} shows the architecture created by the pseudo code
  440. below.
  441. \begin{verbatim}
  442. initialize GUI framework, creating a window and nessecary GUI widgets
  443. create a root event area that synchronizes position and size with the application window
  444. define 'rotation' gesture handler and bind it to the root event area
  445. create an event area with the position and radius of the circle
  446. define 'drag' gesture handler and bind it to the circle event area
  447. create an event area with the position and size of the button
  448. define 'tap' gesture handler and bind it to the button event area
  449. create a new event server and assign the created root event area to it
  450. start the event server in a new thread
  451. start the GUI main loop in the current thread
  452. \end{verbatim}
  453. \examplediagram
  454. \chapter{Test applications}
  455. \label{chapter:testapps}
  456. A reference implementation of the design has been written in Python. Two test
  457. applications have been created to test if the design ``works'' in a practical
  458. application, and to detect its flaws. One application is mainly used to test
  459. the gesture tracker implementations. The other program uses multiple event
  460. areas in a tree structure, demonstrating event delegation and propagation.
  461. To test multi-touch interaction properly, a multi-touch device is required. The
  462. University of Amsterdam (UvA) has provided access to a multi-touch table from
  463. PQlabs. The table uses the TUIO protocol \cite{TUIO} to communicate touch
  464. events. See appendix \ref{app:tuio} for details regarding the TUIO protocol.
  465. %The reference implementation and its test applications are a Proof of Concept,
  466. %meant to show that the architecture design is effective.
  467. %that translates TUIO messages to some common multi-touch gestures.
  468. \section{Reference implementation}
  469. \label{sec:implementation}
  470. The reference implementation is written in Python and available at
  471. \cite{gitrepos}. The following component implementations are included:
  472. \textbf{Event drivers}
  473. \begin{itemize}
  474. \item TUIO driver, using only the support for simple touch points with an
  475. $(x, y)$ position.
  476. \end{itemize}
  477. \textbf{Gesture trackers}
  478. \begin{itemize}
  479. \item Basic tracker, supports $point\_down,~point\_move,~point\_up$ gestures.
  480. \item Tap tracker, supports $tap,~single\_tap,~double\_tap$ gestures.
  481. \item Transformation tracker, supports $rotate,~pinch,~drag$ gestures.
  482. \end{itemize}
  483. \textbf{Event areas}
  484. \begin{itemize}
  485. \item Circular area
  486. \item Rectangular area
  487. \item Full screen area
  488. \end{itemize}
  489. The implementation does not include a network protocol to support the daemon
  490. setup as described in section \ref{sec:daemon}. Therefore, it is only usable in
  491. Python programs. Thus, the two test programs are also written in Python.
  492. The event area implementations contain some geometric functions to determine
  493. whether an event should be delegated to an event area. All gesture trackers
  494. have been implemented using an imperative programming style. Technical details
  495. about the implementation of gesture detection are described in appendix
  496. \ref{app:implementation-details}.
  497. \section{Full screen Pygame program}
  498. %The goal of this program was to experiment with the TUIO
  499. %protocol, and to discover requirements for the architecture that was to be
  500. %designed. When the architecture design was completed, the program was rewritten
  501. %using the new architecture components. The original variant is still available
  502. %in the ``experimental'' folder of the Git repository \cite{gitrepos}.
  503. An implementation of the detection of some simple multi-touch gestures (single
  504. tap, double tap, rotation, pinch and drag) using Processing\footnote{Processing
  505. is a Java-based programming environment with an export possibility for Android.
  506. See also \cite{processing}.} can be found in a forum on the Processing website
  507. \cite{processingMT}. The program has been ported to Python and adapted to
  508. receive input from the TUIO protocol. The implementation is fairly simple, but
  509. it yields some appealing results (see figure \ref{fig:draw}). In the original
  510. program, the detection logic of all gestures is combined in a single class
  511. file. As predicted by the GART article \cite{GART}, this leads to over-complex
  512. code that is difficult to read and debug.
  513. The application has been rewritten using the reference implementation of the
  514. architecture. The detection code is separated into two different gesture
  515. trackers, which are the ``tap'' and ``transformation'' trackers mentioned in
  516. section \ref{sec:implementation}.
  517. The application receives TUIO events and translates them to \emph{point\_down},
  518. \emph{point\_move} and \emph{point\_up} events. These events are then
  519. interpreted to be \emph{single tap}, \emph{double tap}, \emph{rotation} or
  520. \emph{pinch} gestures. The positions of all touch objects are drawn using the
  521. Pygame library. Since the Pygame library does not provide support to find the
  522. location of the display window, the root event area captures events in the
  523. entire screens surface. The application can be run either full screen or in
  524. windowed mode. If windowed, screen-wide gesture coordinates are mapped to the
  525. size of the Pyame window. In other words, the Pygame window always represents
  526. the entire touch surface. The output of the program can be seen in figure
  527. \ref{fig:draw}.
  528. \begin{figure}[h!]
  529. \center
  530. \includegraphics[scale=0.4]{data/pygame_draw.png}
  531. \caption{Output of the experimental drawing program. It draws all touch
  532. points and their centroid on the screen (the centroid is used for rotation
  533. and pinch detection). It also draws a green rectangle which
  534. \label{fig:draw}
  535. responds to rotation and pinch events.}
  536. \end{figure}
  537. \section{GTK/Cairo program}
  538. The second test application uses the GIMP toolkit (GTK+) \cite{GTK} to create
  539. its user interface. Since GTK+ defines a main event loop that is started in
  540. order to use the interface, the architecture implementation runs in a separate
  541. thread. The application creates a main window, whose size and position are
  542. synchronized with the root event area of the architecture.
  543. % TODO
  544. \emph{TODO: uitbreiden en screenshots erbij (dit programma is nog niet af)}
  545. \section{Discussion}
  546. % TODO
  547. \emph{TODO: Tekortkomingen aangeven die naar voren komen uit de tests}
  548. % Verschillende apparaten/drivers geven een ander soort primitieve events af.
  549. % Een vertaling van deze device-specifieke events naar een algemeen formaat van
  550. % events is nodig om gesture detection op een generieke manier te doen.
  551. % Door input van meerdere drivers door dezelfde event driver heen te laten gaan
  552. % is er ondersteuning voor meerdere apparaten tegelijkertijd.
  553. % Event driver levert low-level events. niet elke event hoort bij elke gesture,
  554. % dus moet er een filtering plaatsvinden van welke events bij welke gesture
  555. % horen. Areas geven de mogelijkheid hiervoor op apparaten waarvan het
  556. % filteren locatiegebonden is.
  557. % Het opsplitsten van gesture detection voor gesture trackers is een manier om
  558. % flexibel te zijn in ondersteunde types detection logic, en het beheersbaar
  559. % houden van complexiteit.
  560. \chapter{Suggestions for future work}
  561. \label{chapter:futurework}
  562. \section{A generic method for grouping events}
  563. \label{sec:eventfilter}
  564. As mentioned in section \ref{sec:areas}, the concept of an event area is based
  565. on the assumption that the set or originating events that form a particular
  566. gesture, can be determined based exclusively on the location of the events.
  567. Since this thesis focuses on multi-touch surface based devices, and every
  568. object on a multi-touch surface has a position, this assumption is valid.
  569. However, the design of the architecture is meant to be more generic; to provide
  570. a structured design of managing gesture detection.
  571. An in-air gesture detection device, such as the Microsoft Kinect \cite{kinect},
  572. provides 3D positions. Some multi-touch tables work with a camera that can also
  573. determine the shape and rotational orientation of objects touching the surface.
  574. For these devices, events delegated by the event driver have more parameters
  575. than a 2D position alone. The term ``area'' is not suitable to describe a group
  576. of events that consist of these parameters.
  577. A more generic term for a component that groups similar events is the
  578. \emph{event filter}. The concept of an event filter is based on the same
  579. principle as event areas, which is the assumption that gestures are formed from
  580. a subset of all events. However, an event filter takes all parameters of an
  581. event into account. An application on the camera-based multi-touch table could
  582. be to group all objects that are triangular into one filter, and all
  583. rectangular objects into another. Or, to separate small finger tips from large
  584. ones to be able to recognize whether a child or an adult touches the table.
  585. \section{Using a state machine for gesture detection}
  586. All gesture trackers in the reference implementation are based on the explicit
  587. analysis of events. Gesture detection is a widely researched subject, and the
  588. separation of detection logic into different trackers allows for multiple types
  589. of gesture detection in the same architecture. An interesting question is
  590. whether multi-touch gestures can be described in a formal way so that explicit
  591. detection code can be avoided.
  592. \cite{GART} and \cite{conf/gw/RigollKE97} propose the use of machine learning
  593. to recognizes gestures. To use machine learning, a set of input events forming
  594. a particular gesture must be represented as a feature vector. A learning set
  595. containing a set of feature vectors that represent some gesture ``teaches'' the
  596. machine what the feature of the gesture looks like.
  597. An advantage of using explicit gesture detection code is the fact that it
  598. provides a flexible way to specify the characteristics of a gesture, whereas
  599. the performance of feature vector-based machine learning is dependent on the
  600. quality of the learning set.
  601. A better method to describe a gesture might be to specify its features as a
  602. ``signature''. The parameters of such a signature must be be based on input
  603. events. When a set of input events matches the signature of some gesture, the
  604. gesture is be triggered. A gesture signature should be a complete description
  605. of all requirements the set of events must meet to form the gesture.
  606. A way to describe signatures on a multi-touch surface can be by the use of a
  607. state machine of its touch objects. The states of a simple touch point could be
  608. ${down, move, up, hold}$ to indicate respectively that a point is put down, is
  609. being moved, is held on a position for some time, and is released. In this
  610. case, a ``drag'' gesture can be described by the sequence $down - move - up$
  611. and a ``select'' gesture by the sequence $down - hold$. If the set of states is
  612. not sufficient to describe a desired gesture, a developer can add additional
  613. states. For example, to be able to make a distinction between an element being
  614. ``dragged'' or ``thrown'' in some direction on the screen, two additional
  615. states can be added: ${start, stop}$ to indicate that a point starts and stops
  616. moving. The resulting state transitions are sequences $down - start - move -
  617. stop - up$ and $down - start - move - up$ (the latter does not include a $stop$
  618. to indicate that the element must keep moving after the gesture had been
  619. performed).
  620. An additional way to describe even more complex gestures is to use other
  621. gestures in a signature. An example is to combine $select - drag$ to specify
  622. that an element must be selected before it can be dragged.
  623. The application of a state machine to describe multi-touch gestures is an
  624. subject well worth exploring in the future.
  625. \section{Daemon implementation}
  626. Section \ref{sec:daemon} proposes the usage of a network protocol to
  627. communicate between an architecture implementation and (multiple) gesture-based
  628. applications, as illustrated in figure \ref{fig:daemon}. The reference
  629. implementation does not support network communication. If the architecture
  630. design is to become successful in the future, the implementation of network
  631. communication is a must. ZeroMQ (or $\emptyset$MQ) \cite{ZeroMQ} is a
  632. high-performance software library with support for a wide range of programming
  633. languages. A good basis for a future implementation could use this library as
  634. the basis for its communication layer.
  635. If an implementation of the architecture will be released, a good idea would be
  636. to do so within a community of application developers. A community can
  637. contribute to a central database of gesture trackers, making the interaction
  638. from their applications available for use other applications.
  639. Ideally, a user can install a daemon process containing the architecture so
  640. that it is usable for any gesture-based application on the device. Applications
  641. that use the architecture can specify it as being a software dependency, or
  642. include it in a software distribution.
  643. \bibliographystyle{plain}
  644. \bibliography{report}{}
  645. \appendix
  646. \chapter{The TUIO protocol}
  647. \label{app:tuio}
  648. The TUIO protocol \cite{TUIO} defines a way to geometrically describe tangible
  649. objects, such as fingers or objects on a multi-touch table. Object information
  650. is sent to the TUIO UDP port (3333 by default).
  651. For efficiency reasons, the TUIO protocol is encoded using the Open Sound
  652. Control \cite[OSC]{OSC} format. An OSC server/client implementation is
  653. available for Python: pyOSC \cite{pyOSC}.
  654. A Python implementation of the TUIO protocol also exists: pyTUIO \cite{pyTUIO}.
  655. However, the execution of an example script yields an error regarding Python's
  656. built-in \texttt{socket} library. Therefore, the reference implementation uses
  657. the pyOSC package to receive TUIO messages.
  658. The two most important message types of the protocol are ALIVE and SET
  659. messages. An ALIVE message contains the list of session id's that are currently
  660. ``active'', which in the case of multi-touch a table means that they are
  661. touching the screen. A SET message provides geometric information of a session
  662. id, such as position, velocity and acceleration.
  663. Each session id represents an object. The only type of objects on the
  664. multi-touch table are what the TUIO protocol calls ``2DCur'', which is a (x, y)
  665. position on the screen.
  666. ALIVE messages can be used to determine when an object touches and releases the
  667. screen. For example, if a session id was in the previous message but not in the
  668. current, The object it represents has been lifted from the screen.
  669. SET provide information about movement. In the case of simple (x, y) positions,
  670. only the movement vector of the position itself can be calculated. For more
  671. complex objects such as fiducials, arguments like rotational position and
  672. acceleration are also included.
  673. ALIVE and SET messages can be combined to create ``point down'', ``point move''
  674. and ``point up'' events (as used by the Windows 7 implementation
  675. \cite{win7touch}).
  676. TUIO coordinates range from $0.0$ to $1.0$, with $(0.0, 0.0)$ being the left
  677. top corner of the screen and $(1.0, 1.0)$ the right bottom corner. To focus
  678. events within a window, a translation to window coordinates is required in the
  679. client application, as stated by the online specification
  680. \cite{TUIO_specification}:
  681. \begin{quote}
  682. In order to compute the X and Y coordinates for the 2D profiles a TUIO
  683. tracker implementation needs to divide these values by the actual sensor
  684. dimension, while a TUIO client implementation consequently can scale these
  685. values back to the actual screen dimension.
  686. \end{quote}
  687. \chapter{Gesture detection in the reference implementation}
  688. \label{app:implementation-details}
  689. Both rotation and pinch use the centroid of all touch points. A \emph{rotation}
  690. gesture uses the difference in angle relative to the centroid of all touch
  691. points, and \emph{pinch} uses the difference in distance. Both values are
  692. normalized using division by the number of touch points. A pinch event contains
  693. a scale factor, and therefore uses a division of the current by the previous
  694. average distance to the centroid.
  695. % TODO
  696. \emph{TODO: rotatie en pinch gaan iets anders/uitgebreider worden beschreven.}
  697. \end{document}