X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=main.cc;h=974cbea1a8d7e602bb347b3b2a0f5294571ff4eb;hb=6408d9fe6e1b82ad9aa71d6e1702ec100a8c3ca1;hp=5a1d562fbd0a9ca2b4a8dedcd9080a467e3ac0c9;hpb=a845456cf185afc67d4fdb3aee7fed27c488b4fe;p=universe.git diff --git a/main.cc b/main.cc index 5a1d562..974cbea 100644 --- a/main.cc +++ b/main.cc @@ -17,59 +17,19 @@ using namespace std; #include "task.h" #include "simple_window.h" #include "universe.h" +#include "plotter.h" #include "retina.h" #include "manipulator.h" #include "intelligence.h" -#include "xfig_tracer.h" - -#ifdef CAIRO_SUPPORT -#include +#include "canvas_cairo.h" -static cairo_status_t write_cairo_to_file(void *closure, - const unsigned char *data, - unsigned int length) { - fwrite(data, 1, length, (FILE *) closure); - return CAIRO_STATUS_SUCCESS; -} +#include "xfig_tracer.h" void generate_png(Universe *universe, scalar_t scale, FILE *file) { - const int depth = 4; - const int width = int(universe->width() * scale); - const int height = int(universe->height() * scale); - - cairo_surface_t *image; - cairo_t* context_resource; - unsigned char *data; - - data = new unsigned char [width * height * depth]; - - image = cairo_image_surface_create_for_data(data, - CAIRO_FORMAT_RGB24, - width, - height, - width * depth); - - context_resource = cairo_create(image); - - cairo_scale(context_resource, scale, scale); - - cairo_set_source_rgb(context_resource, 1.0, 1.0, 1.0); - - cairo_rectangle(context_resource, 0, 0, - universe->width(), universe->height()); - - cairo_fill(context_resource); - - universe->draw(context_resource); - - cairo_surface_write_to_png_stream(image, write_cairo_to_file, file); - - cairo_destroy(context_resource); - cairo_surface_destroy(image); - - delete[] data; + CanvasCairo canvas(scale, universe->width(), universe->height()); + universe->draw(&canvas); + canvas.write_png(file); } -#endif // To train // ./main --task hit_shape.task 0 --action-mode=random --nb-ticks=5000 --proportion-for-training=0.5 --save-file=dump.mem --no-window @@ -193,7 +153,7 @@ int main(int argc, char **argv) { cout << "FlatLand, a toy universe for goal-planning experiments." << endl; if(!task) { - task = load_task("dummy.task"); + task = load_task("dummy.so"); task_degree = 0; } @@ -218,12 +178,12 @@ int main(int argc, char **argv) { retina.set_location(manipulator.hand_x(), manipulator.hand_y()); SimpleWindow *window_main = 0, *window_brain = 0; + int window_main_fd = -1; + #ifdef CAIRO_SUPPORT - cairo_t *cairo_cr = 0; + // cairo_t *window_main_cairo_cr = 0; #endif - int window_main_fd = -1; - MapConcatener sensory_map(2); sensory_map.add_map(&retina); sensory_map.add_map(&manipulator); @@ -255,7 +215,7 @@ int main(int argc, char **argv) { window_main_fd = window_main->file_descriptor(); window_main->map(); #ifdef CAIRO_SUPPORT - cairo_cr = window_main->get_cairo_context_resource(); + // window_main_cairo_cr = window_main->get_cairo_context_resource(); #endif cout << "When the main window has the focus, press `q' to quit and click and drag to move" << endl << "objects." << endl; @@ -347,14 +307,16 @@ int main(int argc, char **argv) { window_main->color(0.0, 0.0, 0.0); window_main->color(1.0, 1.0, 1.0); window_main->fill(); - task->draw(window_main); -#ifdef CAIRO_SUPPORT - universe.draw(cairo_cr); -#else +// #ifdef CAIRO_SUPPORT + // CanvasCairo cc; + // cc._context_resource = window_main_cairo_cr; + // universe.draw(&cc); +// #else universe.draw(window_main); -#endif +// #endif + task->draw(window_main); manipulator.draw_on_universe(window_main); retina.draw_on_universe(window_main); @@ -461,10 +423,17 @@ int main(int argc, char **argv) { 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 {