Browse Source

Add pointset::dump and plot{2,3}d

Olivier Marty 8 years ago
parent
commit
f5e057c562
6 changed files with 29 additions and 2 deletions
  1. 1 0
      .gitignore
  2. 4 2
      src/main.cpp
  3. 7 0
      src/plot2d
  4. 8 0
      src/plot3d
  5. 6 0
      src/pointset.cpp
  6. 3 0
      src/pointset.h

+ 1 - 0
.gitignore

@@ -25,3 +25,4 @@ _build/
 main.pdf
 *.o
 /src/main
+/src/dump

+ 4 - 2
src/main.cpp

@@ -3,8 +3,10 @@
 #include "pointset.h"
 
 int main(int argc, char **argv) {
-  int npoints = 3, dim = 2;
-  printf("%g\n", pointset(dim, npoints).discrepancy());
+  int npoints = 10, dim = 3;
+  pointset ps(dim, npoints);
+  printf("%g\n", ps.discrepancy());
+  ps.dump(fopen("dump", "w"));
 
   return EXIT_SUCCESS;
 }

+ 7 - 0
src/plot2d

@@ -0,0 +1,7 @@
+# gnuplot file to procude 2d graphs from dump file 'dump'
+# usage : run gnuplot, type "load 'plot2d'"
+
+set autoscale
+set xrange [0:1]
+set yrange [0:1]
+plot "dump" using 1:2 title "" with points

+ 8 - 0
src/plot3d

@@ -0,0 +1,8 @@
+# gnuplot file to procude 2d graphs from dump file 'dump'
+# usage : run gnuplot, type "load 'plot3d'"
+
+set autoscale
+set xrange [0:1]
+set yrange [0:1]
+set zrange [0:1]
+splot "dump" using 1:2:3 title "" with points

+ 6 - 0
src/pointset.cpp

@@ -17,3 +17,9 @@ double pointset::discrepancy() {
   double lower;
   return oydiscr(data, dim, npoints, &lower);
 }
+
+void pointset::dump(FILE* f) {
+  for(int y = 0; y < npoints; y++)
+    for(int x = 0; x < dim; x++)
+      fprintf(f, "%lf%c", data[y][x], (x==dim-1) ? '\n' : '\t');
+}

+ 3 - 0
src/pointset.h

@@ -1,11 +1,14 @@
 #ifndef POINTSET_H
 #define POINTSET_H
 
+#include <cstdio>
+
 class pointset {
   public:
     pointset(int dim, int npoints);
     ~pointset();
     double discrepancy();
+    void dump(FILE *f);
   protected:
     int dim, npoints;
     double **data;