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);
112 sm_error(
"Unknown color component: %s.\n", buf);
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);
124 sm_error(
"Unknown color component: %s.\n", buf);
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);
284 cairo_move_to(cr, 0.0, 0.0);
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]);
void cr_ld_draw_corr(cairo_t *cr, LDP laser_ref, LDP laser_sens)
void ls_add_options(line_style *ls, struct option *ops, const char *prefix, const char *desc_prefix)
void cr_lda_draw_pose_path(cairo_t *cr, LDP *scans, int nscans, ld_reference use_reference)
void lds_add_options(ld_style *lds, struct option *ops, const char *prefix, const char *desc_prefix)
double *restrict readings_sigma
int create_pdf_surface(const char *file, int max_width_points, int max_height_points, double bb_min[2], double bb_max[2], cairo_surface_t **surface_p, cairo_t **cr)
const char * ld_reference_to_string(ld_reference r)
void compute_stroke_sequence(LDP ld, struct stroke_sequence *draw_info, double horizon, double connect_threshold)
INLINE int ld_valid_corr(LDP ld, int i)
INLINE int ld_valid_ray(LDP ld, int i)
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
enum correspondence::@5 type
INLINE int ld_valid_alpha(LDP ld, int i)
void cr_ld_draw_points(cairo_t *, LDP, double radius)
void cr_set_reference(cairo_t *cr, double *pose)
void cr_ld_draw_normals(cairo_t *cr, LDP ld, double length)
double * ld_get_reference_pose(LDP ld, ld_reference use_reference)
void cr_set_color(cairo_t *cr, const char *color)
double *restrict readings
void cr_ld_draw(cairo_t *cr, LDP ld, ld_style *p)
const char * cat(const char *a, const char *b)
void cr_ld_draw_rays(cairo_t *, LDP)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
point2d *restrict points_w
void projection_on_line_d(const double a[2], const double b[2], const double p[2], double res[2], double *distance)
struct correspondence *restrict corr
void ls_set_defaults(line_style *ls)
int create_image_surface(int max_width_pixels, int max_height_pixels, double bb_min[2], double bb_max[2], cairo_surface_t **surface_p, cairo_t **cr)
void sm_debug(const char *msg,...)
void cr_ld_draw_countour(cairo_t *, LDP, double, double)
void cr_ld_draw_sigma(cairo_t *cr, LDP ld, double multiplier)
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
void projection_on_segment_d(const double a[2], const double b[2], const double x[2], double proj[2])
void cr_set_style(cairo_t *cr, line_style *ls)
void sm_error(const char *msg,...)
void lds_set_defaults(ld_style *lds)