2 import vtk, qt, ctk, slicer, logging
9 """ Abstract scripted segment editor effects for effects implemented in python 12 1. Instantiation and registration 13 Instantiate segment editor effect adaptor class from 14 module (e.g. from setup function), and set python source: 15 > import qSlicerSegmentationsEditorEffectsPythonQt as effects 16 > scriptedEffect = effects.qSlicerSegmentEditorScriptedEffect(None) 17 > scriptedEffect.setPythonSource(MyEffect.filePath) 18 > scriptedEffect.self().register() 19 If effect name is added to slicer.modules.segmenteditorscriptedeffectnames 20 list then the above instantiation and registration steps are not necessary, 21 as the SegmentEditor module do all these. 23 2. Call host C++ implementation using 24 > self.scriptedEffect.functionName() 26 2.a. Most frequently used such methods are: 27 Parameter get/set: parameter, integerParameter, doubleParameter, setParameter 28 Add options widget: addOptionsWidget 29 Coordinate transforms: rasToXy, xyzToRas, xyToRas, xyzToIjk, xyToIjk 30 Convenience getters: renderWindow, renderer, viewNode 32 2.b. Always call API functions (the ones that are defined in the adaptor 33 class qSlicerSegmentEditorScriptedEffect) using the adaptor accessor: 34 > self.scriptedEffect.updateGUIFromMRML() 36 3. To prevent deactivation of an effect by clicking place fiducial toolbar button, 37 override interactionNodeModified(self, interactionNode) 39 An example for a generic effect is the ThresholdEffect 47 import qSlicerSegmentationsEditorEffectsPythonQt
49 factory = qSlicerSegmentationsEditorEffectsPythonQt.qSlicerSegmentEditorEffectFactory()
50 effectFactorySingleton = factory.instance()
57 rasVector = qt.QVector3D(ras[0], ras[1], ras[2])
59 return [xyPoint.x(), xyPoint.y()]
62 xyzVector = qt.QVector3D(xyz[0], xyz[1], xyz[2])
64 return [rasVector.x(), rasVector.y(), rasVector.z()]
67 xyPoint = qt.QPoint(xy[0], xy[1])
69 return [rasVector.x(), rasVector.y(), rasVector.z()]
71 def xyzToIjk(self, xyz, viewWidget, image, parentTransformNode=None):
72 import vtkSegmentationCorePython
as vtkSegmentationCore
73 xyzVector = qt.QVector3D(xyz[0], xyz[1], xyz[2])
75 return [int(ijkVector.x()), int(ijkVector.y()), int(ijkVector.z())]
77 def xyToIjk(self, xy, viewWidget, image, parentTransformNode=None):
78 import vtkSegmentationCorePython
as vtkSegmentationCore
79 xyPoint = qt.QPoint(xy[0], xy[1])
81 return [int(ijkVector.x()), int(ijkVector.y()), int(ijkVector.z())]
90 spinbox.unitAwareProperties &= ~(slicer.qMRMLSpinBox.MinimumValue | slicer.qMRMLSpinBox.MaximumValue | slicer.qMRMLSpinBox.Precision)
91 stepSize = 10**(math.floor(math.log10(min(imageData.GetSpacing())/10.0)))
92 spinbox.minimum = stepSize
93 spinbox.maximum = 10**(math.ceil(math.log10(max(imageData.GetSpacing())*100.0)))
94 spinbox.singleStep = stepSize
96 spinbox.decimals = max(int(-math.floor(math.log10(stepSize))),0)
def xyzToIjk(self, xyz, viewWidget, image, parentTransformNode=None)
def __init__(self, scriptedEffect)
def xyToIjk(self, xy, viewWidget, image, parentTransformNode=None)
def xyzToRas(self, xyz, viewWidget)
def setWidgetMinMaxStepFromImageSpacing(self, spinbox, imageData)
def xyToRas(self, xy, viewWidget)
def rasToXy(self, ras, viewWidget)