class MainWindow(QMainWindow): def __init__(self, opt_engine, parent=None, win_size=450): QMainWindow.__init__(self, parent) self.widget = QWidget() self.opt_engine = opt_engine # hbox1 widgets voxel viewer widget self.frame = QFrame() self.viewerWidget = GUIViewer(self.frame, opt_engine) self.viewerWidget.setFixedSize(win_size, win_size) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget) self.frame.setLayout(viewerBox) # hbox2 widgets self.btnSave = QPushButton("Save") btnLayout1 = QHBoxLayout() btnLayout1.addWidget(self.btnSave) btnWidget1 = QWidget() btnWidget1.setLayout(btnLayout1) btnWidget1.setFixedWidth(win_size) hbox1 = QHBoxLayout() hbox1.addWidget(self.frame) hbox2 = QHBoxLayout() hbox2.addWidget(btnWidget1) vbox1 = QVBoxLayout() vbox1.addLayout(hbox1) vbox1.addLayout(hbox2) self.widget.setLayout(vbox1) self.setCentralWidget(self.widget) mainWidth = self.viewerWidget.width() + 35 mainHeight = self.viewerWidget.height() + 70 self.setGeometry(0, 0, mainWidth, mainHeight) self.setFixedSize(self.width(), self.height()) self.btnSave.clicked.connect(self.save_data) self.connect(self.opt_engine, SIGNAL('update_voxels'), self.viewerWidget.update_actor) self.opt_engine.start() def closeEvent(self, event): self.opt_engine.quit() self.opt_engine.model.sess.close() def save_data(self): try: self.number except: self.number = 1 util.save_binvox("./out/{0}.binvox".format(self.number), self.opt_engine.current_shape) print "saved {0}.binvox".format(self.number) self.number += 1
def view_model(self): start = self.current_index banch = self.banch end = start + banch if end > self.models_count: end = self.models_count i = 0 width = (self.width * 2 / banch) * 0.95 height = (self.height / 2) * 0.95 mainWidth = width + 10 mainHeight = height + 10 self.setWindowTitle("model_view models_count:" + str(self.models_count) + " current:(" + str(start) + "~" + str(end - 1) + ")") for index in range(start, end): model = (self.opt_engine[index, :, :, :, :]) self.frame.append(QFrame()) self.mdi_Win.append(QMdiSubWindow()) self.mdi_Win[i].opt_engine = ConstrainedOpt(model, index) self.mdi_Win[i].setWindowTitle("model_" + str(index)) self.mdi_Win[i].setGeometry(0, 0, mainWidth, mainHeight) self.viewerWidget.append( GUIViewer(self.frame[i], self.mdi_Win[i].opt_engine, self.camerax, self.cameray, self.cameraz)) self.viewerWidget[i].resize(width, height) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget[i]) self.frame[i].setLayout(viewerBox) self.mdi_Win[i].setWidget(self.frame[i]) # saveAction = QAction("&Save", self) # saveAction.setShortcut(QKeySequence.Open) # saveAction.setToolTip("Save current image") # saveAction.setStatusTip("Save current image") # self.mdi_Win[i].connect(saveAction, SIGNAL("triggered()"), self.viewerWidget[i].save_image) # # # create toolbar # toolbar = self.mdi_Win[i].addToolBar("tool") # toolbar.setMovable(False) # toolbar.setObjectName("ToolBar") # toolbar.addAction(saveAction) self.viewerWidget[i].interactor.Initialize() self.connect(self.mdi_Win[i].opt_engine, SIGNAL('update_voxels'), self.viewerWidget[i].update_actor) self.connect(self.mdi_Win[i], SIGNAL('save_image'), self.viewerWidget[i].save_image2) self.signal_save_images.connect(self.viewerWidget[i].save_image1) self.signal_setCamera.connect(self.viewerWidget[i].set_camera) self.mdi_Win[i].opt_engine.start() self.mdi_Area.addSubWindow(self.mdi_Win[i]) self.mdi_Win[i].show() i = i + 1
def __init__(self, opt_engine, parent=None, win_size=450): QMainWindow.__init__(self, parent) self.widget = QWidget() self.opt_engine = opt_engine # hbox1 widgets voxel viewer widget self.frame = QFrame() self.viewerWidget = GUIViewer(self.frame, opt_engine) self.viewerWidget.setFixedSize(win_size, win_size) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget) self.frame.setLayout(viewerBox) # hbox2 widgets self.btnSave = QPushButton("Save") btnLayout1 = QHBoxLayout() btnLayout1.addWidget(self.btnSave) btnWidget1 = QWidget() btnWidget1.setLayout(btnLayout1) btnWidget1.setFixedWidth(win_size) hbox1 = QHBoxLayout() hbox1.addWidget(self.frame) hbox2 = QHBoxLayout() hbox2.addWidget(btnWidget1) vbox1 = QVBoxLayout() vbox1.addLayout(hbox1) vbox1.addLayout(hbox2) self.widget.setLayout(vbox1) self.setCentralWidget(self.widget) mainWidth = self.viewerWidget.width() + 35 mainHeight = self.viewerWidget.height() + 70 self.setGeometry(0, 0, mainWidth, mainHeight) self.setFixedSize(self.width(), self.height()) self.btnSave.clicked.connect(self.save_data) self.connect(self.opt_engine, SIGNAL('update_voxels'), self.viewerWidget.update_actor) self.opt_engine.start()
def view_model(self): start = self.current_index banch = self.banch end = start + banch i = start width = (self.width * 2 / 8) * 0.95 height = (self.height / 2) * 0.95 mainWidth = width + 10 mainHeight = height + 10 self.setWindowTitle("model_view models_count:" + str(len(self.files))) for index in range(start, end): model = self.models.pop() self.models_count = self.models_count - 1 self.frame.append(QFrame()) self.mdi_Win.append(QMdiSubWindow()) self.mdi_Win[i].opt_engine = ConstrainedOpt(model, index) self.mdi_Win[i].setWindowTitle("model_" + model['name']) self.mdi_Win[i].setGeometry(0, 0, mainWidth, mainHeight) self.viewerWidget.append( GUIViewer(self.frame[i], self.mdi_Win[i].opt_engine, self.camerax, self.cameray, self.cameraz)) self.viewerWidget[i].resize(width, height) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget[i]) self.frame[i].setLayout(viewerBox) self.mdi_Win[i].setWidget(self.frame[i]) self.viewerWidget[i].interactor.Initialize() self.connect(self.mdi_Win[i].opt_engine, SIGNAL('update_voxels'), self.viewerWidget[i].update_actor) self.connect(self.mdi_Win[i], SIGNAL('save_image'), self.viewerWidget[i].save_image2) self.signal_save_images.connect(self.viewerWidget[i].save_image1) self.mdi_Win[i].opt_engine.start() self.mdi_Area.addSubWindow(self.mdi_Win[i]) self.mdi_Win[i].show() i = i + 1 print 'sucess'
def __init__(self, opt_engine, parent=None, win_size=450): QMainWindow.__init__(self, parent) self.widget = QWidget() self.opt_engine = opt_engine # voxel viewer widget self.frame = QFrame() self.viewerWidget = GUIViewer(self.frame, opt_engine) self.viewerWidget.setFixedSize(win_size, win_size) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget) self.frame.setLayout(viewerBox) # drawing widget self.drawWidget = GUIDraw(opt_engine, win_size) self.drawWidget.setFixedSize(win_size, win_size) # hbox2 widgets self.btnSave = QPushButton("Save") self.btnSample = QPushButton("Sample") self.btnDilation = QPushButton("Dilation") self.btnErosion = QPushButton("Erosion") self.btnColor = QRadioButton("Coloring") self.btnSketch = QRadioButton("Sketching") self.btnEraser = QRadioButton("Eraser") # group self.btnSketch.setChecked(True) btnGroup1 = QButtonGroup() btnGroup1.addButton(self.btnColor) btnGroup1.addButton(self.btnSketch) btnGroup1.addButton(self.btnEraser) # layouts btnLayout1 = QHBoxLayout() btnLayout1.addWidget(self.btnSave) btnLayout1.addWidget(self.btnSample) btnLayout1.addWidget(self.btnDilation) btnLayout1.addWidget(self.btnErosion) btnLayout1.setSpacing(30) btnWidget1 = QWidget() btnWidget1.setLayout(btnLayout1) btnWidget1.setFixedWidth(win_size) btnLayout2 = QHBoxLayout() btnLayout2.addWidget(self.btnColor) btnLayout2.addWidget(self.btnSketch) btnLayout2.addWidget(self.btnEraser) btnWidget2 = QWidget() btnWidget2.setLayout(btnLayout2) btnWidget2.setFixedWidth(win_size) # hbox3 widgets categoryLayout = self.category_layout() categoryWidget = QWidget() categoryWidget.setLayout(categoryLayout) scroll = QScrollArea() scroll.setWidget(categoryWidget) scroll.setFixedHeight(200) hbox1 = QHBoxLayout() hbox1.addWidget(self.frame) hbox1.addWidget(self.drawWidget) hbox1.addStretch(1) hbox2 = QHBoxLayout() hbox2.addWidget(btnWidget1) hbox2.addWidget(btnWidget2) hbox3 = QHBoxLayout() hbox3.addWidget(scroll) vbox1 = QVBoxLayout() vbox1.addLayout(hbox1) vbox1.addLayout(hbox2) vbox1.addLayout(hbox3) self.widget.setLayout(vbox1) self.setCentralWidget(self.widget) mainWidth = self.viewerWidget.width() + self.drawWidget.width() + 70 mainHeight = self.viewerWidget.height() + 320 self.setGeometry(200, 200, mainWidth, mainHeight) self.setFixedSize(self.width(), self.height()) self.btnSave.clicked.connect(self.save_data) self.btnSample.clicked.connect(self.opt_engine.sample_z) self.btnDilation.clicked.connect(self.opt_engine.dilation) self.btnErosion.clicked.connect(self.opt_engine.erosion) self.btnColor.toggled.connect(self.drawWidget.use_color) self.btnSketch.toggled.connect(self.drawWidget.use_edge) self.btnEraser.toggled.connect(self.drawWidget.use_eraser) self.connect(self.opt_engine, SIGNAL('update_voxels'), self.viewerWidget.update_actor) self.opt_engine.start()
class MainWindow(QMainWindow): def __init__(self, opt_engine, parent=None, win_size=450): QMainWindow.__init__(self, parent) self.widget = QWidget() self.opt_engine = opt_engine # voxel viewer widget self.frame = QFrame() self.viewerWidget = GUIViewer(self.frame, opt_engine) self.viewerWidget.setFixedSize(win_size, win_size) viewerBox = QVBoxLayout() viewerBox.addWidget(self.viewerWidget) self.frame.setLayout(viewerBox) # drawing widget self.drawWidget = GUIDraw(opt_engine, win_size) self.drawWidget.setFixedSize(win_size, win_size) # hbox2 widgets self.btnSave = QPushButton("Save") self.btnSample = QPushButton("Sample") self.btnDilation = QPushButton("Dilation") self.btnErosion = QPushButton("Erosion") self.btnColor = QRadioButton("Coloring") self.btnSketch = QRadioButton("Sketching") self.btnEraser = QRadioButton("Eraser") # group self.btnSketch.setChecked(True) btnGroup1 = QButtonGroup() btnGroup1.addButton(self.btnColor) btnGroup1.addButton(self.btnSketch) btnGroup1.addButton(self.btnEraser) # layouts btnLayout1 = QHBoxLayout() btnLayout1.addWidget(self.btnSave) btnLayout1.addWidget(self.btnSample) btnLayout1.addWidget(self.btnDilation) btnLayout1.addWidget(self.btnErosion) btnLayout1.setSpacing(30) btnWidget1 = QWidget() btnWidget1.setLayout(btnLayout1) btnWidget1.setFixedWidth(win_size) btnLayout2 = QHBoxLayout() btnLayout2.addWidget(self.btnColor) btnLayout2.addWidget(self.btnSketch) btnLayout2.addWidget(self.btnEraser) btnWidget2 = QWidget() btnWidget2.setLayout(btnLayout2) btnWidget2.setFixedWidth(win_size) # hbox3 widgets categoryLayout = self.category_layout() categoryWidget = QWidget() categoryWidget.setLayout(categoryLayout) scroll = QScrollArea() scroll.setWidget(categoryWidget) scroll.setFixedHeight(200) hbox1 = QHBoxLayout() hbox1.addWidget(self.frame) hbox1.addWidget(self.drawWidget) hbox1.addStretch(1) hbox2 = QHBoxLayout() hbox2.addWidget(btnWidget1) hbox2.addWidget(btnWidget2) hbox3 = QHBoxLayout() hbox3.addWidget(scroll) vbox1 = QVBoxLayout() vbox1.addLayout(hbox1) vbox1.addLayout(hbox2) vbox1.addLayout(hbox3) self.widget.setLayout(vbox1) self.setCentralWidget(self.widget) mainWidth = self.viewerWidget.width() + self.drawWidget.width() + 70 mainHeight = self.viewerWidget.height() + 320 self.setGeometry(200, 200, mainWidth, mainHeight) self.setFixedSize(self.width(), self.height()) self.btnSave.clicked.connect(self.save_data) self.btnSample.clicked.connect(self.opt_engine.sample_z) self.btnDilation.clicked.connect(self.opt_engine.dilation) self.btnErosion.clicked.connect(self.opt_engine.erosion) self.btnColor.toggled.connect(self.drawWidget.use_color) self.btnSketch.toggled.connect(self.drawWidget.use_edge) self.btnEraser.toggled.connect(self.drawWidget.use_eraser) self.connect(self.opt_engine, SIGNAL('update_voxels'), self.viewerWidget.update_actor) self.opt_engine.start() def closeEvent(self, event): self.opt_engine.quit() self.opt_engine.model.sess.close() def category_layout(self): gridLayout = QGridLayout() gridLayout.setHorizontalSpacing(20) gridLayout.setVerticalSpacing(10) categories = np.genfromtxt("category.csv", usecols=(0, 1, 2), dtype=np.str, delimiter=',') for i, c in enumerate(categories): index, _, name = c label = QLabel(name) slider = QSlider(Qt.Horizontal) slider.setRange(0, 100) slider.setValue(0) slider.valueChanged.connect(lambda value, j=int( index): self.opt_engine.set_label(float(value) / 100, j)) gridLayout.addWidget(label, i, 0) gridLayout.addWidget(slider, i, 1) return gridLayout def save_data(self): try: self.number except: self.number = 1 self.drawWidget.uiColor.save() self.drawWidget.uiSketch.save() np.save("out/model-{0}.npy".format(self.number), self.opt_engine.get_3d_model()) self.number += 1
### Data contributor # MI2RL researchers # Dongwoo Seo, Emergency Medicine@AMC # Namkug Kim, Convergence Medicine@AMC ### references # I3D Network (https://github.com/hassony2/kinetics_i3d_pytorch) ##### ''' import cv2 import sys from PyQt5 import QtWidgets from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from gui_viewer import GUIViewer if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) viewer = GUIViewer() viewer.show() app.exec_()