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:
60 if not self.scriptedEffect.confirmCurrentSegmentVisible():
63 self.scriptedEffect.saveStateForUndo()
66 import vtkSegmentationCorePython
as vtkSegmentationCore
67 modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
70 pipeline.appendPolyMask(modifierLabelmap)
72 self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeAdd)
74 elif eventId == vtk.vtkCommand.MouseMoveEvent:
75 if pipeline.actionState ==
'':
76 xy = callerInteractor.GetEventPosition()
80 elif eventId == vtk.vtkCommand.RightButtonPressEvent
or eventId == vtk.vtkCommand.MiddleButtonPressEvent:
81 pipeline.actionState =
'interacting' 82 elif eventId == vtk.vtkCommand.RightButtonReleaseEvent
or eventId == vtk.vtkCommand.MiddleButtonReleaseEvent:
83 pipeline.actionState =
'' 84 elif eventId == vtk.vtkCommand.EnterEvent:
85 pipeline.actor.VisibilityOn()
86 elif eventId == vtk.vtkCommand.LeaveEvent:
87 pipeline.actor.VisibilityOff()
93 if callerViewNode
and callerViewNode.IsA(
'vtkMRMLSliceNode'):
97 logging.error(
'processViewNodeEvents: Invalid pipeline')
101 if pipeline.actionState ==
'' and self.
lastXY:
102 pipeline.preview(self.
lastXY)
112 renderer = self.scriptedEffect.renderer(sliceWidget)
114 logging.error(
"setupPreviewDisplay: Failed to get renderer!")
116 self.scriptedEffect.addActor2D(sliceWidget, pipeline.actor)
125 """ Visualization objects and pipeline for each slice view for level tracing 141 actorProperty = self.
actor.GetProperty()
142 actorProperty.SetColor( 107/255., 190/255., 99/255. )
143 actorProperty.SetLineWidth( 1 )
146 actorProperty = self.
actor.GetProperty()
147 actorProperty.SetColor(1,1,0)
148 actorProperty.SetLineWidth(1)
154 import vtkSegmentationCorePython
as vtkSegmentationCore
155 masterImageData = self.
effect.scriptedEffect.masterVolumeImageData()
157 segmentationNode = self.
effect.scriptedEffect.parameterSetNode().GetSegmentationNode()
158 parentTransformNode =
None 160 parentTransformNode = segmentationNode.GetParentTransformNode()
163 ijk = self.
effect.xyToIjk(xy, self.
sliceWidget, masterImageData, parentTransformNode)
164 dimensions = masterImageData.GetDimensions()
166 for index
in range(3):
169 if ijk[index] < 1
or ijk[index] >= dimensions[index]-1:
177 offset = max(sliceNode.GetDimensions())
179 i0,j0,k0 = self.
effect.xyToIjk((0,0), self.
sliceWidget, masterImageData, parentTransformNode)
180 i1,j1,k1 = self.
effect.xyToIjk((offset,offset), self.
sliceWidget, masterImageData, parentTransformNode)
192 xyToRas = sliceNode.GetXYToRAS()
193 rasToIjk = vtk.vtkMatrix4x4()
194 masterImageData.GetImageToWorldMatrix(rasToIjk)
196 xyToIjk = vtk.vtkGeneralTransform()
197 xyToIjk.PostMultiply()
198 xyToIjk.Concatenate(xyToRas)
199 if parentTransformNode:
200 worldToSegmentation = vtk.vtkMatrix4x4()
201 parentTransformNode.GetMatrixTransformFromWorld(worldToSegmentation)
202 xyToIjk.Concatenate(worldToSegmentation)
203 xyToIjk.Concatenate(rasToIjk)
204 ijkToXy = xyToIjk.GetInverse()
205 ijkToXy.TransformPoints(polyData.GetPoints(), self.
xyPoints)
213 if lines.GetNumberOfCells() == 0:
217 segmentationNode = self.
effect.scriptedEffect.parameterSetNode().GetSegmentationNode()
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)