Removed generate.
authorFrancois Fleuret <francois@fleuret.org>
Tue, 20 Sep 2016 11:55:54 +0000 (13:55 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Tue, 20 Sep 2016 11:55:54 +0000 (13:55 +0200)
generate.cc [deleted file]

diff --git a/generate.cc b/generate.cc
deleted file mode 100644 (file)
index 999c753..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-
-////////////////////////////////////////////////////////////////////
-// START_IP_HEADER                                                //
-//                                                                //
-// Written by Francois Fleuret                                    //
-// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
-//                                                                //
-// END_IP_HEADER                                                  //
-////////////////////////////////////////////////////////////////////
-
-// for i in {0..49}; do u=$(printf %03d $i); mkdir $u && mv dyn_${u}* ${u}; done
-
-#include <iostream>
-#include <fstream>
-#include <cmath>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-
-using namespace std;
-
-#include "misc.h"
-#include "task.h"
-#include "simple_window.h"
-#include "universe.h"
-#include "plotter.h"
-#include "retina.h"
-#include "manipulator.h"
-#include "intelligence.h"
-#include "canvas_cairo.h"
-
-void generate_png(Universe *universe, scalar_t scale, FILE *file) {
-  CanvasCairo canvas(scale, universe->width(), universe->height());
-  canvas.set_line_width(1.0 / scale);
-  universe->draw(&canvas);
-  canvas.write_png(file);
-}
-
-int main(int argc, char **argv) {
-  const scalar_t world_width = 400;
-  const scalar_t world_height = 400;
-  const scalar_t grab_start_x = world_width * 0.5;
-  const scalar_t grab_start_y = world_height * 0.75;
-  const int nb_blocks = 1;
-  const scalar_t block_size = 80;
-
-  const scalar_t dt = 0.1;
-  const int nb_steps = 5;
-  const int nb_iterations_per_steps = 20;
-
-  Universe *universe;
-  Polygon *grabbed_polygon;
-
-  if(argc < 2 || argc > 3) {
-    cerr << argv[0] << " <nb pairs to generate> [<dir> [<seed>]]" << endl;
-    exit(1);
-  }
-
-  int nb_pairs = atoi(argv[1]);
-
-  char dir[1024] = "/tmp/";
-
-  if(argc > 2) {
-    strncpy(dir, argv[2], sizeof(dir) / sizeof(char) - 1);
-  }
-
-  if(argc > 3) {
-    srand48(atoi(argv[1]));
-  }
-
-  universe = new Universe(10, world_width, world_height);
-
-  for(int n = 0; n < nb_pairs; n++) {
-    if(n%1000 == 0) { cout << "Example #" << n+1 << endl; }
-
-    do {
-      universe->clear();
-
-      const int nb_attempts_max = 100;
-      int nb_attempts = 0;
-
-      for(int u = 0; u < nb_blocks; u++) {
-        Polygon *pol = 0;
-
-        nb_attempts = 0;
-
-        do {
-          scalar_t x[] = {
-            - block_size * 0.4,
-            + block_size * 0.4,
-            + block_size * 0.4,
-            - block_size * 0.4,
-          };
-
-          scalar_t y[] = {
-            - block_size * 0.6,
-            - block_size * 0.6,
-            + block_size * 0.6,
-            + block_size * 0.6,
-          };
-
-          scalar_t delta = block_size / sqrt(2.0);
-          scalar_t object_center_x = delta + (world_width - 2 * delta) * drand48();
-          scalar_t object_center_y = delta + (world_height - 2 * delta) * drand48();
-          scalar_t red, green, blue;
-          red = 1.00;
-          green = red;
-          blue = red;
-          delete pol;
-          pol = new Polygon(0.5,
-                            red, green, blue,
-                            x, y, sizeof(x)/sizeof(scalar_t));
-          pol->set_position(object_center_x, object_center_y, M_PI * 2 * drand48());
-          pol->set_speed(0, 0, 0);
-          universe->initialize_polygon(pol);
-          nb_attempts++;
-        } while(nb_attempts < nb_attempts_max && universe->collide(pol));
-
-        if(nb_attempts == nb_attempts_max) {
-          delete pol;
-          u = 0;
-          universe->clear();
-          nb_attempts = 0;
-        } else {
-          universe->add_polygon(pol);
-        }
-      }
-
-      grabbed_polygon = universe->pick_polygon(grab_start_x, grab_start_y);
-    } while(!grabbed_polygon);
-
-    const scalar_t scaling = 0.16;
-
-    CanvasCairo grab_trace(scaling, world_width, world_height);
-
-    {
-      char buffer[1024];
-      sprintf(buffer, "%s/%03d/", dir, n/1000);
-      mkdir(buffer, 0777);
-    }
-
-    scalar_t grab_relative_x = grabbed_polygon->relative_x(grab_start_x, grab_start_y);
-    scalar_t grab_relative_y = grabbed_polygon->relative_y(grab_start_x, grab_start_y);
-
-    {
-      int n = 36;
-      scalar_t xp[n], yp[n];
-      for(int k = 0; k < n; k++) {
-        scalar_t radius = 1/scaling;
-        scalar_t alpha = 2 * M_PI * scalar_t(k) / scalar_t(n);
-        xp[k] = grab_start_x + radius * cos(alpha);
-        yp[k] = grab_start_y + radius * sin(alpha);
-      }
-      grab_trace.set_drawing_color(0.0, 0.0, 0.0);
-      grab_trace.set_line_width(2.0);
-      grab_trace.draw_polygon(1, n, xp, yp);
-    }
-
-    for(int s = 0; s < nb_steps; s++) {
-      {
-        char buffer[1024];
-        sprintf(buffer, "%s/%03d/dyn_%06d_world_%03d.png", dir, n/1000, n, s);
-        FILE *file = fopen(buffer, "w");
-        generate_png(universe, scaling, file);
-        fclose(file);
-      }
-
-      for(int i = 0; i < nb_iterations_per_steps; i++) {
-        scalar_t xf = grabbed_polygon->absolute_x(grab_relative_x, grab_relative_y);
-        scalar_t yf = grabbed_polygon->absolute_y(grab_relative_x, grab_relative_y);
-        grabbed_polygon->apply_force(dt, xf, yf, 0.0, -1.0);
-        universe->update(dt);
-      }
-    }
-
-    {
-      char buffer[1024];
-      sprintf(buffer, "%s/%03d/dyn_%06d_grab.png", dir, n/1000, n);
-      FILE *file = fopen(buffer, "w");
-      grab_trace.write_png(file);
-      fclose(file);
-    }
-  }
-
-  delete universe;
-}