-
Notifications
You must be signed in to change notification settings - Fork 12
/
registration.py
85 lines (76 loc) · 2.57 KB
/
registration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import silhouette
import svgwrite
def translate(vectors, offset):
ret = []
for vector in vectors:
vector = map(sum, zip(vector, offset))
ret.append(vector)
return ret
def to_dpi(vector):
return [val.to("dpi").magnitude for val in vector]
class RegistrationMarks(object):
Defaults = {
"top_margin": ".394in",
"bottom_margin": ".394in",
"left_margin": ".394in",
"right_margin": ".394in",
"width": "8.5inch",
"height": "11inch",
"thickness": "0.039in",
"length": "0.787in",
"square": "5mm",
}
def __init__(self, **kw):
_kw = self.Defaults.copy()
_kw.update(kw)
_kw = {key: silhouette.unit(val) for (key, val) in _kw.items()}
self.__dict__.update(_kw)
def cube_mark(self):
# top left
insert = (self.top_margin - self.thickness / 2.0, self.right_margin - self.thickness / 2.0)
insert = to_dpi(insert)
size = to_dpi((self.square + self.thickness, self.square + self.thickness))
rect = svgwrite.shapes.Rect(insert=insert, size=size)
return rect
def top_angle_mark(self):
length = self.length + self.thickness / 2.0
width = self.thickness
points = [
[0, 0],
[length, 0],
[length, length],
[length - width, length],
[length - width, width],
[0, width],
]
origin_x = self.width - self.right_margin - self.length
origin_y = self.top_margin - width / 2.0
points = translate(points, (origin_x, origin_y))
points = map(to_dpi, points)
polygon = svgwrite.shapes.Polygon(points=points)
return polygon
def bottom_angle_mark(self):
length = self.length + self.thickness / 2.0
width = self.thickness
points = [
[0, 0],
[width, 0],
[width, length - width],
[length, length - width],
[length, length],
[0, length],
]
origin_x = self.left_margin - width / 2.0
origin_y = self.height - self.bottom_margin - self.length
points = translate(points, (origin_x, origin_y))
points = map(to_dpi, points)
polygon = svgwrite.shapes.Polygon(points=points)
return polygon
def generate(self, svgfn="registration.svg"):
svg = svgwrite.Drawing(svgfn)
svg.add(self.cube_mark())
svg.add(self.top_angle_mark())
svg.add(self.bottom_angle_mark())
svg.save()
marks = RegistrationMarks()
marks.generate()