5 from matplotlib.pyplot import *
12 def FixedScales(binname, x0=0, y0=0, w0=1, h0=1, s=0.5, steps=100, xz = 0.5, yz = 0.5, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1):
15 n = open("/dev/null", "w")
17 p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True)
18 p.stdin.write("%s\n" % renderer)
19 p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0)))
20 p.stdin.write("loadsvg %s\n" % testsvg)
21 p.stdin.write("querygpubounds original.dat\n")
22 p.stdin.write("screenshot original.bmp\n")
23 for i in xrange(steps):
24 p.stdin.write("clear\n")
25 p.stdin.write("loop 1 zoom %s %s %s\n" % (str(xz), str(yz), str(s)))
26 p.stdin.write("loadsvg %s\n" % testsvg)
27 p.stdin.write("querygpubounds step%d.dat\n" % i)
28 while not os.path.isfile("step%d.dat" % i):
30 p.stdin.write("loop %d printfps\n" % fps) # Print an FPS count to signal it is safe to read the file
31 fpsout = p.stdout.readline().strip(" \r\n").split("\t")
33 p.stdin.write("printbounds\n")
34 bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
36 performance += [map(float, fpsout)]
37 accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \
38 gpubounds.UniqueBounds("step%d.dat" % i)]]
40 os.unlink("step%d.dat" % i) # Don't need it any more
41 if accuracy[-1][-1] <= 0:
42 print "%s - Quit early after %d steps" % (binname, i)
45 p.stdin.write("screenshot final.bmp\n")
46 p.stdin.write("quit\n")
48 return {"accuracy" : asarray(accuracy),
49 "performance" : asarray(performance)}
52 def TestInvariance(binname, x0=0, y0=0, w0=1, h0=1, s=-1, steps=1000, xz = 0.5, yz = 0.5, testsvg="svg-tests/grid.svg", renderer="gpu", fps=1):
55 n = open("/dev/null", "w")
57 p = subprocess.Popen(binname + " -s stdin", bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=n, shell=True)
58 p.stdin.write("%s\n" % renderer)
59 p.stdin.write("setbounds %s %s %s %s\n" % (str(x0),str(y0),str(w0),str(h0)))
60 p.stdin.write("loadsvg %s\n" % testsvg)
61 p.stdin.write("querygpubounds original.dat\n")
62 p.stdin.write("screenshot original.bmp\n")
63 p.stdin.write("printbounds\n")
64 bounds_orig = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
65 for i in xrange(1,steps,50):
66 p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(int(s))))
67 p.stdin.write("printbounds\n")
68 bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
69 p.stdin.write("loop %d pxzoom %s %s %s\n" % (i, str(xz), str(yz), str(-int(s))))
70 p.stdin.write("querygpubounds step%d.dat\n" % i)
71 while not os.path.isfile("step%d.dat" % i):
73 p.stdin.write("loop %d printfps\n" % fps) # Print an FPS count to signal it is safe to read the file
74 fpsout = p.stdout.readline().strip(" \r\n").split("\t")
78 bounds[0] = bounds[0]-bounds_orig[0]
79 bounds[1] = bounds[1]-bounds_orig[1]
80 bounds[2] = bounds[2]/bounds_orig[2]
81 bounds[3] = bounds[3]/bounds_orig[3]
82 performance += [map(float, fpsout)]
83 accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \
84 gpubounds.UniqueBounds("step%d.dat" % i)]]
86 os.unlink("step%d.dat" % i) # Don't need it any more
87 if accuracy[-1][-1] <= 0:
88 print "%s - Quit early after %d steps" % (binname, i)
91 p.stdin.write("screenshot final.bmp\n")
92 p.stdin.write("quit\n")
94 return {"accuracy" : asarray(accuracy),
95 "performance" : asarray(performance)}
97 if __name__ == "__main__":
98 results = Scaling("./single", xz=0, yz=0, fps=100)