def __init__(self, parent=None): super(OverviewScene, self).__init__(parent) self.coordEventObserver = None self.colorTable = None self.anaglyph = False self.sceneItems = [] self.cutter = 3*[None] self.objects = [] self.planes = None self.axes = None self._dataShape = None layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(0) self.qvtk = QVTKOpenGLWidget() layout.addWidget(self.qvtk) self.setLayout(layout) self.qvtk.init() hbox = QHBoxLayout(None) hbox.setMargin(0) hbox.setSpacing(5) hbox.setContentsMargins(5,3,5,3) def delete_gl_widget(): # This is called just before the app quits to avoid this error during shutdown: # QGLContext::makeCurrent: Cannot make invalid context current self.qvtk.setParent(None) del self.qvtk QApplication.instance().aboutToQuit.connect( delete_gl_widget ) b1 = QToolButton() b1.setIcon(QIcon(':icons/icons/x-axis.png')) b1.setToolTip("Show x slicing plane") b1.setCheckable(True); b1.setChecked(True) b2 = QToolButton() b2.setIcon(QIcon(':icons/icons/y-axis.png')) b2.setToolTip("Show y slicing plane") b2.setCheckable(True); b2.setChecked(True) b3 = QToolButton() b3.setIcon(QIcon(':icons/icons/z-axis.png')) b3.setToolTip("Show z slicing plane") b3.setCheckable(True); b3.setChecked(True) bAnaglyph = QToolButton() bAnaglyph.setIcon(QIcon(':icons/icons/3d_glasses.png')) bAnaglyph.setToolTip("Show in anaglyph 3D") bAnaglyph.setCheckable(True); bAnaglyph.setChecked(False) self.bUndock = QToolButton() self.bUndock.setIcon(QIcon(":/icons/icons/arrow_up.png")) self.bUndock.setToolTip("Dock/undock this view") ''' bCutter = QToolButton() bCutter.setIcon(QIcon(':icons/icons/edit-cut.png')) bCutter.setCheckable(True); bCutter.setChecked(False) self.bCutter = bCutter bExportMesh = QToolButton() bExportMesh.setIcon(QIcon(':icons/icons/document-save-as.png')) ''' hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.addWidget(bAnaglyph) hbox.addWidget(self.bUndock) #hbox.addWidget(bCutter) hbox.addStretch() #hbox.addWidget(bExportMesh) layout.addLayout(hbox) self.connect(b1, SIGNAL("clicked()"), self.TogglePlaneWidgetX) self.connect(b2, SIGNAL("clicked()"), self.TogglePlaneWidgetY) self.connect(b3, SIGNAL("clicked()"), self.TogglePlaneWidgetZ) self.connect(bAnaglyph, SIGNAL("clicked()"), self.ToggleAnaglyph3D) #self.connect(bExportMesh, SIGNAL("clicked()"), self.exportMesh) #bCutter.toggled.connect(self.useCutterToggled) self.connect(self.qvtk, SIGNAL("objectPicked"), self.__onObjectPicked) def layerContextMenu(layer, menu): self.layerContextMenu(layer,menu) Event.register("layerContextMenuRequested", layerContextMenu)
def _add_actions( layer, menu ): if isinstance(layer, GrayscaleLayer): _add_actions_grayscalelayer( layer, menu ) elif isinstance( layer, RGBALayer ): _add_actions_rgbalayer( layer, menu ) Event.trigger("layerContextMenuRequested", layer = layer, menu = menu)
def __init__(self, parent=None): super(OverviewScene, self).__init__(parent) self.coordEventObserver = None self.colorTable = None self.anaglyph = False self.sceneItems = [] self.cutter = 3 * [None] self.objects = [] self.planes = None self.axes = None self._dataShape = None layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(0) self.qvtk = QVTKOpenGLWidget() layout.addWidget(self.qvtk) self.setLayout(layout) self.qvtk.init() hbox = QHBoxLayout(None) hbox.setMargin(0) hbox.setSpacing(5) hbox.setContentsMargins(5, 3, 5, 3) def delete_gl_widget(): # This is called just before the app quits to avoid this error during shutdown: # QGLContext::makeCurrent: Cannot make invalid context current self.qvtk.setParent(None) del self.qvtk QApplication.instance().aboutToQuit.connect(delete_gl_widget) b1 = QToolButton() b1.setIcon(QIcon(':icons/icons/x-axis.png')) b1.setToolTip("Show x slicing plane") b1.setCheckable(True) b1.setChecked(True) b2 = QToolButton() b2.setIcon(QIcon(':icons/icons/y-axis.png')) b2.setToolTip("Show y slicing plane") b2.setCheckable(True) b2.setChecked(True) b3 = QToolButton() b3.setIcon(QIcon(':icons/icons/z-axis.png')) b3.setToolTip("Show z slicing plane") b3.setCheckable(True) b3.setChecked(True) bAnaglyph = QToolButton() bAnaglyph.setIcon(QIcon(':icons/icons/3d_glasses.png')) bAnaglyph.setToolTip("Show in anaglyph 3D") bAnaglyph.setCheckable(True) bAnaglyph.setChecked(False) self.bUndock = QToolButton() self.bUndock.setIcon(QIcon(":/icons/icons/arrow_up.png")) self.bUndock.setToolTip("Dock/undock this view") ''' bCutter = QToolButton() bCutter.setIcon(QIcon(':icons/icons/edit-cut.png')) bCutter.setCheckable(True); bCutter.setChecked(False) self.bCutter = bCutter bExportMesh = QToolButton() bExportMesh.setIcon(QIcon(':icons/icons/document-save-as.png')) ''' hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.addWidget(bAnaglyph) hbox.addWidget(self.bUndock) #hbox.addWidget(bCutter) hbox.addStretch() #hbox.addWidget(bExportMesh) layout.addLayout(hbox) self.connect(b1, SIGNAL("clicked()"), self.TogglePlaneWidgetX) self.connect(b2, SIGNAL("clicked()"), self.TogglePlaneWidgetY) self.connect(b3, SIGNAL("clicked()"), self.TogglePlaneWidgetZ) self.connect(bAnaglyph, SIGNAL("clicked()"), self.ToggleAnaglyph3D) #self.connect(bExportMesh, SIGNAL("clicked()"), self.exportMesh) #bCutter.toggled.connect(self.useCutterToggled) self.connect(self.qvtk, SIGNAL("objectPicked"), self.__onObjectPicked) def layerContextMenu(layer, menu): self.layerContextMenu(layer, menu) Event.register("layerContextMenuRequested", layerContextMenu)
def reinitialize(self): """ For some reason, we can't remove the items from the 3D scene when the datashape changes. Calling self.qvtk.renderer.RemoveActor(self.planes) seems to have no effect. So here we go for the nuclear option. Remove all contents of the widget and simply start over. """ def delete_gl_widget(): # This is called just before the app quits to avoid this error during shutdown: # QGLContext::makeCurrent: Cannot make invalid context current if self.qvtk is not None: self.qvtk.setParent(None) self.qvtk = None delete_gl_widget() layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(0) self.qvtk = QVTKOpenGLWidget() layout.addWidget(self.qvtk) if self.layout() is not None: # We can't give ourselves a new layout until we remove the old one. # The easiest way to remove the old one is to assign it to a temporary widget. temp_widget = QWidget() temp_widget.setLayout( self.layout() ) assert self.layout() is None self.setLayout(layout) self.qvtk.init() hbox = QHBoxLayout(None) hbox.setMargin(0) hbox.setSpacing(5) hbox.setContentsMargins(5,3,5,3) QApplication.instance().aboutToQuit.connect( delete_gl_widget ) b1 = QToolButton() b1.setIcon(QIcon(':icons/icons/x-axis.png')) b1.setToolTip("Show x slicing plane") b1.setCheckable(True); b1.setChecked(True) b2 = QToolButton() b2.setIcon(QIcon(':icons/icons/y-axis.png')) b2.setToolTip("Show y slicing plane") b2.setCheckable(True); b2.setChecked(True) b3 = QToolButton() b3.setIcon(QIcon(':icons/icons/z-axis.png')) b3.setToolTip("Show z slicing plane") b3.setCheckable(True); b3.setChecked(True) bAnaglyph = QToolButton() bAnaglyph.setIcon(QIcon(':icons/icons/3d_glasses.png')) bAnaglyph.setToolTip("Show in anaglyph 3D") bAnaglyph.setCheckable(True); bAnaglyph.setChecked(False) self.bUndock = QToolButton() self.bUndock.setIcon(QIcon(":/icons/icons/arrow_up.png")) self.bUndock.setToolTip("Dock/undock this view") ''' bCutter = QToolButton() bCutter.setIcon(QIcon(':icons/icons/edit-cut.png')) bCutter.setCheckable(True); bCutter.setChecked(False) self.bCutter = bCutter bExportMesh = QToolButton() bExportMesh.setIcon(QIcon(':icons/icons/document-save-as.png')) ''' hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.addWidget(bAnaglyph) hbox.addWidget(self.bUndock) #hbox.addWidget(bCutter) hbox.addStretch() #hbox.addWidget(bExportMesh) layout.addLayout(hbox) b1.clicked.connect( self.TogglePlaneWidgetX ) b2.clicked.connect( self.TogglePlaneWidgetY ) b3.clicked.connect( self.TogglePlaneWidgetZ ) bAnaglyph.clicked.connect( self.ToggleAnaglyph3D ) #self.connect(bExportMesh, SIGNAL("clicked()"), self.exportMesh) #bCutter.toggled.connect(self.useCutterToggled) self.connect(self.qvtk, SIGNAL("objectPicked"), self.__onObjectPicked) #self.qvtk.objectPicked.connect( self.__onObjectPicked ) def layerContextMenu(layer, menu): self.layerContextMenu(layer,menu) Event.register("layerContextMenuRequested", layerContextMenu) if self._dataShape is not None: self._initialize_slicing_planes() self.reinitialized.emit()
def reinitialize(self): """ For some reason, we can't remove the items from the 3D scene when the datashape changes. Calling self.qvtk.renderer.RemoveActor(self.planes) seems to have no effect. So here we go for the nuclear option. Remove all contents of the widget and simply start over. """ def delete_gl_widget(): # This is called just before the app quits to avoid this error during shutdown: # QGLContext::makeCurrent: Cannot make invalid context current if self.qvtk is not None: self.qvtk.setParent(None) self.qvtk = None delete_gl_widget() layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(0) self.qvtk = QVTKOpenGLWidget() layout.addWidget(self.qvtk) if self.layout() is not None: # We can't give ourselves a new layout until we remove the old one. # The easiest way to remove the old one is to assign it to a temporary widget. temp_widget = QWidget() temp_widget.setLayout(self.layout()) assert self.layout() is None self.setLayout(layout) self.qvtk.init() hbox = QHBoxLayout(None) hbox.setMargin(0) hbox.setSpacing(5) hbox.setContentsMargins(5, 3, 5, 3) QApplication.instance().aboutToQuit.connect(delete_gl_widget) b1 = QToolButton() b1.setIcon(QIcon(':icons/icons/x-axis.png')) b1.setToolTip("Show x slicing plane") b1.setCheckable(True) b1.setChecked(True) b2 = QToolButton() b2.setIcon(QIcon(':icons/icons/y-axis.png')) b2.setToolTip("Show y slicing plane") b2.setCheckable(True) b2.setChecked(True) b3 = QToolButton() b3.setIcon(QIcon(':icons/icons/z-axis.png')) b3.setToolTip("Show z slicing plane") b3.setCheckable(True) b3.setChecked(True) bAnaglyph = QToolButton() bAnaglyph.setIcon(QIcon(':icons/icons/3d_glasses.png')) bAnaglyph.setToolTip("Show in anaglyph 3D") bAnaglyph.setCheckable(True) bAnaglyph.setChecked(False) self.bUndock = QToolButton() self.bUndock.setIcon(QIcon(":/icons/icons/arrow_up.png")) self.bUndock.setToolTip("Dock/undock this view") ''' bCutter = QToolButton() bCutter.setIcon(QIcon(':icons/icons/edit-cut.png')) bCutter.setCheckable(True); bCutter.setChecked(False) self.bCutter = bCutter bExportMesh = QToolButton() bExportMesh.setIcon(QIcon(':icons/icons/document-save-as.png')) ''' hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.addWidget(bAnaglyph) hbox.addWidget(self.bUndock) #hbox.addWidget(bCutter) hbox.addStretch() #hbox.addWidget(bExportMesh) layout.addLayout(hbox) b1.clicked.connect(self.TogglePlaneWidgetX) b2.clicked.connect(self.TogglePlaneWidgetY) b3.clicked.connect(self.TogglePlaneWidgetZ) bAnaglyph.clicked.connect(self.ToggleAnaglyph3D) #self.connect(bExportMesh, SIGNAL("clicked()"), self.exportMesh) #bCutter.toggled.connect(self.useCutterToggled) self.connect(self.qvtk, SIGNAL("objectPicked"), self.__onObjectPicked) #self.qvtk.objectPicked.connect( self.__onObjectPicked ) def layerContextMenu(layer, menu): self.layerContextMenu(layer, menu) Event.register("layerContextMenuRequested", layerContextMenu) if self._dataShape is not None: self._initialize_slicing_planes() self.reinitialized.emit()
def __init__(self, parent=None): super(OverviewScene, self).__init__(parent) self.colorTable = None self.anaglyph = False self.sceneItems = [] self.cutter = 3*[None] self.objects = [] self.planes = None self.axes = None layout = QVBoxLayout() layout.setMargin(0) layout.setSpacing(0) self.qvtk = QVTKOpenGLWidget() layout.addWidget(self.qvtk) self.setLayout(layout) self.qvtk.init() hbox = QHBoxLayout(None) hbox.setMargin(0) hbox.setSpacing(5) hbox.setContentsMargins(5,3,5,3) b1 = QToolButton() b1.setIcon(QIcon(path.join(_icondir, 'x-axis.png'))) b1.setCheckable(True); b1.setChecked(True) b2 = QToolButton() b2.setIcon(QIcon(path.join(_icondir, 'y-axis.png'))) b2.setCheckable(True); b2.setChecked(True) b3 = QToolButton() b3.setIcon(QIcon(path.join(_icondir, 'z-axis.png'))) b3.setCheckable(True); b3.setChecked(True) bAnaglyph = QToolButton() bAnaglyph.setIcon(QIcon(path.join(_icondir, '3d_glasses.png'))) bAnaglyph.setCheckable(True); bAnaglyph.setChecked(False) bCutter = QToolButton() bCutter.setIcon(QIcon(path.join(_icondir, 'edit-cut.png'))) bCutter.setCheckable(True); bCutter.setChecked(False) self.bCutter = bCutter bExportMesh = QToolButton() bExportMesh.setIcon(QIcon(path.join(_icondir, 'document-save-as.png'))) hbox.addWidget(b1) hbox.addWidget(b2) hbox.addWidget(b3) hbox.addWidget(bAnaglyph) hbox.addWidget(bCutter) hbox.addStretch() hbox.addWidget(bExportMesh) layout.addLayout(hbox) self.connect(b1, SIGNAL("clicked()"), self.TogglePlaneWidgetX) self.connect(b2, SIGNAL("clicked()"), self.TogglePlaneWidgetY) self.connect(b3, SIGNAL("clicked()"), self.TogglePlaneWidgetZ) self.connect(bAnaglyph, SIGNAL("clicked()"), self.ToggleAnaglyph3D) self.connect(bExportMesh, SIGNAL("clicked()"), self.exportMesh) bCutter.toggled.connect(self.useCutterToggled) self.connect(self.qvtk, SIGNAL("objectPicked"), self.__onObjectPicked) def layerContextMenu(layer, menu): self.layerContextMenu(layer,menu) Event.register("layerContextMenuRequested", layerContextMenu)