The smooth zooming is a very nice feature. For more customization, I am going to try and complete this python feature to give more control. Below is my updated code. Buttons “D” and “F” decrease and increase the diameter, and buttons “E” and “R” decrease/increase the increment by which the diameter is changed. One additional problem I had to deal with is that when there were multiple segments and a segment other than the first one was selected, after running my code the selection would change back to the first segment. I fixed this by getting the selected-segment-id from the segment-editor-node and then setting the ID later in the segment-editor widget.
from functools import partial
from qt import QCursor
from time import sleep
PARAM_DIAM = "BrushAbsoluteDiameter"
increment = 0.5
pos_unused = [0,0,0]
sliceNode = crosshairNode.GetCursorPositionXYZ(pos_unused)
# force updating displayed brush size
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorNode = slicer.mrmlScene.GetSingletonNode("SegmentEditor", "vtkMRMLSegmentEditorNode")
# Once node passed to widget the selected segment will get set back to first
selectedSegmentID = segmentEditorNode.GetSelectedSegmentID()
# Set selected segment back to what it was before
effect = segmentEditorWidget.activeEffect()
currentDiam = float(effect.parameter(PARAM_DIAM))
newDiam = currentDiam + (increment*direction)
if newDiam <= 0:
print("decreasing to new diam of %0.2f" % newDiam)
newIncrement = increment + (0.1*direction)
if newIncrement <= 0:
increment = newIncrement
print("Increment: %0.2f" % increment)
shortcutDecrease = qt.QShortcut(slicer.util.mainWindow())
shortcutDecrease.connect("activated()", partial(changeDiameter, -1))
shortcutIncrease = qt.QShortcut(slicer.util.mainWindow())
shortcutIncrease.connect("activated()", partial(changeDiameter, 1))
shortcutDecreaseFactor = qt.QShortcut(slicer.util.mainWindow())
shortcutDecreaseFactor.connect("activated()", partial(changeIncrement, -1))
shortcutIncreaseFactor = qt.QShortcut(slicer.util.mainWindow())
shortcutIncreaseFactor.connect("activated()", partial(changeIncrement, 1))
While the code serves its functional purpose, the last remaining bug is that after running this code you can no longer use the UI of the segment editor widget to change the diameter. The diameter is held to whatever is programatically set and neither using Shift+Scroll nor the UI can change it. I figure there must be some way to release the effect back to the default but not sure how to do this. If you have the time would appreciate how I can eliminate this last bug.
Thanks for your continued help!