report.tex 45 KB

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