10 from SegmentEditorEffects
import *
14 """ LevelTracingEffect is a LabelEffect implementing level tracing fill 15 using intensity-based isolines 19 scriptedEffect.name =
'Level tracing' 20 AbstractScriptedSegmentEditorLabelEffect.__init__(self, scriptedEffect)
27 import qSlicerSegmentationsEditorEffectsPythonQt
as effects
28 clonedEffect = effects.qSlicerSegmentEditorScriptedLabelEffect(
None)
29 clonedEffect.setPythonSource(__file__.replace(
'\\',
'/'))
33 iconPath = os.path.join(os.path.dirname(__file__),
'Resources/Icons/LevelTracing.png')
34 if os.path.exists(iconPath):
35 return qt.QIcon(iconPath)
39 return """<html>Add uniform intensity region to selected segment<br>. 40 <p><ul style="margin: 0"> 41 <li><b>Mouse move:</b> current background voxel is used to find a closed path that 42 follows the same intensity value back to the starting point within the current slice.</li> 43 <li><b>Left-click:</b> add the previewed region to the current segment.</li> 58 self.scriptedEffect.removeActor2D(sliceWidget, pipeline.actor)
66 if viewWidget.className() !=
"qMRMLSliceWidget":
73 anyModifierKeyPressed = callerInteractor.GetShiftKey()
or callerInteractor.GetControlKey()
or callerInteractor.GetAltKey()
75 if eventId == vtk.vtkCommand.LeftButtonPressEvent
and not anyModifierKeyPressed:
77 if not self.scriptedEffect.confirmCurrentSegmentVisible():
80 self.scriptedEffect.saveStateForUndo()
83 modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
86 pipeline.appendPolyMask(modifierLabelmap)
88 self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
90 elif eventId == vtk.vtkCommand.MouseMoveEvent:
91 if pipeline.actionState ==
'':
92 xy = callerInteractor.GetEventPosition()
93 if pipeline.preview(xy):
97 +
"Slice view is not aligned with segmentation axis.<br>To use this effect, click the 'Slice views orientation' warning button." 101 elif eventId == vtk.vtkCommand.EnterEvent:
103 pipeline.actor.VisibilityOn()
104 elif eventId == vtk.vtkCommand.LeaveEvent:
106 pipeline.actor.VisibilityOff()
112 if callerViewNode
and callerViewNode.IsA(
'vtkMRMLSliceNode'):
116 logging.error(
'processViewNodeEvents: Invalid pipeline')
120 if pipeline.actionState ==
'' and self.
lastXY:
121 pipeline.preview(self.
lastXY)
131 renderer = self.scriptedEffect.renderer(sliceWidget)
133 logging.error(
"setupPreviewDisplay: Failed to get renderer!")
135 self.scriptedEffect.addActor2D(sliceWidget, pipeline.actor)
145 """ Visualization objects and pipeline for each slice view for level tracing 162 actorProperty = self.
actor.GetProperty()
163 actorProperty.SetColor(107 / 255., 190 / 255., 99 / 255.)
164 actorProperty.SetLineWidth(1)
167 actorProperty = self.
actor.GetProperty()
168 actorProperty.SetColor(1, 1, 0)
169 actorProperty.SetLineWidth(1)
172 """Calculate the current level trace view if the mouse is inside the volume extent 173 Returns False if slice views are rotated. 177 sourceImageData = self.
effect.scriptedEffect.sourceVolumeImageData()
179 segmentationNode = self.
effect.scriptedEffect.parameterSetNode().GetSegmentationNode()
180 parentTransformNode =
None 182 parentTransformNode = segmentationNode.GetParentTransformNode()
185 ijk = self.
effect.xyToIjk(xy, self.
sliceWidget, sourceImageData, parentTransformNode)
186 dimensions = sourceImageData.GetDimensions()
194 offset = max(sliceNode.GetDimensions())
196 i0, j0, k0 = self.
effect.xyToIjk((0, 0), self.
sliceWidget, sourceImageData, parentTransformNode)
197 i1, j1, k1 = self.
effect.xyToIjk((offset, offset), self.
sliceWidget, sourceImageData, parentTransformNode)
213 xyToRas = sliceNode.GetXYToRAS()
214 rasToIjk = vtk.vtkMatrix4x4()
215 sourceImageData.GetImageToWorldMatrix(rasToIjk)
217 xyToIjk = vtk.vtkGeneralTransform()
218 xyToIjk.PostMultiply()
219 xyToIjk.Concatenate(xyToRas)
220 if parentTransformNode:
221 worldToSegmentation = vtk.vtkMatrix4x4()
222 parentTransformNode.GetMatrixTransformFromWorld(worldToSegmentation)
223 xyToIjk.Concatenate(worldToSegmentation)
224 xyToIjk.Concatenate(rasToIjk)
225 ijkToXy = xyToIjk.GetInverse()
226 if polyData.GetPoints():
227 ijkToXy.TransformPoints(polyData.GetPoints(), self.
xyPoints)
237 if lines.GetNumberOfCells() == 0:
241 segmentationNode = self.
effect.scriptedEffect.parameterSetNode().GetSegmentationNode()
def setupOptionsFrame(self)
def __init__(self, effect, sliceWidget)
def __init__(self, scriptedEffect)
def pipelineForWidget(self, sliceWidget)
def processViewNodeEvents(self, callerViewNode, eventId, viewWidget)
def appendPolyMask(self, modifierLabelmap)
def processInteractionEvents(self, callerInteractor, eventId, viewWidget)