Go to the documentation of this file.
11 #include "../csm/csm_all.h"
12 #include "../csm/laser_data_drawing.h"
13 #include "../csm/laser_data_cairo.h"
44 int main(
int argc,
const char** argv)
55 options_int(
ops,
"write_info", &
p.write_info, 0,
"Writes informations and statistics in the picture.");
56 options_int(
ops,
"max_iterations", &
p.max_iterations, 10,
"Maximum number of iterations");
57 options_int(
ops,
"zoom_ray", &
p.zoom_ray, -1,
"If >= 0, the action is zoomed on a particular ray.");
58 options_int(
ops,
"width_pt", &
p.width_pt, 500,
"Maximum width, in points, of the PDF.");
59 options_int(
ops,
"height_pt", &
p.height_pt, 500,
"Maximum height, in points, of the PDF.");
60 options_double(
ops,
"padding", &
p.padding, 0.2,
"Padding, in meters, to be added around figure.");
67 sm_info(
"Draws ICP animation. It reads the output created by sm2 when given the 'file_jj' switch. \n\nUsage:\n");
78 sprintf(filename,
p.file_output, count);
79 sm_info(
"Writing frame %s \n",
p.file_output);
91 JO jo_sens =
jo_get(jo,
"laser_sens");
92 if(!jo_ref || !jo_sens) {
93 sm_error(
"Could not get laser_ref/laser_sens.\n");
99 if(!laser_ref || !laser_sens) {
100 sm_error(
"Could not read laser_ref/laser_sens from JSON representation.\n");
107 double ld_min[2], ld_max[2];
108 if(
p->zoom_ray == -1) {
109 double zero[3] = {0,0,0};
111 sm_error(
"Not enough good points to establish bounding box.\n");
115 if(
p->zoom_ray < 0 ||
p->zoom_ray >= laser_ref->
nrays || !
ld_valid_ray(laser_ref,
p->zoom_ray)) {
116 sm_error(
"Ray index #%d is not valid in laser_ref.\n",
p->zoom_ray);
120 ld_min[0] = ld_max[0] = laser_ref->
points[
p->zoom_ray].
p[0];
121 ld_min[1] = ld_max[1] = laser_ref->
points[
p->zoom_ray].
p[1];
124 ld_min[0] -=
p->padding;
125 ld_min[1] -=
p->padding;
126 ld_max[0] +=
p->padding;
127 ld_max[1] +=
p->padding;
129 sm_info(
"Bounding box: %f %f -- %f %f\n", ld_min[0], ld_min[1], ld_max[0], ld_max[1]);
131 cairo_surface_t *surface;
135 ld_min, ld_max, &surface, &cr))
return 0;
137 JO iterations =
jo_get(jo,
"iterations");
139 fprintf(stderr,
"Could not read iterations.\n");
144 if(niterations>
p->max_iterations) niterations =
p->max_iterations;
145 sm_info(
"Displaying %d iterations.\n", niterations);
148 for(it=0;it<niterations;it++) {
151 double x_old[3], x_new[3];
162 JO corr0 =
jo_get(iteration,
"corr0");
163 JO corr1 =
jo_get(iteration,
"corr1");
164 JO corr2 =
jo_get(iteration,
"corr2");
165 if(!corr1 || !corr2 || !corr0) {
166 sm_error(
"Iteration %d: could not read correspondences (field 'corr<i>'). Probably ICP failed here?\n", it);
169 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
173 cairo_set_source_rgb (cr, 1.0, 0.0, 1.0);
177 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
189 cairo_identity_matrix(cr);
190 cairo_set_font_size (cr, 20.0f);
191 cairo_select_font_face (cr,
"Sans",
192 CAIRO_FONT_SLANT_NORMAL,
193 CAIRO_FONT_WEIGHT_NORMAL);
196 sprintf(text,
"Iteration #%d: x_old: %s", it,
friendly_pose(x_old));
197 cairo_move_to(cr, 0.0, -20.0 );
198 cairo_show_text(cr, text);
204 cairo_show_page (cr);
211 cairo_surface_destroy (surface);
221 p->laser_ref_s.points.color =
"#00f";
222 p->laser_sens_s.points.color =
"#f00";
223 p->laser_ref_s.pose.color =
p->laser_ref_s.points.color;
224 p->laser_sens_s.pose.color =
p->laser_sens_s.points.color;
225 p->laser_sens_s.pose_radius =
226 p->laser_ref_s.pose_radius = 0.015;
int draw_animation(anim_params *p, JO jo, const char *filename)
int jo_read_double_array(JO s, const char *name, double *p, int n, double when_null)
void set_defaults(anim_params *p)
INLINE int ld_valid_ray(LDP ld, int i)
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)
int ld_get_bounding_box(LDP ld, double bb_min[2], double bb_max[2], double pose[3], double horizon)
void ls_add_options(line_style *ls, struct option *ops, const char *prefix, const char *desc_prefix)
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
void cr_set_reference(cairo_t *cr, double *pose)
void sm_set_program_name(const char *name)
void ld_compute_world_coords(LDP ld, const double *pose)
const char * friendly_pose(const double *pose)
void cr_ld_draw(cairo_t *cr, LDP ld, ld_style *p)
struct json_object * json_object_array_get_idx(struct json_object *this, int idx)
struct option * options_allocate(int n)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
int json_object_array_length(struct json_object *this)
JO json_read_stream(FILE *f)
struct correspondence *restrict corr
FILE * open_file_for_reading(const char *filename)
void sm_info(const char *msg,...)
void options_print_help(struct option *options, FILE *f)
void ls_set_defaults(line_style *ls)
int json_object_is_type(struct json_object *this, int type)
int json_to_corr(JO array, struct correspondence *corr, int n)
void cr_ld_draw_corr(cairo_t *cr, LDP laser_ref, LDP laser_sens)
void sm_error(const char *msg,...)
void ld_compute_cartesian(LDP ld)
void lds_add_options(ld_style *lds, struct option *ops, const char *prefix, const char *desc_prefix)
void cr_set_style(cairo_t *cr, line_style *ls)
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
int options_parse_args(struct option *ops, int argc, const char *argv[])
void lds_set_defaults(ld_style *lds)
int main(int argc, const char **argv)
csm
Author(s): Andrea Censi
autogenerated on Wed Aug 17 2022 02:50:34