1#ifndef __JBXL_OPENNI2_TOOL_H_
2#define __JBXL_OPENNI2_TOOL_H_
35typedef struct XnVector3D
44typedef struct XnMatrix3X3
50typedef XnVector3D XnPoint3D;
53#define XN_SKEL_PROFILE_ALL 2
54#define XN_SKEL_PROFILE_UPPER 3
64 virtual ~COpenNiTool(
void) { free();}
68 COpenNi2Device* device;
69 COpenNi2Device* dev_backup;
74 unsigned int tracking_user;
75 unsigned int tracking_deny;
78 BOOL init(BOOL use_camera);
80 void delete_Device(
void);
82 void clear_JointsData(
void);
83 void clear_JointsPosData(
void);
84 void clear_JointsRotData(
void);
86 nite::UserData* get_Avatar(
unsigned int id);
90 void get_JointsPositionData(
unsigned int nId);
91 void get_JointsRotationData(
unsigned int nId);
93 XnVector3D joint_PositionData(
int joint);
94 XnMatrix3X3 joint_RotationData(
int joint);
95 double joint_PositionConfidence(
int joint);
96 double joint_RotationConfidence(
int joint);
100 BOOL start_Detection(
int profile,
double smooth);
101 BOOL stop_Detection(
void);
103 unsigned int get_TrackingUser(
void);
104 void set_DenyTrackingSearch(
unsigned int user);
107 BOOL backupDevice(
void);
108 BOOL restoreDevice(
void);
112 XnVector3D jointPosData[OPENNI_JOINT_NUM];
113 XnMatrix3X3 jointRotData[OPENNI_JOINT_NUM];
114 double jointPosConfidence[OPENNI_JOINT_NUM];
115 double jointRotConfidence[OPENNI_JOINT_NUM];
121 BOOL initDevice(BOOL image) {
if (device!=NULL)
return device->init(image);
else return FALSE;}
122 BOOL initDevice(
char* fname, BOOL image) {
if (device!=NULL)
return device->init(fname, image);
else return FALSE;}
124 BOOL resetDevice(BOOL image) { deleteDepth(); deleteImage();
return initDevice(image);}
125 BOOL resetDevice(
char* fname, BOOL image) { deleteDepth(); deleteImage();
return initDevice(fname, image);}
127 BOOL hasBackupDev(
void) {
if (dev_backup!=NULL)
return TRUE;
else return FALSE;}
128 void deleteBackupDev(
void) {
if (dev_backup!=NULL) {
delete(dev_backup); dev_backup=NULL;}}
130 int getDevState(
void) {
if (device!=NULL)
return device->m_state;
else return NI_STATE_UNKNOWN;}
131 void setDevState(
int state) {
if (device!=NULL) device->m_state = state;}
133 BOOL hasContext(
void) {
if (device!=NULL && device->context!=NULL)
return TRUE;
else return FALSE;}
134 BOOL hasImageGen(
void) {
if (device!=NULL && device->image!=NULL)
return TRUE;
else return FALSE;}
135 BOOL hasDepthGen(
void) {
if (device!=NULL && device->depth!=NULL)
return TRUE;
else return FALSE;}
137 BOOL createContext(
void){
if (device!=NULL)
return device->create_Context();
else return FALSE;}
138 BOOL createImage(
void) {
if (device!=NULL)
return device->create_Image();
else return FALSE;}
139 BOOL createDepth(
void) {
if (device!=NULL)
return device->create_Depth();
else return FALSE;}
141 void deleteContext(
void){
if (device!=NULL) device->delete_Context();}
142 void deleteImage(
void) {
if (device!=NULL) device->delete_Image();}
143 void deleteDepth(
void) {
if (device!=NULL) device->delete_Depth();}
146 void waitStreamData(
void) {
if (device!=NULL) device->wait_StreamData();}
148 BOOL setImageData(
void) {
if (device!=NULL)
return device->set_ImageData();
else return FALSE;}
149 BOOL setDepthData(
void) {
if (device!=NULL)
return device->set_DepthData();
else return FALSE;}
150 BOOL setSceneData(
void) {
if (device!=NULL)
return device->set_SceneData();
else return FALSE;}
152 uByte* getImageData(
void) {
if (device!=NULL)
return device->get_ImageData();
else return NULL; }
153 uByte* getDepthData(
void) {
if (device!=NULL)
return device->get_DepthData();
else return NULL; }
154 uByte* getSceneData(
void) {
if (device!=NULL)
return device->get_SceneData();
else return NULL; }
157 BOOL isTracking(
unsigned int user)
159 nite::UserData* avatar = get_Avatar(user);
160 if (avatar==NULL || avatar->isLost())
return FALSE;
165 void stopTracking(
unsigned int user)
167 if (device!=NULL && device->user!=NULL) {
168 device->user->stopSkeletonTracking((nite::UserId)user);
173 void setGlobalMirror(BOOL mirror)
177 if (mirror) mirr =
true;
178 if (device->image!=NULL) device->image->setMirroringEnabled(mirr);
179 if (device->depth!=NULL) device->depth->setMirroringEnabled(mirr);
184 int getXSize(
void) {
if (device!=NULL)
return device->m_xsize;
else return 0;}
185 int getYSize(
void) {
if (device!=NULL)
return device->m_ysize;
else return 0;}
186 int getFPS(
void) {
if (device!=NULL)
return device->m_nfps;
else return 0;}
189 void setViewPoint(
void) {}
192 void convertDepth2Image(
int dx,
int dy,
unsigned short dz,
int* ix,
int* iy)
194 if (device!=NULL && device->image!=NULL && device->depth!=NULL) {
195 openni::CoordinateConverter::convertDepthToColor(*(device->depth), *(device->image), dx, dy, (openni::DepthPixel)dz, ix, iy);
200 void convert2Projective(
unsigned int c, XnPoint3D* a, XnPoint3D* b)
202 if (device==NULL && device->user!=NULL) {
203 memset(b, 0, c*
sizeof(XnPoint3D));
207 for (
unsigned int i=0; i<c; i++) {
208 device->user->convertJointCoordinatesToDepth(a->X, a->Y, a->Z, &(b->X), &(b->Y));
217 BOOL startRecorde(
char* file_name, BOOL use_image) {
218 if (device!=NULL)
return device->start_Recorde(file_name, use_image);
222 void stopRecorde(
void) { device->stop_Recorde();}
225 void playerSetRepeat(BOOL rep) {}
226 void playerSetSeek(
int tm) {}
229 BOOL open_USBDevice(
void) {
if (device!=NULL)
return device->open_USB_Device();
else return FALSE;}
230 void close_USBDevice(
void) {
if (device!=NULL) device->close_USB_Device();}
231 void set_LEDColor(
int col) {
if (device!=NULL) device->set_LED_Color(col);}
232 void set_TiltMotor(
int ang) {
if (device!=NULL) device->set_Tilt_Motor(ang);}