int parser_save(struct katcp_dispatch *d, char *filename, int force){ struct kcs_basic *kb; struct p_parser *p; kb = get_mode_katcp(d,KCS_MODE_BASIC); if (kb == NULL) return KATCP_RESULT_FAIL; p = kb->b_parser; if (p != NULL) { int rtn; if (filename == NULL && !force){ rtn = save_tree(p,p->filename,force); if (rtn == KATCP_RESULT_FAIL){ log_message_katcp(d,KATCP_LEVEL_WARN,NULL,"File has been edited behind your back!!! use ?parser save newfilename or force save ?parser forcesave"); return KATCP_RESULT_FAIL; } } else if (force) rtn = save_tree(p,p->filename,force); else rtn = save_tree(p,filename,force); if (rtn == KATCP_RESULT_OK){ log_message_katcp(d,KATCP_LEVEL_INFO,NULL,"Saved configuration file as %s",(filename == NULL)?p->filename:filename); return rtn; } } log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"No configuration file loaded yet, use ?parser load [filename]"); return KATCP_RESULT_FAIL; }
void campaign_editor::OnMoveDown() { int i, j; campaign_tree_link temp; HTREEITEM h1, h2; if (Cur_campaign_link >= 0) { save_tree(); for (i=0; i<Total_links; i++) if (Links[i].from == Cur_campaign_mission) if (i == Cur_campaign_link) break; for (j=i+1; j<Total_links; j++) if (Links[j].from == Cur_campaign_mission) break; if (j < Total_links) { h1 = m_tree.GetParentItem(m_tree.handle(Links[i].node)); h2 = m_tree.GetParentItem(m_tree.handle(Links[j].node)); m_tree.swap_roots(h1, h2); m_tree.SelectItem(m_tree.GetParentItem(m_tree.handle(Links[i].node))); temp = Links[j]; Links[j] = Links[i]; Links[i] = temp; Cur_campaign_link = j; } } GetDlgItem(IDC_SEXP_TREE)->SetFocus(); }
void campaign_editor::OnMoveUp() { int i, last = -1; campaign_tree_link temp; HTREEITEM h1, h2; if (Cur_campaign_link >= 0) { save_tree(); for (i=0; i<Total_links; i++){ if (Links[i].from == Cur_campaign_mission) { if (i == Cur_campaign_link){ break; } last = i; } } if ((last != -1) && (i < Total_links)) { h1 = m_tree.GetParentItem(m_tree.handle(Links[i].node)); h2 = m_tree.GetParentItem(m_tree.handle(Links[last].node)); m_tree.swap_roots(h1, h2); m_tree.SelectItem(m_tree.GetParentItem(m_tree.handle(Links[i].node))); temp = Links[last]; Links[last] = Links[i]; Links[i] = temp; Cur_campaign_link = last; } } GetDlgItem(IDC_SEXP_TREE)->SetFocus(); }
static void tree_destroy (WTree *tree) { tree_store_remove_entry_remove_hook (remove_callback); save_tree (tree); g_free (tree->tree_shown); tree->tree_shown = 0; tree->selected_ptr = NULL; }
static void codify(FILE *fin, huff_node_t *root, int **codes, int *lengths, FILE *fout) { rewind(fin); save_tree(fout, codes, lengths); char c, prin_c = (char)0; int i, index, k; long unsigned int bits_count = 0; while (fscanf(fin, "%c", &c) != EOF) { index = (int)c + CHARS_NUM/2; for(i = 0; i < lengths[index]; i++) { prin_c = (prin_c << 1) | codes[index][i]; ++bits_count; if (++k == 8) { fprintf(fout, " %c ", prin_c); prin_c = (char)0; k = 0; } } } fclose(fout); }
void campaign_editor::load_tree(int save_first) { char text[80]; int i; HTREEITEM h; if (save_first) save_tree(); m_tree.clear_tree(); m_tree.DeleteAllItems(); m_num_links = 0; UpdateData(TRUE); update_loop_desc_window(); m_last_mission = Cur_campaign_mission; if (Cur_campaign_mission < 0) { GetDlgItem(IDC_SEXP_TREE)->EnableWindow(FALSE); GetDlgItem(IDC_BRIEFING_CUTSCENE)->EnableWindow(FALSE); return; } GetDlgItem(IDC_SEXP_TREE)->EnableWindow(TRUE); GetDlgItem(IDC_BRIEFING_CUTSCENE)->EnableWindow(TRUE); GetDlgItem(IDC_MISSISON_LOOP_DESC)->EnableWindow(FALSE); GetDlgItem(IDC_LOOP_BRIEF_ANIM)->EnableWindow(FALSE); GetDlgItem(IDC_LOOP_BRIEF_SOUND)->EnableWindow(FALSE); GetDlgItem(IDC_LOOP_BRIEF_BROWSE)->EnableWindow(FALSE); GetDlgItem(IDC_LOOP_BRIEF_SOUND_BROWSE)->EnableWindow(FALSE); for (i=0; i<Total_links; i++) { if (Links[i].from == Cur_campaign_mission) { Links[i].node = m_tree.load_sub_tree(Links[i].sexp); m_num_links++; if (Links[i].from == Links[i].to) { strcpy(text, "Repeat mission"); } else if ( (Links[i].to == -1) && (Links[i].from != -1) ) { strcpy(text, "End of Campaign"); } else { sprintf(text, "Branch to %s", Campaign.missions[Links[i].to].name); } // insert item into tree int image, sel_image; if (Links[i].mission_loop) { image = BITMAP_BLUE_DOT; sel_image = BITMAP_GREEN_DOT; } else { image = BITMAP_BLACK_DOT; sel_image = BITMAP_RED_DOT; } h = m_tree.insert(text, image, sel_image); m_tree.SetItemData(h, Links[i].node); m_tree.add_sub_tree(Links[i].node, h); } } }
int main() { stringstream ss; clock_t begin, end, training_time; string is_save; srand(time(NULL)); cout << "Human pose estimation CVPR2016 based on SMMC DB" << endl; cout << "Developed by Gyeongsik Moon" << endl << endl; cout << "SAVE or LOAD: "; cin >> is_save; cout << endl; vector<node*> tree_head; point *point_train; joint **joint_train; point *point_matching; joint **joint_matching; point *point_test; joint **joint_test; if (!is_save.compare("SAVE")) { point_train = new point[TRAIN_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_train = new joint *[TRAIN_FRAME_NUM]; for (int f = 0; f < TRAIN_FRAME_NUM; f++) joint_train[f] = new joint[JOINT_NUMBER]; //Load training data cout << "Loading training data..." << endl; load_data(point_train, joint_train, TRAINING); cout << endl; //Train a tree cout << "Training start!" << endl; begin = clock(); tree_train(point_train, joint_train, tree_head); end = clock(); training_time = end - begin; cout << endl << "Training complete!" << endl; cout << (float)(end - begin) / CLOCKS_PER_SEC << "seconds for training" << endl << endl; cout << "Saving tree..." << endl; save_tree(tree_head); for (long long int pid = 0; pid < TRAIN_FRAME_NUM * Q_HEIGHT * Q_WIDTH; pid++) { if (point_train[pid].depth != BACKGROUND_DEPTH) { for (int nid = 0; nid < NEAREST_NUM; nid++) delete[] point_train[pid].offset[nid]; delete[] point_train[pid].offset; } } delete[] point_train; for (int f = 0; f < TRAIN_FRAME_NUM; f++) delete[] joint_train[f]; delete[] joint_train; } else if (!is_save.compare("LOAD")) { cout << "Loading tree..." << endl; training_time = 0; load_tree(&tree_head); } else { cout << "Not a proper input..." << endl; return 0; } point_matching = new point[POINT_MATCHING_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_matching = new joint *[POINT_MATCHING_FRAME_NUM]; for (int f = 0; f < POINT_MATCHING_FRAME_NUM; f++) joint_matching[f] = new joint[JOINT_NUMBER]; cout << "Loading DB for point matching..." << endl; load_data(point_matching, joint_matching, POINT_MATCHING); float** center_matching; center_matching = new float*[POINT_MATCHING_FRAME_NUM]; for (int matching_f = 0; matching_f < POINT_MATCHING_FRAME_NUM; matching_f++) { center_matching[matching_f] = new float[COORDINATE_DIM]; center_matching[matching_f][0] = 0; center_matching[matching_f][1] = 0; center_matching[matching_f][2] = 0; float pixel_num = 0; for (int matching_i = 0; matching_i < Q_WIDTH * Q_HEIGHT; matching_i++) { if (point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].depth != BACKGROUND_DEPTH) { center_matching[matching_f][0] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].x_world; center_matching[matching_f][1] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].y_world; center_matching[matching_f][2] += point_matching[matching_f * Q_HEIGHT * Q_WIDTH + matching_i].depth; pixel_num++; } } center_matching[matching_f][0] /= pixel_num; center_matching[matching_f][1] /= pixel_num; center_matching[matching_f][2] /= pixel_num; } delete[] point_matching; point_test = new point[TEST_FRAME_NUM * Q_HEIGHT * Q_WIDTH]; joint_test = new joint *[TEST_FRAME_NUM]; for (int f = 0; f < TEST_FRAME_NUM; f++) joint_test[f] = new joint[JOINT_NUMBER]; //load test dataset cout << "Loading test dataset..." << endl; load_data(point_test, joint_test, TEST); //Test cout << "Testing start!" << endl; begin = clock(); //tree traversal tree_traversal(point_test, joint_test, center_matching, joint_matching, tree_head); end = clock(); cout << "Testing complete!" << endl << endl; cout << (float)training_time / CLOCKS_PER_SEC << "seoncds for training" << endl; cout << (float)(end - begin) / CLOCKS_PER_SEC << "seoncds for testing" << endl; for (int matching_f = 0; matching_f < POINT_MATCHING_FRAME_NUM; matching_f++) delete[] center_matching[matching_f]; delete[] center_matching; for (int f = 0; f < POINT_MATCHING_FRAME_NUM; f++) delete[] joint_matching[f]; delete[] joint_matching; for (int f = 0; f < TEST_FRAME_NUM; f++) delete[] joint_test[f]; delete[] joint_test; delete[] point_test; return 0; }