6240718f490782a1647d3b39109ed2c0326c2f13
[ipdf/code.git] / tools / scaling.py
1 #!/usr/bin/python -u
2
3 import sys
4 import os
5 from matplotlib.pyplot import *
6 from numpy import *
7 import subprocess
8 import time
9
10 import gpubounds
11
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):
13         accuracy = []
14         performance = []
15         n = open("/dev/null", "w")
16         #n = sys.stderr
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):
29                         pass
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")
32                 #print(str(fpsout))
33                 p.stdin.write("printbounds\n")
34                 bounds = map(float, p.stdout.readline().strip(" \r\n").split("\t"))
35                 
36                 performance += [map(float, fpsout)]
37                 accuracy += [bounds + [gpubounds.ComputeError("original.dat", "step%d.dat" % i), \
38                                  gpubounds.UniqueBounds("step%d.dat" % i)]]
39                                  
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)
43                         break
44         
45         p.stdin.write("screenshot final.bmp\n")
46         p.stdin.write("quit\n")
47         p.stdin.close()
48         return {"accuracy" : asarray(accuracy),
49                         "performance" : asarray(performance)}
50
51
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):
53         accuracy = []
54         performance = []
55         n = open("/dev/null", "w")
56         #n = sys.stderr
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):
72                         pass
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")
75                 #print(str(fpsout))
76                 
77                 
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)]]
85                                  
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)
89                         break
90                 
91         p.stdin.write("screenshot final.bmp\n")
92         p.stdin.write("quit\n")
93         p.stdin.close()
94         return {"accuracy" : asarray(accuracy),
95                         "performance" : asarray(performance)}
96
97 if __name__ == "__main__":
98         results = Scaling("./single", xz=0, yz=0, fps=100)
99
100         

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