JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
OpenNi2Tool.h
Go to the documentation of this file.
1#ifndef __JBXL_OPENNI2_TOOL_H_
2#define __JBXL_OPENNI2_TOOL_H_
3
10//
11#ifdef ENABLE_OPENNI2
12#ifdef ENABLE_OPENNI
13#undef ENABLE_OPENNI
14#endif
15#endif
16
17
18#ifdef ENABLE_OPENNI2
19
20
22// OpenNI2
23//
24
25#include "OpenNi2Device.h"
26#include "NiDevice.h"
27
28
29namespace jbxl {
30
31
33// compatible for OpenNI ver 1.x
34
35typedef struct XnVector3D
36{
37 double X;
38 double Y;
39 double Z;
40} XnVector3D;
41
42
43//
44typedef struct XnMatrix3X3
45{
46 double elements[9];
47} XnMatrix3X3;
48
49
50typedef XnVector3D XnPoint3D;
51
52
53#define XN_SKEL_PROFILE_ALL 2
54#define XN_SKEL_PROFILE_UPPER 3
55
56
58//
59
60class COpenNiTool
61{
62public:
63 COpenNiTool(void);
64 virtual ~COpenNiTool(void) { free();}
65
66
67private:
68 COpenNi2Device* device;
69 COpenNi2Device* dev_backup;
70
71public:
72 Buffer m_err_mesg;
73
74 unsigned int tracking_user;
75 unsigned int tracking_deny;
76
77public:
78 BOOL init(BOOL use_camera);
79 void free(void);
80 void delete_Device(void);
81
82 void clear_JointsData(void);
83 void clear_JointsPosData(void);
84 void clear_JointsRotData(void);
85
86 nite::UserData* get_Avatar(unsigned int id);
87
88public:
89 // Joints
90 void get_JointsPositionData(unsigned int nId);
91 void get_JointsRotationData(unsigned int nId);
92
93 XnVector3D joint_PositionData(int joint);
94 XnMatrix3X3 joint_RotationData(int joint);
95 double joint_PositionConfidence(int joint);
96 double joint_RotationConfidence(int joint);
97
98public:
99 // Detection
100 BOOL start_Detection(int profile, double smooth);
101 BOOL stop_Detection(void);
102
103 unsigned int get_TrackingUser(void);
104 void set_DenyTrackingSearch(unsigned int user);
105
106 // Device
107 BOOL backupDevice(void);
108 BOOL restoreDevice(void);
109
110protected:
111// Data
112 XnVector3D jointPosData[OPENNI_JOINT_NUM]; // no data at [0]
113 XnMatrix3X3 jointRotData[OPENNI_JOINT_NUM]; // no data at [0]
114 double jointPosConfidence[OPENNI_JOINT_NUM];
115 double jointRotConfidence[OPENNI_JOINT_NUM];
116
117// device Interface
118public:
119 ONI_EnuDev getEnuDevice(void) { if (device!=NULL) return device->m_enu_dev; else return EnuDev_Unknown;}
120
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;}
123
124 BOOL resetDevice(BOOL image) { deleteDepth(); deleteImage(); return initDevice(image);}
125 BOOL resetDevice(char* fname, BOOL image) { deleteDepth(); deleteImage(); return initDevice(fname, image);}
126
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;}}
129
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;}
132
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;}
136
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;}
140
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();}
144
145 //
146 void waitStreamData(void) { if (device!=NULL) device->wait_StreamData();}
147
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;}
151 //
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; }
155
156 //
157 BOOL isTracking(unsigned int user)
158 {
159 nite::UserData* avatar = get_Avatar(user);
160 if (avatar==NULL || avatar->isLost()) return FALSE;
161 return TRUE;
162 }
163
164 //
165 void stopTracking(unsigned int user)
166 {
167 if (device!=NULL && device->user!=NULL) {
168 device->user->stopSkeletonTracking((nite::UserId)user);
169 }
170 }
171
172 //
173 void setGlobalMirror(BOOL mirror)
174 {
175 if (device!=NULL) {
176 bool mirr = false;
177 if (mirror) mirr = true;
178 if (device->image!=NULL) device->image->setMirroringEnabled(mirr);
179 if (device->depth!=NULL) device->depth->setMirroringEnabled(mirr);
180 }
181 }
182
183 //
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;}
187
188 //
189 void setViewPoint(void) {}
190
191 //
192 void convertDepth2Image(int dx, int dy, unsigned short dz, int* ix, int* iy)
193 {
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);
196 }
197 }
198
199 //
200 void convert2Projective(unsigned int c, XnPoint3D* a, XnPoint3D* b)
201 {
202 if (device==NULL && device->user!=NULL) {
203 memset(b, 0, c*sizeof(XnPoint3D));
204 return;
205 }
206 //
207 for (unsigned int i=0; i<c; i++) {
208 device->user->convertJointCoordinatesToDepth(a->X, a->Y, a->Z, &(b->X), &(b->Y));
209 a++;
210 b++;
211 }
212 //
213 // 本当はさらに Image座標系に変換しないといけない.
214 }
215
216 //
217 BOOL startRecorde(char* file_name, BOOL use_image) {
218 if (device!=NULL) return device->start_Recorde(file_name, use_image);
219 else return FALSE;
220 }
221 //
222 void stopRecorde(void) { device->stop_Recorde();}
223
224 //
225 void playerSetRepeat(BOOL rep) {}
226 void playerSetSeek(int tm) {}
227
228 // USB
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);}
233};
234
235
236} // namespace
237
238
239#endif
240
241#endif // __JBXL_OPENNI2_TOOL_H_
242
243
244
246// Information
247
248/*
249XnTypes.h
250
251typedef enum XnSkeletonJoint
252{
253 XN_SKEL_HEAD = 1,
254 XN_SKEL_NECK = 2,
255 XN_SKEL_TORSO = 3,
256 XN_SKEL_WAIST = 4,
257
258 XN_SKEL_LEFT_COLLAR = 5,
259 XN_SKEL_LEFT_SHOULDER = 6,
260 XN_SKEL_LEFT_ELBOW = 7,
261 XN_SKEL_LEFT_WRIST = 8,
262 XN_SKEL_LEFT_HAND = 9,
263 XN_SKEL_LEFT_FINGERTIP =10,
264
265 XN_SKEL_RIGHT_COLLAR =11,
266 XN_SKEL_RIGHT_SHOULDER =12,
267 XN_SKEL_RIGHT_ELBOW =13,
268 XN_SKEL_RIGHT_WRIST =14,
269 XN_SKEL_RIGHT_HAND =15,
270 XN_SKEL_RIGHT_FINGERTIP =16,
271
272 XN_SKEL_LEFT_HIP =17,
273 XN_SKEL_LEFT_KNEE =18,
274 XN_SKEL_LEFT_ANKLE =19,
275 XN_SKEL_LEFT_FOOT =20,
276
277 XN_SKEL_RIGHT_HIP =21,
278 XN_SKEL_RIGHT_KNEE =22,
279 XN_SKEL_RIGHT_ANKLE =23,
280 XN_SKEL_RIGHT_FOOT =24
281} XnSkeletonJoint;
282*/
283
284
285/*
286NiteCEnums.h
287
288typedef enum
289{
290 NITE_JOINT_HEAD,
291 NITE_JOINT_NECK,
292
293 NITE_JOINT_LEFT_SHOULDER,
294 NITE_JOINT_RIGHT_SHOULDER,
295 NITE_JOINT_LEFT_ELBOW,
296 NITE_JOINT_RIGHT_ELBOW,
297 NITE_JOINT_LEFT_HAND,
298 NITE_JOINT_RIGHT_HAND,
299
300 NITE_JOINT_TORSO,
301
302 NITE_JOINT_LEFT_HIP,
303 NITE_JOINT_RIGHT_HIP,
304 NITE_JOINT_LEFT_KNEE,
305 NITE_JOINT_RIGHT_KNEE,
306 NITE_JOINT_LEFT_FOOT,
307 NITE_JOINT_RIGHT_FOOT,
308} NiteJointType;
309*/
310
#define NI_STATE_UNKNOWN
Definition NiDevice.h:39
ONI_EnuDev
Definition NiDevice.h:17
@ EnuDev_Unknown
Definition NiDevice.h:18
#define TRUE
Definition common.h:226
#define FALSE
Definition common.h:223
unsigned char uByte
1Byte
Definition common.h:332
Definition Brep.h:29