-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeb-VR-Tiff-Renderer.py
387 lines (333 loc) · 16 KB
/
Web-VR-Tiff-Renderer.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
ZetCode PyQt5 tutorial
In this example, we select a file with a
QFileDialog and display its contents
in a QTextEdit.
Author: Jan Bodnar
Website: zetcode.com
Last edited: August 2017
"""
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import (QMainWindow, QTextEdit,
QAction, QFileDialog, QApplication, QLabel, QProgressBar,QWidget, QPushButton, QLineEdit,
QFrame, QApplication, QMessageBox)
from PyQt5.QtGui import QIcon, QPixmap
import PyQt5.QtGui
import sys
from server import start
import readTiff
import shutil
import os
import threading
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.currentAxis = 0
self.initUI()
def initUI(self):
self.fname= [False]
self.thread = False
self.test = False
self.currentInvert = True
self.currentColormap = 'Greys'
self.folder = False
self.statusBar()
openFile = QAction(QIcon('open.png'), 'Open', self)
openFile.setShortcut('Ctrl+O')
openFile.setStatusTip('Open new File')
openFile.triggered.connect(self.showDialogFile)
self.statusBar().showMessage('Current Axis is X')
self.yB = QtWidgets.QPushButton(self)
self.yB.setGeometry(QtCore.QRect(90, 120, 75, 23))
self.yB.setObjectName("yB")
self.zB = QtWidgets.QPushButton(self)
self.zB.setGeometry(QtCore.QRect(170, 120, 75, 23))
self.zB.setObjectName("zB")
self.label1b = QtWidgets.QLabel(self)
self.label1b.setGeometry(QtCore.QRect(30, 20, 271, 31))
self.label1b.setStyleSheet("")
self.label1b.setObjectName("label1b")
self.photo = QtWidgets.QLabel(self)
self.photo.setGeometry(QtCore.QRect(350, 10, 256, 401))
self.photo.setObjectName("photo")
self.line = QtWidgets.QFrame(self)
self.line.setGeometry(QtCore.QRect(10, 70, 301, 16))
self.line.setStyleSheet("")
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.fileOpenB = QtWidgets.QPushButton(self)
self.fileOpenB.setGeometry(QtCore.QRect(170, 50, 75, 23))
self.fileOpenB.setObjectName("fileOpenB")
self.folderOpenB = QtWidgets.QPushButton(self)
self.folderOpenB .setGeometry(QtCore.QRect(90, 50, 75, 23))
self.folderOpenB.setObjectName("folderOpenB")
self.label1a = QtWidgets.QLabel(self)
self.label1a.setGeometry(QtCore.QRect(10, 30, 70, 16))
self.label1a.setStyleSheet("font: bold 18px;")
self.label1a.setObjectName("label1a")
self.label2a = QtWidgets.QLabel(self)
self.label2a.setGeometry(QtCore.QRect(10, 90, 47, 21))
self.label2a.setStyleSheet("font: bold 18px;")
self.label2a.setObjectName("label2a")
self.label2b = QtWidgets.QLabel(self)
self.label2b.setGeometry(QtCore.QRect(30, 80, 161, 31))
self.label2b.setStyleSheet("")
self.label2b.setObjectName("label2b")
self.xB = QtWidgets.QPushButton(self)
self.xB.setGeometry(QtCore.QRect(10, 120, 75, 23))
self.xB.setObjectName("xB")
self.label3a = QtWidgets.QLabel(self)
self.label3a.setGeometry(QtCore.QRect(10, 170, 47, 21))
self.label3a.setStyleSheet("font: bold 18px;")
self.label3a.setObjectName("label3a")
self.label3b = QtWidgets.QLabel(self)
self.label3b.setGeometry(QtCore.QRect(30, 160, 251, 31))
self.label3b.setStyleSheet("")
self.label3b.setObjectName("label3b")
self.line_2 = QtWidgets.QFrame(self)
self.line_2.setGeometry(QtCore.QRect(10, 150, 301, 16))
self.line_2.setStyleSheet("")
self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.line_3 = QtWidgets.QFrame(self)
self.line_3.setGeometry(QtCore.QRect(10, 220, 301, 16))
self.line_3.setStyleSheet("")
self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_3.setObjectName("line_3")
self.genB = QtWidgets.QPushButton(self)
self.genB.setGeometry(QtCore.QRect(170, 270, 75, 23))
self.genB.setObjectName("genB")
self.exportB = QtWidgets.QPushButton(self)
self.exportB.setGeometry(QtCore.QRect(90, 270, 75, 23))
self.exportB.setObjectName("exportB")
self.label4a = QtWidgets.QLabel(self)
self.label4a.setGeometry(QtCore.QRect(10, 240, 47, 21))
self.label4a.setStyleSheet("font: bold 18px;")
self.label4a.setObjectName("label4a")
self.label4b = QtWidgets.QLabel(self)
self.label4b.setGeometry(QtCore.QRect(30, 230, 161, 31))
self.label4b.setStyleSheet("")
self.label4b.setObjectName("label4b")
self.line_4 = QtWidgets.QFrame(self)
self.line_4.setGeometry(QtCore.QRect(10, 290, 301, 16))
self.line_4.setStyleSheet("")
self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_4.setObjectName("line_4")
self.label5a = QtWidgets.QLabel(self)
self.label5a.setGeometry(QtCore.QRect(10, 310, 47, 21))
self.label5a.setStyleSheet("font: bold 18px;")
self.label5a.setObjectName("label5a")
self.line_5 = QtWidgets.QFrame(self)
self.line_5.setGeometry(QtCore.QRect(10, 350, 301, 16))
self.line_5.setStyleSheet("")
self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_5.setObjectName("line_5")
self.label5b = QtWidgets.QLabel(self)
self.label5b.setGeometry(QtCore.QRect(30, 300, 310, 61))
self.label5b.setStyleSheet("")
self.label5b.setObjectName("label5b")
self.label6b = QtWidgets.QLabel(self)
self.label6b.setGeometry(QtCore.QRect(30, 360, 291, 90))
self.label6b.setStyleSheet("")
self.label6b.setObjectName("label6b")
self.label6a = QtWidgets.QLabel(self)
self.label6a.setGeometry(QtCore.QRect(10, 370, 47, 21))
self.label6a.setStyleSheet("font: bold 18px;")
self.label6a.setObjectName("label6a")
self.line_7 = QtWidgets.QFrame(self)
self.line_7.setGeometry(QtCore.QRect(10, 450, 301, 16))
self.line_7.setStyleSheet("")
self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_7.setObjectName("line_7")
self.progressBar = QtWidgets.QProgressBar(self)
self.progressBar.setGeometry(QtCore.QRect(20, 470, 271, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.invertCheckbox = QtWidgets.QCheckBox(self)
self.invertCheckbox.setGeometry(QtCore.QRect(200, 200, 70, 17))
self.invertCheckbox.setObjectName("invertCheckbox")
self.invertCheckbox.setChecked(True)
self.colorMapDropdown = QtWidgets.QComboBox(self)
self.colorMapDropdown.setGeometry(QtCore.QRect(80, 200, 101, 22))
self.colorMapDropdown.setObjectName("colorMapDropdown")
cmaps = [
'Greys','viridis', 'plasma', 'inferno', 'magma',
'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn',
'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
'hot', 'afmhot', 'gist_heat', 'copper',
'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic',
'Pastel1', 'Pastel2', 'Paired', 'Accent',
'Dark2', 'Set1', 'Set2', 'Set3',
'tab10', 'tab20', 'tab20b', 'tab20c',
'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar']
for x in cmaps:
self.colorMapDropdown.addItem(x)
self.colorMapDropdown.activated[str].connect(self.changeColorMap)
self.invertCheckbox.stateChanged.connect(self.changeInvert)
self.xB.setCheckable(False)
self.xB.clicked.connect(self.changeAxis)
self.yB.setCheckable(False)
self.yB.clicked.connect(self.changeAxis)
self.zB.setCheckable(False)
self.zB.clicked.connect(self.changeAxis)
self.genB.clicked.connect(self.genFull)
self.exportB.clicked.connect(self.exportFull)
self.fileOpenB.setCheckable(False)
self.fileOpenB.clicked.connect(self.showDialogFile)
self.folderOpenB.setCheckable(False)
self.folderOpenB.clicked.connect(self.showDialogFolder)
# self.label = QLabel(self)
# self.label.setGeometry(200, 40, 250, 250)
self.setGeometry(50,50,583, 515)
self.setWindowTitle('WebVR Tiff Renderer')
self.xyzB = [self.xB, self.yB, self.zB]
self.retranslateUi()
self.show()
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
# Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.yB.setText(_translate("Dialog", "Y"))
self.zB.setText(_translate("Dialog", "Z"))
self.label1b.setText(_translate("Dialog", "Open .tiff file or folder of .tiff files:"))
self.fileOpenB.setText(_translate("Dialog", "Open File"))
self.folderOpenB.setText(_translate("Dialog", "Open Folder"))
self.label1a.setText(_translate("Dialog", "1. "))
self.label2a.setText(_translate("Dialog", "2."))
self.label2b.setText(_translate("Dialog", "Choose orientation of stack:"))
self.xB.setText(_translate("Dialog", "X"))
self.label3a.setText(_translate("Dialog", "3."))
self.label3b.setText(_translate("Dialog", "Choose Colormap:"))
self.genB.setText(_translate("Dialog", "Generate"))
self.exportB.setText(_translate("Dialog", "Export"))
self.label4a.setText(_translate("Dialog", "4."))
self.label4b.setText(_translate("Dialog", "Generate or export the visualization:"))
self.label5a.setText(_translate("Dialog", "5."))
self.label5b.setText(_translate("Dialog", "If you generated the visualization, Go to localhost:8080 on your \n"
"browser Make sure to use the correct browser for your headset\n"
"(Chrome for Vive/Oculus and Edge for Windows Mixed Reality)\n"))
self.label6b.setText(_translate("Dialog", "Click the glasses icon in the lower right hand corner \n"
"to enter VR. To bring the model towards you, hold down\n"
"the trigger and menu buttons (B button on Oculus Rift)\n"
"on the right controller at the same time. To move the \n"
"model hold the right controller’s trigger and move\n"
"your right hand in the direction you want to move the model."
))
self.label6a.setText(_translate("Dialog", "6."))
self.invertCheckbox.setText(_translate("Dialog", "Invert"))
def showDialogFile(self):
self.fname = QFileDialog.getOpenFileName(self, 'Open file', 'C:\\Users\\gadge\\Desktop\\als\ndata\n2017\\')[0]
print(self.fname)
if self.fname:
self.folder = False
self.reGenImage()
# self.textEdit.setText(data)
def showDialogFolder(self):
self.fname = QFileDialog.getExistingDirectory(self, 'Open file', 'C:\\Users\\gadge\\Downloads\\als')
print(self.fname)
if self.fname:
self.folder = True
self.reGenImage()
def reGenImage(self):
if self.fname[0]:
if self.test!= True:
readTiff.readTiff(self.fname, onlyOneFile=True, axis=self.currentAxis, invert=self.currentInvert, colormap = self.currentColormap,folder=self.folder)
pixmap = QPixmap("static/data/test/1.png")
self.photo.setPixmap(pixmap)
# self.resize(pixmap.width(), pixmap.height())
self.show()
def genFull(self, pressed):
print("reading1")
if self.thread:
try:
self.thread.end()
except:
pass
if self.fname[0]:
print("reading")
self.statusBar().showMessage('Generating')
readTiff.readTiff(self.fname, onlyOneFile=False, axis=self.currentAxis, updater = self.progressBar, invert=self.currentInvert, colormap = self.currentColormap,folder=self.folder)
self.thread = threading.Thread(target=start, args=())
self.progressBar.setValue(0)
self.thread.daemon = True # Daemonize thread
self.thread.start()
choice = QMessageBox.question(self, 'Open Vr',
"Type localhost:8080 into the webbrowser of your choice",
QMessageBox.Ok)
def exportFull(self, pressed):
folder = QFileDialog.getExistingDirectory(self, 'Select Directory to export to:', 'C:\\Users\\gadge\\Desktop\\als\ndata\n2017\\')
print(folder)
if folder:
print("Test")
if self.thread:
try:
self.thread.end()
except:
pass
if self.fname[0]:
print("reading")
self.statusBar().showMessage('Generating')
readTiff.readTiff(self.fname, onlyOneFile=False, axis=self.currentAxis, updater = self.progressBar, invert=self.currentInvert, colormap = self.currentColormap,folder=self.folder)
n=0
while n<1000:
n +=1
try:
self.copy("export_version", os.path.join(folder, "VR_Export_%s" %(n)))
self.copy("static/data", os.path.join(folder,"VR_Export_%s/data" %(n)))
break
except:
pass
try:
shutil.rmtree("static/data/test")
except:
pass
self.progressBar.setValue(0)
choice = QMessageBox.question(self, 'Export finished',
"Run using the html server of your choice",
QMessageBox.Ok)
# if self.fname:
def copy(self, src, dest):
shutil.copytree(src, dest)
def changeColorMap(self,text):
self.currentColormap =text
self.reGenImage()
def changeInvert(self,state):
self.currentInvert = state
self.reGenImage()
def changeAxis(self, pressed):
source = self.sender()
# source.toggle()
if source.text() == "X":
self.statusBar().showMessage('Current Dimension is X')
self.currentAxis = 0
self.reGenImage()
if source.text() == "Y":
# if self.currentAxis == 1:
# print(self.currentAxis)
# self.xyzB[self.currentAxis].toggle()
self.currentAxis = 1
self.reGenImage()
self.statusBar().showMessage('Current Dimension is Y')
if source.text() == "Z":
# if self.currentAxis == 2:
# self.xyzB[self.currentAxis].toggle()
self.currentAxis = 2
self.reGenImage()
self.statusBar().showMessage('Current Dimension is Z')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())