Update.
authorFrancois Fleuret <francois@fleuret.org>
Sun, 4 Sep 2016 20:36:13 +0000 (22:36 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sun, 4 Sep 2016 20:36:13 +0000 (22:36 +0200)
main.cc
plotter.cc
plotter.h

diff --git a/main.cc b/main.cc
index 15e97a0..d3b3833 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -17,6 +17,7 @@ using namespace std;
 #include "task.h"
 #include "simple_window.h"
 #include "universe.h"
 #include "task.h"
 #include "simple_window.h"
 #include "universe.h"
+#include "plotter.h"
 #include "retina.h"
 #include "manipulator.h"
 #include "intelligence.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;
 
                 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);
                 {
                   XFigTracer tracer("/tmp/universe.fig");
                   universe.print_xfig(&tracer);
index b546753..a3fb6d5 100644 (file)
@@ -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]) {
   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();
 
   }
   fill();
 
-  unsigned char *image = new unsigned char[_width * _height * 3];
+  unsigned char *image = new unsigned char[(_width/downscale) * (_height/downscale) * 3];
 
   int n = 0;
 
   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;
     }
   }
 
   ofstream out(filename);
   out << "P6" << endl;
-  out << _width << " " << _height << endl;
+  out << _width/downscale << " " << _height/downscale << endl;
   out << 255 << endl;
   out << 255 << endl;
-  out.write((char *) image, _width * _height * 3);
+  out.write((char *) image, (_width/downscale) * (_height/downscale) * 3);
   out.flush();
 
   delete[] image;
   out.flush();
 
   delete[] image;
index d93490d..0845e07 100644 (file)
--- a/plotter.h
+++ b/plotter.h
@@ -90,7 +90,7 @@ public:
   Plotter(int width, int height, int scaling);
   ~Plotter();
 
   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
 };
 
 #endif