Merge branch 'master' of git.ucc.asn.au:ipdf/code
[ipdf/code.git] / tools / gpubounds.py
1 #!/usr/bin/python
2 import sys
3 import os
4 import math
5
6 # Calculates the total error in coordinates of GPU bounds rectangles of objects
7
8 def ComputeError(reference, other):
9         if type(reference) == str:
10                 reference = open(reference, "r")
11         if type(other) == str:
12                 other = open(other, "r")
13                 
14         total = 0.0
15         while True:
16                 a = reference.readline()
17                 b = other.readline()
18                 if a == "" and b == "":
19                         reference.close()
20                         other.close()
21                         return total
22                 if a[0] == '#' and b[0] == '#':
23                         continue
24                 a = map(float, a.strip(" \r\n").split("\t"))
25                 b = map(float, b.strip(" \r\n").split("\t"))
26                 deltaArea = abs(b[3]*b[4] - a[3]*a[4])
27                 
28                 deltaCoord = b[1] - a[1] + b[2] - a[2]
29                 total += math.sqrt(deltaArea) + abs(deltaCoord)
30
31 # Counts the number of unique bounds
32 def UniqueBounds(other):
33         other = open(other, "r")
34         store = {}
35         for l in other.readlines():
36                 if l[0] == "#":
37                         continue
38                 #print "L is " + str(l)
39                 l = map(float, l.strip(" \r\n").split("\t"))
40                 l = tuple(l[1:])
41                 if not l in store.keys():
42                         store[l] = 1
43                 else:
44                         store[l] += 1
45         other.close()
46         return len(store.keys())
47         
48 def main(argv):
49         print str(ComputeError(argv[1], argv[2])) + "\t" + str(UniqueBounds(argv[1])) + "\t" + str(UniqueBounds(argv[2]))
50         return 0
51         
52         
53 if __name__ == "__main__":
54         sys.exit(main(sys.argv))

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