From 01b5ab3f0b75969230e0f9c41e55992b3d29edee Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sun, 4 Sep 2016 22:36:13 +0200 Subject: [PATCH] Update. --- main.cc | 6 ++++++ plotter.cc | 18 +++++++++--------- plotter.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/main.cc b/main.cc index 15e97a0..d3b3833 100644 --- a/main.cc +++ b/main.cc @@ -17,6 +17,7 @@ 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" @@ -422,6 +423,11 @@ 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); + } + { XFigTracer tracer("/tmp/universe.fig"); universe.print_xfig(&tracer); diff --git a/plotter.cc b/plotter.cc index b546753..a3fb6d5 100644 --- a/plotter.cc +++ b/plotter.cc @@ -196,7 +196,7 @@ void Plotter::fill() { } } -void Plotter::save_as_ppm(Universe *universe, const char *filename) { +void Plotter::save_as_ppm(Universe *universe, const char *filename, int downscale) { reset(); for(int p = 0; p < universe->_nb_polygons; p++) { if(universe->_polygons[p]) { @@ -205,22 +205,22 @@ void Plotter::save_as_ppm(Universe *universe, const char *filename) { } fill(); - unsigned char *image = new unsigned char[_width * _height * 3]; + unsigned char *image = new unsigned char[(_width/downscale) * (_height/downscale) * 3]; int n = 0; - for(int y = 0; y < _height / _scaling; y++) { - for(int x = 0; x < _width / _scaling; x++) { - image[n++] = red_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling); - image[n++] = green_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling); - image[n++] = blue_sum(x * _scaling, y * _scaling, (x + 1) * _scaling, (y + 1) * _scaling) / scalar_t(_scaling * _scaling); + for(int y = 0; y < _height / downscale; y++) { + for(int x = 0; x < _width / downscale; x++) { + image[n++] = int(255 * red_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale)); + image[n++] = int(255 * green_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale)); + image[n++] = int(255 * blue_sum(x * downscale, y * downscale, (x + 1) * downscale, (y + 1) * downscale) / scalar_t(downscale * downscale)); } } ofstream out(filename); out << "P6" << endl; - out << _width << " " << _height << endl; + out << _width/downscale << " " << _height/downscale << endl; out << 255 << endl; - out.write((char *) image, _width * _height * 3); + out.write((char *) image, (_width/downscale) * (_height/downscale) * 3); out.flush(); delete[] image; diff --git a/plotter.h b/plotter.h index d93490d..0845e07 100644 --- a/plotter.h +++ b/plotter.h @@ -90,7 +90,7 @@ public: Plotter(int width, int height, int scaling); ~Plotter(); - void save_as_ppm(Universe *universe, const char *filename); + void save_as_ppm(Universe *universe, const char *filename, int downscale); }; #endif -- 2.39.5