92c66c6c5178acf743fa71237be5962fa7043b4b
[ipdf/code.git] / tools / grid_scaling.py
1 #!/usr/bin/python -u
2
3 import sys
4 import os
5 from pylab import *
6 import subprocess
7 import time
8
9 import gpubounds_error
10
11 def grid_scaling(binname, x0, y0, w0, h0, s, steps=100,testsvg="svg-tests/grid.svg"):
12         data = []
13         n = open("/dev/null", "w")
14         p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True)
15         p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0)))
16         p.stdin.write("loadsvg %s\n" % testsvg)
17         p.stdin.write("querygpubounds original.dat\n")
18         p.stdin.write("screenshot original.bmp\n")
19         for i in xrange(steps):
20                 p.stdin.write("clear\n")
21                 p.stdin.write("loop 1 zoom 0.5 0.5 %s\n" % str(s))
22                 p.stdin.write("loadsvg %s\n" % testsvg)
23                 p.stdin.write("querygpubounds step%d.dat\n" % i)
24                 while not os.path.isfile("step%d.dat" % i):
25                         pass
26                 p.stdin.write("clearperf\n")
27                 p.stdin.write("loop 10 wait\n")
28                 p.stdin.write("recordperf\n")
29                 p.stdin.write("printperf\n")
30                 perf = p.stdout.readline()
31                 time.sleep(0.5)
32                 data += [gpubounds_error.ComputeError("original.dat", "step%d.dat" % i)]
33                 #data += [gpubounds_error.UniqueBounds("step%d.dat" % i)]
34         
35         
36         print "Quit"
37         p.stdin.write("screenshot final.bmp\n")
38         p.stdin.write("quit\n")
39         p.stdin.close()
40         
41         data = asarray(data)
42         plot(data)
43         show(block=True)
44         
45
46 if __name__ == "__main__":
47         binname = "../src/ipdf"
48         if len(sys.argv) > 1:
49                 binname = sys.argv[1]
50         grid_scaling(binname, 0.5, 0.5, 1, 1, 0.5)

UCC git Repository :: git.ucc.asn.au