JunkBox_Lib++ (for Windows) 1.10.1
Loading...
Searching...
No Matches
OpenNiTool.h
Go to the documentation of this file.
1#ifndef __JBXL_OPENNI_TOOL_H_
2#define __JBXL_OPENNI_TOOL_H_
3
11//
12#ifdef ENABLE_OPENNI2
13
14#include "OpenNi2Tool.h"
15
16#ifdef ENABLE_OPENNI
17 #undef ENABLE_OPENNI
18#endif
19
20#endif
21
22
23#ifdef ENABLE_OPENNI
24
25#include "OpenNiDevice.h"
26
27
28//
29namespace jbxl {
30
31
32class COpenNiTool
33{
34public:
35 COpenNiTool(void);
36 virtual ~COpenNiTool(void) { free();}
37
38private:
39 COpenNiDevice* device;
40 COpenNiDevice* dev_backup;
41
42public:
43 Buffer m_err_mesg;
44
45 unsigned int tracking_user;
46 unsigned int tracking_deny;
47
48public:
49 BOOL init(BOOL use_camera);
50 void free(void);
51 void delete_Device(void);
52
53 void clear_JointsData(void);
54 void clear_JointsPosData(void);
55 void clear_JointsRotData(void);
56
57public:
58 // Joints
59 void get_JointsPositionData(unsigned int nId);
60 void get_JointsRotationData(unsigned int nId);
61
62 XnVector3D joint_PositionData(int joint);
63 XnMatrix3X3 joint_RotationData(int joint);
64 double joint_PositionConfidence(int joint);
65 double joint_RotationConfidence(int joint);
66
67public:
68 // Detection
69 BOOL start_Detection(int profile, double smooth);
70 BOOL stop_Detection(void);
71
72 unsigned int get_TrackingUser(void);
73 void set_DenyTrackingSearch(unsigned int user);
74
75 // Device
76 BOOL backupDevice(void);
77 BOOL restoreDevice(void);
78
79protected:
80// Data
81 XnVector3D jointPosData[OPENNI_JOINT_NUM]; // no data at [0]
82 XnMatrix3X3 jointRotData[OPENNI_JOINT_NUM]; // no data at [0]
83 double jointPosConfidence[OPENNI_JOINT_NUM];
84 double jointRotConfidence[OPENNI_JOINT_NUM];
85
86// device Interface
87public:
88 ONI_EnuDev getEnuDevice(void) { if (device!=NULL) return device->m_enu_dev; else return EnuDev_Unknown;}
89
90 BOOL initDevice(BOOL image) { if (device!=NULL) return device->init(image); else return FALSE;}
91 BOOL initDevice(char* fname, BOOL image) { if (device!=NULL) return device->init(fname, image); else return FALSE;}
92
93 BOOL resetDevice(BOOL image) { deleteDepth(); deleteImage(); deletePlayer(); return initDevice(image);}
94 BOOL resetDevice(char* fname, BOOL image) { deleteDepth(); deleteImage(); deletePlayer(); return initDevice(fname, image);}
95
96 BOOL hasBackupDev(void) { if (dev_backup!=NULL) return TRUE; else return FALSE;}
97 void deleteBackupDev(void) { if (dev_backup!=NULL) { delete(dev_backup); dev_backup=NULL;}}
98
99 int getDevState(void) { if (device!=NULL) return device->m_state; else return NI_STATE_UNKNOWN;}
100 void setDevState(int state) { if (device!=NULL) device->m_state = state;}
101
102 BOOL hasContext(void) { if (device!=NULL && device->context!=NULL) return TRUE; else return FALSE;}
103 BOOL hasImageGen(void) { if (device!=NULL && device->image!=NULL) return TRUE; else return FALSE;}
104 BOOL hasDepthGen(void) { if (device!=NULL && device->depth!=NULL) return TRUE; else return FALSE;}
105 BOOL hasPlayer(void) { if (device!=NULL && device->player!=NULL) return TRUE; else return FALSE;}
106
107 BOOL createContext(void){ if (device!=NULL) return device->create_Context();else return FALSE;}
108 BOOL createImage(void) { if (device!=NULL) return device->create_Image(); else return FALSE;}
109 BOOL createDepth(void) { if (device!=NULL) return device->create_Depth(); else return FALSE;}
110 BOOL createPlayer(void) { if (device!=NULL) return device->create_Player(); else return FALSE;}
111
112 void deleteContext(void){ if (device!=NULL) device->delete_Context();}
113 void deleteImage(void) { if (device!=NULL) device->delete_Image();}
114 void deleteDepth(void) { if (device!=NULL) device->delete_Depth();}
115 void deletePlayer(void) { if (device!=NULL) device->delete_Player();}
116
117 void waitStreamData(void) { if (device!=NULL && device->context!=NULL) device->context->WaitAndUpdateAll();}
118
119 //
120 BOOL setImageData(void)
121 {
122 if (device!=NULL && device->image!=NULL && device->imageMD!=NULL) {
123 device->image->GetMetaData(*(device->imageMD));
124 return TRUE;
125 }
126 return FALSE;
127 }
128
129 //
130 BOOL setDepthData(void)
131 {
132 if (device!=NULL && device->depth!=NULL && device->depthMD!=NULL) {
133 device->depth->GetMetaData(*(device->depthMD));
134 return TRUE;
135 }
136 return FALSE;
137 }
138
139 //
140 BOOL setSceneData(void)
141 {
142 if (device!=NULL && device->user!=NULL && device->sceneMD!=NULL) {
143 device->user->GetUserPixels(0, *(device->sceneMD));
144 return TRUE;
145 }
146 return FALSE;
147 }
148
149 //
150 uByte* getImageData(void)
151 {
152 if (device!=NULL && device->imageMD!=NULL) return (uByte*)device->imageMD->RGB24Data();
153 else return NULL;
154 }
155
156 //
157 uByte* getDepthData(void)
158 {
159 if (device!=NULL && device->depthMD!=NULL) return (uByte*)device->depthMD->Data();
160 else return NULL;
161 }
162
163 //
164 uByte* getSceneData(void)
165 {
166 if (device!=NULL && device->sceneMD!=NULL) return (uByte*)device->sceneMD->Data();
167 else return NULL;
168 }
169
170 //
171 BOOL isTracking(unsigned int user)
172 {
173 if (device!=NULL && device->skeleton!=NULL && device->skeleton->IsTracking((XnUserID)user)) return TRUE;
174 else return FALSE;
175 }
176 void stopTracking(unsigned int user)
177 {
178 if (device!=NULL && device->skeleton!=NULL) device->skeleton->StopTracking((XnUserID)user);
179 }
180
181 //
182 void setGlobalMirror(BOOL mirror)
183 {
184 if (device!=NULL && device->context!=NULL) device->context->SetGlobalMirror(mirror);
185 }
186
187 //
188 int getXSize(void) { if (device!=NULL) return device->m_xsize; else return 0;}
189 int getYSize(void) { if (device!=NULL) return device->m_ysize; else return 0;}
190 int getFPS(void) { if (device!=NULL) return device->m_nfps; else return 0;}
191
192 //
193 void setViewPoint(void)
194 {
195 if (device!=NULL && device->depth!=NULL && device->image!=NULL) {
196 device->depth->GetAlternativeViewPointCap().SetViewPoint(*(device->image));
197 }
198 }
199
200 //
201 void convertDepth2Image(int dx, int dy, unsigned short dz, int* ix, int* iy)
202 {
203 (*ix) = dx;
204 (*iy) = dy;
205 }
206
207 //
208 void convert2Projective(unsigned int c, XnPoint3D* a, XnPoint3D* b)
209 {
210 if (device!=NULL && device->depth!=NULL) device->depth->ConvertRealWorldToProjective(c, a, b);
211 }
212
213 //
214 BOOL startRecorde(char* file_name, BOOL use_image)
215 {
216 if (device!=NULL) return device->start_Recorde(file_name, use_image);
217 else return FALSE;
218 }
219
220 //
221 void stopRecorde(void) { device->stop_Recorde();}
222 //
223 void playerSetRepeat(BOOL rep) { if (device!=NULL && device->player!=NULL) device->player->SetRepeat(rep); }
224 void playerSetSeek(XnInt64 tm) { if (device!=NULL && device->player!=NULL) device->player->SeekToTimeStamp(tm, XN_PLAYER_SEEK_SET);}
225
226 // USB
227 BOOL open_USBDevice(void) { if (device!=NULL) return device->open_USB_Device(); else return FALSE;}
228 void close_USBDevice(void) { if (device!=NULL) device->close_USB_Device();}
229 void set_LEDColor(int col) { if (device!=NULL) device->set_LED_Color(col);}
230 void set_TiltMotor(int ang) { if (device!=NULL) device->set_Tilt_Motor(ang);}
231};
232
233
234} // namespace
235
236
237
238#endif
239
240#endif // __JBXL_OPENNI_TOOL_H_
241
242
243
244
245
246
247
248
249
250
252// Information
253
254/*
255XnTypes.h
256
257typedef enum XnSkeletonJoint
258{
259 XN_SKEL_HEAD = 1,
260 XN_SKEL_NECK = 2,
261 XN_SKEL_TORSO = 3,
262 XN_SKEL_WAIST = 4,
263
264 XN_SKEL_LEFT_COLLAR = 5,
265 XN_SKEL_LEFT_SHOULDER = 6,
266 XN_SKEL_LEFT_ELBOW = 7,
267 XN_SKEL_LEFT_WRIST = 8,
268 XN_SKEL_LEFT_HAND = 9,
269 XN_SKEL_LEFT_FINGERTIP =10,
270
271 XN_SKEL_RIGHT_COLLAR =11,
272 XN_SKEL_RIGHT_SHOULDER =12,
273 XN_SKEL_RIGHT_ELBOW =13,
274 XN_SKEL_RIGHT_WRIST =14,
275 XN_SKEL_RIGHT_HAND =15,
276 XN_SKEL_RIGHT_FINGERTIP =16,
277
278 XN_SKEL_LEFT_HIP =17,
279 XN_SKEL_LEFT_KNEE =18,
280 XN_SKEL_LEFT_ANKLE =19,
281 XN_SKEL_LEFT_FOOT =20,
282
283 XN_SKEL_RIGHT_HIP =21,
284 XN_SKEL_RIGHT_KNEE =22,
285 XN_SKEL_RIGHT_ANKLE =23,
286 XN_SKEL_RIGHT_FOOT =24
287} XnSkeletonJoint;
288*/
289
290
291
#define NI_STATE_UNKNOWN
Definition NiDevice.h:39
ONI_EnuDev
Definition NiDevice.h:17
@ EnuDev_Unknown
Definition NiDevice.h:18
OpenNI2用 ツール ヘッダ
#define TRUE
Definition common.h:226
#define FALSE
Definition common.h:223
unsigned char uByte
1Byte
Definition common.h:332
Definition Brep.h:29