00001 #ifndef __JBXL_OPENNI2_TOOL_H_
00002 #define __JBXL_OPENNI2_TOOL_H_
00003
00011
00012 #ifdef ENABLE_OPENNI2
00013 #ifdef ENABLE_OPENNI
00014 #undef ENABLE_OPENNI
00015 #endif
00016 #endif
00017
00018
00019
00020 #ifdef ENABLE_OPENNI2
00021
00022
00024
00025
00026
00027 #include "OpenNi2Device.h"
00028 #include "NiDevice.h"
00029
00030
00031
00032 namespace jbxl {
00033
00034
00036
00037
00038 typedef struct XnVector3D
00039 {
00040 double X;
00041 double Y;
00042 double Z;
00043 } XnVector3D;
00044
00045
00046
00047 typedef struct XnMatrix3X3
00048 {
00049 double elements[9];
00050 } XnMatrix3X3;
00051
00052
00053 typedef XnVector3D XnPoint3D;
00054
00055
00056 #define XN_SKEL_PROFILE_ALL 2
00057 #define XN_SKEL_PROFILE_UPPER 3
00058
00059
00060
00062
00063
00064 class COpenNiTool
00065 {
00066 public:
00067 COpenNiTool(void);
00068 virtual ~COpenNiTool(void) { free();}
00069
00070
00071 private:
00072 COpenNi2Device* device;
00073 COpenNi2Device* dev_backup;
00074
00075 public:
00076 Buffer m_err_mesg;
00077
00078 unsigned int tracking_user;
00079 unsigned int tracking_deny;
00080
00081
00082 public:
00083 BOOL init(BOOL use_camera);
00084 void free(void);
00085 void delete_Device(void);
00086
00087 void clear_JointsData(void);
00088 void clear_JointsPosData(void);
00089 void clear_JointsRotData(void);
00090
00091 nite::UserData* get_Avatar(unsigned int id);
00092
00093
00094 public:
00095
00096 void get_JointsPositionData(unsigned int nId);
00097 void get_JointsRotationData(unsigned int nId);
00098
00099 XnVector3D joint_PositionData(int joint);
00100 XnMatrix3X3 joint_RotationData(int joint);
00101 double joint_PositionConfidence(int joint);
00102 double joint_RotationConfidence(int joint);
00103
00104
00105 public:
00106
00107 BOOL start_Detection(int profile, double smooth);
00108 BOOL stop_Detection(void);
00109
00110 unsigned int get_TrackingUser(void);
00111 void set_DenyTrackingSearch(unsigned int user);
00112
00113
00114
00115 BOOL backupDevice(void);
00116 BOOL restoreDevice(void);
00117
00118 protected:
00119
00120 XnVector3D jointPosData[OPENNI_JOINT_NUM];
00121 XnMatrix3X3 jointRotData[OPENNI_JOINT_NUM];
00122 double jointPosConfidence[OPENNI_JOINT_NUM];
00123 double jointRotConfidence[OPENNI_JOINT_NUM];
00124
00125
00126 public:
00127 ONI_EnuDev getEnuDevice(void) { if (device!=NULL) return device->m_enu_dev; else return EnuDev_Unknown;}
00128
00129 BOOL initDevice(BOOL image) { if (device!=NULL) return device->init(image); else return FALSE;}
00130 BOOL initDevice(char* fname, BOOL image) { if (device!=NULL) return device->init(fname, image); else return FALSE;}
00131
00132 BOOL resetDevice(BOOL image) { deleteDepth(); deleteImage(); return initDevice(image);}
00133 BOOL resetDevice(char* fname, BOOL image) { deleteDepth(); deleteImage(); return initDevice(fname, image);}
00134
00135 BOOL hasBackupDev(void) { if (dev_backup!=NULL) return TRUE; else return FALSE;}
00136 void deleteBackupDev(void) { if (dev_backup!=NULL) { delete(dev_backup); dev_backup=NULL;}}
00137
00138 int getDevState(void) { if (device!=NULL) return device->m_state; else return NI_STATE_UNKNOWN;}
00139 void setDevState(int state) { if (device!=NULL) device->m_state = state;}
00140
00141 BOOL hasContext(void) { if (device!=NULL && device->context!=NULL) return TRUE; else return FALSE;}
00142 BOOL hasImageGen(void) { if (device!=NULL && device->image!=NULL) return TRUE; else return FALSE;}
00143 BOOL hasDepthGen(void) { if (device!=NULL && device->depth!=NULL) return TRUE; else return FALSE;}
00144
00145 BOOL createContext(void){ if (device!=NULL) return device->create_Context(); else return FALSE;}
00146 BOOL createImage(void) { if (device!=NULL) return device->create_Image(); else return FALSE;}
00147 BOOL createDepth(void) { if (device!=NULL) return device->create_Depth(); else return FALSE;}
00148
00149 void deleteContext(void){ if (device!=NULL) device->delete_Context();}
00150 void deleteImage(void) { if (device!=NULL) device->delete_Image();}
00151 void deleteDepth(void) { if (device!=NULL) device->delete_Depth();}
00152
00153
00154 void waitStreamData(void) { if (device!=NULL) device->wait_StreamData();}
00155
00156 BOOL setImageData(void) { if (device!=NULL) return device->set_ImageData(); else return FALSE;}
00157 BOOL setDepthData(void) { if (device!=NULL) return device->set_DepthData(); else return FALSE;}
00158 BOOL setSceneData(void) { if (device!=NULL) return device->set_SceneData(); else return FALSE;}
00159
00160 uByte* getImageData(void) { if (device!=NULL) return device->get_ImageData(); else return NULL; }
00161 uByte* getDepthData(void) { if (device!=NULL) return device->get_DepthData(); else return NULL; }
00162 uByte* getSceneData(void) { if (device!=NULL) return device->get_SceneData(); else return NULL; }
00163
00164
00165 BOOL isTracking(unsigned int user)
00166 {
00167 nite::UserData* avatar = get_Avatar(user);
00168 if (avatar==NULL || avatar->isLost()) return FALSE;
00169 return TRUE;
00170 }
00171
00172
00173 void stopTracking(unsigned int user)
00174 {
00175 if (device!=NULL && device->user!=NULL) {
00176 device->user->stopSkeletonTracking((nite::UserId)user);
00177 }
00178 }
00179
00180
00181 void setGlobalMirror(BOOL mirror)
00182 {
00183 if (device!=NULL) {
00184 bool mirr = false;
00185 if (mirror) mirr = true;
00186 if (device->image!=NULL) device->image->setMirroringEnabled(mirr);
00187 if (device->depth!=NULL) device->depth->setMirroringEnabled(mirr);
00188 }
00189 }
00190
00191
00192 int getXSize(void) { if (device!=NULL) return device->m_xsize; else return 0;}
00193 int getYSize(void) { if (device!=NULL) return device->m_ysize; else return 0;}
00194 int getFPS(void) { if (device!=NULL) return device->m_nfps; else return 0;}
00195
00196
00197 void setViewPoint(void) {}
00198
00199
00200 void convertDepth2Image(int dx, int dy, unsigned short dz, int* ix, int* iy)
00201 {
00202 if (device!=NULL && device->image!=NULL && device->depth!=NULL) {
00203 openni::CoordinateConverter::convertDepthToColor(*(device->depth), *(device->image), dx, dy, (openni::DepthPixel)dz, ix, iy);
00204 }
00205 }
00206
00207
00208 void convert2Projective(unsigned int c, XnPoint3D* a, XnPoint3D* b)
00209 {
00210 if (device==NULL && device->user!=NULL) {
00211 memset(b, 0, c*sizeof(XnPoint3D));
00212 return;
00213 }
00214
00215 for (unsigned int i=0; i<c; i++) {
00216 device->user->convertJointCoordinatesToDepth(a->X, a->Y, a->Z, &(b->X), &(b->Y));
00217 a++;
00218 b++;
00219 }
00220
00221
00222 }
00223
00224
00225 BOOL startRecorde(char* file_name, BOOL use_image) {
00226 if (device!=NULL) return device->start_Recorde(file_name, use_image);
00227 else return FALSE;
00228 }
00229
00230 void stopRecorde(void) { device->stop_Recorde();}
00231
00232
00233 void playerSetRepeat(BOOL rep) {}
00234 void playerSetSeek(int tm) {}
00235
00236
00237 BOOL open_USBDevice(void) { if (device!=NULL) return device->open_USB_Device(); else return FALSE;}
00238 void close_USBDevice(void) { if (device!=NULL) device->close_USB_Device();}
00239 void set_LEDColor(int col) { if (device!=NULL) device->set_LED_Color(col);}
00240 void set_TiltMotor(int ang) { if (device!=NULL) device->set_Tilt_Motor(ang);}
00241
00242 };
00243
00244
00245
00246 }
00247
00248
00249
00250
00251 #endif
00252
00253
00254
00255 #endif // __JBXL_OPENNI2_TOOL_H_
00256
00257
00258
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323