#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 <cairo.h>
+#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
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);
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;
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);
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
{