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