10 const char*
cat(
const char*a,
const char*b);
22 for(i=0; i < laser_sens->
nrays; i++) {
27 int j1 = laser_sens->
corr[i].
j1;
28 int j2 = laser_sens->
corr[i].
j2;
30 const double *p_j1 = laser_ref->
points[j1].
p;
31 const double *p_j2 = laser_ref->
points[j2].
p;
32 const double *p_i_w = laser_sens->
points_w[i].
p;
35 if(laser_sens->
corr[i].
type == corr_pl)
40 cairo_move_to(cr, p_i_w[0], p_i_w[1]);
41 cairo_line_to(cr, proj[0], proj[1]);
46 const char*
cat(
const char*a,
const char*b) {
47 size_t la = strlen(a);
48 size_t lb = strlen(b);
49 char*
buf = malloc(la+lb+3);
56 const char*
prefix,
const char*desc_prefix)
59 ls->
draw,
cat(desc_prefix,
"Whether to draw it (0,1)"));
62 ls->
color,
cat(desc_prefix,
"Color ('red', '#f00')"));
65 ls->
width,
cat(desc_prefix,
"line width (meters)"));
71 const char*
prefix,
const char*desc_prefix)
100 lds->
horizon,
cat(desc_prefix,
"Maximum distance to plot (m)."));
104 if(strlen(color) == 4 && color[0] ==
'#') {
105 char buf[2] = {0, 0};
107 int i;
for(i=0;i<3;i++) {
110 rgb[i] = (1/15.0) * strtol(
buf, &endptr, 16);
115 cairo_set_source_rgb (cr, rgb[0], rgb[1], rgb[2]);
116 }
else if(strlen(color) == 5 && color[0] ==
'#') {
117 char buf[2] = {0, 0};
119 int i;
for(i=0;i<4;i++) {
122 rgba[i] = (1/15.0) * strtol(
buf, &endptr, 16);
127 cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
129 if(!strcmp(color,
"black")) {
130 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
132 sm_error(
"Unknown color: %s.\n", color);
133 cairo_set_source_rgb (cr, 0.0, 1.0, 1.0);
140 cairo_set_line_width(cr, ls->
width);
144 int k;
int first_pose=1;
145 for(k=0;k<nscans;k++) {
149 sm_error(
"No '%s' pose specified for scan #%d, continuing.\n",
156 cairo_move_to(cr, pose[0], pose[1]);
158 cairo_line_to(cr, pose[0], pose[1]);
167 int i;
for(i=0;i<ld->
nrays;i++) {
170 double threshold = 0.03;
174 double x1 = threshold * cos(ld->
theta[i]);
175 double y1 = threshold * sin(ld->
theta[i]);
179 cairo_move_to(cr,x1,y1);
180 cairo_line_to(cr,x2,y2);
192 for(i=0;i<ld->nrays;i++) {
194 if(draw_info[i].
valid==0)
continue;
196 double *
p = draw_info[i].
p;
199 cairo_move_to(cr,
p[0],
p[1]);
201 cairo_line_to(cr,
p[0],
p[1]);
208 int i;
for(i=0;i<ld->
nrays;i++) {
214 cairo_arc (cr, x, y, radius, 0.0, 2*
M_PI);
220 int i;
for(i=0;i<ld->
nrays;i++) {
223 double alpha = ld->
alpha[i];
226 double x2 = x1 + cos(alpha) * length;
227 double y2 = y1 + sin(alpha) * length;
229 cairo_move_to(cr, x1, y1);
230 cairo_line_to(cr, x2, y2);
236 int i;
for(i=0;i<ld->
nrays;i++) {
239 double theta = ld->
theta[i];
242 double x0 = ld->
readings[i] * cos(theta);
243 double y0 = ld->
readings[i] * sin(theta);
244 double x1 = x0 + cos(theta) * length;
245 double y1 = y0 + sin(theta) * length;
246 double x2 = x0 - cos(theta) * length;
247 double y2 = y0 - sin(theta) * length;
249 cairo_move_to(cr, x1, y1);
250 cairo_line_to(cr, x2, y2);
262 if(
p->countour.draw) {
272 if(
p->normals.draw) {
284 cairo_move_to(cr, 0.0, 0.0);
285 cairo_arc (cr, 0.0, 0.0,
p->pose_radius, 0.0, 2*
M_PI);
291 cairo_translate(cr,pose[0],pose[1]);
292 cairo_rotate(cr,pose[2]);
327 double bb_min[2],
double bb_max[2], cairo_surface_t**surface_p, cairo_t **cr) {
328 double bb_width = bb_max[0] - bb_min[0], bb_height = bb_max[1] - bb_min[1];
331 double surface_width, surface_height;
332 if( bb_width > bb_height ) {
334 surface_width = max_width_points;
335 surface_height = (surface_width / bb_width) * bb_height;
338 surface_height = max_height_points;
339 surface_width = (surface_height / bb_height) * bb_width;
342 sm_debug(
"bb: %f %f\n", bb_width, bb_height);
343 sm_debug(
"surface: %f %f\n", surface_width, surface_height);
345 *surface_p = cairo_pdf_surface_create(file, surface_width, surface_height);
346 *cr = cairo_create (*surface_p);
347 cairo_status_t status = cairo_status (*cr);
350 sm_error(
"Failed to create pdf surface for file %s: %s\n",
351 file, cairo_status_to_string (status));
355 double world_to_surface = surface_width / bb_width;
356 cairo_scale(*cr, world_to_surface, -world_to_surface );
357 cairo_translate(*cr, -bb_min[0], -bb_max[1]);
363 double bb_min[2],
double bb_max[2], cairo_surface_t**surface_p, cairo_t **cr) {
364 double bb_width = bb_max[0] - bb_min[0], bb_height = bb_max[1] - bb_min[1];
366 double surface_width, surface_height;
367 if( bb_width > bb_height ) {
369 surface_width = max_width_pixels;
370 surface_height = (surface_width / bb_width) * bb_height;
373 surface_height = max_height_pixels;
374 surface_width = (surface_height / bb_height) * bb_width;
377 sm_debug(
"bb: %f %f\n", bb_width, bb_height);
378 sm_debug(
"surface: %f %f\n", surface_width, surface_height);
380 *surface_p = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (
int) surface_width, (
int)surface_height);
381 *cr = cairo_create (*surface_p);
382 cairo_status_t status = cairo_status (*cr);
385 sm_error(
"Failed to create image surface: %s\n",
386 cairo_status_to_string (status));
390 double world_to_surface = surface_width / bb_width;
391 cairo_scale(*cr, world_to_surface, -world_to_surface );
392 cairo_translate(*cr, -bb_min[0], -bb_max[1]);