From: Francois Fleuret Date: Fri, 10 Jul 2009 15:56:02 +0000 (+0200) Subject: Automatic commit X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=762714b0bd3e8db3e57ef1e29bcf2adfefe7e5a5;p=universe.git Automatic commit --- diff --git a/Makefile b/Makefile index 3ad3823..3b4ea46 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,17 @@ all: main TAGS $(TASK_OBJ) TAGS: *.cc *.h etags *.cc *.h -main: main.o misc.o simple_window.o universe.o polygon.o map.o \ - task.o retina.o manipulator.o approximer.o intelligence.o +main: main.o misc.o \ + simple_window.o \ + universe.o \ + xfig_tracer.o \ + polygon.o \ + map.o \ + task.o \ + retina.o \ + manipulator.o \ + approximer.o \ + intelligence.o $(CXX) -lX11 $(CXXFLAGS) -o $@ $^ $(LDFLAGS) art: art.o misc.o simple_window.o universe.o polygon.o map.o \ diff --git a/main.cc b/main.cc index b677526..405354c 100644 --- a/main.cc +++ b/main.cc @@ -20,6 +20,7 @@ using namespace std; #include "retina.h" #include "manipulator.h" #include "intelligence.h" +#include "xfig_tracer.h" // 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 @@ -394,8 +395,8 @@ int main(int argc, char **argv) { retina.save_as_ppm("/tmp/retina.ppm"); cout << "Retina screen shot saved in /tmp/retina.ppm" << endl; { - ofstream out("/tmp/universe.fig"); - universe.print_fig(out); + XFigTracer tracer("/tmp/universe.fig"); + universe.print_fig(&tracer); } } else if(strcmp(se.key, "Shift_L") == 0 || strcmp(se.key, "Shift_R") == 0) press_shift = true; diff --git a/mash.cc b/mash.cc index ed85d2c..04a49b1 100644 --- a/mash.cc +++ b/mash.cc @@ -1,4 +1,4 @@ -// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc -L/usr/X11R6/lib/"; -*- +// -*- compile-command:"g++ -lX11 -Wall -g -O3 -o mash misc.o universe.o polygon.o mash.cc xfig_tracer.o -L/usr/X11R6/lib/"; -*- #include #include @@ -15,7 +15,7 @@ using namespace std; #include "universe.h" int main(int argc, char **argv) { - int nb_heur = 75; + int nb_heur = 50; int w = 1000, h = 1000; Universe universe(nb_heur + 1, w, h); @@ -72,7 +72,7 @@ int main(int argc, char **argv) { if(y < 0) y = 0; else if(y >= nb_max_edges) y = nb_max_edges-1; } - fail = (n < 8) || (x != 0) || (y != 0); + fail = (n < 10) || (x != 0) || (y != 0); } while(fail); scalar_t xs[nb_max_edges], ys[nb_max_edges]; @@ -80,8 +80,8 @@ int main(int argc, char **argv) { for(int l = 0; l < n; l++) { int pl = (l + n - 1)%n, nl = (l + 1)%n; if(xt[nl] - xt[l] != xt[l] - xt[pl] || yt[nl] - yt[l] != yt[l] - yt[pl]) { - xs[nb_edges] = scalar_t(xt[l]) * 15; - ys[nb_edges] = scalar_t(yt[l]) * 15; + xs[nb_edges] = scalar_t(xt[l]) * 25; + ys[nb_edges] = scalar_t(yt[l]) * 25; nb_edges++; } } @@ -111,14 +111,14 @@ int main(int argc, char **argv) { if(n%1000 == 0) { char buffer[1024]; sprintf(buffer, "/tmp/mash_%06d.fig", n); - ofstream os(buffer); - universe.print_fig(os); + XFigTracer tracer(buffer); + universe.print_fig(&tracer); cout << "Wrote " << buffer << endl; } } - ofstream os("/tmp/mash.fig"); - universe.print_fig(os); + XFigTracer tracer("/tmp/mash.fig"); + universe.print_fig(&tracer); exit(0); } diff --git a/polygon.cc b/polygon.cc index f8189d5..1b8b362 100644 --- a/polygon.cc +++ b/polygon.cc @@ -47,17 +47,8 @@ Polygon *Polygon::clone() { return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices); } -void Polygon::print_fig(ostream &os) { - // os << "2 3 0 1 0 7 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl; - int c; - do { c = int(drand48() * 32); } while(c == 7); - os << "2 3 0 1 0 6 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl; - // os << "2 3 0 0 0 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl; - // os << "2 3 0 2 7 " << c << " 50 -1 20 0.000 0 0 -1 0 0 " << _nb_vertices + 1 << endl; - os << " "; - for(int n = 0; n < _nb_vertices; n++) os << " " << int(_x[n]*10) << " " << int(_y[n]*10); - os << " " << int(_x[0]*10) << " " << int(_y[0]*10); - os << endl; +void Polygon::print_fig(XFigTracer *tracer) { + tracer->draw_polygon(_nb_vertices, _x, _y); } void Polygon::draw(SimpleWindow *window) { diff --git a/polygon.h b/polygon.h index 9d35d3b..87181e0 100644 --- a/polygon.h +++ b/polygon.h @@ -7,6 +7,7 @@ #include "misc.h" #include "simple_window.h" +#include "xfig_tracer.h" class Polygon { struct Triangle { @@ -65,7 +66,7 @@ public: Polygon *clone(); - void print_fig(ostream &os); + void print_fig(XFigTracer *tracer); void draw(SimpleWindow *window); void draw_contours(SimpleWindow *window); void set_vertex(int k, scalar_t x, scalar_t y); diff --git a/universe.cc b/universe.cc index d349e40..5d6ed91 100644 --- a/universe.cc +++ b/universe.cc @@ -116,17 +116,12 @@ Polygon *Universe::pick_polygon(scalar_t x, scalar_t y) { return 0; } -void Universe::print_fig(ostream &os) { - os << "#FIG 3.2" << endl; - os << "Portrait" << endl; - os << "Center" << endl; - os << "Metric" << endl; - os << "A4 " << endl; - os << "100.00" << endl; - os << "Single" << endl; - os << "-2" << endl; - os << "1200 2" << endl; - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->print_fig(os); +void Universe::print_fig(XFigTracer *tracer) { + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->print_fig(tracer); + } + } } void Universe::draw(SimpleWindow *window) { diff --git a/universe.h b/universe.h index 72dc519..d411bb6 100644 --- a/universe.h +++ b/universe.h @@ -32,7 +32,7 @@ public: void apply_collision_forces(scalar_t dt); bool update(scalar_t dt); Polygon *pick_polygon(scalar_t x, scalar_t y); - void print_fig(ostream &os); + void print_fig(XFigTracer *tracer); void draw(SimpleWindow *window); };