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)
20 import qSlicerSegmentationsEditorEffectsPythonQt
as effects
21 clonedEffect = effects.qSlicerSegmentEditorScriptedLabelEffect(
None)
22 clonedEffect.setPythonSource(__file__.replace(
'\\',
'/'))
26 iconPath = os.path.join(os.path.dirname(__file__),
'Resources/Icons/LevelTracing.png')
27 if os.path.exists(iconPath):
28 return qt.QIcon(iconPath)
32 return """<html>Add uniform intensity region to selected segment<br>. 33 <p><ul style="margin: 0"> 34 <li><b>Mouse move:</b> current background voxel is used to find a closed path that 35 follows the same intensity value back to the starting point within the current slice.</li> 36 <li><b>Left-click:</b> add the previewed region to the current segment.</li> 42 self.scriptedEffect.removeActor2D(sliceWidget, pipeline.actor)
49 if viewWidget.className() !=
"qMRMLSliceWidget":
56 if eventId == vtk.vtkCommand.LeftButtonPressEvent:
57 self.scriptedEffect.saveStateForUndo()
60 import vtkSegmentationCorePython
as vtkSegmentationCore
61 modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
64 pipeline.appendPolyMask(modifierLabelmap)
66 self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
68 elif eventId == vtk.vtkCommand.MouseMoveEvent:
69 if pipeline.actionState ==
'':
70 xy = callerInteractor.GetEventPosition()
73 elif eventId == vtk.vtkCommand.RightButtonPressEvent
or eventId == vtk.vtkCommand.MiddleButtonPressEvent:
74 pipeline.actionState =
'interacting' 75 elif eventId == vtk.vtkCommand.RightButtonReleaseEvent
or eventId == vtk.vtkCommand.MiddleButtonReleaseEvent:
76 pipeline.actionState =
'' 77 elif eventId == vtk.vtkCommand.EnterEvent:
78 pipeline.actor.VisibilityOn()
79 elif eventId == vtk.vtkCommand.LeaveEvent:
80 pipeline.actor.VisibilityOff()
92 renderer = self.scriptedEffect.renderer(sliceWidget)
94 logging.error(
"setupPreviewDisplay: Failed to get renderer!")
96 self.scriptedEffect.addActor2D(sliceWidget, pipeline.actor)
105 """ Visualization objects and pipeline for each slice view for level tracing 121 actorProperty = self.
actor.GetProperty()
122 actorProperty.SetColor( 107/255., 190/255., 99/255. )
123 actorProperty.SetLineWidth( 1 )
126 actorProperty = self.
actor.GetProperty()
127 actorProperty.SetColor(1,1,0)
128 actorProperty.SetLineWidth(1)
134 import vtkSegmentationCorePython
as vtkSegmentationCore
135 masterImageData = self.
effect.scriptedEffect.masterVolumeImageData()
139 dimensions = masterImageData.GetDimensions()
141 for index
in xrange(3):
144 if ijk[index] < 1
or ijk[index] >= dimensions[index]-1:
152 offset = max(sliceNode.GetDimensions())
154 i1,j1,k1 = self.
effect.xyToIjk((offset,offset), self.
sliceWidget, masterImageData)
166 xyToRas = sliceNode.GetXYToRAS()
167 rasToIjk = vtk.vtkMatrix4x4()
168 masterImageData.GetImageToWorldMatrix(rasToIjk)
170 xyToIjk = vtk.vtkGeneralTransform()
171 xyToIjk.PostMultiply()
172 xyToIjk.Concatenate(xyToRas)
173 xyToIjk.Concatenate(rasToIjk)
174 ijkToXy = xyToIjk.GetInverse()
175 ijkToXy.TransformPoints(polyData.GetPoints(), self.
xyPoints)
183 if lines.GetNumberOfCells() == 0:
def __init__(self, effect, sliceWidget)
def __init__(self, scriptedEffect)
def pipelineForWidget(self, sliceWidget)
def appendPolyMask(self, modifierLabelmap)
def processInteractionEvents(self, callerInteractor, eventId, viewWidget)