Mercurial > hg > grouptrack
changeset 13:b82da07b6800
Added run script to set up environment.
author | samer |
---|---|
date | Mon, 20 Feb 2012 15:02:59 +0000 |
parents | af71ea70b7f4 |
children | 34156549d423 |
files | termapp/run.sh termapp/termapp termapp/termapp.cpp |
diffstat | 3 files changed, 44 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/termapp/run.sh Mon Feb 20 15:02:59 2012 +0000 @@ -0,0 +1,3 @@ +#!/bin/sh +export OPEN_NI_INSTALL_PATH=/opt/OpenNI +DYLD_FALLBACK_LIBRARY_PATH=$OPEN_NI_INSTALL_PATH/usr/lib ./termapp "$@"
--- a/termapp/termapp.cpp Sat Feb 18 13:36:01 2012 +0000 +++ b/termapp/termapp.cpp Mon Feb 20 15:02:59 2012 +0000 @@ -43,9 +43,10 @@ UserData users[MAX_USERS]; - void update_user(int id, UserStats& stats, UserData *user); - void send_osc_i(const char *path, int arg); - void send_track(int id, float x, float y, int *coors, float area); + void update_user(lo_bundle bundle, int id, UserStats& stats, UserData *user); + + static void append_msg_i(lo_bundle bundle, const char *path, int arg); + static void append_track(lo_bundle bundle, int id, float x, float y, int *coors, float area); public: termapp(const char *host, const char *port, int fps); @@ -173,8 +174,11 @@ //-------------------------------------------------------------- void termapp::update() { + lo_timetag now; + if (check_nonfatal(context.WaitOneUpdateAll(depthGenerator),"update")) return; - + + lo_timetag_now(&now); userGenerator.GetUserPixels(0, sceneMetaData); // 0 for all users timestamp = sceneMetaData.Timestamp(); got_floor = (sceneAnalyzer.GetFloor(floor_pie)==XN_STATUS_OK); @@ -186,9 +190,10 @@ // get pixels for all users, for each compute centroid and bounding rectangle { const XnDepthPixel *depthMap = depthGenerator.GetDepthMap(); - unsigned short *userRawPixels = (unsigned short*)sceneMetaData.Data(); - UserStats stats[MAX_USERS]; - + unsigned short *userRawPixels = (unsigned short*)sceneMetaData.Data(); + UserStats stats[MAX_USERS]; + lo_bundle bundle=lo_bundle_new(now); + for (int i=0, y=0; y<IMGHEIGHT; y++) { for (int x=0; x<IMGWIDTH; x++, i++) { int id=userRawPixels[i]; @@ -201,23 +206,25 @@ for (int id0=0; id0<MAX_USERS; id0++) { if (stats[id0].area()>0) { if (!users[id0].present) { - send_osc_i("/birth",id0+1); - send_osc_i("/randinit",id0+1); - send_osc_i("/start",id0+1); + append_msg_i(bundle,"/birth",id0+1); + append_msg_i(bundle,"/randinit",id0+1); + append_msg_i(bundle,"/start",id0+1); users[id0].present=true; } - update_user(id0+1,stats[id0],&users[id0]); + update_user(bundle,id0+1,stats[id0],&users[id0]); } else { if (users[id0].present) { - send_osc_i("/death",id0+1); + append_msg_i(bundle,"/death",id0+1); users[id0].present=false; } } } + lo_send_bundle(target,bundle); + lo_bundle_free_messages(bundle); } } -void termapp::update_user(int id, UserStats& stats, UserData *user) { +void termapp::update_user(lo_bundle bundle, int id, UserStats& stats, UserData *user) { XnVector3D proj[3], real[3]; int *coors=user->plot_coors; @@ -248,7 +255,7 @@ on_floor.Y -= floor_offset.Y; on_floor.Z -= floor_offset.Z; - send_track(id, on_floor.X, on_floor.Y, coors, stats.area()); + append_track(bundle,id, on_floor.X, on_floor.Y, coors, stats.area()); } } @@ -270,15 +277,14 @@ } } -void termapp::send_osc_i(const char *path, int arg) { +void termapp::append_msg_i(lo_bundle bundle, const char *path, int arg) { lo_message msg=lo_message_new(); lo_message_add_int32(msg,arg); - lo_send_message(target,path,msg); - // printf("- sent %s %d.\n",path,arg); + lo_bundle_add_message(bundle,path,msg); } -void termapp::send_track( int id, float x, float y, int *coors, float area) +void termapp::append_track(lo_bundle bundle, int id, float x, float y, int *coors, float area) { lo_message m=lo_message_new(); float z=coors[2]; // depth @@ -297,13 +303,13 @@ // area, corrected for perspective lo_message_add_int32(m,z*sqrt(area)); - lo_send_message(target,"/track",m); + lo_bundle_add_message(bundle,"/track",m); } static termapp *app=NULL; static void signal_handler(int sig) { - printf("\nCaught SIGINT - terminating.\n"); + printf("\nCaught signal %d - terminating.\n", sig); if (app) { delete app; app=NULL; } exit(0); } @@ -314,7 +320,7 @@ void reset_terminal_mode() { printf("Resetting terminal...\n"); - tcsetattr(0, TCSANOW, &orig_termios); + tcsetattr(0, TCSANOW, &orig_termios); } void set_conio_terminal_mode() @@ -332,34 +338,36 @@ int kbhit() { - struct timeval tv = { 0L, 0L }; - fd_set fds; - FD_ZERO(&fds); - FD_SET(0, &fds); - return select(1, &fds, NULL, NULL, &tv); + struct timeval tv = { 0L, 0L }; + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + return select(1, &fds, NULL, NULL, &tv); } int getch() { - unsigned char c; - int r=read(0, &c, sizeof(c)); - return (r<0) ? r : c; + unsigned char c; + int r=read(0, &c, sizeof(c)); + return (r<0) ? r : c; } int main(int argc, const char **argv) { int i,ch; app=new termapp( - argc>1 ? argv[1] : HOST, - argc>2 ? argv[2] : PORT, - argc>3 ? atoi(argv[3]) : 15); + argc>1 ? argv[1] : HOST, + argc>2 ? argv[2] : PORT, + argc>3 ? atoi(argv[3]) : 15); signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGKILL, signal_handler); printf("Setting up...\n"); app->setup(); printf("Running...\n"); - set_conio_terminal_mode(); + set_conio_terminal_mode(); for (;;) { app->update(); app->draw();