Exemplo n.º 1
0
Arquivo: sync.c Projeto: golems/amino
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    struct aa_rx_win * win =
        aa_rx_win_default_create ( "Sync Test", SCREEN_WIDTH, SCREEN_HEIGHT );

    struct aa_rx_sg *sg0 = aa_rx_dl_sg__scenegraph (NULL);

    aa_rx_sg_init(sg0); /* initialize scene graph internal structures */
    aa_rx_win_sg_gl_init(win, sg0); /* Initialize scene graph GL-rendering objects */
    aa_rx_win_set_sg(win, sg0); /* Set the scenegraph for the window */

    // start display
    aa_rx_win_start(win);

    int n_thread = 10;
    pthread_t thread[n_thread];
    for( size_t i = 0; i < n_thread; i ++ ) {
        pthread_create( thread + i, NULL, fun, win );
    }
    for( size_t i = 0; i < n_thread; i ++ ) {
        pthread_join(thread[i], NULL );
    }


    // Cleanup
    aa_rx_win_join(win);
    aa_rx_win_destroy(win);
    SDL_Quit();

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    struct aa_rx_win * win =
        aa_rx_win_default_create ( "UR10 Demo", SCREEN_WIDTH, SCREEN_HEIGHT );
    printf("OpenGL Version: %s\n", glGetString(GL_VERSION));

    // Initialize scene graph
    struct aa_rx_sg *scenegraph = aa_rx_dl_sg__ur(NULL);
    aa_rx_sg_init(scenegraph); /* initialize scene graph internal structures */
    aa_rx_win_set_sg(win, scenegraph); /* Set the scenegraph for the window */

    // start display
    aa_rx_win_start(win);

    // Cleanup
    aa_rx_win_join(win);
    aa_rx_sg_destroy(scenegraph);
    aa_rx_win_destroy(win);
    SDL_Quit();

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    (void)argc; (void)argv;

    // Enable collision checking
    aa_rx_cl_init();

    // Initialize scene graph
    struct aa_rx_sg *scenegraph = aa_rx_dl_sg__scenegraph(NULL);
    aa_rx_sg_init(scenegraph);
    aa_rx_sg_cl_init(scenegraph);


    // setup window
    struct aa_rx_win * win = baxter_demo_setup_window(scenegraph);
    struct aa_gl_globals *globals = aa_rx_win_gl_globals(win);
    aa_gl_globals_set_show_visual(globals, 0);
    aa_gl_globals_set_show_collision(globals, 1);

    struct display_cx cx = {0};
    cx.win = win;
    cx.scenegraph = scenegraph;
    cx.i_q = aa_rx_sg_config_id(scenegraph, "left_s0");
    cx.cl = aa_rx_cl_create( scenegraph );

    {
        aa_rx_frame_id n = aa_rx_sg_frame_count(scenegraph);
        aa_rx_frame_id m = aa_rx_sg_config_count(scenegraph);
        double q[m];
        AA_MEM_ZERO(q,m);
        double TF_rel[7*n];
        double TF_abs[7*n];
        aa_rx_sg_tf(scenegraph, m, q,
                    n,
                    TF_rel, 7,
                    TF_abs, 7 );

        struct aa_rx_cl_set *allowed = aa_rx_cl_set_create( scenegraph );
        int col = aa_rx_cl_check( cx.cl, n, TF_abs, 7, allowed );
        aa_rx_cl_allow_set( cx.cl, allowed );
        aa_rx_cl_set_destroy( allowed );
    }

    aa_rx_win_set_display( win, display, &cx );
    aa_rx_win_display_loop(win);


    // Cleanup
    aa_rx_cl_destroy( cx.cl );
    aa_rx_sg_destroy(scenegraph);
    aa_rx_win_destroy(win);
    SDL_Quit();

    return 0;
}
Exemplo n.º 4
0
void Init(void)
{
    scenegraph = aa_rx_sg_create();

    // box
    {
        aa_rx_sg_add_frame_fixed( scenegraph,
                                  "", "box",
                                  aa_tf_quat_ident, aa_tf_vec_ident );

        struct aa_rx_geom_opt *box_opt = aa_rx_geom_opt_create();
        aa_rx_geom_opt_set_color3( box_opt, 1, 0, 0);
        aa_rx_geom_opt_set_specular3( box_opt, .3, .3, .3);

        double d[3] = {.1, .1, .1};
        aa_rx_geom_attach( scenegraph, "box", aa_rx_geom_box(box_opt, d) );

        aa_rx_geom_opt_destroy(box_opt);
    }

    // cylinder
    {
        aa_rx_sg_add_frame_fixed( scenegraph,
                                  "", "cylinder",
                                  aa_tf_quat_ident, aa_tf_vec_ident );

        struct aa_rx_geom_opt *opt = aa_rx_geom_opt_create();
        aa_rx_geom_opt_set_color3( opt, 0, 0, 1);
        aa_rx_geom_opt_set_specular3( opt, .3, .3, .3);

        aa_rx_geom_attach( scenegraph, "cylinder",
                           aa_rx_geom_cylinder(opt, .2, .1) );

        aa_rx_geom_opt_destroy(opt);
    }

    // grid
    {
        aa_rx_sg_add_frame_fixed( scenegraph,
                                  "", "grid",
                                  aa_tf_quat_ident, aa_tf_vec_ident );
        struct aa_rx_geom_opt *grid_opt = aa_rx_geom_opt_create();
        aa_rx_geom_opt_set_color3( grid_opt, .5, .5, .5);

        double dim[2] = {1,1};
        double delta[2] = {.05, .05};
        aa_rx_geom_attach( scenegraph, "grid",
                           aa_rx_geom_grid(grid_opt, dim, delta, 2.5e-3) );

        aa_rx_geom_opt_destroy(grid_opt);
    }
    aa_rx_sg_init(scenegraph);
    aa_rx_sg_gl_init(scenegraph);

}
Exemplo n.º 5
0
Arquivo: sync.c Projeto: golems/amino
static void* fun( void *arg )
{
    fprintf(stderr, "+ worker thread starting\n");
    struct aa_rx_win * win = (struct aa_rx_win * ) arg;

    struct aa_rx_sg *sg0 = aa_rx_dl_sg__scenegraph (NULL);

    for( size_t i = 0; i < 102400; i ++ ) {
        struct aa_rx_sg *sg1 = aa_rx_dl_sg__scenegraph(NULL);
        aa_rx_sg_init(sg1); /* initialize scene graph internal structures */
        aa_rx_win_sg_gl_init(win, sg1); /* Initialize scene graph GL-rendering objects */

        aa_rx_win_set_sg(win, sg1);

        aa_rx_sg_destroy(sg0);

        sg0 = sg1;
    }
    fprintf(stderr, "- worker thread finished\n");
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    int visual = 1;
    int collision = 0;

    /* Parse Options */
    {
        int c;
        opterr = 0;

        while( (c = getopt( argc, argv, "?c")) != -1 ) {
            switch(c) {
            case 'c':
                visual = 0;
                collision = 1;
                break;
            case '?':
                puts("Usage: COMMAND [OPTIONS] \n"
                     "Viewer for Amino scene graphs"
                     "\n"
                     "Options:\n"
                     "  -c              view collision geometry\n"
                     "\n"
                     "\n"
                     "Report bugs to " PACKAGE_BUGREPORT "\n" );
                exit(EXIT_SUCCESS);
                break;
            }

        }
    }

    /* Initialize scene graph */
    struct aa_rx_sg *scenegraph = NAME( NULL);

    assert(scenegraph);
    aa_rx_sg_init(scenegraph); /* initialize scene graph internal structures */

    /* Center configurations */
    size_t m = aa_rx_sg_config_count(scenegraph);
    double q[m];
    for(size_t i = 0; i < m; i ++ ) {
        double min=0,max=0;
        aa_rx_sg_get_limit_pos(scenegraph,(aa_rx_config_id)i,&min,&max);
        q[i] = (max + min)/2;
    }

    /* setup window */
    struct aa_rx_win * win =
        aa_rx_win_default_create ( "Amino: AARX-View", SCREEN_WIDTH, SCREEN_HEIGHT );
    aa_rx_win_set_sg(win, scenegraph); /* Set the scenegraph for the window */
    aa_rx_win_set_config(win, m, q);

    struct aa_gl_globals *globals = aa_rx_win_gl_globals(win);
    aa_gl_globals_set_show_visual(globals, visual);
    aa_gl_globals_set_show_collision(globals, collision);

    /* start display */
    aa_rx_win_start(win);

    /* Cleanup */
    aa_rx_win_join(win);
    aa_rx_sg_destroy(scenegraph);
    aa_rx_win_destroy(win);
    SDL_Quit();

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    const char *name="scenegraph";
    const char *plugin=NULL;
    const char *end_effector=NULL;
    int visual = 1;
    int collision = 0;

    int print_config = 0;
    int print_frame = 0;

    /* Parse Options */
    {
        int c;
        opterr = 0;

        while( (c = getopt( argc, argv, "n:e:?cQF")) != -1 ) {
            switch(c) {
            case 'n':
                name = optarg;
                break;
            case 'c':
                visual = 0;
                collision = 1;
                break;
            case 'e':
                end_effector = optarg;
                break;
            case 'Q':
                print_config = 1;
                break;
            case 'F':
                print_frame = 1;
                break;
            case '?':
                puts("Usage: aarx-view [OPTIONS] PLUGIN_NAME\n"
                     "Viewer for Amino scene graphs"
                     "\n"
                     "Options:\n"
                     "  -n NAME         scene graph name (default: scenegraph)\n"
                     "  -e NAME         name of an end-effector to control\n"
                     "  -Q              Print configuration names and exit\n"
                     "  -F              Print frame names and exit\n"
                     "  -c              view collision geometry\n"
                     "\n"
                     "\n"
                     "Report bugs to " PACKAGE_BUGREPORT "\n" );
                exit(EXIT_SUCCESS);
                break;
            default:
                plugin=optarg;
            }

        }

        while( optind < argc ) {
            plugin = argv[optind++];
        }
    }

    if( NULL == plugin ) {
        fprintf(stderr,
                "ERROR: scene graph plugin not specified.  "
                "See `aarx-view -?` for options\n");
        exit(EXIT_FAILURE);
    }

    /* Initialize scene graph */
    struct aa_rx_sg *scenegraph = aa_rx_dl_sg(plugin, name, NULL);
    assert(scenegraph);
    aa_rx_sg_init(scenegraph); /* initialize scene graph internal structures */

    /* print things */
    if( print_config || print_frame ) {

        if( print_config ) {
            for( aa_rx_config_id i = 0; i < aa_rx_sg_config_count(scenegraph); i ++ ) {
                printf("config[%d]: %s\n", i, aa_rx_sg_config_name(scenegraph, i));
            }
        }
        if( print_frame ) {
            for( aa_rx_frame_id i = 0; i < aa_rx_sg_frame_count(scenegraph); i ++ ) {
                printf("frame[%d]: %s\n", i, aa_rx_sg_frame_name(scenegraph, i));
            }
        }
        exit(EXIT_SUCCESS);
    }

    /* Center configurations */
    size_t m = aa_rx_sg_config_count(scenegraph);
    double q[m];
    for(size_t i = 0; i < m; i ++ ) {
        double min=0,max=0;
        aa_rx_sg_get_limit_pos(scenegraph,(aa_rx_config_id)i,&min,&max);
        q[i] = (max + min)/2;
    }

    /* setup window */
    struct aa_rx_win * win =
        aa_rx_win_default_create ( "Amino: AARX-View", SCREEN_WIDTH, SCREEN_HEIGHT );

    /* Set the scenegraph for the window */
    struct aa_rx_sg_sub *sub = NULL;
    if( end_effector ) {

        aa_rx_frame_id id = aa_rx_sg_frame_id(scenegraph, end_effector);
        if( AA_RX_FRAME_NONE == id ) {
            fprintf(stderr, "Could not find frame `%s'\n", end_effector);
            exit(EXIT_FAILURE);
        }
        sub = aa_rx_sg_chain_create( scenegraph, AA_RX_FRAME_ROOT, id);
        aa_rx_win_set_sg_sub(win, sub);
    } else {
        aa_rx_win_set_sg(win, scenegraph);
    }
    aa_rx_win_set_config(win, m, q);

    struct aa_gl_globals *globals = aa_rx_win_gl_globals(win);
    aa_gl_globals_set_show_visual(globals, visual);
    aa_gl_globals_set_show_collision(globals, collision);

    /* start display */
    aa_rx_win_run();

    /* Cleanup */
    aa_rx_sg_destroy(scenegraph);
    aa_rx_win_destroy(win);
    SDL_Quit();

    return 0;
}
Exemplo n.º 8
0
static struct aa_rx_sg *
create_sg(void)
{
    // Initialize scene graph
    struct aa_rx_sg * scenegraph = aa_rx_sg_create();

    // Add a Box
    {
        static const double q[4] = {0.0, 0.0, 0.0, 1.0};
        static const double v[3] = {0.0, 0.0, 0.05};
        aa_rx_sg_add_frame_fixed(scenegraph, "", "boxframe", q, v);

        struct aa_rx_geom_opt * opt = aa_rx_geom_opt_create();
        aa_rx_geom_opt_set_color3(opt, 1.0, 0.0, 0.0);
        aa_rx_geom_opt_set_specular3(opt, 0.3, 0.3, 0.3);
        aa_rx_geom_opt_set_visual(opt, 1);
        aa_rx_geom_opt_set_collision(opt, 1);
        static const double dimension[3] = {0.1, 0.1, 0.1};
        struct aa_rx_geom *geom = aa_rx_geom_box(opt, dimension);
        aa_rx_geom_attach(scenegraph, "boxframe", geom);
        aa_rx_geom_opt_destroy(opt);
    }

    // Add a Mesh
    {
        double v[3] = {0,0,-1e-3};
        aa_rx_sg_add_frame_fixed(scenegraph, "", "mesh", aa_tf_quat_ident, v);
        struct aa_rx_mesh * mesh = aa_rx_mesh_create();
#define F .5
        static const float vertices[4*3] = { -F,-F,0,
                                             -F,F,0,
                                             F,-F,0,
                                             F,F,0 };
        static const float normals[4*3] = { 0,0,1,
                                            0,0,1,
                                            0,0,1,
                                            0,0,1 };
        static const unsigned indices [3*2] = {0, 1, 2,
                                               3,1,2};
        aa_rx_mesh_set_vertices(mesh, 4, vertices, 0);
        aa_rx_mesh_set_normals(mesh, 4, normals, 0);
        aa_rx_mesh_set_indices(mesh, 2, indices, 0);

        struct aa_rx_geom * geom;
        struct aa_rx_geom_opt * opt = aa_rx_geom_opt_create();
        double d = .5;
        aa_rx_geom_opt_set_color3(opt, d*.91, d*.96, d*.88);

        aa_rx_geom_opt_set_alpha(opt, 1.0);
        aa_rx_geom_opt_set_visual(opt, 1);
        aa_rx_geom_opt_set_collision(opt, 0);
        aa_rx_geom_opt_set_no_shadow(opt, 0);
        aa_rx_mesh_set_texture(mesh, opt);
        (geom) = (aa_rx_geom_mesh(opt, mesh));
        aa_rx_geom_attach(scenegraph, "mesh", geom);
        aa_rx_geom_opt_destroy(opt);
    }


    assert(scenegraph);
    aa_rx_sg_init(scenegraph); /* initialize scene graph internal structures */

    return scenegraph;
}