kinecttcpclient
Class KinectTCPClient

java.lang.Object
  extended by java.lang.Thread
      extended by kinecttcpclient.KinectTCPClient
All Implemented Interfaces:
java.lang.Runnable

public class KinectTCPClient
extends java.lang.Thread

KinectTCPClient contains all methods needed to communicate with a KinectTCP server. It implements all commands defined in the documentation of KinectTCP. For more detailed information, please see documentation of kinectTCP on https://sites.google.com/a/temple.edu/kinecttcp/


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 int audioAmplitude
           
static int CMD_ENABLEDEPTHXYZINDEX
           
static int CMD_GETDEPTHMODE
           
static int CMD_GETRGBMODE
           
static int CMD_HELLO
           
static int CMD_INITDEPTH320X240
           
static int CMD_INITDEPTH640X480
           
static int CMD_INITDEPTH80X60
           
static int CMD_INITRGB1280X1024
           
static int CMD_INITRGB640X480
           
static int CMD_NODEPTH
           
static int CMD_NORGB
           
static int CMD_NUMDEVICES
           
static int CMD_READDEPTH
           
static int CMD_READDEPTHRGB
           
static int CMD_READDEPTHXYZ
           
static int CMD_READDEPTHXYZRGB
           
static int CMD_READRGB
           
static int CMD_READSKELETON
           
static int CMD_STARTKINECT
           
static int CMD_STARTKINECTDEFAULT
           
static int CMD_STREAMAUDIOSTART
           
static int CMD_STREAMAUDIOSTOP
           
 long timestamp
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
KinectTCPClient()
          Default constructor, connects to localhost, port 8001
KinectTCPClient(java.lang.String ipaddress, int port)
          Constructor, creates socket connection
 
Method Summary
 int enableDepthXYZIndex()
          Send command: enableDepthXYZIndex
 int getDepthMode()
          Send command: getDepthMode
static int[][] getJointPositions(int[] skel, int skelIndex)
          getJointPositions: convenience routine to extract joints from skeleton data
 int getRGBMode()
          Send command: getRGBMode.
 int initDepth(int resX)
          Send command: initDepth
 int initRGB(int resX)
          Send command: initRGB
 int[] readDataFromCommunactionChannel(int channel)
          MULTIBYTECOMMAND: read data from communication channel
 int[][] readDepth()
          Read Depth Image.
 int[][] readDepthXYZ()
          Read Depth Point Cloud.
 int[][] readDepthXYZIndex()
          command: READ DepthXYZIndex.
 int[] readRGBImage()
          command: READ RGB
 int[] readSkeleton()
          Command Read Skeleton.
 void run()
          start routine for thread.
 int sayHello()
          Send command: Hello.
 int startKinect(boolean deflt)
          Send command: start kinectTCP
 void stopAudio()
          Command to stop audio streaming.
 void streamAudio()
          Stream Audio: an example method for audio handling.
static void writeArrayToASCIIFile(int[] data, java.lang.String filename)
          for debugging: write 1D array to a data file
 int writeDataToCommunactionChannel(int channel, byte[] data)
          MULTIBYTECOMMAND: write to communication channel
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

timestamp

public long timestamp

audioAmplitude

public int audioAmplitude

CMD_HELLO

public static int CMD_HELLO

CMD_NUMDEVICES

public static int CMD_NUMDEVICES

CMD_STARTKINECT

public static int CMD_STARTKINECT

CMD_STARTKINECTDEFAULT

public static int CMD_STARTKINECTDEFAULT

CMD_ENABLEDEPTHXYZINDEX

public static int CMD_ENABLEDEPTHXYZINDEX

CMD_INITRGB640X480

public static int CMD_INITRGB640X480

CMD_INITRGB1280X1024

public static int CMD_INITRGB1280X1024

CMD_GETRGBMODE

public static int CMD_GETRGBMODE

CMD_INITDEPTH80X60

public static int CMD_INITDEPTH80X60

CMD_INITDEPTH320X240

public static int CMD_INITDEPTH320X240

CMD_INITDEPTH640X480

public static int CMD_INITDEPTH640X480

CMD_GETDEPTHMODE

public static int CMD_GETDEPTHMODE

CMD_NORGB

public static int CMD_NORGB

CMD_NODEPTH

public static int CMD_NODEPTH

CMD_READRGB

public static int CMD_READRGB

CMD_READDEPTH

public static int CMD_READDEPTH

CMD_READDEPTHXYZ

public static int CMD_READDEPTHXYZ

CMD_READDEPTHRGB

public static int CMD_READDEPTHRGB

