#include <BVHTool.h>
Public Member Functions | |
CBVHTool (void) | |
virtual | ~CBVHTool (void) |
void | init (void) |
void | free_data (void) |
void | clear_data (void) |
void | copy_bvh_data (BVHData *bvh) |
BVHData | setback_bvh_data (void) |
BOOL | readFile (char *fname) |
BOOL | writeFile (char *fname) |
BOOL | writeMultiFile (char *fname, int sec, int space) |
BOOL | readBVH (FILE *fp) |
BOOL | printBVH (FILE *fp) |
void | setHierarchy (tTree *hrchy) |
Vector< double > * | getPosOffset (void) |
Vector< double > * | getPosData (int frame) |
Quaternion< double > * | getQuaternion (int frame) |
Public Attributes | |
Buffer * | joint_name |
int * | channel_num |
int * | channel_idx |
Buffer | flex_joint |
Private Member Functions | |
void | set_offset (void) |
void | _set_offset (tTree *tree, int *jnum) |
void | get_bvh_params (void) |
void | _get_bvh_params (tTree *tree, int **ch, Buffer **jn) |
Definition at line 24 of file BVHTool.h.
CBVHTool | ( | void | ) | [inline] |
Definition at line 27 of file BVHTool.h.
References CBVHTool::init().
00027 { init();}
~CBVHTool | ( | void | ) | [virtual] |
Definition at line 18 of file BVHTool.cpp.
References DEBUG_INFO, and CBVHTool::free_data().
00019 { 00020 DEBUG_INFO("DESTRUCTOR: CBVHTool"); 00021 00022 free_data(); 00023 }
Definition at line 399 of file BVHTool.cpp.
References cat_Buffer(), dup_Buffer(), and CBVHTool::flex_joint.
Referenced by CBVHTool::get_bvh_params().
00400 { 00401 if (tree!=NULL) { 00402 while(tree->esis!=NULL) tree = tree->esis; 00403 00404 do { 00405 tList_data ld = tree->ldat; 00406 00408 if ((*ch)!=NULL) { 00409 **ch = ld.lv; 00410 (*ch)++; 00411 } 00412 cat_Buffer(&ld.val, &flex_joint); 00413 00414 **jn = dup_Buffer(ld.key); 00415 (*jn)++; 00417 00418 00419 if (tree->next!=NULL) { 00420 _get_bvh_params(tree->next, ch, jn); 00421 } 00422 tree = tree->ysis; 00423 // 00424 } while(tree!=NULL); 00425 } 00426 00427 return; 00428 }
void _set_offset | ( | tTree * | tree, | |
int * | jnum | |||
) | [private] |
Definition at line 324 of file BVHTool.cpp.
Referenced by CBVHTool::set_offset().
00325 { 00326 if (tree!=NULL) { 00327 while(tree->esis!=NULL) tree = tree->esis; 00328 00329 do { 00330 tList_data* ld = &(tree->ldat); 00331 00333 if (ld->ptr==NULL) { 00334 ld->sz = sizeof(vector); 00335 ld->ptr = (void*)malloc(ld->sz); 00336 } 00337 *((vector*)ld->ptr) = offset[*jnum]; 00338 (*jnum)++; 00340 00341 if (tree->next!=NULL) _set_offset(tree->next, jnum); 00342 tree = tree->ysis; 00343 // 00344 } while(tree!=NULL); 00345 } 00346 00347 return; 00348 00349 00350 }
void clear_data | ( | void | ) |
Definition at line 77 of file BVHTool.cpp.
References CBVHTool::channel_idx, CBVHTool::channel_num, CBVHTool::flex_joint, free_Buffer(), and CBVHTool::joint_name.
Referenced by CBVHTool::free_data().
00078 { 00079 if (joint_name!=NULL) { 00080 for (int j=0; j<joint_num; j++) { 00081 free_Buffer(&joint_name[j]); 00082 } 00083 free(joint_name); 00084 } 00085 joint_name = NULL; 00086 00087 if (channel_num!=NULL) { 00088 free(channel_num); 00089 channel_num = NULL; 00090 } 00091 00092 if (channel_idx!=NULL) { 00093 free(channel_idx); 00094 channel_idx = NULL; 00095 } 00096 00097 free_Buffer(&flex_joint); 00098 }
void copy_bvh_data | ( | BVHData * | bvh | ) |
Definition at line 102 of file BVHTool.cpp.
Referenced by CBVHTool::readBVH().
00103 { 00104 if (bvh==NULL) return; 00105 00106 joint_num = bvh->joint_num; 00107 frame_num = bvh->frame_num; 00108 frame_time = bvh->frame_time; 00109 framepsec = bvh->framepsec; 00110 channels = bvh->channels; 00111 state = bvh->state; 00112 00113 hierarchy = bvh->hierarchy; 00114 motion = bvh->motion; 00115 offset = bvh->offset; 00116 }
void free_data | ( | void | ) |
Definition at line 50 of file BVHTool.cpp.
References CBVHTool::clear_data(), and del_tTree().
Referenced by CBVHTool::setHierarchy(), and CBVHTool::~CBVHTool().
00051 { 00052 state = 0; 00053 joint_num = 0; 00054 channels = 0; 00055 frame_num = 0; 00056 frame_time = 0.0; 00057 framepsec = 0; 00058 00059 if (hierarchy!=NULL) { 00060 del_tTree(&hierarchy); 00061 hierarchy = NULL; 00062 } 00063 if (motion!=NULL) { 00064 free(motion); 00065 motion = NULL; 00066 } 00067 if (offset!=NULL) { 00068 free(offset); 00069 offset = NULL; 00070 } 00071 00072 clear_data(); 00073 }
void get_bvh_params | ( | void | ) | [private] |
既存の hierarchyデータから以下のデータを得る. channel_num, channel_idx, flex_joint, joint_name
Definition at line 364 of file BVHTool.cpp.
References CBVHTool::_get_bvh_params(), CBVHTool::channel_idx, CBVHTool::channel_num, CBVHTool::flex_joint, CBVHTool::joint_name, and make_Buffer().
Referenced by CBVHTool::readBVH(), and CBVHTool::setHierarchy().
00365 { 00366 size_t len = sizeof(int)*joint_num; 00367 channel_num = (int*)malloc(len); 00368 channel_idx = (int*)malloc(len); 00369 // 00370 if (channel_num==NULL || channel_idx==NULL) { 00371 if (channel_num!=NULL) free(channel_num); 00372 if (channel_idx!=NULL) free(channel_idx); 00373 channel_num = NULL; 00374 channel_idx = NULL; 00375 return; 00376 } 00377 memset(channel_num, 0, sizeof((int)len)); 00378 memset(channel_idx, 0, sizeof((int)len)); 00379 00380 // 00381 flex_joint = make_Buffer(joint_num*6); 00382 joint_name = (Buffer*)malloc(sizeof(Buffer)*joint_num); 00383 00384 int* ch = channel_num; 00385 Buffer* jn = joint_name; 00386 00387 _get_bvh_params(hierarchy, &ch, &jn); 00388 00389 // 00390 channel_idx[0] = 0; 00391 for (int j=1; j<joint_num; j++) { 00392 channel_idx[j] = channel_idx[j-1] + channel_num[j-1]; 00393 } 00394 00395 }
Vector< double > * getPosData | ( | int | frame | ) |
Definition at line 436 of file BVHTool.cpp.
References Buffer::buf, CBVHTool::channel_idx, CBVHTool::channel_num, FALSE, CBVHTool::flex_joint, Vector< T >::set(), TRUE, Vector< T >::x, Vector< T >::y, and Vector< T >::z.
00437 { 00438 if (frame<0 || frame>=frame_num) return NULL; 00439 00440 size_t len = sizeof(Vector<double>)*joint_num; 00441 Vector<double>* vect = (Vector<double>*)malloc(len); 00442 if (vect==NULL) return NULL; 00443 memset(vect, 0, len); 00444 00445 int frm = frame*channels; 00446 00447 for (int j=0; j<joint_num; j++) { 00448 // 00449 BOOL exstf = FALSE; 00450 int chnum = channel_num[j]; 00451 int index = channel_idx[j]; 00452 char* tpchr = (char*)&flex_joint.buf[index*2]; 00453 00454 for (int i=0; i<chnum; i++) { 00455 if (tpchr[i*2]=='P') { 00456 exstf = TRUE; 00457 index = frm + index + i; 00458 tpchr+= i*2; 00459 break; 00460 } 00461 } 00462 00463 // 00464 vect[j].set(0.0, 0.0, 0.0); 00465 00466 if (exstf) { 00467 for (int k=0; k<3; k++) { 00468 int k2 = k*2; 00469 if (tpchr[k2]=='P') { 00470 if (tpchr[k2+1]=='X') vect[j].x = motion[index+k]; 00471 else if (tpchr[k2+1]=='Y') vect[j].y = motion[index+k]; 00472 else if (tpchr[k2+1]=='Z') vect[j].z = motion[index+k]; 00473 } 00474 } 00475 } 00476 } 00477 00478 return vect; 00479 }
Vector< double > * getPosOffset | ( | void | ) |
Definition at line 556 of file BVHTool.cpp.
References vector::n, Vector< T >::n, vector::x, Vector< T >::x, vector::y, Vector< T >::y, vector::z, and Vector< T >::z.
00557 { 00558 size_t len = sizeof(Vector<double>)*joint_num; 00559 Vector<double>* vect = (Vector<double>*)malloc(len); 00560 00561 if (vect==NULL) return NULL; 00562 memset(vect, 0, len); 00563 00564 for (int j=0; j<joint_num; j++) { 00565 vector vt = offset[j]; 00566 vect[j].x = vt.x; 00567 vect[j].y = vt.y; 00568 vect[j].z = vt.z; 00569 vect[j].n = vt.n; 00570 } 00571 00572 return vect; 00573 }
Quaternion< double > * getQuaternion | ( | int | frame | ) |
Definition at line 483 of file BVHTool.cpp.
References Buffer::buf, CBVHTool::channel_idx, CBVHTool::channel_num, FALSE, CBVHTool::flex_joint, PI, Quaternion< T >::set(), Quaternion< T >::setRotation(), and TRUE.
00484 { 00485 if (frame<0 || frame>=frame_num) return NULL; 00486 00487 size_t len = sizeof(Quaternion<double>)*joint_num; 00488 Quaternion<double>* quat = (Quaternion<double>*)malloc(len); 00489 if (quat==NULL) return NULL; 00490 00491 Vector<double> ex(1.0, 0.0, 0.0, 1.0); 00492 Vector<double> ey(0.0, 1.0, 0.0, 1.0); 00493 Vector<double> ez(0.0, 0.0, 1.0, 1.0); 00494 00495 double d2r = PI/180.0; 00496 int frm = frame*channels; 00497 00498 // 00499 for (int j=0; j<joint_num; j++) { 00500 // 00501 BOOL exstf = FALSE; 00502 int chnum = channel_num[j]; 00503 int index = channel_idx[j]; 00504 char* tpchr = (char*)&flex_joint.buf[index*2]; 00505 00506 quat[j].set(1.0, 0.0, 0.0, 0.0, 1.0); 00507 // 00508 int chfwd = 0; 00509 for (int i=0; i<chnum; i++) { 00510 if (tpchr[i*2]=='R') { 00511 exstf = TRUE; // 回転用データの存在 00512 index = frm + index + i; // MOTION データの位置 00513 tpchr+= i*2; // チャンネルインデックスの位置 00514 chfwd = i; // 処理済チャンネル数 00515 break; 00516 } 00517 } 00518 00519 // 00520 if (exstf) { 00521 Quaternion<double> q1(1.0, 0.0, 0.0, 0.0, 1.0); 00522 Quaternion<double> q2(1.0, 0.0, 0.0, 0.0, 1.0); 00523 Quaternion<double> q3(1.0, 0.0, 0.0, 0.0, 1.0); 00524 00525 // X->Y, Y->Z, Z->X 00526 double th = motion[index]*d2r; 00527 if (tpchr[1]=='X') q3.setRotation(th, ey); 00528 else if (tpchr[1]=='Y') q3.setRotation(th, ez); 00529 else if (tpchr[1]=='Z') q3.setRotation(th, ex); 00530 00531 chnum = chnum - chfwd - 1; // 残りの回転用チャンネル数 00532 if (chnum>0 && tpchr[2]=='R') { 00533 th = motion[index+1]*d2r; 00534 if (tpchr[3]=='X') q2.setRotation(th, ey); 00535 else if (tpchr[3]=='Y') q2.setRotation(th, ez); 00536 else if (tpchr[3]=='Z') q2.setRotation(th, ex); 00537 00538 chnum--; 00539 if (chnum>0 && tpchr[4]=='R') { 00540 th = motion[index+2]*d2r; 00541 if (tpchr[5]=='X') q1.setRotation(th, ey); 00542 else if (tpchr[5]=='Y') q1.setRotation(th, ez); 00543 else if (tpchr[5]=='Z') q1.setRotation(th, ex); 00544 } 00545 } 00546 00547 quat[j] = q3*q2*q1; 00548 } 00549 00550 } 00551 return quat; 00552 }
void init | ( | void | ) |
Definition at line 27 of file BVHTool.cpp.
References CBVHTool::channel_idx, CBVHTool::channel_num, CBVHTool::flex_joint, init_Buffer(), and CBVHTool::joint_name.
Referenced by CBVHTool::CBVHTool().
00028 { 00029 // BVHData 00030 joint_num = 0; // 関節の数(End Site を含まない) 00031 frame_num = 0; // フレームの数 00032 frame_time = 0.0; // フレーム間の時間 s 00033 framepsec = 0; // FPS 00034 channels = 0; // 総チャンネル数.チャンネル数の合計.モーションデータの数. 00035 state = 0; // データの状態 00036 00037 hierarchy = NULL; // 関節部のツリーデータへのポインタ.上記参照. 00038 motion = NULL; // MOTION データへのポインタ joint_num*frame_num 00039 offset = NULL; // 関節のOFFSET 00040 // 00041 channel_num = NULL; 00042 channel_idx = NULL; 00043 joint_name = NULL; 00044 00045 flex_joint = init_Buffer(); 00046 }
BOOL printBVH | ( | FILE * | fp | ) |
Definition at line 286 of file BVHTool.cpp.
References BVH_ERR_INVLD_ARGS, bvh_print_data(), FALSE, CBVHTool::setback_bvh_data(), and TRUE.
00287 { 00288 state = BVH_ERR_INVLD_ARGS; 00289 if (fp==NULL) return FALSE; 00290 00291 state = 0; 00292 BVHData bvh_data = setback_bvh_data(); 00293 state = bvh_print_data(fp, &bvh_data); 00294 if (state!=0) return FALSE; 00295 00296 return TRUE; 00297 }
BOOL readBVH | ( | FILE * | fp | ) |
Definition at line 165 of file BVHTool.cpp.
References BVH_ERR_FAIL_OP, BVH_ERR_INVLD_ARGS, bvh_read_data, CBVHTool::copy_bvh_data(), del_BVHData(), FALSE, CBVHTool::get_bvh_params(), and TRUE.
Referenced by CBVHTool::readFile().
00166 { 00167 state = BVH_ERR_INVLD_ARGS; 00168 if (fp==NULL) return FALSE; 00169 00170 state = BVH_ERR_FAIL_OP; 00171 BVHData* ptr = bvh_read_data(fp); 00172 if (ptr==NULL) return FALSE; 00173 if (ptr->state!=0) { 00174 del_BVHData(&ptr); 00175 return FALSE; 00176 } 00177 // 00178 copy_bvh_data(ptr); 00179 get_bvh_params(); 00180 00181 return TRUE; 00182 }
BOOL readFile | ( | char * | fname | ) |
Definition at line 146 of file BVHTool.cpp.
References BVH_ERR_FAIL_FOPEN, BVH_ERR_INVLD_ARGS, FALSE, file_size(), and CBVHTool::readBVH().
00147 { 00148 state = BVH_ERR_INVLD_ARGS; 00149 if (fname==NULL || fname[0]=='\0') return FALSE; 00150 00151 unsigned long int sz = file_size(fname); 00152 if (sz==0) return FALSE; 00153 00154 state = BVH_ERR_FAIL_FOPEN; 00155 FILE* fp = fopen(fname, "r"); 00156 if (fp==NULL) return FALSE; 00157 00158 BOOL ret = readBVH(fp); 00159 00160 return ret; 00161 }
void set_offset | ( | void | ) | [private] |
Definition at line 314 of file BVHTool.cpp.
References CBVHTool::_set_offset().
Referenced by CBVHTool::setback_bvh_data().
00315 { 00316 if (offset==NULL) return; 00317 00318 int jnum = 0; 00319 _set_offset(hierarchy, &jnum); 00320 }
BVHData setback_bvh_data | ( | void | ) |
Definition at line 120 of file BVHTool.cpp.
References CBVHTool::set_offset().
Referenced by CBVHTool::printBVH(), CBVHTool::writeFile(), and CBVHTool::writeMultiFile().
00121 { 00122 BVHData bvh; 00123 00124 set_offset(); 00125 00126 bvh.joint_num = joint_num; 00127 bvh.frame_num = frame_num; 00128 bvh.frame_time = frame_time; 00129 bvh.framepsec = framepsec; 00130 bvh.channels = channels; 00131 bvh.state = state; 00132 00133 bvh.hierarchy = hierarchy; 00134 bvh.motion = motion; 00135 bvh.offset = offset; 00136 00137 return bvh; 00138 }
void setHierarchy | ( | tTree * | hrchy | ) |
Definition at line 301 of file BVHTool.cpp.
References bvh_count_channels(), bvh_count_joints(), CBVHTool::free_data(), and CBVHTool::get_bvh_params().
00302 { 00303 free_data(); 00304 00305 hierarchy = hrchy; 00306 joint_num = bvh_count_joints(hierarchy); 00307 channels = bvh_count_channels(hierarchy); 00308 00309 get_bvh_params(); 00310 }
BOOL writeFile | ( | char * | fname | ) |
Definition at line 186 of file BVHTool.cpp.
References BVH_ERR_INVLD_ARGS, bvh_write_file(), FALSE, CBVHTool::setback_bvh_data(), and TRUE.
00187 { 00188 state = BVH_ERR_INVLD_ARGS; 00189 if (fname==NULL || fname[0]=='\0') return FALSE; 00190 00191 state = 0; 00192 BVHData bvh_data = setback_bvh_data(); 00193 state = bvh_write_file(fname, &bvh_data); 00194 if (state!=0) return FALSE; 00195 00196 return TRUE; 00197 }
BOOL writeMultiFile | ( | char * | fname, | |
int | sec, | |||
int | space | |||
) |
BOOL CBVHTool::writeMultiFile(char* fname, int sec, int space)
sec秒区切りで.BVHファイルを出力する.のりしろ(フレーム数)付き.
fname | 出力ファイル名のベース.fname_00 〜 fname_99 のファイルが出力される. | |
sec | 1ファイルの最大再生時間(秒). | |
space | のりしろのフレーム数. |
TRUE | 成功 | |
FALSE | 失敗 |
Definition at line 212 of file BVHTool.cpp.
References Buffer::buf, BVH_ERR_INVLD_ARGS, bvh_write_file(), cat_s2Buffer, CBVHTool::channel_num, dup_str(), FALSE, free_Buffer(), get_file_extension(), make_Buffer_bystr, numbering_name(), CBVHTool::setback_bvh_data(), and TRUE.
00213 { 00214 state = BVH_ERR_INVLD_ARGS; 00215 if (fname==NULL || fname[0]=='\0') return FALSE; 00216 00217 int echfrm = (int)(sec/frame_time); // 1ファイルのフレーム数 00218 int num = (frame_num + echfrm - 1)/echfrm; // 出力ファイルの数 00219 if (num==0 || num>99) return FALSE; 00220 00221 // 00222 char* fn = dup_str(fname); 00223 char* et = get_file_extension(fn); 00224 if (et!=NULL) et[-1] = '\0'; 00225 00226 Buffer format = make_Buffer_bystr(fn); 00227 cat_s2Buffer("_%02d", &format); 00228 if (et!=NULL) { 00229 cat_s2Buffer(".", &format); 00230 cat_s2Buffer(et, &format); 00231 } 00232 ::free(fn); 00233 00234 // 00235 state = 0; 00236 BVHData bvh_data = setback_bvh_data(); 00237 00238 for (int i=0; i<num; i++) { 00239 // 00240 int outfrm = i*echfrm; // 今まで出力した有効フレーム数 00241 00242 if (i==num-1) { 00243 bvh_data.frame_num = frame_num - outfrm; // 残りのフレーム数.のりしろは使用しない. 00244 } 00245 else if (i==num-2) { 00246 if ((num-1)*echfrm + space > frame_num) { // のりしろが大きすぎる 00247 space = frame_num - (num-1)*echfrm; 00248 } 00249 bvh_data.frame_num = echfrm + space; 00250 } 00251 else { 00252 bvh_data.frame_num = echfrm + space; 00253 } 00254 00255 if (i!=0 && space>0) { 00256 bvh_data.frame_num++; // 00257 bvh_data.motion = &(motion[(outfrm-1)*channels]); // -1: のりしろ 00258 if (channel_num[0]==6) { // ROOT のチャンネル数 00259 bvh_data.motion[0] = motion[0]; 00260 bvh_data.motion[1] = motion[1]; 00261 bvh_data.motion[2] = motion[2]; 00262 bvh_data.motion[3] = 0.0; 00263 bvh_data.motion[4] = 0.0; 00264 bvh_data.motion[5] = 0.0; 00265 } 00266 } 00267 else { 00268 bvh_data.motion = &(motion[outfrm*channels]); 00269 } 00270 00271 // 00272 char* fn = numbering_name((char*)format.buf, i); 00273 state = bvh_write_file(fn, &bvh_data); 00274 free(fn); 00275 if (state!=0) break; 00276 } 00277 00278 free_Buffer(&format); 00279 00280 if (state!=0) return FALSE; 00281 return TRUE; 00282 }
int* channel_idx |
Definition at line 77 of file BVHTool.h.
Referenced by CBVHTool::clear_data(), CBVHTool::get_bvh_params(), CBVHTool::getPosData(), CBVHTool::getQuaternion(), and CBVHTool::init().
int* channel_num |
Definition at line 76 of file BVHTool.h.
Referenced by CBVHTool::clear_data(), CBVHTool::get_bvh_params(), CBVHTool::getPosData(), CBVHTool::getQuaternion(), CBVHTool::init(), and CBVHTool::writeMultiFile().
Definition at line 78 of file BVHTool.h.
Referenced by CBVHTool::_get_bvh_params(), CBVHTool::clear_data(), CBVHTool::get_bvh_params(), CBVHTool::getPosData(), CBVHTool::getQuaternion(), and CBVHTool::init().
Definition at line 75 of file BVHTool.h.
Referenced by CBVHTool::clear_data(), CBVHTool::get_bvh_params(), and CBVHTool::init().