-
Notifications
You must be signed in to change notification settings - Fork 2
/
styles.py
218 lines (169 loc) · 8.02 KB
/
styles.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import numpy as np
from skimage.draw import disk, line as line_, polygon
def renderFrame(args, bins, j):
if len(bins) == 1:
bins = bins[0]
frame = renderMonoChannel(args, bins, j)
if len(bins) == 2:
frame = renderStereoChannel(args, bins, j)
return frame
def renderMonoChannel(args, bins, j):
if args.mirror == 0:
height = args.height
else:
fullFrame = np.full((args.height, args.width, 3), args.backgroundColor).astype(np.uint8)
height = int(args.height/2)
frame = np.full((height, args.width, 3), args.backgroundColor).astype(np.uint8)
if not args.radial:
if args.style == "bars" and args.barHeight == -1:
for k in range(args.bins):
frame[:int(np.ceil(bins[j,k]*height)),
int(k/args.bins*args.width + args.binSpacing/2):int((k+1)/args.bins*args.width - args.binSpacing/2)] = args.color
if args.style == "bars" and args.barHeight != -1 or args.style == "circles" or args.style == "donuts":
point = renderPoint(args)
binSpace = height - point.shape[0]
for k in range(args.bins):
binStart = int(k*args.binWidth + k*args.binSpacing)
offset = int(args.binWidth - point.shape[1])
frame[int(bins[j,k]*binSpace):int(bins[j,k]*binSpace + point.shape[0]),
int(k/args.bins*args.width + args.binSpacing/2):int((k+1)/args.bins*args.width - args.binSpacing/2)] = point
if args.style == "line":
binSpace = height - args.lineThickness
paddedFrame = np.full((height, args.width + 2*args.lineThickness, 3), args.backgroundColor).astype(np.uint8)
for k in range(args.bins):
vector1Y = int(bins[j,k]*binSpace)
if k == 0:
vector1X = 0
else:
vector1X = int(k/args.bins*args.width)
if k == args.bins - 1:
vector2Y = int(bins[j,k]*binSpace)
vector2X = frame.shape[1] - 1
else:
vector2Y = int(bins[j,k+1]*binSpace)
vector2X = int((k+1)/args.bins*args.width)
rr, cc = line_(vector1Y, vector1X, vector2Y, vector2X)
for i in range(len(rr)):
paddedFrame[rr[i]:int(rr[i]+args.lineThickness), int(cc[i] + 0.5*args.lineThickness):int(cc[i]+ 1.5*args.lineThickness)] = args.color
frame = paddedFrame[:,int(args.lineThickness):int(-args.lineThickness)]
if args.style == "fill":
for k in range(args.bins):
vector1Y = np.ceil(bins[j,k]*height)
if k == 0:
vector1X = 0
else:
vector1X = int(k/args.bins*args.width)
if k == args.bins - 1:
vector2Y = np.ceil(bins[j,k]*height)
vector2X = frame.shape[1] - 1
else:
vector2Y = np.ceil(bins[j,k+1]*height)
vector2X = int((k+1)/args.bins*args.width)
r = [vector1Y, vector2Y, 0, 0]
c = [vector1X, vector2X, vector2X, vector1X]
rr, cc = polygon(r, c, frame.shape)
frame[rr, cc] = args.color
if args.radial:
midHeight = int(height/2)
midWidth = int(args.width/2)
maxVectorLength = args.radiusEnd - args.radiusStart
if args.style == "bars":
for k in range(args.bins):
angleStart = k/args.bins + (args.binSpacing/2)/args.width
angleEnd = (k+1)/args.bins + (-args.binSpacing/2)/args.width
vector1Y = int(midHeight + args.radiusStart * radialVectorY(args, angleStart))
vector1X = int(midWidth + args.radiusStart * radialVectorX(args, angleStart))
vector2Y = int(midHeight + (args.radiusStart + bins[j,k] * maxVectorLength) * radialVectorY(args, angleStart))
vector2X = int(midWidth + (args.radiusStart + bins[j,k]*maxVectorLength) * radialVectorX(args, angleStart))
vector3Y = int(midHeight + (args.radiusStart + bins[j,k]*maxVectorLength) * radialVectorY(args, angleEnd))
vector3X = int(midWidth + (args.radiusStart + bins[j,k]*maxVectorLength) * radialVectorX(args, angleEnd))
vector4Y = int(midHeight + args.radiusStart * radialVectorY(args, angleEnd))
vector4X = int(midWidth + args.radiusStart * radialVectorX(args, angleEnd))
r = [vector1Y, vector2Y, vector3Y, vector4Y]
c = [vector1X, vector2X, vector3X, vector4X]
rr, cc = polygon(r, c, frame.shape)
frame[rr, cc] = args.color
if args.style == "line":
for k in range(args.bins):
angleStart = k/args.bins
angleEnd = (k+1)/args.bins
vector1Y = int(midHeight + (args.radiusStart + bins[j,k] * maxVectorLength) * radialVectorY(args, angleStart) - 1)
vector1X = int(midWidth + (args.radiusStart + bins[j,k]*maxVectorLength) * radialVectorX(args, angleStart) - 1)
if k == args.bins - 1:
k = k - 1
vector2Y = int(midHeight + (args.radiusStart + bins[j,k+1]*maxVectorLength) * radialVectorY(args, angleEnd) - 1)
vector2X = int(midWidth + (args.radiusStart + bins[j,k+1]*maxVectorLength) * radialVectorX(args, angleEnd) - 1)
rr, cc = line_(vector1Y, vector1X, vector2Y, vector2X)
for i in range(len(rr)):
frame[rr[i]:int(rr[i]+args.lineThickness), int(cc[i] + 0.5*args.lineThickness):int(cc[i]+ 1.5*args.lineThickness)] = args.color
if args.style == "fill":
for k in range(args.bins):
angleStart = k/args.bins
angleEnd = (k+1)/args.bins
vector1Y = int(midHeight + args.radiusStart * radialVectorY(args, angleStart))
vector1X = int(midWidth + args.radiusStart * radialVectorX(args, angleStart))
vector2Y = int(midHeight + (args.radiusStart + bins[j,k] * maxVectorLength) * radialVectorY(args, angleStart))
vector2X = int(midWidth + (args.radiusStart + bins[j,k]*maxVectorLength) * radialVectorX(args, angleStart))
if k == args.bins - 1:
k = k - 1
vector3Y = int(midHeight + (args.radiusStart + bins[j,k+1]*maxVectorLength) * radialVectorY(args, angleEnd))
vector3X = int(midWidth + (args.radiusStart + bins[j,k+1]*maxVectorLength) * radialVectorX(args, angleEnd))
vector4Y = int(midHeight + args.radiusStart * radialVectorY(args, angleEnd))
vector4X = int(midWidth + args.radiusStart * radialVectorX(args, angleEnd))
r = [vector1Y, vector2Y, vector3Y, vector4Y]
c = [vector1X, vector2X, vector3X, vector4X]
rr, cc = polygon(r, c, frame.shape)
frame[rr, cc] = args.color
frame = np.flipud(frame)
if args.channel != "stereo":
if args.mirror == 1:
fullFrame[:frame.shape[0],:] = frame
fullFrame[frame.shape[0]:frame.shape[0]*2,:] = np.flipud(frame)
frame = fullFrame
elif args.mirror == 2:
fullFrame[:frame.shape[0],:] = np.flipud(frame)
fullFrame[frame.shape[0]:frame.shape[0]*2,:] = frame
frame = fullFrame
if args.image and args.radial:
frame[args.frameMask] = args.radialImage[args.radialImageMask,:3]
return frame
def renderStereoChannel(args, bins, j):
left = bins[0]
right = bins[1]
frame = np.full((args.height, args.width, 3), args.backgroundColor).astype(np.uint8)
frame1 = renderMonoChannel(args, left, j)
frame2 = renderMonoChannel(args, right, j)
if args.mirror == 1:
frame[:frame1.shape[0],:] = frame1
frame[frame2.shape[0]:frame2.shape[0]*2,:] = np.flipud(frame2)
elif args.mirror == 2:
frame[:frame1.shape[0],:] = np.flipud(frame1)
frame[frame2.shape[0]:frame.shape[0]*2,:] = frame2
if args.radial:
frame[:,:int(frame1.shape[1]/2)] = np.fliplr(frame1[:,int(frame1.shape[1]/2):])
frame[:,int(frame2.shape[1]/2):] = frame2[:,int(frame2.shape[1]/2):]
if args.image:
frame[args.frameMask] = args.radialImage[args.radialImageMask,:3]
return frame
def renderPoint(args):
if args.style == "bars":
point = np.full((int(args.barHeight), int(args.binWidth), 3), args.color)
return point
if args.style == "circles":
point = np.full((int(args.binWidth), int(args.binWidth), 3), args.backgroundColor)
rr, cc = disk((int(args.binWidth/2), int(args.binWidth/2)), int(args.binWidth/2))
point[rr, cc, :] = args.color
return point
if args.style == "donuts":
point = np.full((int(args.binWidth), int(args.binWidth), 3), args.backgroundColor)
rr, cc = disk((int(args.binWidth/2), int(args.binWidth/2)), int(args.binWidth/2))
point[rr, cc, :] = args.color
rr, cc = disk((int(args.binWidth/2), int(args.binWidth/2)), int(args.binWidth/2 * 0.5))
point[rr, cc, :] = args.backgroundColor
return point
def radialVectorY(args, angle):
vector = np.cos(2*np.pi * (angle * args.circumference + args.rotation))
return vector
def radialVectorX(args, angle):
vector = np.sin(2*np.pi * (angle * args.circumference + args.rotation))
return vector