CMD_READDEPTHXYZRGB

public static int CMD_READDEPTHXYZRGB

CMD_READSKELETON

public static int CMD_READSKELETON

CMD_STREAMAUDIOSTART

public static int CMD_STREAMAUDIOSTART

CMD_STREAMAUDIOSTOP

public static int CMD_STREAMAUDIOSTOP
Constructor Detail

KinectTCPClient

public KinectTCPClient(java.lang.String ipaddress,
                       int port)
Constructor, creates socket connection

Parameters:
ipaddress: - ipaddress of kinectTCP server (kinectTCP server displays its ip-address)
port: - port of kinectTCP server (kinectTCP server displays its port).

KinectTCPClient

public KinectTCPClient()
Default constructor, connects to localhost, port 8001

Method Detail

run

public void run()
start routine for thread. In case the client is used as audio client, this routine will start the audio streaming

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sayHello

public int sayHello()
Send command: Hello.

Returns:
Answers (int) from server. KinectTCP defines a valid answer as "214" (= -42).

getRGBMode

public int getRGBMode()
Send command: getRGBMode.

Returns:
0 = noRGB, 3 = 640x480, 4 = 1280x1024

getDepthMode

public int getDepthMode()
Send command: getDepthMode

Returns:
0 = no depth, 1 = 80x60, 2= 320x240, 3=640x480

enableDepthXYZIndex

public int enableDepthXYZIndex()
Send command: enableDepthXYZIndex

Returns:
1 if successful, 0 otherwise.

initRGB

public int initRGB(int resX)
Send command: initRGB

Parameters:
resX= - 640 | 1280 | 0
Returns:
1 if successful, 0 otherwise. A "0" would be returned from kinectTCP if the server is already initialized/started.

initDepth

public int initDepth(int resX)
Send command: initDepth

Parameters:
resX= - 640 | 320 | 80 | 0
Returns:
1 if successful, 0 otherwise. A "0" would be returned from kinectTCP if the server is already initialized/started.

startKinect

public int startKinect(boolean deflt)
Send command: start kinectTCP

Parameters:
deflt - (boolean), true: starts kinectTCP with default settings, otherwise kinectTCP will be started with settings submitted by initDepth and initRGB
Returns:
1 on success, 0 otherwise

readDepth

public int[][] readDepth()
Read Depth Image.

Returns:
Returns a 2D array. First dimension contains distance, second dimension contains player index.

readDepthXYZ

public int[][] readDepthXYZ()
Read Depth Point Cloud. kinectTCP only submits points which have a valid distance (>0), hence the returned data stream has varying size. This is the point cloud WITHOUT player index. For index see readDepthXYZIndex().

Returns:
2D array of point coordinates. [][0-2] = x,y,z

readDepthXYZIndex

public int[][] readDepthXYZIndex()
command: READ DepthXYZIndex. depth as point cloud. attention! this enables the index-reading (command 4), yet does NOT disable it!

Returns:
2D array, depth in [][0-2] = x,y,z, index in [][3]

readRGBImage

public int[] readRGBImage()
command: READ RGB

Returns:
rgb as color image, alpha value = 0xff

readSkeleton

public int[] readSkeleton()
Command Read Skeleton. Usually followed by "get joint positions" for more convenient access.

Returns:
raw skeleton data int[]. See documentation of kinectTCP.

getJointPositions

public static int[][] getJointPositions(int[] skel,
                                        int skelIndex)
getJointPositions: convenience routine to extract joints from skeleton data

Parameters:
skel: - skeleton data array, as obtained from readSkeleton()
skelIndex: - index of skeleton (1 or 2)
Returns:

streamAudio

public void streamAudio()
Stream Audio: an example method for audio handling. Opens a JFrame and shows the amplitude of the audio data. This method is called by the 'run()' method of the thread.


stopAudio

public void stopAudio()
Command to stop audio streaming.


writeDataToCommunactionChannel

public int writeDataToCommunactionChannel(int channel,
                                          byte[] data)
MULTIBYTECOMMAND: write to communication channel

Parameters:
channel - (int, 0..9)
data - (byte[], max. length: 65535)
Returns:
1 on success, 0 otherwise.

readDataFromCommunactionChannel

public int[] readDataFromCommunactionChannel(int channel)
MULTIBYTECOMMAND: read data from communication channel

Parameters:
channel - (int, 0..9)
Returns:
int[] data, or null if not successful.

writeArrayToASCIIFile

public static void writeArrayToASCIIFile(int[] data,
                                         java.lang.String filename)
for debugging: write 1D array to a data file

Parameters:
data - int[]
filename -