5 #include <linux/limits.h>
10 #include <cairo-pdf.h>
14 #include "../csm/csm_all.h"
18 const char*
reference_name[4] = {
"invalid",
"odometry",
"estimate",
"true_pose"};
44 void ld_getbb(
LDP ld,
double*x0,
double*y0,
double*x1,
double*y1,
47 int main(
int argc,
const char*argv[]) {
49 fprintf(stderr,
"carmen2pdf:\t *** Please use log2pdf instead. ***\n\n");
56 options_string(
ops,
"out", &
p.output_filename,
"",
"output file (if empty, input file + '.pdf')");
60 options_double(
ops,
"dimension", &
p.dimension, 500.0,
"dimension of the image (points)");
61 options_int(
ops,
"draw_confidence", &
p.draw_confidence, 0,
" Draws confidence (readings_sigma[i]) ");
63 options_double(
ops,
"offset_theta_deg", &
p.offset_theta_deg, 0.0,
" rotate entire map by this angle (deg) ");
65 options_string(
ops,
"use", &
p.use,
"estimate",
"One in 'odometry','estimate','true_pose'");
68 sm_error(
"Could not parse arguments.\n");
74 if(strlen(
p.output_filename)==0) {
76 sprintf(
buf,
"%s.pdf",
p.input_filename);
77 p.output_filename = strdup(
buf);
78 sm_info(
"Writing on file '%s'.\n",
p.output_filename);
82 int i;
for(i=1;i<=3;i++)
87 "Use one in 'odometry','estimate','true_pose'.\n",
p.use);
95 if(!
p.input_file)
return -1;
102 return counter%
p->interval == 0;
116 *bx = (wx-bb->
x0) * scale;
117 *by = bb->
height- (wy-bb->
y0) * scale;
135 sm_error(
"Invalid laser data (#%d in file)\n", counter);
140 ld_getbb(ld,&x0,&y0,&x1,&y1,
p->use_reference,
p->horizon);
142 bb->
x0 = GSL_MIN(x0, bb->
x0);
143 bb->
x1 = GSL_MAX(x1, bb->
x1);
144 bb->
y0 = GSL_MIN(y0, bb->
y0);
145 bb->
y1 = GSL_MAX(y1, bb->
y1);
158 sm_info(
"Considering %d of %d scans.\n", considered, counter+1);
159 rewind(
p->input_file);
161 bb->
x0 -=
p->padding;
162 bb->
x1 +=
p->padding;
163 bb->
y0 -=
p->padding;
164 bb->
y1 +=
p->padding;
170 switch(use_reference) {
177 sm_error(
"Required field '%s' not set in laser scan.\n",
179 sm_error(
"I will abruptly exit() because of a panic attack.\n");
193 double wwidth = bb.
x1-bb.
x0;
194 double wheight= bb.
y1-bb.
y0;
195 if(wwidth > wheight) {
205 cairo_surface_t *surface;
207 cairo_status_t status;
209 surface = cairo_pdf_surface_create(
p.output_filename, bb.
width, bb.
height);
210 cr = cairo_create (surface);
211 status = cairo_status (cr);
214 sm_error(
"Failed to create pdf surface for file %s: %s\n",
215 p.output_filename, cairo_status_to_string (status));
220 int first_pose=1;
double old_pose_bx=0,old_pose_by=0;
233 cairo_set_line_width(cr, 0.5);
234 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
235 cairo_move_to(cr, old_pose_bx, old_pose_by);
236 cairo_line_to(cr, bx, by);
237 cairo_close_path(cr);
253 int begin_new_stroke;
256 } draw_info[ld->
nrays];
259 int last_valid = -1;
int first = 1;
260 int i;
for(i=0;i<ld->
nrays;i++) {
263 draw_info[i].valid = 0;
266 draw_info[i].valid = 1;
269 pose, &(draw_info[i].w[0]), &(draw_info[i].w[1]),
270 &bb, &(draw_info[i].b[0]), &(draw_info[i].b[1]));
274 draw_info[i].begin_new_stroke = 1;
275 draw_info[i].end_stroke = 0;
277 int near =
square(
p.line_threshold) >
279 draw_info[i].begin_new_stroke = near ? 0 : 1;
280 draw_info[i].end_stroke = 0;
281 draw_info[last_valid].end_stroke = draw_info[i].begin_new_stroke;
286 draw_info[last_valid].end_stroke = 1;
290 if(
p.draw_confidence) {
294 double big_interval = 0.3;
295 for(i=0;i<ld->
nrays;i++) {
if(draw_info[i].valid==0)
continue;
302 cairo_set_source_rgb(cr, 1.0, 0.5, 0.5);
303 cairo_set_line_width(cr, 0.1);
305 int j=0;
for(j=0;j<2;j++)
306 for(i=0;i<ld->
nrays;i++) {
if(draw_info[i].valid==0)
continue;
310 pose, 0, 0, &bb, &(b[0]), &(b[1]));
312 if(draw_info[i].begin_new_stroke)
313 cairo_move_to(cr, b[0], b[1]);
315 cairo_line_to(cr, b[0], b[1]);
316 if(draw_info[i].end_stroke)
324 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
325 cairo_set_line_width(cr, 0.5);
326 for(i=0;i<ld->
nrays;i++) {
327 if(draw_info[i].valid==0)
continue;
328 double *b = draw_info[i].b;
329 if(draw_info[i].begin_new_stroke)
330 cairo_move_to(cr, b[0], b[1]);
332 cairo_line_to(cr, b[0], b[1]);
333 if(draw_info[i].end_stroke)
344 cairo_show_page (cr);
347 cairo_surface_destroy (surface);
355 point[0] = cos(phi) * rho;
356 point[1] = sin(phi) * rho;
364 if( (bb!=0) & (bx!=0) & (by!=0) )
365 bb_w2b(bb, pw[0], pw[1], bx, by);
367 if((x!=0) && (y!=0)) {
368 *x = pw[0]; *y = pw[1];
373 reference use_reference,
double horizon) {
378 int i;
for(i=0;i<ld->
nrays;i++) {
379 if(!ld->
valid[i])
continue;
380 if(ld->
readings[i]>horizon)
continue;
389 *x0 = GSL_MIN(*x0, x);
390 *y0 = GSL_MIN(*y0, y);
391 *x1 = GSL_MAX(*x1, x);
392 *y1 = GSL_MAX(*y1, y);