X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=flatland.git;a=blobdiff_plain;f=sequence_generator.cc;h=ddc337b13e8332e7d14810e2cb693f0820178b53;hp=540c57427cfa25a9ee03c3444cfd6ef3aa3e7ad0;hb=7e2780052c458a329fc36253b83eb5194ffb7fed;hpb=1f91ec6f67da83525115f49dcc7d535ff2e71ef0 diff --git a/sequence_generator.cc b/sequence_generator.cc index 540c574..ddc337b 100644 --- a/sequence_generator.cc +++ b/sequence_generator.cc @@ -67,12 +67,14 @@ void draw_grabbing_point_on_canvas(CanvasCairo *canvas, scalar_t scaling, extern "C" void fl_generate_sequence(int nb_images, int width, int height, + int nb_shapes, int random_shape_size, int random_colors, unsigned char *output) { - const scalar_t world_width = width * 8; - const scalar_t world_height = height * 8; - const scalar_t scaling = 0.125; + const scalar_t super_definition = 8; + const scalar_t world_width = width * super_definition; + const scalar_t world_height = height * super_definition; + const scalar_t scaling = 1 / super_definition; const scalar_t dt = 0.1; const int nb_iterations_per_steps = 5; @@ -87,7 +89,6 @@ extern "C" void fl_generate_sequence(int nb_images, int every_nth = 16; int nb_simulated_frames = 1 + (nb_images - 1) * every_nth; int random_grasp = 1; - int nb_shapes = 10; Universe *universe; Polygon *grabbed_polygon; @@ -110,6 +111,9 @@ extern "C" void fl_generate_sequence(int nb_images, int failed; + int total_nb_attempts = 0; + const int max_total_nb_attempts = 1000000; + do { if(random_grasp) { grab_start_x = world_width * (0.1 + 0.8 * drand48()); @@ -185,6 +189,7 @@ extern "C" void fl_generate_sequence(int nb_images, } grabbed_polygon = universe->pick_polygon(grab_start_x, grab_start_y); + } while(!grabbed_polygon); failed = 0; @@ -218,7 +223,6 @@ extern "C" void fl_generate_sequence(int nb_images, for(int i = 0; i < nb_iterations_per_steps; i++) { scalar_t xf = grabbed_polygon->absolute_x(grab_relative_x, grab_relative_y); scalar_t yf = grabbed_polygon->absolute_y(grab_relative_x, grab_relative_y); - cout << "xf = " << xf << " yf = " << yf << endl; if (xf < 0 || xf >= world_width || yf < 0 || yf >= world_height) { failed = 1; } @@ -228,8 +232,12 @@ extern "C" void fl_generate_sequence(int nb_images, } } - if(failed) cout << "** FAILED" << endl; - else cout << "** DONE" << endl; + total_nb_attempts++; + + if(total_nb_attempts >= max_total_nb_attempts) { + cerr << "There was " << max_total_nb_attempts << " attempts at generating the sequences." << endl; + abort(); + } } while(failed);