goo_laser_data.c
Go to the documentation of this file.
00001 
00002 #include "goo_laser_data.h"
00003 
00004 /* Use the GLib convenience macro to define the type. GooLaserData is the
00005    class struct, goo_laser_data is the function prefix, and our class is a
00006    subclass of GOO_TYPE_CANVAS_ITEM_SIMPLE. */
00007 G_DEFINE_TYPE (GooLaserData, goo_laser_data, GOO_TYPE_CANVAS_ITEM_SIMPLE)
00008 
00009 
00010 /* The standard object initialization function. */
00011 static void
00012 goo_laser_data_init (GooLaserData *gld)
00013 {
00014         
00015 }
00016 
00017 
00018 /* The convenience function to create new items. This should start with a 
00019    parent argument and end with a variable list of object properties to fit
00020    in with the standard canvas items. */
00021 GooCanvasItem*
00022 goo_laser_data_new (GooCanvasItem      *parent, viewer_params *p, LDP ld) 
00023 {
00024   GooCanvasItem *item;
00025   GooLaserData *gld;
00026 
00027         item = g_object_new (goo_laser_data_get_type(), NULL);
00028 
00029         gld = (GooLaserData*) item;
00030 
00031         ld_get_bounding_box(ld, gld->bb_min, gld->bb_max, ld->estimate, 10);
00032         double padding = 1;
00033         gld->bb_min[0] -= padding;
00034         gld->bb_min[1] -= padding;
00035         gld->bb_max[0] += padding;
00036         gld->bb_max[1] += padding;
00037         
00038         
00039         gld->p = p;
00040         gld->ld = ld;
00041 
00042         ld_get_oriented_bbox(ld, 20, &(gld->obbox) );
00043         oplus_d(ld->estimate, gld->obbox.pose, gld->obbox.pose);
00044 
00045 /*  va_start (var_args, height);
00046   first_property = va_arg (var_args, char*);
00047   if (first_property)
00048     g_object_set_valist ((GObject*) item, first_property, var_args);
00049   va_end (var_args);
00050 */
00051   if (parent)
00052     {
00053       goo_canvas_item_add_child (parent, item, -1);
00054       g_object_unref (item);
00055     }
00056 
00057   return item;
00058 }
00059 
00060 
00061 /* The update method. This is called when the canvas is initially shown and
00062    also whenever the object is updated and needs to change its size and/or
00063    shape. It should calculate its new bounds in its own coordinate space,
00064    storing them in simple->bounds. */
00065 static void
00066 goo_laser_data_update  (GooCanvasItemSimple *simple,
00067                        cairo_t             *cr)
00068 {
00069   GooLaserData *gld = (GooLaserData*) simple;
00070 
00071 double padding = 0;
00072   /* Compute the new bounds. */
00073   simple->bounds.x1 = gld->bb_min[0] - padding;
00074   simple->bounds.y1 = gld->bb_min[1] - padding;
00075   simple->bounds.x2 = gld->bb_max[0] + padding;
00076   simple->bounds.y2 = gld->bb_max[1] + padding;
00077 
00078 /*sm_debug("Bound %f %f %f %f\n", gld->bb_min[0],
00079 gld->bb_min[1], gld->bb_max[0],
00080 gld->bb_max[1]);*/
00081 
00082 }
00083 
00084 /* The paint method. This should draw the item on the given cairo_t, using
00085    the item's own coordinate space. */
00086 static void
00087 goo_laser_data_paint (GooCanvasItemSimple   *simple,
00088                      cairo_t               *cr,
00089                      const GooCanvasBounds *bounds)
00090 {
00091         GooLaserData *gld = (GooLaserData*) simple;
00092 /*
00093         cairo_set_line_width (cr, 0.01);
00094         cairo_move_to (cr, gld->bb_min[0], gld->bb_min[1]);
00095         cairo_line_to (cr, gld->bb_max[0], gld->bb_min[1]);
00096         cairo_line_to (cr, gld->bb_max[0], gld->bb_max[0]);
00097         cairo_line_to (cr, gld->bb_min[0], gld->bb_max[0]);
00098         cairo_line_to (cr, gld->bb_min[0], gld->bb_min[1]);
00099         cairo_close_path (cr);
00100         cairo_set_source_rgb(cr, 0.8, 0.9, 0.8);
00101         cairo_stroke (cr);
00102 */
00103 
00104         cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE );
00105 
00106 
00107         cairo_set_source_rgb(cr, 0.3, 0, 1.0);
00108         cairo_arc(cr, 0,0,  0.4, 0.0, 2*M_PI);
00109         cairo_fill(cr);
00110         
00111         cr_ld_draw(cr, gld->ld, &(gld->p->laser));
00112 }
00113 
00114 
00115 /* Hit detection. This should check if the given coordinate (in the item's
00116    coordinate space) is within the item. If it is it should return TRUE,
00117    otherwises it should return FALSE. */
00118 static gboolean
00119 goo_laser_data_is_item_at (GooCanvasItemSimple *simple,
00120                           gdouble              x,
00121                           gdouble              y,
00122                           cairo_t             *cr,
00123                           gboolean             is_pointer_event)
00124 {
00125   GooLaserData *gld = (GooLaserData*) simple;
00126 
00127 /*  if (x < gld->x || (x > gld->x + gld->width)
00128       || y < gld->y || (y > gld->y + gld->height))*/
00129     return FALSE;
00130 
00131   return TRUE;
00132 }
00133 
00134 
00135 /* The class initialization function. Here we set the class' update(), paint()
00136    and is_item_at() methods. */
00137 static void
00138 goo_laser_data_class_init (GooLaserDataClass *klass)
00139 {
00140   GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
00141 
00142   simple_class->simple_update        = goo_laser_data_update;
00143   simple_class->simple_paint         = goo_laser_data_paint;
00144   simple_class->simple_is_item_at    = goo_laser_data_is_item_at;
00145 }
00146 
00147 


csm
Author(s): Andrea Censi
autogenerated on Mon Jan 16 2017 03:48:29