def _updateLabelShortcuts(self): numShortcuts = len(self._labelShortcuts) numRows = len(self._labelControlUi.labelListModel) mgr = ShortcutManager() ActionInfo = ShortcutManager.ActionInfo # Add any shortcuts we don't have yet. for i in range(numShortcuts, numRows): toolTipObject = LabelListModel.EntryToolTipAdapter( self._labelControlUi.labelListModel, i) action_info = ActionInfo( "Labeling", "Select Label {}".format(i + 1), "Select Label {}".format(i + 1), partial(self._labelControlUi.labelListView.selectRow, i), self._labelControlUi.labelListView, toolTipObject, ) mgr.register(str(i + 1), action_info) self._labelShortcuts.append(action_info) # Make sure that all shortcuts have an appropriate description for i in range(numRows): action_info = self._labelShortcuts[i] description = "Select " + self._labelControlUi.labelListModel[ i].name new_action_info = mgr.update_description(action_info, description) self._labelShortcuts[i] = new_action_info
def _updateLabelShortcuts(self): numShortcuts = len(self._labelShortcuts) numRows = len(self._labelControlUi.labelListModel) # Add any shortcuts we don't have yet. for i in range(numShortcuts, numRows): shortcut = QShortcut( QKeySequence(str(i + 1)), self, member=partial(self._labelControlUi.labelListView.selectRow, i)) self._labelShortcuts.append(shortcut) toolTipObject = LabelListModel.EntryToolTipAdapter( self._labelControlUi.labelListModel, i) ShortcutManager().register("Labeling", "", shortcut, toolTipObject) # Make sure that all shortcuts have an appropriate description for i in range(numRows): shortcut = self._labelShortcuts[i] description = "Select " + self._labelControlUi.labelListModel[ i].name ShortcutManager().setDescription(shortcut, description)
def __init__(self, parentApplet, topLevelOperatorView, drawerUiPath=None ): self.topLevelOperatorView = topLevelOperatorView #members self._doneSegmentationLayer = None self._showSegmentationIn3D = False self._showUncertaintyLayer = False #end: members labelingSlots = LabelingGui.LabelingSlots() labelingSlots.labelInput = topLevelOperatorView.WriteSeeds labelingSlots.labelOutput = topLevelOperatorView.opLabelArray.Output labelingSlots.labelEraserValue = topLevelOperatorView.opLabelArray.EraserLabelValue labelingSlots.labelNames = topLevelOperatorView.LabelNames labelingSlots.labelDelete = topLevelOperatorView.opLabelArray.DeleteLabel labelingSlots.maxLabelValue = topLevelOperatorView.opLabelArray.MaxLabelValue labelingSlots.labelsAllowed = topLevelOperatorView.LabelsAllowed # We provide our own UI file (which adds an extra control for interactive mode) directory = os.path.split(__file__)[0] if drawerUiPath is None: drawerUiPath = os.path.join(directory, 'carvingDrawer.ui') self.dialogdirCOM = os.path.join(directory, 'carvingObjectManagement.ui') self.dialogdirSAD = os.path.join(directory, 'saveAsDialog.ui') rawInputSlot = topLevelOperatorView.RawData super(CarvingGui, self).__init__(parentApplet, labelingSlots, topLevelOperatorView, drawerUiPath, rawInputSlot) self.labelingDrawerUi.currentObjectLabel.setText("<not saved yet>") # Init special base class members self.minLabelNumber = 2 self.maxLabelNumber = 2 mgr = ShortcutManager() ActionInfo = ShortcutManager.ActionInfo #set up keyboard shortcuts mgr.register( "3", ActionInfo( "Carving", "Run interactive segmentation", "Run interactive segmentation", self.labelingDrawerUi.segment.click, self.labelingDrawerUi.segment, self.labelingDrawerUi.segment ) ) try: self.render = True self._shownObjects3D = {} self._renderMgr = RenderingManager( self.editor.view3d ) except: self.render = False # Segmentation is toggled on by default in _after_init, below. # (We can't enable it until the layers are all present.) self._showSegmentationIn3D = False self._segmentation_3d_label = None self.labelingDrawerUi.segment.clicked.connect(self.onSegmentButton) self.labelingDrawerUi.segment.setEnabled(True) self.topLevelOperatorView.Segmentation.notifyDirty( bind( self._update_rendering ) ) self.topLevelOperatorView.HasSegmentation.notifyValueChanged( bind( self._updateGui ) ) ## uncertainty self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) def onUncertaintyFGButton(): logger.debug( "uncertFG button clicked" ) pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=2) self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) self.labelingDrawerUi.pushButtonUncertaintyFG.clicked.connect(onUncertaintyFGButton) def onUncertaintyBGButton(): logger.debug( "uncertBG button clicked" ) pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=1) self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) self.labelingDrawerUi.pushButtonUncertaintyBG.clicked.connect(onUncertaintyBGButton) def onUncertaintyCombo(value): if value == 0: value = "none" self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) self._showUncertaintyLayer = False else: if value == 1: value = "localMargin" elif value == 2: value = "exchangeCount" elif value == 3: value = "gabow" else: raise RuntimeError("unhandled case '%r'" % value) self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(True) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(True) self._showUncertaintyLayer = True logger.debug( "uncertainty changed to %r" % value ) self.topLevelOperatorView.UncertaintyType.setValue(value) self.updateAllLayers() #make sure that an added/deleted uncertainty layer is recognized self.labelingDrawerUi.uncertaintyCombo.currentIndexChanged.connect(onUncertaintyCombo) ## background priority def onBackgroundPrioritySpin(value): logger.debug( "background priority changed to %f" % value ) self.topLevelOperatorView.BackgroundPriority.setValue(value) self.labelingDrawerUi.backgroundPrioritySpin.valueChanged.connect(onBackgroundPrioritySpin) def onBackgroundPriorityDirty(slot, roi): oldValue = self.labelingDrawerUi.backgroundPrioritySpin.value() newValue = self.topLevelOperatorView.BackgroundPriority.value if newValue != oldValue: self.labelingDrawerUi.backgroundPrioritySpin.setValue(newValue) self.topLevelOperatorView.BackgroundPriority.notifyDirty(onBackgroundPriorityDirty) ## bias def onNoBiasBelowDirty(slot, roi): oldValue = self.labelingDrawerUi.noBiasBelowSpin.value() newValue = self.topLevelOperatorView.NoBiasBelow.value if newValue != oldValue: self.labelingDrawerUi.noBiasBelowSpin.setValue(newValue) self.topLevelOperatorView.NoBiasBelow.notifyDirty(onNoBiasBelowDirty) def onNoBiasBelowSpin(value): logger.debug( "background priority changed to %f" % value ) self.topLevelOperatorView.NoBiasBelow.setValue(value) self.labelingDrawerUi.noBiasBelowSpin.valueChanged.connect(onNoBiasBelowSpin) ## save self.labelingDrawerUi.save.clicked.connect(self.onSaveButton) ## clear self.labelingDrawerUi.clear.clicked.connect(self._onClearAction) ## object names self.labelingDrawerUi.namesButton.clicked.connect(self.onShowObjectNames) if hasattr( self.labelingDrawerUi, 'exportAllMeshesButton' ): self.labelingDrawerUi.exportAllMeshesButton.clicked.connect(self._exportAllObjectMeshes) def labelBackground(): self.selectLabel(0) def labelObject(): self.selectLabel(1) self._labelControlUi.labelListModel.allowRemove(False) bgToolTipObject = LabelListModel.EntryToolTipAdapter(self._labelControlUi.labelListModel, 0) mgr.register( "1", ActionInfo( "Carving", "Select background label", "Select background label", labelBackground, self.viewerControlWidget(), bgToolTipObject ) ) fgToolTipObject = LabelListModel.EntryToolTipAdapter(self._labelControlUi.labelListModel, 1) mgr.register( "2", ActionInfo( "Carving", "Select object label", "Select object label", labelObject, self.viewerControlWidget(), fgToolTipObject ) ) def layerIndexForName(name): return self.layerstack.findMatchingIndex(lambda x: x.name == name) def addLayerToggleShortcut(layername, shortcut): def toggle(): row = layerIndexForName(layername) self.layerstack.selectRow(row) layer = self.layerstack[row] layer.visible = not layer.visible self.viewerControlWidget().layerWidget.setFocus() mgr.register(shortcut, ActionInfo( "Carving", "Toggle layer %s" % layername, "Toggle layer %s" % layername, toggle, self.viewerControlWidget(), None ) ) #TODO addLayerToggleShortcut("Completed segments (unicolor)", "d") addLayerToggleShortcut("Segmentation", "s") addLayerToggleShortcut("Input Data", "r") ''' def updateLayerTimings(): s = "Layer timings:\n" for l in self.layerstack: s += "%s: %f sec.\n" % (l.name, l.averageTimePerTile) self.labelingDrawerUi.layerTimings.setText(s) t = QTimer(self) t.setInterval(1*1000) # 10 seconds t.start() t.timeout.connect(updateLayerTimings) ''' def makeColortable(): self._doneSegmentationColortable = [QColor(0,0,0,0).rgba()] for i in range(254): r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) # ensure colors have sufficient distance to pure red and pure green while (255 - r)+g+b<128 or r+(255-g)+b<128: r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) self._doneSegmentationColortable.append(QColor(r,g,b).rgba()) self._doneSegmentationColortable.append(QColor(0,255,0).rgba()) makeColortable() def onRandomizeColors(): if self._doneSegmentationLayer is not None: logger.debug( "randomizing colors ..." ) makeColortable() self._doneSegmentationLayer.colorTable = self._doneSegmentationColortable if self.render and self._renderMgr.ready: self._update_rendering() #self.labelingDrawerUi.randomizeColors.clicked.connect(onRandomizeColors) self._updateGui()