2 import vtk, qt, ctk, slicer
4 from SegmentEditorEffects
import *
8 """ LevelTracingEffect is a LabelEffect implementing level tracing fill 9 using intensity-based isolines 13 scriptedEffect.name =
'Level tracing' 14 AbstractScriptedSegmentEditorLabelEffect.__init__(self, scriptedEffect)
21 import qSlicerSegmentationsEditorEffectsPythonQt
as effects
22 clonedEffect = effects.qSlicerSegmentEditorScriptedLabelEffect(
None)
23 clonedEffect.setPythonSource(__file__.replace(
'\\',
'/'))
27 iconPath = os.path.join(os.path.dirname(__file__),
'Resources/Icons/LevelTracing.png')
28 if os.path.exists(iconPath):
29 return qt.QIcon(iconPath)
33 return """<html>Add uniform intensity region to selected segment<br>. 34 <p><ul style="margin: 0"> 35 <li><b>Mouse move:</b> current background voxel is used to find a closed path that 36 follows the same intensity value back to the starting point within the current slice.</li> 37 <li><b>Left-click:</b> add the previewed region to the current segment.</li> 43 self.scriptedEffect.removeActor2D(sliceWidget, pipeline.actor)
51 if viewWidget.className() !=
"qMRMLSliceWidget":
58 if eventId == vtk.vtkCommand.LeftButtonPressEvent:
59 self.scriptedEffect.saveStateForUndo()
62 import vtkSegmentationCorePython
as vtkSegmentationCore
63 modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
66 pipeline.appendPolyMask(modifierLabelmap)
68 self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
70 elif eventId == vtk.vtkCommand.MouseMoveEvent:
71 if pipeline.actionState ==
'':
72 xy = callerInteractor.GetEventPosition()
76 elif eventId == vtk.vtkCommand.RightButtonPressEvent
or eventId == vtk.vtkCommand.MiddleButtonPressEvent:
77 pipeline.actionState =
'interacting' 78 elif eventId == vtk.vtkCommand.RightButtonReleaseEvent
or eventId == vtk.vtkCommand.MiddleButtonReleaseEvent:
79 pipeline.actionState =
'' 80 elif eventId == vtk.vtkCommand.EnterEvent:
81 pipeline.actor.VisibilityOn()
82 elif eventId == vtk.vtkCommand.LeaveEvent:
83 pipeline.actor.VisibilityOff()
89 if callerViewNode
and callerViewNode.IsA(
'vtkMRMLSliceNode'):
93 logging.error(
'processViewNodeEvents: Invalid pipeline')
97 if pipeline.actionState ==
'' and self.
lastXY:
98 pipeline.preview(self.
lastXY)
108 renderer = self.scriptedEffect.renderer(sliceWidget)
110 logging.error(
"setupPreviewDisplay: Failed to get renderer!")
112 self.scriptedEffect.addActor2D(sliceWidget, pipeline.actor)
121 """ Visualization objects and pipeline for each slice view for level tracing 137 actorProperty = self.
actor.GetProperty()
138 actorProperty.SetColor( 107/255., 190/255., 99/255. )
139 actorProperty.SetLineWidth( 1 )
142 actorProperty = self.
actor.GetProperty()
143 actorProperty.SetColor(1,1,0)
144 actorProperty.SetLineWidth(1)
150 import vtkSegmentationCorePython
as vtkSegmentationCore
151 masterImageData = self.
effect.scriptedEffect.masterVolumeImageData()
155 dimensions = masterImageData.GetDimensions()
157 for index
in xrange(3):
160 if ijk[index] < 1
or ijk[index] >= dimensions[index]-1:
168 offset = max(sliceNode.GetDimensions())
170 i1,j1,k1 = self.
effect.xyToIjk((offset,offset), self.
sliceWidget, masterImageData)
182 xyToRas = sliceNode.GetXYToRAS()
183 rasToIjk = vtk.vtkMatrix4x4()
184 masterImageData.GetImageToWorldMatrix(rasToIjk)
186 xyToIjk = vtk.vtkGeneralTransform()
187 xyToIjk.PostMultiply()
188 xyToIjk.Concatenate(xyToRas)
189 xyToIjk.Concatenate(rasToIjk)
190 ijkToXy = xyToIjk.GetInverse()
191 ijkToXy.TransformPoints(polyData.GetPoints(), self.
xyPoints)
199 if lines.GetNumberOfCells() == 0:
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)