class MainWindow(QMainWindow, Ui_MainWindow): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget (QWidget) """ # calling base initializers super(MainWindow, self).__init__(parent) # calling base setupUi for ui configuration self.setupUi(self) # setting up the gui self.setup_gui() def setup_gui(self): """ """ self.glWidget = GLWidget(parent = self.gridWidget_4, width = 1508, height = 713, bgcolor = (.5, .5, 0.9), enable_light = False) self.gridLayout_4.addWidget(self.glWidget) #for now, pbExtCluster will be invisible self.pbExtCluster.setVisible(False) # adding the editing items to ROI table # double spinbox for x,y and z coordinates self.dspbxcoord = QtGui.QDoubleSpinBox() self.tblROI.setCellWidget(3, 1, self.dspbxcoord) self.dspbycoord = QtGui.QDoubleSpinBox() self.tblROI.setCellWidget(4, 1, self.dspbycoord) self.dspbzcoord = QtGui.QDoubleSpinBox() self.tblROI.setCellWidget(5, 1, self.dspbzcoord) self.spbrad = QtGui.QSpinBox() self.tblROI.setCellWidget(6, 1, self.spbrad) # define method ROI self.roimethod = 1 #tractome inside # color button self.colorlist = [QtGui.QColor('red'), QtGui.QColor('blue'), QtGui.QColor('green'), QtGui.QColor('yellow'), QtGui.QColor('cyan'), QtGui.QColor('black')] self.btncolor = QtGui.QPushButton() self.tblROI.setCellWidget(2, 1, self.btncolor) self.btncolor.setAutoFillBackground(True) # connect button with QColorDialog self.connect(self.btncolor, QtCore.SIGNAL("clicked()"), self.on_btncolor_clicked) # visibility checkbox self.chkbvis = QtGui.QCheckBox() self.chkbvis.setCheckState(QtCore.Qt.Checked) self.connect(self.chkbvis, QtCore.SIGNAL("stateChanged(int)"), self.on_chkbvis_stateChanged) self.tblROI.setCellWidget(1, 1, self.chkbvis) # self.show_hide_rows(True) # creating the main Scene self.tractome= Tractome() self.add_scene(self.tractome.scene) def changenumstreamlines_handler(self, n_stream): """ """ if (n_stream< 1e5) and (n_stream>= 50): default = 50 else: default = n_stream self.spbRecluster.setValue(default) self.spbRecluster.setRange(1, n_stream) self.hSlReCluster.setValue(default) self.hSlReCluster.setMinimum(1) self.hSlReCluster.setMaximum(min(150, n_stream)) self.tblTract.item(1, 1).setText(str(n_stream)) def changenumrepresentatives_handler(self, n_rep): """ """ self.tblTract.item(2, 1).setText(str(n_rep)) def changenumknnextend_handler(self, changenn): """ """ if changenn is True: self.hSlExtclust.setValue(0) def on_dspbxcoord_valueChanged(self, value): """ """ self.tractome.update_ROI(self.tblROI.item(0, 1).text(), coordx = value, rebuild = self.list_chkROIS[self.activeROI].isChecked()) self.glWidget.updateGL() def on_dspbycoord_valueChanged(self, value): """ """ self.tractome.update_ROI(self.tblROI.item(0, 1).text(), coordy = value, rebuild = self.list_chkROIS[self.activeROI].isChecked()) self.glWidget.updateGL() def on_dspbzcoord_valueChanged(self, value): self.tractome.update_ROI(self.tblROI.item(0, 1).text(), coordz = value, rebuild = self.list_chkROIS[self.activeROI].isChecked()) self.glWidget.updateGL() def on_spbrad_valueChanged(self, value): """ """ self.tractome.update_ROI(self.tblROI.item(0, 1).text(), radius=value, rebuild = self.list_chkROIS[self.activeROI].isChecked()) self.glWidget.updateGL() def on_chkbvis_stateChanged(self, state): """ Shows or hides the ROI if the visibility checkbox is checked or not correspondingly. """ self.tractome.show_hide_actor(self.tblROI.item(0, 1).text(), state) self.glWidget.updateGL() @Slot(QtGui.QTreeWidgetItem, int) def on_treeObject_itemClicked(self, item, column): """ If the item selected is a ROI, the corresponding information will be shown in the tableROI. """ name = str(item.text(0)) xcoord, ycoord, zcoord, radius, color= self.tractome.information_from_ROI(name) index= self.treeObject.indexFromItem(item) self.activeROI = index.row() self.disconnect(self.tblROI, QtCore.SIGNAL("itemChanged(QtGui.QTableWidgetItem)"), self.on_tblROI_itemChanged) self.updateROItable(name, xcoord, ycoord, zcoord, radius, color) self.connect(self.tblROI, QtCore.SIGNAL("itemChanged(QtGui.QTableWidgetItem)"), self.on_tblROI_itemChanged) def on_btncolor_clicked(self): """ """ color = QtGui.QColorDialog().getColor() self.btncolor.setStyleSheet( u'background-color:%s' % color.name()) self.tractome.update_ROI(self.tblROI.item(0, 1).text(), color = color.getRgbF()) @Slot(int) def on_chkbShowTract_stateChanged(self, state): """ Shows or hides the tractography if the Checkbox is checked or not correspondingly """ self.tractome.show_hide_actor('Bundle Picker', state) self.glWidget.updateGL() @Slot(int) def on_chkbShowStruct_stateChanged(self, state): """ Shows or hides the structural image if the Checkbox is checked or not correspondingly """ self.tractome.show_hide_actor('Volume Slicer', state) self.glWidget.updateGL() # @Slot(bool) # def on_rdbInsSphere_toggled(self, checked): # """ # Use method of Tractome inside sphere to compute the ROI # """ # if checked: # self.roimethod = 1 # self.tractome.update_ROI(self.tblROI.item(0, 1).text(), method = self.roimethod, rebuild= True) # if len(self.list_chkROIS)>0: # self.tractome.compute_streamlines_ROIS() # @Slot(bool) # def on_rdbtrackvis_toggled(self, checked): # """ # Use method of Trackvis to compute the ROI # """ # if checked: # self.roimethod = 0 # self.tractome.update_ROI(self.tblROI.item(0, 1).text(), method = self.roimethod, rebuild= True) # if len(self.list_chkROIS)>0: # self.tractome.compute_streamlines_ROIS() @Slot(int) def on_spbRecluster_valueChanged(self, p0): """ Update slider Recluster """ self.hSlReCluster.setValue(p0) @Slot(int) def on_hSlReCluster_valueChanged(self, value): """ Update spbRecluster """ self.spbRecluster.setValue(value) @Slot() def on_pbRecluster_clicked(self): """ Call re-cluster function from tractome and update values of possible number of clusters for related objects. """ self.tractome.recluster(self.spbRecluster.value()) self.hSlExtclust.setValue(0) self.glWidget.updateGL() @Slot(int) def on_spbExtClust_valueChanged(self, p0): """ Update hSlExtclust and call method that computes kdtree-query. """ self.hSlExtclust.setValue(p0) try: self.tractome.compute_kqueries(p0) self.glWidget.updateGL() except TractomeError,e: msgBox = QtGui.QMessageBox.critical(self, "Tractome Message", ''.join(e.args))