From: Francois Fleuret Date: Sun, 3 Mar 2019 15:12:24 +0000 (+0100) Subject: Cleaning up for DL. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=599bf3fa2eb01b05ec677b628e65adb2fe4f91c3;p=universe.git Cleaning up for DL. --- diff --git a/main.cc b/main.cc index 6f423a9..fe14161 100644 --- a/main.cc +++ b/main.cc @@ -18,12 +18,10 @@ using namespace std; #include "simple_window.h" #include "universe.h" #include "plotter.h" -#include "retina.h" #include "manipulator.h" #include "intelligence.h" -#include "canvas_cairo.h" -#include "xfig_tracer.h" +#include "canvas_cairo.h" void generate_png(Universe *universe, scalar_t scale, FILE *file) { CanvasCairo canvas(scale, universe->width(), universe->height()); @@ -119,23 +117,26 @@ int main(int argc, char **argv) { while(*o) *u++ = *o++; } - if(strcmp(variable_name, "nb-ticks") == 0) + if(strcmp(variable_name, "nb-ticks") == 0) { nb_ticks = atoi(variable_value); - else if(strcmp(variable_name, "nb-training-iterations") == 0) + } else if(strcmp(variable_name, "nb-training-iterations") == 0) { nb_training_iterations = atoi(variable_value); - else if(strcmp(variable_name, "proportion-for-training") == 0) + } else if(strcmp(variable_name, "proportion-for-training") == 0) { proportion_for_training = atof(variable_value); - else if(strcmp(variable_name, "no-window") == 0) + } else if(strcmp(variable_name, "no-window") == 0) { no_window = true; - else if(strcmp(variable_name, "save-file") == 0) + } else if(strcmp(variable_name, "save-file") == 0) { strcpy(intelligence_save_file, variable_value); - else if(strcmp(variable_name, "load-file") == 0) + } else if(strcmp(variable_name, "load-file") == 0) { strcpy(intelligence_load_file, variable_value); - else if(strcmp(variable_name, "action-mode") == 0) { - if(strcmp(variable_value, "idle") == 0) action_mode = IDLE; - else if(strcmp(variable_value, "random") == 0) action_mode = RANDOM; - else if(strcmp(variable_value, "intelligent") == 0) action_mode = INTELLIGENT; - else { + } else if(strcmp(variable_name, "action-mode") == 0) { + if(strcmp(variable_value, "idle") == 0) { + action_mode = IDLE; + } else if(strcmp(variable_value, "random") == 0) { + action_mode = RANDOM; + } else if(strcmp(variable_value, "intelligent") == 0) { + action_mode = INTELLIGENT; + } else { cerr << "The only known modes are idle, random and intelligent" << endl; exit(1); } @@ -172,12 +173,10 @@ int main(int argc, char **argv) { Universe universe(100, task->width(), task->height()); task->init(&universe, task_degree); - Retina retina(&universe); Manipulator manipulator(task); manipulator.force_move(task->width()/2, task->height()/2); - retina.set_location(manipulator.hand_x(), manipulator.hand_y()); - SimpleWindow *window_main = 0, *window_brain = 0; + SimpleWindow *window_main = 0; int window_main_fd = -1; #ifdef CAIRO_SUPPORT @@ -185,7 +184,6 @@ int main(int argc, char **argv) { #endif MapConcatener sensory_map(2); - sensory_map.add_map(&retina); sensory_map.add_map(&manipulator); sensory_map.init(); @@ -219,10 +217,6 @@ int main(int argc, char **argv) { #endif cout << "When the main window has the focus, press `q' to quit and click and drag to move" << endl << "objects." << endl; - window_brain = new SimpleWindow("Universe (brain)", - 12 + task->width(), 4, - retina.width(), retina.height() + manipulator.parameter_height()); - window_brain->map(); } int tick = 0; @@ -238,6 +232,16 @@ int main(int argc, char **argv) { int r; fd_set fds; +#ifdef CAIRO_SUPPORT + if(tick < 100) { + char buffer[1024]; + sprintf(buffer, "frame-%06d.png", tick); + FILE *file = fopen(buffer, "w"); + generate_png(&universe, 0.25, file); + cout << "Universe image saved in " << buffer << endl; + fclose(file); + } +#endif if(window_main) { struct timeval tv; @@ -301,25 +305,14 @@ int main(int argc, char **argv) { last_hand_y = manipulator.hand_y(); last_grabbing = manipulator.grabbing(); - retina.set_location(manipulator.hand_x(), - manipulator.hand_y()); - if(window_main) { window_main->color(0.0, 0.0, 0.0); window_main->color(1.0, 1.0, 1.0); window_main->fill(); - -// #ifdef CAIRO_SUPPORT - // CanvasCairo cc; - // cc._context_resource = window_main_cairo_cr; - // universe.draw(&cc); -// #else universe.draw(window_main); -// #endif task->draw(window_main); manipulator.draw_on_universe(window_main); - retina.draw_on_universe(window_main); if(grabbed_polygon) { int x, y, delta = 3; @@ -331,12 +324,6 @@ int main(int argc, char **argv) { } window_main->show(); - - if(window_brain) { - retina.draw_parameters(0, 0, window_brain); - manipulator.draw_parameters(0, retina.height() + 1, window_brain); - window_brain->show(); - } } } @@ -421,27 +408,17 @@ int main(int argc, char **argv) { else if(strcmp(se.key, "s") == 0) { - retina.save_as_ppm("/tmp/retina.ppm"); - cout << "Retina screen shot saved in /tmp/retina.ppm" << endl; - { Plotter plotter(int(universe.width()), int(universe.height()), 4); plotter.save_as_ppm(&universe, "/tmp/plotter.ppm", 16); } -#ifdef XFIG_SUPPORT - { - XFigTracer tracer("/tmp/universe.fig"); - universe.print_xfig(&tracer); - } -#endif - #ifdef CAIRO_SUPPORT { - FILE *file = fopen("/tmp/universe.png", "w"); + FILE *file = fopen("/tmp/screenshot.png", "w"); generate_png(&universe, 0.25, file); - // generate_png(task->width(), task->height(), &universe, "/tmp/universe.png"); - cout << "Universe image saved in /tmp/universe.png" << endl; + cout << "Universe image saved in /tmp/screenshot.png" << endl; + fclose(file); } #endif @@ -531,7 +508,6 @@ int main(int argc, char **argv) { intelligence.save(os); } - delete window_brain; delete window_main; } diff --git a/polygon.cc b/polygon.cc index 9e55d80..35bbd9c 100644 --- a/polygon.cc +++ b/polygon.cc @@ -2,9 +2,13 @@ // Written and (C) by Francois Fleuret // Contact for comments & bug reports +#include + #include #include "polygon.h" +using namespace std; + static const scalar_t dl = 20.0; static const scalar_t repulsion_constant = 0.2; static const scalar_t dissipation = 0.5; diff --git a/universe.h b/universe.h index 520a123..07cf7f0 100644 --- a/universe.h +++ b/universe.h @@ -53,7 +53,9 @@ public: void draw(SimpleWindow *window); #endif +#ifdef CAIRO_SUPPORT void draw(Canvas *canvas); }; +#endif #endif