Exemple #1
0
Renderer* renderer_velodyne_new( Viewer *viewer)
{
    RendererVelodyne *self = 
        (RendererVelodyne*) calloc(1, sizeof(RendererVelodyne));

    Renderer *renderer = (Renderer*) self;

    // build color table
    for (int i = 0; i < VELODYNE_NUM_LASERS; i++) {
        float f[4];
        srand(i);
        color_util_rand_color(f, .6, .3);
        self->laser_colors[i][0] = f[0];
        self->laser_colors[i][1] = f[1];
        self->laser_colors[i][2] = f[2];
    }

    renderer->draw = my_draw;
    renderer->name = "Velodyne";
    renderer->destroy = my_free;
    renderer->widget = gtk_vbox_new ( FALSE, 0);
    renderer->enabled = 1;
    renderer->user = self;

    self->pw = GTKU_PARAM_WIDGET (gtku_param_widget_new ());
    self->circular = gu_ptr_circular_new(1000, free_velodyne_data, NULL);
    self->viewer = viewer;

    gtku_param_widget_add_enum( self->pw, COLOR_MENU, GTKU_PARAM_WIDGET_MENU,
                                COLOR_Z,
                                "Drab", COLOR_DRAB,
                                "Height", COLOR_Z,
                                "Counted", COLOR_COUNTED,
                                "Intensity", COLOR_INTENSITY,
                                "Laser", COLOR_LASER,
                                NULL);

    gtk_box_pack_start (GTK_BOX (renderer->widget), GTK_WIDGET (self->pw),
                        FALSE, TRUE, 0);
    gtk_widget_show (GTK_WIDGET (self->pw));

    self->lc = globals_get_lcm();
    self->ctrans = globals_get_ctrans();

    self->calib = velodyne_calib_create();

    lcmtypes_velodyne_t_subscribe(self->lc, "VELODYNE", on_velodyne, self);

    g_signal_connect( G_OBJECT(self->pw), "changed", G_CALLBACK(on_param_changed), self);

    g_signal_connect (G_OBJECT (viewer), "load-preferences", 
            G_CALLBACK (on_load_preferences), self);
    g_signal_connect (G_OBJECT (viewer), "save-preferences",
            G_CALLBACK (on_save_preferences), self);

    return (Renderer*) self;
}
int main(int argc, char **argv)
{
    printf("param_widget_test\n");

    GtkWidget *window;
    GtkuParamWidget *pw;

    gtk_init( &argc, &argv );

    window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    g_signal_connect( G_OBJECT(window), "delete_event", gtk_main_quit, NULL );
    g_signal_connect( G_OBJECT(window), "destroy", gtk_main_quit, NULL );
    gtk_container_set_border_width( GTK_CONTAINER(window), 10 );

    pw = GTKU_PARAM_WIDGET( gtku_param_widget_new() );
    gtk_container_add( GTK_CONTAINER(window), GTK_WIDGET( pw ) );

    gtku_param_widget_add_int( pw, "Integer 1", GTKU_PARAM_WIDGET_SPINBOX,
            INT_MIN, INT_MAX, 1, 10 );

    gtku_param_widget_add_int( pw, "Integer Slider", GTKU_PARAM_WIDGET_SLIDER,
            0, 100, 50, 1 );

    gtku_param_widget_add_double( pw, "Double Slider", GTKU_PARAM_WIDGET_SLIDER,
            0, 1, 0.01, 0.5 );

    gtku_param_widget_add_booleans( pw, GTKU_PARAM_WIDGET_CHECKBOX,
            "check1", 0, 
            "check2", 1, 
            "check3", 0, NULL );

    gtku_param_widget_add_enum( pw, "Menu", GTKU_PARAM_WIDGET_MENU,
            MENU_1,
            "entry 1", MENU_1,
            "entry 2", MENU_2,
            "entry 3", MENU_3,
            NULL );

    g_signal_connect( G_OBJECT( pw ), "changed", 
            G_CALLBACK( on_param_changed ), NULL );

    gtk_widget_show_all( window );
    gtk_main();

    return 0;
}
Exemple #3
0
static void 
on_image (const lcm_recv_buf_t *rbuf, const char *channel, 
        const lcmtypes_image_t *msg, void *user_data)
{
    RendererCamThumb *self = (RendererCamThumb*) user_data;

    if (! self->renderer.enabled) return;

    cam_renderer_t *cr = g_hash_table_lookup (self->cam_handlers, channel);
    if (!cr) {
        cr = (cam_renderer_t*) calloc (1, sizeof (cam_renderer_t));
        cr->renderer = self;
        cr->render_place = 0;
        cr->channel = strdup (channel);
        g_hash_table_replace (self->cam_handlers, cr->channel, cr);
    }

    if (! cr->msg_received) {
        cr->gl_area = GTKU_GL_DRAWING_AREA (gtku_gl_drawing_area_new (FALSE));

        cr->pw = GTKU_PARAM_WIDGET (gtku_param_widget_new ());
        gtku_param_widget_add_enum (cr->pw, PARAM_RENDER_IN, 
                0,
                cr->render_place,
                "Here", RENDER_IN_WIDGET,
                "Top Left", RENDER_IN_TOP_LEFT,
                "Top Cent.", RENDER_IN_TOP_CENTER,
                "Top Right", RENDER_IN_TOP_RIGHT,
                "Bot. Left", RENDER_IN_BOTTOM_LEFT,
                "Bot. Cent.", RENDER_IN_BOTTOM_CENTER,
                "Bot. Right", RENDER_IN_BOTTOM_RIGHT,
                NULL);

        cr->expander = gtk_expander_new (channel);
        gtk_box_pack_start (GTK_BOX (self->renderer.widget),
                cr->expander, TRUE, TRUE, 0);
        GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (cr->expander), vbox);

        gtk_box_pack_start (GTK_BOX (vbox), 
               GTK_WIDGET (cr->pw), TRUE, TRUE, 0);
        gtk_box_pack_start (GTK_BOX (vbox), 
               GTK_WIDGET (cr->gl_area), TRUE, TRUE, 0);

        g_signal_connect (G_OBJECT (cr->gl_area), "size-allocate",
                G_CALLBACK (on_gl_area_size), cr);
        cr->width = msg->width;
        cr->height = msg->height;

        gtk_widget_show_all (GTK_WIDGET (cr->expander));
        gtk_expander_set_expanded (GTK_EXPANDER (cr->expander), cr->expanded);

        if (cr->render_place == RENDER_IN_WIDGET) {
            gtk_widget_show (GTK_WIDGET (cr->gl_area));
        } else {
            gtk_widget_hide (GTK_WIDGET (cr->gl_area));
        }

        g_signal_connect (G_OBJECT (cr->pw), "changed",
                G_CALLBACK (on_cam_renderer_param_widget_changed), cr);
        g_signal_connect (G_OBJECT (cr->gl_area), "expose-event", 
                G_CALLBACK (on_gl_area_expose), cr);

        g_signal_connect (G_OBJECT (cr->expander), "notify::expanded",
                G_CALLBACK (on_expander_expanded), cr);

        cr->texture = NULL;
        cr->last_image = NULL;
        cr->renderer = self;
        cr->uncompressed_buffer_size = msg->width * msg->height * 3;
        cr->uncompresed_buffer = 
            (uint8_t*) malloc (cr->uncompressed_buffer_size);

        cr->msg_received = 1;
    }

    if (cr->last_image) {
        lcmtypes_image_t_destroy (cr->last_image);
    }
    cr->last_image = lcmtypes_image_t_copy (msg);
    cr->is_uploaded = 0;

    switch (gtku_param_widget_get_enum (cr->pw, PARAM_RENDER_IN)) {
        case RENDER_IN_WIDGET:
            if (gtk_expander_get_expanded (GTK_EXPANDER (cr->expander)))
                gtku_gl_drawing_area_invalidate (cr->gl_area);
        default:
            viewer_request_redraw (self->viewer);
            break;
    }
}