def __init__(self, parent=None, optionsFrame=None): self.effects = [] self.effectButtons = {} self.effectMapper = qt.QSignalMapper() self.effectMapper.connect('mapped(const QString&)', self.selectEffect) self.editUtil = EditUtil.EditUtil() self.undoRedo = EditUtil.UndoRedo() self.undoRedo.stateChangedCallback = self.updateUndoRedoButtons # check for extensions - if none have been registered, just create the empty dictionary try: slicer.modules.editorExtensions except AttributeError: slicer.modules.editorExtensions = {} # register the builtin extensions self.editorBuiltins = {} self.editorBuiltins["PaintEffect"] = EditorLib.PaintEffect self.editorBuiltins["DrawEffect"] = EditorLib.DrawEffect self.editorBuiltins["ThresholdEffect"] = EditorLib.ThresholdEffect self.editorBuiltins["RectangleEffect"] = EditorLib.RectangleEffect self.editorBuiltins[ "LevelTracingEffect"] = EditorLib.LevelTracingEffect self.editorBuiltins["MakeModelEffect"] = EditorLib.MakeModelEffect self.editorBuiltins["ErodeEffect"] = EditorLib.ErodeEffect self.editorBuiltins["DilateEffect"] = EditorLib.DilateEffect self.editorBuiltins["ChangeLabelEffect"] = EditorLib.ChangeLabelEffect self.editorBuiltins[ "RemoveIslandsEffect"] = EditorLib.RemoveIslandsEffect self.editorBuiltins[ "IdentifyIslandsEffect"] = EditorLib.IdentifyIslandsEffect self.editorBuiltins["SaveIslandEffect"] = EditorLib.SaveIslandEffect self.editorBuiltins[ "ChangeIslandEffect"] = EditorLib.ChangeIslandEffect self.editorBuiltins["GrowCutEffect"] = EditorLib.GrowCutEffect if not parent: self.parent = qt.QFrame() self.parent.setLayout(qt.QVBoxLayout()) self.create() self.parent.show() else: self.parent = parent self.create() # frame that holds widgets specific for each effect if not optionsFrame: self.optionsFrame = qt.QFrame(self.parent) else: self.optionsFrame = optionsFrame # state variables for selected effect in the box # - currentOption is an instance of an option GUI # - currentTools is a list of EffectTool instances self.currentOption = None self.currentTools = []
def __init__(self, sliceWidget): # sliceWidget to operate on and convenience variables # to access the internals self.sliceWidget = sliceWidget self.sliceView = self.sliceWidget.sliceView() self.interactor = self.sliceView.interactorStyle().GetInteractor() self.renderWindow = self.sliceWidget.sliceView().renderWindow() self.renderer = self.renderWindow.GetRenderers().GetItemAsObject(0) self.editUtil = EditUtil.EditUtil() # optionally set by users of the class self.undoRedo = None # actors in the renderer that need to be cleaned up on destruction self.actors = [] # the current operation self.actionState = None # set up observers on the interactor # - keep track of tags so these can be removed later # - currently all editor effects are restricted to these events # - make the observers high priority so they can override other # event processors self.interactorObserverTags = [] events = ("LeftButtonPressEvent", "LeftButtonReleaseEvent", "MiddleButtonPressEvent", "MiddleButtonReleaseEvent", "RightButtonPressEvent", "RightButtonReleaseEvent", "MouseMoveEvent", "KeyPressEvent", "EnterEvent", "LeaveEvent") for e in events: tag = self.interactor.AddObserver(e, self.processEvent, 1.0) self.interactorObserverTags.append(tag)
def __init__(self, parent=None): self.parent = parent self.updatingGUI = False self.observerTags = [] self.widgets = [] self.parameterNode = None self.parameterNodeTag = None self.editUtil = EditUtil.EditUtil() self.tools = [] # connections is a list of widget/signal/slot tripples # for the options gui that can be connected/disconnected # as needed to prevent triggering mrml updates while # updating the state of the gui # - each level of the inheritance tree can add entries # to this list for use by the connectWidgets # and disconnectWidgets methods self.connections = [] self.connectionsConnected = False # 1) find the parameter node in the scene and observe it # 2) set the defaults (will only set them if they are not # already set) self.updateParameterNode(self.parameterNode, vtk.vtkCommand.ModifiedEvent) self.setMRMLDefaults() # TODO: change this to look for specfic events (added, removed...) # but this requires being able to access events by number from wrapped code tag = slicer.mrmlScene.AddObserver(vtk.vtkCommand.ModifiedEvent, self.updateParameterNode) self.observerTags.append( (slicer.mrmlScene, tag) )
def updateParameterNode(self, caller, event): node = EditUtil.getParameterNode() if node != self.parameterNode: if self.parameterNode: node.RemoveObserver(self.parameterNodeTag) self.parameterNode = node self.parameterNodeTag = node.AddObserver("ModifiedEvent", self.updateGUIFromMRML)
def updateParameterNode(self, caller, event): node = EditUtil.getParameterNode() if node != self.parameterNode: if self.parameterNode: node.RemoveObserver(self.parameterNodeTag) self.parameterNode = node self.parameterNodeTag = node.AddObserver("ModifiedEvent", self.updateGUIFromMRML)
def __init__(self, sliceLogic): self.sliceLogic = sliceLogic self.editUtil = EditUtil.EditUtil() # optionally set by users of the class self.undoRedo = None self.scope = 'All' # # instance variables used internally # - buffer for result of scoped editing self.scopedImageBuffer = vtk.vtkImageData() # - slice paint is used to extract/replace scoped regions self.scopedSlicePaint = slicer.vtkImageSlicePaint()
def __init__(self, parent=0, parameter='label'): self.observerTags = [] self.parameterNode = None self.parameterNodeTag = None self.parameter = parameter self.editUtil = EditUtil.EditUtil() self.colorBox = None if parent == 0: self.parent = slicer.qMRMLWidget() self.parent.setLayout(qt.QVBoxLayout()) self.parent.setMRMLScene(slicer.mrmlScene) self.create() self.parent.show() else: self.parent = parent self.create()
def __init__(self, sliceWidget): # sliceWidget to operate on and convenience variables # to access the internals self.sliceWidget = sliceWidget self.sliceLogic = sliceWidget.sliceLogic() self.sliceView = self.sliceWidget.sliceView() self.interactor = self.sliceView.interactorStyle().GetInteractor() self.renderWindow = self.sliceWidget.sliceView().renderWindow() self.renderer = self.renderWindow.GetRenderers().GetItemAsObject(0) self.editUtil = EditUtil.EditUtil() # optionally set by users of the class self.undoRedo = None # actors in the renderer that need to be cleaned up on destruction self.actors = [] # the current operation self.actionState = None # set up observers on the interactor # - keep track of tags so these can be removed later # - currently all editor effects are restricted to these events # - make the observers high priority so they can override other # event processors self.interactorObserverTags = [] events = (vtk.vtkCommand.LeftButtonPressEvent, vtk.vtkCommand.LeftButtonReleaseEvent, vtk.vtkCommand.MiddleButtonPressEvent, vtk.vtkCommand.MiddleButtonReleaseEvent, vtk.vtkCommand.RightButtonPressEvent, vtk.vtkCommand.RightButtonReleaseEvent, vtk.vtkCommand.MouseMoveEvent, vtk.vtkCommand.KeyPressEvent, vtk.vtkCommand.EnterEvent, vtk.vtkCommand.LeaveEvent) for e in events: tag = self.interactor.AddObserver(e, self.processEvent, 1.0) self.interactorObserverTags.append(tag) self.sliceNodeTags = [] sliceNode = self.sliceLogic.GetSliceNode() tag = sliceNode.AddObserver(vtk.vtkCommand.ModifiedEvent, self.processEvent, 1.0) self.sliceNodeTags.append(tag) # spot for tracking the current cursor while it is turned off for paining self.savedCursor = None
def __init__(self, parent=0, optionsFrame=None, embedded=False, suppliedEffects=[]): self.effects = [] self.effectButtons = {} self.effectMapper = qt.QSignalMapper() self.effectMapper.connect('mapped(const QString&)', self.selectEffect) self.editUtil = EditUtil.EditUtil() # check for extensions - if none have been registered, just create the empty dictionary try: slicer.modules.editorExtensions except AttributeError: slicer.modules.editorExtensions = {} # embedded boolean specifies whether or not this edit box is to be embedded # into another moduleWidget # - if it is, all effect buttons will be displayed in a single row self.embedded = embedded # save the list of supplied effects that the caller wants to use # (should be a subset of EditBox.availableMouseTools + EditBox.availableOperations) self.suppliedEffects = suppliedEffects if parent == 0: self.parent = qt.QFrame() self.parent.setLayout(qt.QVBoxLayout()) self.create() self.parent.show() else: self.parent = parent self.create() # frame that holds widgets specific for each effect if not optionsFrame: self.optionsFrame = qt.QFrame(self.parent) else: self.optionsFrame = optionsFrame # state variables for selected effect in the box # - currentOption is an instance of an option GUI # - currentTools is a list of EffectTool instances self.currentOption = None self.currentTools = []
def __init__(self, parent=None): self.editUtil = EditUtil.EditUtil() # mrml volume node instances self.master = None self.merge = None self.masterWhenMergeWasSet = None # string self.createMergeOptions = "" # pairs of (node instance, observer tag number) self.observerTags = [] # instance of a ColorBox self.colorBox = None # slicer helper class self.applicationLogic = slicer.app.applicationLogic() self.volumesLogic = slicer.modules.volumes.logic() self.colorLogic = slicer.modules.colors.logic() # qt model/view classes to track per-structure volumes self.structures = qt.QStandardItemModel() self.items = [] self.brushes = [] # widgets that are dynamically created on demand self.colorSelect = None self.labelSelect = None self.labelSelector = None # pseudo signals # - python callable that gets True or False self.mergeValidCommand = None self.selectCommand = None # mrml node for invoking command line modules self.CLINode = None if not parent: self.parent = slicer.qMRMLWidget() self.parent.setLayout(qt.QVBoxLayout()) self.parent.setMRMLScene(slicer.mrmlScene) self.create() self.parent.show() else: self.parent = parent self.create()
def __init__(self, parent=0): # get pixel-size-dependent parameters # calculate this before calling superclass init # so it can be used to set mrml defaults if needed labelVolume = EditUtil.EditUtil().getLabelVolume() if labelVolume and labelVolume.GetImageData(): spacing = labelVolume.GetSpacing() dimensions = labelVolume.GetImageData().GetDimensions() self.minimumRadius = 0.5 * min(spacing) bounds = [a * b for a, b in zip(spacing, dimensions)] self.maximumRadius = 0.5 * max(bounds) else: self.minimumRadius = 0.01 self.maximumRadius = 100 super(PaintEffectOptions, self).__init__(parent) # option to use 'min' or 'diag' # - min means pixel radius is min spacing # - diag means corner to corner length self.radiusPixelMode = 'min'
def __init__(self, parent=None, optionsFrame=None): self.effects = [] self.effectButtons = {} self.effectCursors = {} self.effectMapper = qt.QSignalMapper() self.effectMapper.connect('mapped(const QString&)', self.selectEffect) self.editUtil = EditUtil.EditUtil() self.undoRedo = EditUtil.UndoRedo() self.undoRedo.stateChangedCallback = self.updateUndoRedoButtons self.toggleShortcut = None # check for extensions - if none have been registered, just create the empty dictionary try: slicer.modules.editorExtensions except AttributeError: slicer.modules.editorExtensions = {} # register the builtin extensions self.editorBuiltins = {} self.editorBuiltins["PaintEffect"] = EditorLib.PaintEffect self.editorBuiltins["DrawEffect"] = EditorLib.DrawEffect self.editorBuiltins["ThresholdEffect"] = EditorLib.ThresholdEffect self.editorBuiltins["RectangleEffect"] = EditorLib.RectangleEffect self.editorBuiltins[ "LevelTracingEffect"] = EditorLib.LevelTracingEffect self.editorBuiltins["MakeModelEffect"] = EditorLib.MakeModelEffect self.editorBuiltins["ErodeEffect"] = EditorLib.ErodeEffect self.editorBuiltins["DilateEffect"] = EditorLib.DilateEffect self.editorBuiltins["ChangeLabelEffect"] = EditorLib.ChangeLabelEffect self.editorBuiltins[ "RemoveIslandsEffect"] = EditorLib.RemoveIslandsEffect self.editorBuiltins[ "IdentifyIslandsEffect"] = EditorLib.IdentifyIslandsEffect self.editorBuiltins["SaveIslandEffect"] = EditorLib.SaveIslandEffect self.editorBuiltins[ "ChangeIslandEffect"] = EditorLib.ChangeIslandEffect self.editorBuiltins["GrowCutEffect"] = EditorLib.GrowCutEffect self.editorBuiltins[ "WatershedFromMarkerEffect"] = EditorLib.WatershedFromMarkerEffect self.editorBuiltins[ "FastMarchingEffect"] = EditorLib.FastMarchingEffect self.editorBuiltins["WandEffect"] = EditorLib.WandEffect if not parent: self.parent = qt.QFrame() self.parent.setLayout(qt.QVBoxLayout()) self.create() self.parent.show() else: self.parent = parent self.create() # frame that holds widgets specific for each effect if not optionsFrame: self.optionsFrame = qt.QFrame(self.parent) self.optionsFrame.objectName = 'OptionsFrame' else: self.optionsFrame = optionsFrame # state variables for selected effect in the box # - currentOption is an instance of an option GUI # - currentTools is a list of EffectTool instances self.currentOption = None self.currentTools = [] # listen for changes in the Interaction Mode appLogic = slicer.app.applicationLogic() interactionNode = appLogic.GetInteractionNode() self.interactionNodeTag = interactionNode.AddObserver( interactionNode.InteractionModeChangedEvent, self.onInteractionModeChanged)
def __init__(self, parent=None, optionsFrame=None): VTKObservationMixin.__init__(self) self.effects = [] self.effectButtons = {} self.effectCursors = {} self.effectActionGroup = qt.QActionGroup(parent) self.effectActionGroup.connect('triggered(QAction*)', self._onEffectActionTriggered) self.effectActionGroup.exclusive = True self.currentEffect = None self.editUtil = EditUtil.EditUtil() self.undoRedo = EditUtil.UndoRedo() self.undoRedo.stateChangedCallback = self.updateUndoRedoButtons self.toggleShortcut = None # check for extensions - if none have been registered, just create the empty dictionary try: slicer.modules.editorExtensions except AttributeError: slicer.modules.editorExtensions = {} # register the builtin extensions self.editorBuiltins = {} self.editorBuiltins["PaintEffect"] = EditorLib.PaintEffect self.editorBuiltins["DrawEffect"] = EditorLib.DrawEffect self.editorBuiltins["ThresholdEffect"] = EditorLib.ThresholdEffect self.editorBuiltins["RectangleEffect"] = EditorLib.RectangleEffect self.editorBuiltins["LevelTracingEffect"] = EditorLib.LevelTracingEffect self.editorBuiltins["MakeModelEffect"] = EditorLib.MakeModelEffect self.editorBuiltins["ErodeEffect"] = EditorLib.ErodeEffect self.editorBuiltins["DilateEffect"] = EditorLib.DilateEffect self.editorBuiltins["ChangeLabelEffect"] = EditorLib.ChangeLabelEffect self.editorBuiltins["RemoveIslandsEffect"] = EditorLib.RemoveIslandsEffect self.editorBuiltins["IdentifyIslandsEffect"] = EditorLib.IdentifyIslandsEffect self.editorBuiltins["SaveIslandEffect"] = EditorLib.SaveIslandEffect self.editorBuiltins["ChangeIslandEffect"] = EditorLib.ChangeIslandEffect self.editorBuiltins["GrowCutEffect"] = EditorLib.GrowCutEffect self.editorBuiltins["WatershedFromMarkerEffect"] = EditorLib.WatershedFromMarkerEffect self.editorBuiltins["FastMarchingEffect"] = EditorLib.FastMarchingEffect self.editorBuiltins["WandEffect"] = EditorLib.WandEffect # frame that holds widgets specific for each effect if not optionsFrame: self.optionsFrame = qt.QFrame(self.parent) self.optionsFrame.objectName = 'OptionsFrame' else: self.optionsFrame = optionsFrame # state variables for selected effect in the box # - currentOption is an instance of an option GUI # - currentTools is a list of EffectTool instances self.currentOption = None self.currentTools = [] # listen for changes in the Interaction Mode interactionNode = slicer.app.applicationLogic().GetInteractionNode() self.addObserver(interactionNode, interactionNode.InteractionModeChangedEvent, self.onInteractionModeChanged) # Listen for changed on the Parameter node self.addObserver(self.editUtil.getParameterNode(), vtk.vtkCommand.ModifiedEvent, self._onParameterNodeModified) if not parent: self.parent = qt.QFrame() self.parent.setLayout( qt.QVBoxLayout() ) self.create() self.parent.show() else: self.parent = parent self.create()