goo_laser_data.c
Go to the documentation of this file.
1 
2 #include "goo_laser_data.h"
3 
4 /* Use the GLib convenience macro to define the type. GooLaserData is the
5  class struct, goo_laser_data is the function prefix, and our class is a
6  subclass of GOO_TYPE_CANVAS_ITEM_SIMPLE. */
7 G_DEFINE_TYPE (GooLaserData, goo_laser_data, GOO_TYPE_CANVAS_ITEM_SIMPLE)
8 
9 
10 /* The standard object initialization function. */
11 static void
13 {
14 
15 }
16 
17 
18 /* The convenience function to create new items. This should start with a
19  parent argument and end with a variable list of object properties to fit
20  in with the standard canvas items. */
21 GooCanvasItem*
22 goo_laser_data_new (GooCanvasItem *parent, viewer_params *p, LDP ld)
23 {
24  GooCanvasItem *item;
25  GooLaserData *gld;
26 
27  item = g_object_new (goo_laser_data_get_type(), NULL);
28 
29  gld = (GooLaserData*) item;
30 
31  ld_get_bounding_box(ld, gld->bb_min, gld->bb_max, ld->estimate, 10);
32  double padding = 1;
33  gld->bb_min[0] -= padding;
34  gld->bb_min[1] -= padding;
35  gld->bb_max[0] += padding;
36  gld->bb_max[1] += padding;
37 
38 
39  gld->p = p;
40  gld->ld = ld;
41 
42  ld_get_oriented_bbox(ld, 20, &(gld->obbox) );
43  oplus_d(ld->estimate, gld->obbox.pose, gld->obbox.pose);
44 
45 /* va_start (var_args, height);
46  first_property = va_arg (var_args, char*);
47  if (first_property)
48  g_object_set_valist ((GObject*) item, first_property, var_args);
49  va_end (var_args);
50 */
51  if (parent)
52  {
53  goo_canvas_item_add_child (parent, item, -1);
54  g_object_unref (item);
55  }
56 
57  return item;
58 }
59 
60 
61 /* The update method. This is called when the canvas is initially shown and
62  also whenever the object is updated and needs to change its size and/or
63  shape. It should calculate its new bounds in its own coordinate space,
64  storing them in simple->bounds. */
65 static void
66 goo_laser_data_update (GooCanvasItemSimple *simple,
67  cairo_t *cr)
68 {
69  GooLaserData *gld = (GooLaserData*) simple;
70 
71 double padding = 0;
72  /* Compute the new bounds. */
73  simple->bounds.x1 = gld->bb_min[0] - padding;
74  simple->bounds.y1 = gld->bb_min[1] - padding;
75  simple->bounds.x2 = gld->bb_max[0] + padding;
76  simple->bounds.y2 = gld->bb_max[1] + padding;
77 
78 /*sm_debug("Bound %f %f %f %f\n", gld->bb_min[0],
79 gld->bb_min[1], gld->bb_max[0],
80 gld->bb_max[1]);*/
81 
82 }
83 
84 /* The paint method. This should draw the item on the given cairo_t, using
85  the item's own coordinate space. */
86 static void
87 goo_laser_data_paint (GooCanvasItemSimple *simple,
88  cairo_t *cr,
89  const GooCanvasBounds *bounds)
90 {
91  GooLaserData *gld = (GooLaserData*) simple;
92 /*
93  cairo_set_line_width (cr, 0.01);
94  cairo_move_to (cr, gld->bb_min[0], gld->bb_min[1]);
95  cairo_line_to (cr, gld->bb_max[0], gld->bb_min[1]);
96  cairo_line_to (cr, gld->bb_max[0], gld->bb_max[0]);
97  cairo_line_to (cr, gld->bb_min[0], gld->bb_max[0]);
98  cairo_line_to (cr, gld->bb_min[0], gld->bb_min[1]);
99  cairo_close_path (cr);
100  cairo_set_source_rgb(cr, 0.8, 0.9, 0.8);
101  cairo_stroke (cr);
102 */
103 
104  cairo_set_antialias( cr, CAIRO_ANTIALIAS_NONE );
105 
106 
107  cairo_set_source_rgb(cr, 0.3, 0, 1.0);
108  cairo_arc(cr, 0,0, 0.4, 0.0, 2*M_PI);
109  cairo_fill(cr);
110 
111  cr_ld_draw(cr, gld->ld, &(gld->p->laser));
112 }
113 
114 
115 /* Hit detection. This should check if the given coordinate (in the item's
116  coordinate space) is within the item. If it is it should return TRUE,
117  otherwises it should return FALSE. */
118 static gboolean
119 goo_laser_data_is_item_at (GooCanvasItemSimple *simple,
120  gdouble x,
121  gdouble y,
122  cairo_t *cr,
123  gboolean is_pointer_event)
124 {
125  GooLaserData *gld = (GooLaserData*) simple;
126 
127 /* if (x < gld->x || (x > gld->x + gld->width)
128  || y < gld->y || (y > gld->y + gld->height))*/
129  return FALSE;
130 
131  return TRUE;
132 }
133 
134 
135 /* The class initialization function. Here we set the class' update(), paint()
136  and is_item_at() methods. */
137 static void
139 {
140  GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
141 
142  simple_class->simple_update = goo_laser_data_update;
143  simple_class->simple_paint = goo_laser_data_paint;
144  simple_class->simple_is_item_at = goo_laser_data_is_item_at;
145 }
146 
147 
static gboolean goo_laser_data_is_item_at(GooCanvasItemSimple *simple, gdouble x, gdouble y, cairo_t *cr, gboolean is_pointer_event)
#define TRUE
Definition: json_object.h:21
static void goo_laser_data_update(GooCanvasItemSimple *simple, cairo_t *cr)
static void goo_laser_data_paint(GooCanvasItemSimple *simple, cairo_t *cr, const GooCanvasBounds *bounds)
#define M_PI
Definition: math_utils.h:7
void ld_get_oriented_bbox(LDP ld, double horizon, oriented_bbox *obbox)
ld_style laser
Definition: gtk_viewer.h:10
#define FALSE
Definition: json_object.h:18
void cr_ld_draw(cairo_t *cr, LDP ld, ld_style *p)
struct @0 p
GType goo_laser_data_get_type(void) G_GNUC_CONST
double bb_min[2]
oriented_bbox obbox
static void goo_laser_data_init(GooLaserData *gld)
void oplus_d(const double x1[3], const double x2[3], double res[3])
Definition: math_utils.c:96
double estimate[3]
Definition: laser_data.h:40
static void goo_laser_data_class_init(GooLaserDataClass *klass)
viewer_params * p
double bb_max[2]
int ld_get_bounding_box(LDP ld, double bb_min[2], double bb_max[2], double pose[3], double horizon)
GooCanvasItem * goo_laser_data_new(GooCanvasItem *parent, viewer_params *p, LDP ld)


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23