1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

TUIO

Description

fiducial_exampleThe TUIO library is able to receive and parse data following the TUIO protocol by the Music Technology Group, "which was specially designed for transmitting the state of tangible objects and multi-touch control on a table surface."

Download

downloadtuio.zip (8.1KB)
Version: 0.1 (initial release)
Licensed under the MIT License
Author: Jannis Leidel

 

Sample fiducial (Nr. 10)

Installation

In order to use this library you need to have the cross-plattform reacTIVision application that does the heavy lifting of tracking the tangible objects, so-called fiducials. It transmits the received data (e.g. positional information) as OSC messages via an UDP socket to your client software which uses this library.

Documentation

Basic use

To use this library in general you should follow these steps:

1. Get a camera or webcam, like iSight, Quickcam, etc., install its drivers if necessary, try it with the reacTIVision software. Print the fiducials to attach them to objects.

2. Look at the examples to get started.

3. Build the tangible interface, table, stage, vehicle, game, whatever.

4. Combine it with Blender, Pygame or Nodebox

5. Use the source, Luke.

The Tracking class

The Tracking class should be used to initialize a socket connection for receiving the OSC messages from reacTIVision. It handles all incoming data and calls the appropriate functions, depending on the type of message.

When started it loads every possible profile from the profiles submodule and initializes a callback manager from the OSC module.

A simple example can be found in the examples directory in example1.py:

1. Import it:

tuio = ximport("tuio")

2. Setup the tracking program:

def setup():
    global tracking
    tracking = tuio.Tracking()

3. Setup the main loop and draw all recognized object and rotate them accordingly:

def draw():
    global tracking
    tracking.update()
    fontsize(10)
    for obj in tracking.objects():
        x = obj.xpos * WIDTH
        y = obj.ypos * HEIGHT
        rotate(obj.angle)
        rect(x, y, 20, 20)
        reset()
        text(obj, x, y)

a) You need to update the tracking information on each loop manually.

b) Access the tracked objects by using one of the helper function that return a list of these objects.

c) Stop the tracking manually on every exception to prevent socket errors

4. Stop the tracking when Nodebox stops the program.

def stop():
    global tracking
    tracking.stop()

While holding two fiducials in front of the camera the visual output of this script was, for example:

tuio_objects

The described script can also be found in the distribution of pyTUIO.

The objects submodule

The objects submodule contains a series of classes that represent types of tangible objects. They all are subclasses of the also included objects.TuioObject. The following object types are defined at the moment:

Tuio2DCursor - An abstract cursor object, e.g. a finger. This object has limited information and is only sent by reacTIVision if the smallest possible fiducial marker was found: a point. In combination with a tangible table this can also be achieved by using fingers on the table surface.

It has the following attributes:

  • sessionid - The unique sessionid it belongs to
  • xpos - The relative position on the x-axis
  • ypos - The relative position on the y-axis
  • xmot - The movement vector on the x-axis
  • ymot - The movement vector on the y-axis
  • mot_accel - The motion acceleration

Tuio2DObject - An abstract object representing a fiducial. This object has detailed information about its state and is sent by reacTIVision if a fiducial was recognized.

It has the following attributes:

  • sessionid - The unique sessionid it belongs to
  • xpos - The relative position on the x-axis
  • ypos - The relative position on the y-axis
  • angle - The current angle in degrees
  • xmot - The movement vector on the x-axis
  • ymot - The movement vector on the y-axis
  • rot_vector - The rotation vector
  • mot_accel - The motion acceleration
  • rot_accel - The rotation acceleration

The TUIO protocol provides even more possible object types, depending on the purpose of the intactive surface, e.g.:

  • 2.5D Interactive Surface - Tuio25DCursor and Tuio25DObject
  • 3D Interactive Surface - Tuio3DCursor and Tuio3DObject
  • raw profile - at the moment only dtouch specs are supported

But these profiles are left to be implemented by the user. Just have a look in objects.py and profiles.py and subclass the base classes there.

The profiles submodule

The profiles submodule contains a number of abstract descriptions of what should happen if a certain object type is used. Depending on the desirable tangible object attributes you can customize the profiles for your own need.

For example, if you want to receive the data for a 2D tracking object you need to use the according profile, because it knows how to handle the dataset of this type of object.

Every profile subclasses from a TuioProfile base class that has the following required methods whose names originate from the name of the raw OSC message:

  • set - The state of each alive (but unchanged) fiducial is periodically resent with 'set' messages. The attributes are sent as a list or tuple.
  • alive - The 'alive' message contains the session ids of all alive fiducials known to reacTIVision.
  • fseq - fseq messages associate a unique frame id with a set of setand alive messages

Other methods and attributes are:

  • list_label - Defines the names of the helper methods that are automatically created while initialization of the Tracking instance and maps to the objs method of the used profile.
  • address - Defines the OSC address to bind to the CallBackmanagerand start listening to while starting the Tracking instance.
  • objs - Returns a generator list of all tracked objects which are recognized with this profile and are in the current session. Though please use the helper methods whose names are defined in the class variable list_label.

The OSC submodule

This submodule does most of the heavy lifting of decoding the OSC messages used in the TUIO protocol and provides a convenient CallbackManager. It was written by Daniel Holth and Clinton McChesney.

Learn more about OSC at http://en.wikipedia.org/wiki/OpenSound_Control.

What happens next?

This library should be the start of lecturing about tangible interfaces in combination with the ease of use of the Python programming language.

Feel free to contact the Author Jannis Leidel to get to know more about tangible user interfaces, integration into Pygame and future features.

You can of course use the issue tracking service of the pyTUIO Google Code project site to ask for new features, report bugs or become a project member.