report.tex 42 KB

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