JunkBox_Win_Lib 1.5.3
Loading...
Searching...
No Matches
NiJointsTool.h
Go to the documentation of this file.
1#pragma once
2
3#include "NiToolWin.h"
4#include "Vector.h"
5#include "Rotation.h"
6#include "RingBuffer.h"
7
8
9#define NI_JTXT_FILE_ID "NI_JOINTS_TEXT_FILE"
10
11
12#define NI_NORML_JOINT_NUM 33 // NORMAL JOINTS
13#define NI_SPECL_JOINT_NUM 4 // NI_L_FINGER, NI_R_FINGER, NI_FACE, NI_AVATAR
14#define NI_TOTAL_JOINT_NUM 37 // 33 + 4
15
16
17#define NI_OPENNI_JOINT_NUM 25 // OPENNI_JOINT_NUM
18#define NI_OPENNI2_JOINT_NUM 16 // OPENNI2_JOINT_NUM
19#define NI_KINECT_JOINT_NUM 20 // KINECT_JOINT_NUM, NUI_SKELETON_POSITION_COUNT
20
21//
22#define NI_SDK_IS_TRACKING 0x0100
23#define NI_SDK_PROFILE_UPPER 0x1000
24#define NI_SDK_AVATAR_TRAILER 0x2000
25
26#define NI_PROFILE_UPPER 3
27
28
30// 共通ジョイント番号
31
32#define NI_PELVIS 0
33#define NI_WAIST 1
34#define NI_TORSO 2
35#define NI_CHEST 3
36#define NI_NECK 4
37#define NI_HEAD 5
38#define NI_SKULL 6
39
40#define NI_L_EYE 7
41#define NI_R_EYE 8
42#define NI_L_BUST 9
43#define NI_R_BUST 10
44
45#define NI_L_COLLAR 11
46#define NI_L_SHLDR 12
47#define NI_L_ELBOW 13
48#define NI_L_WRIST 14
49#define NI_L_HAND 15
50#define NI_L_FNGRTIP 16
51
52#define NI_R_COLLAR 17
53#define NI_R_SHLDR 18
54#define NI_R_ELBOW 19
55#define NI_R_WRIST 20
56#define NI_R_HAND 21
57#define NI_R_FNGRTIP 22
58
59#define NI_L_HIP 23
60#define NI_L_KNEE 24
61#define NI_L_ANKLE 25
62#define NI_L_FOOT 26
63#define NI_L_TOE 27
64
65#define NI_R_HIP 28
66#define NI_R_KNEE 29
67#define NI_R_ANKLE 30
68#define NI_R_FOOT 31
69#define NI_R_TOE 32
70
71// Special Joints
72#define NI_L_FINGER 33 // Parameter for Left Finger
73#define NI_R_FINGER 34 // Parameter for Right Finger
74#define NI_FACE 35 // Parameter for Expression
75
76#define NI_AVATAR 36
77
78
80// SDK独立な作業用ジョイント番号.
81// 二つのSDK(OpenNI, Kinect SDK)のジョイント名はこの名前に集約される.
82
83extern int NI_SDK_PELVIS;
84extern int NI_SDK_TORSO;
85extern int NI_SDK_NECK;
86extern int NI_SDK_HEAD;
87
88extern int NI_SDK_L_EYE;
89extern int NI_SDK_R_EYE;
90extern int NI_SDK_L_BUST;
91extern int NI_SDK_R_BUST;
92
93extern int NI_SDK_L_SHLDR;
94extern int NI_SDK_L_ELBOW;
95extern int NI_SDK_L_WRIST;
96extern int NI_SDK_L_HAND;
97
98extern int NI_SDK_R_SHLDR;
99extern int NI_SDK_R_ELBOW;
100extern int NI_SDK_R_WRIST;
101extern int NI_SDK_R_HAND;
102
103extern int NI_SDK_L_HIP;
104extern int NI_SDK_L_KNEE;
105extern int NI_SDK_L_ANKLE;
106extern int NI_SDK_L_FOOT;
107
108extern int NI_SDK_R_HIP;
109extern int NI_SDK_R_KNEE;
110extern int NI_SDK_R_ANKLE;
111extern int NI_SDK_R_FOOT;
112
113extern int NI_SDK_L_FINGER;
114extern int NI_SDK_R_FINGER;
115extern int NI_SDK_FACE;
116
117extern int NI_SDK_AVATAR;
118
119//
120extern jbxl::RBound<double> RBound_NI_TORSO;
121extern jbxl::RBound<double> RBound_NI_CHEST;
122extern jbxl::RBound<double> RBound_NI_NECK;
123extern jbxl::RBound<double> RBound_NI_HEAD;
124
125extern jbxl::RBound<double> RBound_NI_L_COLLAR;
126extern jbxl::RBound<double> RBound_NI_L_COLLAR;
127extern jbxl::RBound<double> RBound_NI_L_COLLAR;
128extern jbxl::RBound<double> RBound_NI_R_COLLAR;
129extern jbxl::RBound<double> RBound_NI_L_SHLDR;
130extern jbxl::RBound<double> RBound_NI_R_SHLDR;
131extern jbxl::RBound<double> RBound_NI_L_ELBOW;
132extern jbxl::RBound<double> RBound_NI_R_ELBOW;
133extern jbxl::RBound<double> RBound_NI_L_WRIST;
134extern jbxl::RBound<double> RBound_NI_R_WRIST;
135extern jbxl::RBound<double> RBound_NI_L_HAND;
136extern jbxl::RBound<double> RBound_NI_R_HAND;
137
138extern jbxl::RBound<double> RBound_NI_L_HIP;
139extern jbxl::RBound<double> RBound_NI_R_HIP;
140extern jbxl::RBound<double> RBound_NI_L_KNEE;
141extern jbxl::RBound<double> RBound_NI_R_KNEE;
142extern jbxl::RBound<double> RBound_NI_L_ANKLE;
143extern jbxl::RBound<double> RBound_NI_R_ANKLE;
144extern jbxl::RBound<double> RBound_NI_L_FOOT;
145extern jbxl::RBound<double> RBound_NI_R_FOOT;
146
147
148
149namespace jbxwl {
150
151using namespace jbxl;
152
153
155
156typedef struct __NiJointData
157{
158 int joint; // Niジョイントの番号
159 int index; // フレームの通し番号.フレームデータの添え字.NiFrameData[i].jdata[j].index==i
160
161 Vector<double> vect; // ジョイントの座標
162 Quaternion<double> quat; // ジョイントの回転
163
164 double angl; // 回転角(度)
165 //
167
168
169//
170typedef struct __NiFrameData
171{
172 int frmn; // フレーム番号
173 int msec; // フレーム時間
174 int jnum; // Joint の数
175 NiJointData* jdat; // Joint データの配列(jnum個)
176 //
178
179
180
182
183// 共通のジョイントの名前と番号
184std::string NiJointName(int n);
185int NiJointNum(char* name);
186
187// SDK 固有のジョイント番号から共通のジョイント名を得る
188std::string NiSDK2JointName(int joint, NiSDK_Lib lib);
189
190// SDK 固有のジョイント番号のミラージョイントの番号を得る
191int NiSDKMirrorJointNum(int joint, NiSDK_Lib lib);
192
193#define NiMirrorJointNum(j) NiSDKMirrorJointNum((j), NiSDK_None)
194
195// 共通のジョイント名から Library 固有のジョイント番号を得る
196int JointName2NiSDK(char* jname, NiSDK_Lib lib);
197
198// 共通ジョイント番号から,SDK 固有の座標用または回転用ジョイント番号を得る
199int Ni2SDKPosJointNum(int joint, NiSDK_Lib lib);
200int Ni2SDKRotJointNum(int joint, NiSDK_Lib lib);
201
202#define Ni2SDKJointNum(j, l) Ni2SDKPosJointNum((j), (l))
203
204// SDK 固有のジョイント番号を設定する
205void NiSetKinectJointNums(void);
206void NiSetOpenNIJointNums(void);
207void NiSetOpenNI2JointNums(void);
208
209// Frame
210//NiFrameData* makeFramesData(int frame, int jnum);
211//NiFrameData* makeVarFrameData(int frame, int* jnum, int* frtm=NULL);
212NiFrameData* makeFramesData(int frame, int joint_num, int* frame_num);
213void freeFramesData(NiFrameData* frmdata, int frm_num);
214
215
216
218// ジョイントの回転角の補正
219
221
222void NiCorrectJointsRotation(Quaternion<double>* quat, NiSDK_Lib lib);
223void NiCorrectJointEuler(int joint, Quaternion<double>* quat, RBound<double> rb);
224
225void NiGetJointEuler(int joint, Quaternion<double>* quat, Vector<double>* vect);
226void NiSetJointEuler(int joint, Vector<double>* vect, Quaternion<double>* quat);
227
228
229
231// 共通ジョイントのクラス
232// ジョイントを抽象化するクラス
233
235{
236public:
237 CNiJoints(void) { init();}
238 CNiJoints(NiSDK_Lib lib) { init(); sdk_lib = lib;}
239 virtual ~CNiJoints(void) {}
240
241 void clear(void) { init();}
242
243public:
245
246public:
247 void init(void);
248
249 void clearNiJointsData(void);
250 void connectJointsData(Vector<double>* vct, Quaternion<double>* qut,
251 Vector<int>* crd, double* agl, CRingBuffer* vrg, CRingBuffer* qrg);
252 void copyJoints2NiJoints(BOOL mirror);
253
254public:
255 Vector<double>* posVect;
256 Quaternion<double>* rotQuat;
257 Vector<int>* crdVect;
258
259 double* jntAngl;
260
261 CRingBuffer* posRing;
262 CRingBuffer* rotRing;
263
265 Quaternion<double> niRotQuat[NI_TOTAL_JOINT_NUM];
267
268// BOOL validPosVect[NI_TOTAL_JOINT_NUM];
269// BOOL validRotQuat[NI_TOTAL_JOINT_NUM];
270// BOOL validJntAngl[NI_TOTAL_JOINT_NUM];
271};
272
273
274
276// CBaseFrameTool Class
277// アニメーションのフレームデータを扱う基本クラス
278
280{
281public:
282 CBaseFrameTool(void);
283 virtual ~CBaseFrameTool(void);
284
285public:
286 virtual unsigned int getFramesNumber(void) { return frames_num;}
287 virtual int getJointsNumber(void) { return joints_num;}
288
289 virtual NiFrameData* getFramesData(void) { return framesData;}
290 virtual NiJointData* getJointsData(int frmnum, int fps) { return jointsData;}
291
292 virtual int getPlayBackTime(void) { return exec_time;}
293 virtual int getPlayBackFPS(void) { return 30;}
294
295 virtual BOOL readFile (FILE* fp) { return FALSE;}
296 virtual BOOL writeFile(FILE* fp) { return FALSE;}
297
298//
299protected:
300 void init_data(void);
301 void free_data(void);
302 void clear_data(void);
303
304protected:
305 unsigned int frames_num;
307
308 int start_time; // msec
309 int stop_time; // msec
310 int exec_time; // msec
311
312protected:
313 NiFrameData* framesData; // 全フレームデータ
315
316 void clearJointsData(int jnum);
317
318protected:
319 // Ni Joints
320 void clearVectorData(int jnum);
321
322 Vector<double>* posVect;
323 Quaternion<double>* rotQuat;
324};
325
326
327} // name space
328
329
330
331/*
332//
333// OpenNI
334//
335 PELVIS ( 0)
336 XN_SKEL_HEAD ( 1)
337 XN_SKEL_NECK ( 2)
338 XN_SKEL_TORSO ( 3)
339 XN_SKEL_WAIST ( 4)
340
341 XN_SKEL_LEFT_COLLAR ( 5)
342 XN_SKEL_LEFT_SHOULDER ( 6)
343 XN_SKEL_LEFT_ELBOW ( 7)
344 XN_SKEL_LEFT_WRIST ( 8)
345 XN_SKEL_LEFT_HAND ( 9)
346 XN_SKEL_LEFT_FINGERTIP (10)
347
348 XN_SKEL_RIGHT_COLLAR (11)
349 XN_SKEL_RIGHT_SHOULDER (12)
350 XN_SKEL_RIGHT_ELBOW (13)
351 XN_SKEL_RIGHT_WRIST (14)
352 XN_SKEL_RIGHT_HAND (15)
353 XN_SKEL_RIGHT_FINGERTIP (16)
354
355 XN_SKEL_LEFT_HIP (17)
356 XN_SKEL_LEFT_KNEE (18)
357 XN_SKEL_LEFT_ANKLE (19)
358 XN_SKEL_LEFT_FOOT (20)
359
360 XN_SKEL_RIGHT_HIP (21)
361 XN_SKEL_RIGHT_KNEE (22)
362 XN_SKEL_RIGHT_ANKLE (23)
363 XN_SKEL_RIGHT_FOOT (24)
364*/
365
366
367/*
368//
369// OpenNI2
370//
371 PELVIS ( 0)
372
373 NITE_JOINT_HEAD 0+1 ( 1)
374 NITE_JOINT_NECK 1+1 ( 2)
375
376 NITE_JOINT_LEFT_SHOULDER 2+1 ( 3)
377 NITE_JOINT_RIGHT_SHOULDER 3+1 ( 4)
378 NITE_JOINT_LEFT_ELBOW 4+1 ( 5)
379 NITE_JOINT_RIGHT_ELBOW 5+1 ( 6)
380 NITE_JOINT_LEFT_HAND 6+1 ( 7)
381 NITE_JOINT_RIGHT_HAND 7+1 ( 8)
382
383 NITE_JOINT_TORSO 8+1 ( 9)
384
385 NITE_JOINT_LEFT_HIP 9+1 (10)
386 NITE_JOINT_RIGHT_HIP 10+1 (11)
387 NITE_JOINT_LEFT_KNEE 11+1 (12)
388 NITE_JOINT_RIGHT_KNEE 12+1 (13)
389 NITE_JOINT_LEFT_FOOT 13+1 (14)
390 NITE_JOINT_RIGHT_FOOT 14+1 (15)
391*/
392
393
394/*
395//
396// Kinect SDK
397//
398 NUI_SKELETON_POSITION_HIP_CENTER ( 0)
399 NUI_SKELETON_POSITION_SPINE ( 1)
400 NUI_SKELETON_POSITION_SHOULDER_CENTER ( 2)
401 NUI_SKELETON_POSITION_HEAD ( 3)
402
403 NUI_SKELETON_POSITION_SHOULDER_LEFT ( 4)
404 NUI_SKELETON_POSITION_ELBOW_LEFT ( 5)
405 NUI_SKELETON_POSITION_WRIST_LEFT ( 6)
406 NUI_SKELETON_POSITION_HAND_LEFT ( 7)
407
408 NUI_SKELETON_POSITION_SHOULDER_RIGHT ( 8)
409 NUI_SKELETON_POSITION_ELBOW_RIGHT ( 9)
410 NUI_SKELETON_POSITION_WRIST_RIGHT (10)
411 NUI_SKELETON_POSITION_HAND_RIGHT (11)
412
413 NUI_SKELETON_POSITION_HIP_LEFT (12)
414 NUI_SKELETON_POSITION_KNEE_LEFT (13)
415 NUI_SKELETON_POSITION_ANKLE_LEFT (14)
416 NUI_SKELETON_POSITION_FOOT_LEFT (15)
417
418 NUI_SKELETON_POSITION_HIP_RIGHT (16)
419 NUI_SKELETON_POSITION_KNEE_RIGHT (17)
420 NUI_SKELETON_POSITION_ANKLE_RIGHT (18)
421 NUI_SKELETON_POSITION_FOOT_RIGHT (19)
422*/
423
int NI_SDK_R_KNEE
jbxl::RBound< double > RBound_NI_L_KNEE
jbxl::RBound< double > RBound_NI_NECK
int NI_SDK_R_HAND
int NI_SDK_L_WRIST
int NI_SDK_L_HAND
jbxl::RBound< double > RBound_NI_TORSO
int NI_SDK_L_HIP
int NI_SDK_R_HIP
jbxl::RBound< double > RBound_NI_R_ELBOW
int NI_SDK_R_SHLDR
jbxl::RBound< double > RBound_NI_L_HIP
int NI_SDK_R_EYE
int NI_SDK_L_SHLDR
jbxl::RBound< double > RBound_NI_R_COLLAR
int NI_SDK_R_ANKLE
int NI_SDK_HEAD
jbxl::RBound< double > RBound_NI_L_FOOT
#define NI_TOTAL_JOINT_NUM
jbxl::RBound< double > RBound_NI_R_FOOT
jbxl::RBound< double > RBound_NI_L_HAND
int NI_SDK_R_FINGER
jbxl::RBound< double > RBound_NI_R_HAND
jbxl::RBound< double > RBound_NI_R_ANKLE
jbxl::RBound< double > RBound_NI_L_SHLDR
int NI_SDK_PELVIS
int NI_SDK_NECK
int NI_SDK_R_ELBOW
int NI_SDK_FACE
int NI_SDK_L_FOOT
int NI_SDK_L_EYE
int NI_SDK_L_KNEE
jbxl::RBound< double > RBound_NI_L_COLLAR
int NI_SDK_AVATAR
jbxl::RBound< double > RBound_NI_L_ANKLE
int NI_SDK_L_ANKLE
int NI_SDK_R_FOOT
int NI_SDK_TORSO
jbxl::RBound< double > RBound_NI_R_SHLDR
jbxl::RBound< double > RBound_NI_CHEST
int NI_SDK_R_BUST
int NI_SDK_L_FINGER
jbxl::RBound< double > RBound_NI_R_WRIST
int NI_SDK_L_ELBOW
int NI_SDK_R_WRIST
jbxl::RBound< double > RBound_NI_L_ELBOW
jbxl::RBound< double > RBound_NI_R_HIP
int NI_SDK_L_BUST
jbxl::RBound< double > RBound_NI_L_WRIST
jbxl::RBound< double > RBound_NI_R_KNEE
jbxl::RBound< double > RBound_NI_HEAD
NiJointData * jointsData
void clearVectorData(int jnum)
virtual ~CBaseFrameTool(void)
virtual unsigned int getFramesNumber(void)
void clearJointsData(int jnum)
virtual NiFrameData * getFramesData(void)
virtual int getPlayBackFPS(void)
virtual BOOL writeFile(FILE *fp)
Vector< double > * posVect
unsigned int frames_num
virtual int getPlayBackTime(void)
NiFrameData * framesData
virtual NiJointData * getJointsData(int frmnum, int fps)
virtual int getJointsNumber(void)
virtual BOOL readFile(FILE *fp)
Quaternion< double > * rotQuat
CNiJoints(NiSDK_Lib lib)
void clearNiJointsData(void)
virtual ~CNiJoints(void)
Quaternion< double > niRotQuat[NI_TOTAL_JOINT_NUM]
void copyJoints2NiJoints(BOOL mirror)
Vector< int > * crdVect
Vector< double > * posVect
void connectJointsData(Vector< double > *vct, Quaternion< double > *qut, Vector< int > *crd, double *agl, CRingBuffer *vrg, CRingBuffer *qrg)
Vector< double > niPosVect[NI_TOTAL_JOINT_NUM]
double niJntAngl[NI_TOTAL_JOINT_NUM]
CRingBuffer * rotRing
CRingBuffer * posRing
Quaternion< double > * rotQuat
NiFrameData * makeFramesData(int frame, int joint_num, int *frame_num)
std::string NiJointName(int n)
void NiInitRBoundJointsRotation(void)
void NiSetOpenNI2JointNums(void)
void NiSetJointEuler(int joint, Vector< double > *vect, Quaternion< double > *quat)
int JointName2NiSDK(char *jname, NiSDK_Lib lib)
void NiCorrectJointsRotation(Quaternion< double > *quat, NiSDK_Lib lib)
int NiSDKMirrorJointNum(int joint, NiSDK_Lib lib)
void NiGetJointEuler(int joint, Quaternion< double > *quat, Vector< double > *vect)
void NiCorrectJointEuler(int joint, Quaternion< double > *quat, RBound< double > rb)
int Ni2SDKPosJointNum(int joint, NiSDK_Lib lib)
void NiSetKinectJointNums(void)
void freeFramesData(NiFrameData *frmdata, int frm_num)
void NiSetOpenNIJointNums(void)
std::string NiSDK2JointName(int joint, NiSDK_Lib lib)
int Ni2SDKRotJointNum(int joint, NiSDK_Lib lib)
NiSDK_Lib
Definition NiToolWin.h:35
int NiJointNum(char *name)
NiJointData * jdat
Quaternion< double > quat
Vector< double > vect