tuioZones
Class TUIOzoneCollection

java.lang.Object
  extended by tuioZones.TUIOzoneCollection
All Implemented Interfaces:
processing.core.PConstants

public class TUIOzoneCollection
extends java.lang.Object
implements processing.core.PConstants

The TUIOzoneCollection class provides a way to define zones that respond to TUIO events in unique ways. It handles the processing of TUIO events and provides methods to get data about each zone and related TUIO events.

Author:
jLyst
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;
PImage b;

void setup(){
  size(screen.width,screen.height);
  // create a draggable, throwable, and scalable zone for a photo
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/2,height/2,400,300);
  zones.setZoneParameter("zone1","DRAGGABLE",true);
  zones.setZoneParameter("zone1","THROWABLE",true);
  zones.setZoneParameter("zone1","SCALABLE",true);
  b = loadImage("photo.jpg");
  noFill();
  smooth();
}

void draw(){
  background(0);
  // use the zone coordinates and size to display the image
  image(b, zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
  // outline photo when pressed
  if (zones.isZonePressed("zone1")) {
    stroke(200,200,0);
    strokeWeight(4);
    rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
  }
  // draw the touch trails for testing hardware calibration
  /*int[][] coord=zones.getPoints();
  stroke(100,100,100);
  strokeWeight(1);
  if (coord.length>0){
    for (int i=0;i1){
        for (int j=1;j

Field Summary
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
TUIOzoneCollection(processing.core.PApplet theParent)
          The Constructor initializes a collection of zones that respond to TUIO cursor actions.
TUIOzoneCollection(processing.core.PApplet theParent, int port)
          The Constructor initializes a collection of zones that respond to TUIO cursor actions.
 
Method Summary
 void applyZone3dMatrix(java.lang.String zNameIn)
          Apply the zone's stored 3d Matrix Transformation.
 void assignZoneToGroup(java.lang.String zone, java.lang.String group)
          Assign a zone to a group.
 void attachZoneTo(java.lang.String child, java.lang.String parent)
          Attach a zone to another zone.
 void changeZoneName(java.lang.String zNameOld, java.lang.String zNameNew)
          Change zone name.
 void clicked(java.lang.String zName)
           
 void drawCirc(java.lang.String zone)
          Draw circle based on a zone's position and size.
 void drawImage(java.lang.String zone, processing.core.PImage image)
          Draw image based on a zone's position and size.
 void drawRect(java.lang.String zone)
          Draw rectangle based on a zone's position and size.
 void drawText(java.lang.String zone, java.lang.String text)
          Draw text centered, horizontally and vertically, on a zone.
 float getGestureRotation(java.lang.String zNameIn)
          Get an active gesture's rotation factor (0.0 to 1.0 for 360 degree sweep).
 float getGestureScale(java.lang.String zNameIn)
          Get an active gesture's scale factor.
 float getGestureXtranslation(java.lang.String zNameIn)
          Get an active gesture's x-axis translation.
 float getGestureYtranslation(java.lang.String zNameIn)
          Get an active gesture's y-axis translation.
 int[][] getPoints()
          Get coordinates and touch ID of all the touch points (TUIO cursors) on the screen.
 int[][] getTrail(int index)
          Get a trail of points left by a touch.
 float[] getZone3dRotationMatrix(java.lang.String zNameIn)
          Get the zones stored 3d Rotation Matrix.
 int getZoneCenterX(java.lang.String zNameIn)
          Get the zone center y-coordinate.
 int getZoneCenterY(java.lang.String zNameIn)
          Get the zone center y-coordinate.
 int[] getZoneData(java.lang.String zNameIn)
          Get zone data.
 int getZoneHeight(java.lang.String zNameIn)
          Get the zone height.
 float getZoneScale(java.lang.String zNameIn)
          Get the zone scale factor.
 int getZoneWidth(java.lang.String zNameIn)
          Get the zone width.
 int getZoneX(java.lang.String zNameIn)
          Get the zone x-coordinate.
 int getZoneY(java.lang.String zNameIn)
          Get the zone y-coordinate.
 boolean isZoneActive(java.lang.String zNameIn)
          Determine if zone is active.
 boolean isZonePressed(java.lang.String zNameIn)
          Determine if the zone is being touched.
 boolean isZoneToggleOn(java.lang.String zNameIn)
          Determine the toggle state of the zone.
 void killZone(java.lang.String zNameIn)
          Kill a zone.
 void makeHswipeEvent(java.lang.String zName)
           
 void makeVswipeEvent(java.lang.String zName)
           
 void pre()
           
 void pullZoneToTop(java.lang.String zNameIn)
          Pull a zone to the top layer.
 void setZone(java.lang.String zNameIn, int xIn, int yIn, int rIn)
          Define a new circular zone that will respond to TUIO events in a unique way.
 void setZone(java.lang.String zNameIn, int xIn, int yIn, int wIn, int hIn)
          Define a new rectangular zone that will respond to TUIO events in a unique way.
 void setZoneActive(java.lang.String zNameIn, boolean active)
          Activate a zone so that it responds to touch.
 void setZoneChildrenActive(java.lang.String zNameIn, boolean active)
          Activate a zone so that it responds to touch.
 void setZoneData(java.lang.String zNameIn, int xIn, int yIn, int rIn)
          Modify circular zone primitive data.
 void setZoneData(java.lang.String zNameIn, int xIn, int yIn, int wIn, int hIn)
          Modify rectangular zone primitive data.
 void setZoneDragLimits(java.lang.String zNameIn, int xlow, int xhigh, int ylow, int yhigh)
          Set zone drag limits.
 void setZoneParameter(java.lang.String zNameIn, java.lang.String paramName, boolean bool)
          Set zone parameters, like 'DRAGGABLE', 'SCALABLE', or 'HSWIPEABLE'.
 void setZoneScaleLimits(java.lang.String zNameIn, float low, float high)
          Set zone scale limits.
 void setZoneScaleSensitivity(java.lang.String zNameIn, float val)
          Set zone scale sensitivity.
 void touchReleased(int index)
           
 java.lang.String version()
          return the version of the library.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TUIOzoneCollection

public TUIOzoneCollection(processing.core.PApplet theParent)
The Constructor initializes a collection of zones that respond to TUIO cursor actions. A default zone, named 'canvas', is set that spans the entire width and height of the sketch. Port 3333 is used by default to receive TUIO messages

Parameters:
theParent -

TUIOzoneCollection

public TUIOzoneCollection(processing.core.PApplet theParent,
                          int port)
The Constructor initializes a collection of zones that respond to TUIO cursor actions. A default zone, named 'canvas', is set that spans the entire width and height of the sketch.

Parameters:
theParent -
port - the port where TUIO messages will be sent to. (for example, 3333)
Method Detail

version

public java.lang.String version()
return the version of the library.

Returns:
String

setZone

public void setZone(java.lang.String zNameIn,
                    int xIn,
                    int yIn,
                    int rIn)
Define a new circular zone that will respond to TUIO events in a unique way.

Parameters:
zNameIn - a name for the zone
xIn - the x-coordinate of the center of the circular zone
yIn - the y-coordinate of the center of the circular zone
rIn - the radius of the circular zone

setZone

public void setZone(java.lang.String zNameIn,
                    int xIn,
                    int yIn,
                    int wIn,
                    int hIn)
Define a new rectangular zone that will respond to TUIO events in a unique way.

Parameters:
zNameIn - a name for the zone
xIn - the x-coordinate of the upper left corner of the zone
yIn - the y-coordinate of the upper left corner of the zone
wIn - the width of the zone
hIn - the height of the zone

setZoneData

public void setZoneData(java.lang.String zNameIn,
                        int xIn,
                        int yIn,
                        int wIn,
                        int hIn)
Modify rectangular zone primitive data.

Parameters:
zNameIn - the name of the zone to be modified
xIn - the x-coordinate of the upper left corner of the zone
yIn - the y-coordinate of the upper left corner of the zone
wIn - the width of the zone
hIn - the height of the zone

setZoneDragLimits

public void setZoneDragLimits(java.lang.String zNameIn,
                              int xlow,
                              int xhigh,
                              int ylow,
                              int yhigh)
Set zone drag limits.

Parameters:
zNameIn - the name of the zone to be modified
xlow - the lower limit of drag x distance
ylow - the lower limit of drag y distance
xhigh - the upper limit of drag x distance
yhigh - the upper limit of drag y distance

setZoneScaleLimits

public void setZoneScaleLimits(java.lang.String zNameIn,
                               float low,
                               float high)
Set zone scale limits.

Parameters:
zNameIn - the name of the zone to be modified
low - the lower limit of scale gesture (<=1)
high - the upper limit of scale gesture (>=1)

setZoneScaleSensitivity

public void setZoneScaleSensitivity(java.lang.String zNameIn,
                                    float val)
Set zone scale sensitivity.

Parameters:
zNameIn - the name of the zone to be modified
val - the sensitivity of scale gesture (default=1.0)

setZoneData

public void setZoneData(java.lang.String zNameIn,
                        int xIn,
                        int yIn,
                        int rIn)
Modify circular zone primitive data.

Parameters:
zNameIn - the name of the zone to be modified
xIn - the x-coordinate of the upper left corner of the zone
yIn - the y-coordinate of the upper left corner of the zone
rIn - the radius of the zone

changeZoneName

public void changeZoneName(java.lang.String zNameOld,
                           java.lang.String zNameNew)
Change zone name.

Parameters:
zNameOld - old name for the zone
zNameNew - new name for the zone

setZoneParameter

public void setZoneParameter(java.lang.String zNameIn,
                             java.lang.String paramName,
                             boolean bool)
Set zone parameters, like 'DRAGGABLE', 'SCALABLE', or 'HSWIPEABLE'.

Parameters:
zNameIn - the name of the zone to be modified
paramName - the name of the parameter to be set. Parameters names can be 'DRAGGABLE', 'SCALABLE', 'VSWIPEABLE', 'HSWIPEABLE', or 'WINDOW3D'. Note, 'HSWIPEABLE' and 'VSWIPEABLE' can only be applied to rectangle zones. 'WINDOW3D' enables a one-finger gesture for applying 3D rotations to an object.
bool - Set the parameter to be true or false.
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;

void setup(){
  size(screen.width,screen.height);
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/2,height/2,200,200);
  zones.setZoneParameter("zone1","DRAGGABLE",true);
  fill (150);
}

void draw(){
  background(0);
  rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
}



attachZoneTo

public void attachZoneTo(java.lang.String child,
                         java.lang.String parent)
Attach a zone to another zone. The attachment is a child/parent relationship. Changes in the parent's size and position will alter the child in the same way, but not the other way around.

Parameters:
child - the name of the child zone.
parent - the name of the parent zone.
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;

void setup(){
  size(screen.width,screen.height);
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/10,height/4,width/3,height/2);
  zones.setZoneParameter("zone1","DRAGGABLE",true);
  zones.setZoneParameter("zone1","SCALABLE",true);
  zones.setZone("subZone1", width*6/10,height/4,width/3,height/2);
  zones.setZoneParameter("subZone1","DRAGGABLE",true);
  zones.setZoneParameter("subZone1","SCALABLE",true);
  zones.attachZoneTo("subZone1","zone1");
}

void draw(){
  background(0); 
  rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
  fill (150); 
  rect(zones.getZoneX("subZone1"),zones.getZoneY("subZone1"),zones.getZoneWidth("subZone1"),zones.getZoneHeight("subZone1"));
}



assignZoneToGroup

public void assignZoneToGroup(java.lang.String zone,
                              java.lang.String group)
Assign a zone to a group. A new group can be created here or an existing group can be used.

Parameters:
zone - the name of the zone to assign to a group.
parent - the name of the group. Can be a new group or existing.
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;

void setup(){
  size(screen.width,screen.height);
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/10,height/4,width/3,height/2);
  zones.setZoneParameter("zone1","DRAGGABLE",true);
  zones.setZoneParameter("zone1","SCALABLE",true);
  zones.assignZoneToGroup("zone1","group1");
  zones.setZone("zone2", width*6/10,height/4,width/3,height/2);
  zones.setZoneParameter("zone2","DRAGGABLE",true);
  zones.setZoneParameter("zone2","SCALABLE",true);
  zones.assignZoneToGroup("zone2","group1");
}

void draw(){
  background(0); 
  rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
  fill (150); 
  rect(zones.getZoneX("zone2"),zones.getZoneY("zone2"),zones.getZoneWidth("zone2"),zones.getZoneHeight("zone2"));
}



pullZoneToTop

public void pullZoneToTop(java.lang.String zNameIn)
Pull a zone to the top layer.

Parameters:
zNameIn - the name of the zone to pull to the top layer.

killZone

public void killZone(java.lang.String zNameIn)
Kill a zone.

Parameters:
zNameIn - the name of the zone to be killed.

setZoneActive

public void setZoneActive(java.lang.String zNameIn,
                          boolean active)
Activate a zone so that it responds to touch. A zone is active by default.

Parameters:
zNameIn - the name of the zone to be activated.
active - boolean to set active state. true for set active, false for set not active

setZoneChildrenActive

public void setZoneChildrenActive(java.lang.String zNameIn,
                                  boolean active)
Activate a zone so that it responds to touch. A zone is active by default.

Parameters:
zNameIn - the name of the zone to be activated.
active - boolean to set active state. true for set active, false for set not active

makeHswipeEvent

public void makeHswipeEvent(java.lang.String zName)

makeVswipeEvent

public void makeVswipeEvent(java.lang.String zName)

touchReleased

public void touchReleased(int index)

clicked

public void clicked(java.lang.String zName)

getZoneX

public int getZoneX(java.lang.String zNameIn)
Get the zone x-coordinate. Upper left corner for rectangle. Center for circle.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

getZoneY

public int getZoneY(java.lang.String zNameIn)
Get the zone y-coordinate. Upper left corner for rectangle. Center for circle.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

getZoneCenterX

public int getZoneCenterX(java.lang.String zNameIn)
Get the zone center y-coordinate.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

getZoneCenterY

public int getZoneCenterY(java.lang.String zNameIn)
Get the zone center y-coordinate.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

applyZone3dMatrix

public void applyZone3dMatrix(java.lang.String zNameIn)
Apply the zone's stored 3d Matrix Transformation. The zone itself is not rotated, but the matrix can be used to transform an object.

Parameters:
zNameIn - the name of the zone.

getZone3dRotationMatrix

public float[] getZone3dRotationMatrix(java.lang.String zNameIn)
Get the zones stored 3d Rotation Matrix. The zone itself is not rotated, but the matrix can be used to transform an object.

Parameters:
zNameIn - the name of the zone.
Returns:
a string

getZoneScale

public float getZoneScale(java.lang.String zNameIn)
Get the zone scale factor.

Parameters:
zNameIn - the name of the zone.
Returns:
a float

getGestureScale

public float getGestureScale(java.lang.String zNameIn)
Get an active gesture's scale factor.

Parameters:
zNameIn - the name of the zone.
Returns:
a float

getGestureXtranslation

public float getGestureXtranslation(java.lang.String zNameIn)
Get an active gesture's x-axis translation.

Parameters:
zNameIn - the name of the zone.
Returns:
an int

getGestureYtranslation

public float getGestureYtranslation(java.lang.String zNameIn)
Get an active gesture's y-axis translation.

Parameters:
zNameIn - the name of the zone.
Returns:
an int

getGestureRotation

public float getGestureRotation(java.lang.String zNameIn)
Get an active gesture's rotation factor (0.0 to 1.0 for 360 degree sweep).

Parameters:
zNameIn - the name of the zone.
Returns:
a float

getZoneWidth

public int getZoneWidth(java.lang.String zNameIn)
Get the zone width.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

getZoneHeight

public int getZoneHeight(java.lang.String zNameIn)
Get the zone height.

Parameters:
zNameIn - the name of the zone.
Returns:
an integer

getZoneData

public int[] getZoneData(java.lang.String zNameIn)
Get zone data.

0-the x-coordinate of the zone (upper left for rectangles and center for circles)

1-the x-coordinate of the zone (upper left for rectangles and center for circles)

2-the width of the zone (the radius if circle)

3-the height of the zone (the radius if circle)

4-the primary touch point x-coordinate (-999 if the zone is not being touched)

5-the primary touch point y-coordinate (-999 if the zone is not being touched)

6-the primary touch point index or ID (for use in getTrail method, -999 if none exist) 7-the second touch point x-coordinate (-999 if the zone is not being touched)

8-the second touch point y-coordinate (-999 if the zone is not being touched)

9-the second touch point index or ID (for use in getTrail method, -999 if none exist)

Parameters:
zNameIn - the name of the zone.
Returns:
Array of zone data as integers

drawText

public void drawText(java.lang.String zone,
                     java.lang.String text)
Draw text centered, horizontally and vertically, on a zone.

Parameters:
zone - the name of the zone.
text - the text to draw.

drawCirc

public void drawCirc(java.lang.String zone)
Draw circle based on a zone's position and size.

Parameters:
zone - the name of the zone.

drawRect

public void drawRect(java.lang.String zone)
Draw rectangle based on a zone's position and size.

Parameters:
zone - the name of the zone.

drawImage

public void drawImage(java.lang.String zone,
                      processing.core.PImage image)
Draw image based on a zone's position and size.

Parameters:
zone - the name of the zone.
image - the PImage to be drawn.

isZonePressed

public boolean isZonePressed(java.lang.String zNameIn)
Determine if the zone is being touched.

Parameters:
zNameIn - the name of the zone.
Returns:
a boolean
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;

void setup(){
  size(screen.width,screen.height);
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/2,height/2,200,200);
}

void draw(){
  background(0);
  if (zones.isZonePressed("zone1")) fill (255); //change brightness when zone is pressed
  else fill (100);
  rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
}



isZoneToggleOn

public boolean isZoneToggleOn(java.lang.String zNameIn)
Determine the toggle state of the zone. Default is false.

Parameters:
zNameIn - the name of the zone.
Returns:
a boolean
+Example
import oscP5.*;
import netP5.*;
import tuioZones.*;

TUIOzoneCollection zones;

void setup(){
  size(screen.width,screen.height);
  zones=new TUIOzoneCollection(this);
  zones.setZone("zone1", width/2,height/2,200,200);
}

void draw(){
  background(0);
  if (zones.isZoneToggleOn("zone1")) fill (255); //change brightness when zone is toggled
  else fill (100);
  rect(zones.getZoneX("zone1"),zones.getZoneY("zone1"),zones.getZoneWidth("zone1"),zones.getZoneHeight("zone1"));
}



isZoneActive

public boolean isZoneActive(java.lang.String zNameIn)
Determine if zone is active.

Parameters:
zNameIn - the name of the zone.
Returns:
a boolean

getPoints

public int[][] getPoints()
Get coordinates and touch ID of all the touch points (TUIO cursors) on the screen.

[i][0] - x coordinate

[i][1] - y coordinate

[i][2] - ID (Useful for getTrail method)

Returns:
double integer array

getTrail

public int[][] getTrail(int index)
Get a trail of points left by a touch.

[i][0] - x coordinate

[i][1] - y coordinate

Parameters:
index - The index of the point trail.
Returns:
a double integer array of coordinates

pre

public void pre()


processing library tuioZones by jLyst. (c) 2009