Example #1
0
void prev_thread(Node *root){
    if (root != NULL){
        if (root->left->child == NULL){
            root->left->child = prev;
            root->left->tag = LINK;
        }
        if (prev != NULL && prev->right->child == NULL){
            prev->right->child = root;
            prev->right->tag = LINK;
        }
        prev = root;
        if (root->left->tag == CHILD)
        prev_thread(root->left->child);
        if (root->right->tag == CHILD)
        prev_thread(root->right->child);
    }
}
void processNormalKeys(unsigned char key, int x, int y)
{
    if (key == 't') {
        key_pressed = MOVETAN;
    }
    else if (key == 'm') {
        key_pressed = MOVEPOS;
    }
    else if (key == 'r') {
        key_pressed = ROTATETAN;
    }
    else if (key == 'n') {
        next_thread();
    } else if (key == 'b') {
        prev_thread();
    } else if (key == 'v') {
        findThreadInIms();
        glutPostRedisplay();
    } else if (key == 'z') {
        /* Step */
        if (thread_vision.hasInit) {
            if (!thread_vision.isDone()) {
                thread_vision.generateNextSetOfHypoths();
                showThread(thread_vision.curr_thread());
            }
            else {
                cout << "Search already finished" << endl;
            }
        }
        else {
            // Taken from start of findThreadInIms();
            thread_vision_searched = true;
            thread_vision.set_max_length(MAX_LENGTH_VIS);
            thread_vision.clear_display();
            updateIms(_start_pt, _start_tan, _end_pt, _end_tan);
            thread_vision.clearStartData();
            thread_vision.addStartData(_start_pt, _start_tan);
            thread_vision.initThreadSearch();
            //cout << "Thread Vision not initialized. Press 'v' to init" << endl;
        }
    } else if (key == 'q') {
        cout << "Flip to prev hypoth" << endl;
        thread_vision.prev_hypoth();
        showThread(thread_vision.curr_thread());
    } else if (key == 'w') {
        cout << "Flip to next hypoth" << endl;
        thread_vision.next_hypoth();
        showThread(thread_vision.curr_thread());
    } else if (key == '1' && key <= '1' + NUM_THREADS_DISPLAY)
    {
    show_threads[((int)key-'1')] = !show_threads[((int)key-'1')];
//    } else if (key == 's') {
//        /* Save current trajectory */
//        cout << "Saving...\n";
//        cout << "Please enter destination file name (without extension): ";
//        char *dstFileName = new char[256];
//        cin >> dstFileName;
//        char *fullPath = new char[256];
//        sprintf(fullPath, "%s%s", "saved_threads/", dstFileName);
//
//        traj_recorder.setFileName(fullPath);
//
//        Thread *newThread = glThreads[currentThread]->getThread();
//        Thread copiedThread(*newThread);
//        traj_recorder.add_thread_to_list(copiedThread);
//        traj_recorder.write_threads_to_file();
    }
    /* Run through all threads, generate guess, save image in test_images */
    else if (key == 'p')
    {
        thread_ind = -1;
        while (true) {
            next_thread();
            DrawStuff();
            cout << endl << "testing thread " << thread_ind << endl << endl;
            start_timer();
            findThreadInIms();
            glutPostRedisplay();
            stop_timer();
            wait(2);
            thread_differences[thread_ind] = thread_difference(glThreads[truthThread]->getThread(), thread_vision.curr_thread());
            generation_times[thread_ind] = seconds_elapsed();
            printf("thread %2d |\t runtime (s): %05.3f | difference: %05.3f\n", thread_ind, generation_times[thread_ind], thread_differences[thread_ind]);
            DrawStuff();
            save_opengl_image();
            if (thread_ind == NUM_THREADS-1) break;
        }
        cout << endl << "-------------------" << endl;
        cout << "PERFORMANCE SUMMARY" << endl;
        cout << "-------------------" << endl;
        for (int i = 1; i < NUM_THREADS; i++)
        {
            printf("thread %2d |\t runtime (s): %05.3f | difference: %05.3f\n", i, generation_times[i], thread_differences[i]);
        }
    }
    else if (key == 27) {
        exit(0);
    }

    lastx_R = x;
    lasty_R = y;

}