9 from SegmentEditorEffects
import *
13 """ ThresholdEffect is an Effect implementing the global threshold 14 operation in the segment editor 16 This is also an example for scripted effects, and some methods have no 17 function. The methods that are not needed (i.e. the default implementation in 18 qSlicerSegmentEditorAbstractEffect is satisfactory) can simply be omitted. 22 AbstractScriptedSegmentEditorEffect.__init__(self, scriptedEffect)
23 scriptedEffect.name =
'Threshold' 44 self.
stencil = vtk.vtkPolyDataToImageStencil()
48 self.
reslice.AutoCropOutputOff()
50 self.
reslice.SetOutputOrigin(0, 0, 0)
51 self.
reslice.SetOutputSpacing(1, 1, 1)
52 self.
reslice.SetOutputDimensionality(3)
53 self.
reslice.GenerateStencilOutputOn()
63 import qSlicerSegmentationsEditorEffectsPythonQt
as effects
64 clonedEffect = effects.qSlicerSegmentEditorScriptedEffect(
None)
65 clonedEffect.setPythonSource(__file__.replace(
'\\',
'/'))
69 iconPath = os.path.join(os.path.dirname(__file__),
'Resources/Icons/Threshold.png')
70 if os.path.exists(iconPath):
71 return qt.QIcon(iconPath)
75 return """<html>Fill segment based on source volume intensity range<br>. Options:<p> 76 <ul style="margin: 0"> 77 <li><b>Use for masking:</b> set the selected intensity range as <dfn>Editable intensity range</dfn> and switch to Paint effect.</li> 78 <li><b>Apply:</b> set the previewed segmentation in the selected segment. Previous contents of the segment is overwritten.</li> 100 """Save current segment opacity and set it to zero 101 to temporarily hide the segment so that threshold preview 103 It also restores opacity of previously previewed segment. 104 Call restorePreviewedSegmentTransparency() to restore original 107 segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
108 if not segmentationNode:
110 displayNode = segmentationNode.GetDisplayNode()
113 segmentID = self.scriptedEffect.parameterSetNode().GetSelectedSegmentID()
128 displayNode.SetSegmentOpacity2DFill(segmentID, 0)
129 displayNode.SetSegmentOpacity2DOutline(segmentID, 0)
132 """Restore previewed segment's opacity that was temporarily 133 made transparen by calling setCurrentSegmentTransparent().""" 134 segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
135 if not segmentationNode:
137 displayNode = segmentationNode.GetDisplayNode()
149 self.
thresholdSliderLabel.setToolTip(
"Set the range of the background values that should be labeled.")
163 " Threshold above/below: sets the range from the computed value to maximum/minimum." 164 " Set as lower/upper value: only modifies one side of the threshold range.")
188 +
" Useful for iterating through all available methods.")
193 +
" Useful for iterating through all available methods.")
199 qSize = qt.QSizePolicy()
200 qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding)
203 autoThresholdFrame = qt.QGridLayout()
210 autoThresholdGroupBox = ctk.ctkCollapsibleGroupBox()
211 autoThresholdGroupBox.setTitle(
"Automatic threshold")
212 autoThresholdGroupBox.setLayout(autoThresholdFrame)
213 autoThresholdGroupBox.collapsed =
True 214 self.scriptedEffect.addOptionsWidget(autoThresholdGroupBox)
216 histogramFrame = qt.QVBoxLayout()
218 histogramBrushFrame = qt.QHBoxLayout()
219 histogramFrame.addLayout(histogramBrushFrame)
255 histogramBrushFrame.addStretch()
304 histogramItemFrame = qt.QHBoxLayout()
305 histogramFrame.addLayout(histogramItemFrame)
310 lowerGroupBox = qt.QGroupBox(
"Lower")
311 lowerHistogramLayout = qt.QHBoxLayout()
312 lowerHistogramLayout.setContentsMargins(0, 3, 0, 3)
313 lowerGroupBox.setLayout(lowerHistogramLayout)
314 histogramItemFrame.addWidget(lowerGroupBox)
343 upperGroupBox = qt.QGroupBox(
"Upper")
344 upperHistogramLayout = qt.QHBoxLayout()
345 upperHistogramLayout.setContentsMargins(0, 3, 0, 3)
346 upperGroupBox.setLayout(upperHistogramLayout)
347 histogramItemFrame.addWidget(upperGroupBox)
373 histogramGroupBox = ctk.ctkCollapsibleGroupBox()
374 histogramGroupBox.setTitle(
"Local histogram")
375 histogramGroupBox.setLayout(histogramFrame)
376 histogramGroupBox.collapsed =
True 377 self.scriptedEffect.addOptionsWidget(histogramGroupBox)
380 self.
useForPaintButton.setToolTip(
"Use specified intensity range for masking and switch to Paint effect.")
384 self.
applyButton.objectName = self.__class__.__name__ +
'Apply' 385 self.
applyButton.setToolTip(
"Fill selected segment in regions that are in the specified intensity range.")
386 self.scriptedEffect.addOptionsWidget(self.
applyButton)
399 masterImageData = self.scriptedEffect.sourceVolumeImageData()
401 lo, hi = masterImageData.GetScalarRange()
404 if (self.scriptedEffect.doubleParameter(
"MinimumThreshold") == self.scriptedEffect.doubleParameter(
"MaximumThreshold")):
406 self.scriptedEffect.setParameter(
"MinimumThreshold", lo + (hi - lo) * 0.25)
407 self.scriptedEffect.setParameter(
"MaximumThreshold", hi)
413 self.scriptedEffect.setParameterDefault(
"MinimumThreshold", 0.)
414 self.scriptedEffect.setParameterDefault(
"MaximumThreshold", 0)
415 self.scriptedEffect.setParameterDefault(
"AutoThresholdMethod", METHOD_OTSU)
416 self.scriptedEffect.setParameterDefault(
"AutoThresholdMode", MODE_SET_LOWER_MAX)
417 self.scriptedEffect.setParameterDefault(HISTOGRAM_BRUSH_TYPE_PARAMETER_NAME, HISTOGRAM_BRUSH_TYPE_CIRCLE)
418 self.scriptedEffect.setParameterDefault(HISTOGRAM_SET_LOWER_PARAMETER_NAME, HISTOGRAM_SET_LOWER)
419 self.scriptedEffect.setParameterDefault(HISTOGRAM_SET_UPPER_PARAMETER_NAME, HISTOGRAM_SET_UPPER)
423 self.
thresholdSlider.setMinimumValue(self.scriptedEffect.doubleParameter(
"MinimumThreshold"))
424 self.
thresholdSlider.setMaximumValue(self.scriptedEffect.doubleParameter(
"MaximumThreshold"))
437 histogramBrushType = self.scriptedEffect.parameter(HISTOGRAM_BRUSH_TYPE_PARAMETER_NAME)
438 self.
boxROIButton.checked = (histogramBrushType == HISTOGRAM_BRUSH_TYPE_BOX)
439 self.
circleROIButton.checked = (histogramBrushType == HISTOGRAM_BRUSH_TYPE_CIRCLE)
440 self.
drawROIButton.checked = (histogramBrushType == HISTOGRAM_BRUSH_TYPE_DRAW)
441 self.
lineROIButton.checked = (histogramBrushType == HISTOGRAM_BRUSH_TYPE_LINE)
443 histogramSetModeLower = self.scriptedEffect.parameter(HISTOGRAM_SET_LOWER_PARAMETER_NAME)
448 histogramSetModeUpper = self.scriptedEffect.parameter(HISTOGRAM_SET_UPPER_PARAMETER_NAME)
456 with slicer.util.NodeModify(self.scriptedEffect.parameterSetNode()):
457 self.scriptedEffect.setParameter(
"MinimumThreshold", self.
thresholdSlider.minimumValue)
458 self.scriptedEffect.setParameter(
"MaximumThreshold", self.
thresholdSlider.maximumValue)
462 self.scriptedEffect.setParameter(
"AutoThresholdMethod", autoThresholdMethod)
466 self.scriptedEffect.setParameter(
"AutoThresholdMode", autoThresholdMode)
468 histogramParameterChanged =
False 470 histogramBrushType = HISTOGRAM_BRUSH_TYPE_CIRCLE
472 histogramBrushType = HISTOGRAM_BRUSH_TYPE_BOX
474 histogramBrushType = HISTOGRAM_BRUSH_TYPE_CIRCLE
476 histogramBrushType = HISTOGRAM_BRUSH_TYPE_DRAW
478 histogramBrushType = HISTOGRAM_BRUSH_TYPE_LINE
480 if histogramBrushType != self.scriptedEffect.parameter(HISTOGRAM_BRUSH_TYPE_PARAMETER_NAME):
481 self.scriptedEffect.setParameter(HISTOGRAM_BRUSH_TYPE_PARAMETER_NAME, histogramBrushType)
482 histogramParameterChanged =
True 484 histogramSetModeLower = HISTOGRAM_SET_LOWER
486 histogramSetModeLower = HISTOGRAM_SET_MINIMUM
488 histogramSetModeLower = HISTOGRAM_SET_LOWER
490 histogramSetModeLower = HISTOGRAM_SET_AVERAGE
491 if histogramSetModeLower != self.scriptedEffect.parameter(HISTOGRAM_SET_LOWER_PARAMETER_NAME):
492 self.scriptedEffect.setParameter(HISTOGRAM_SET_LOWER_PARAMETER_NAME, histogramSetModeLower)
493 histogramParameterChanged =
True 495 histogramSetModeUpper = HISTOGRAM_SET_UPPER
497 histogramSetModeUpper = HISTOGRAM_SET_AVERAGE
499 histogramSetModeUpper = HISTOGRAM_SET_UPPER
501 histogramSetModeUpper = HISTOGRAM_SET_MAXIMUM
502 if histogramSetModeUpper != self.scriptedEffect.parameter(HISTOGRAM_SET_UPPER_PARAMETER_NAME):
503 self.scriptedEffect.setParameter(HISTOGRAM_SET_UPPER_PARAMETER_NAME, histogramSetModeUpper)
504 histogramParameterChanged =
True 506 if histogramParameterChanged:
516 parameterSetNode = self.scriptedEffect.parameterSetNode()
517 parameterSetNode.SourceVolumeIntensityMaskOn()
520 self.scriptedEffect.selectEffect(
"Paint")
538 autoThresholdMethod = self.scriptedEffect.parameter(
"AutoThresholdMethod")
539 autoThresholdMode = self.scriptedEffect.parameter(
"AutoThresholdMode")
543 if autoThresholdMethod == METHOD_HUANG:
545 elif autoThresholdMethod == METHOD_INTERMODES:
547 elif autoThresholdMethod == METHOD_ISO_DATA:
549 elif autoThresholdMethod == METHOD_KITTLER_ILLINGWORTH:
551 elif autoThresholdMethod == METHOD_LI:
553 elif autoThresholdMethod == METHOD_MAXIMUM_ENTROPY:
555 elif autoThresholdMethod == METHOD_MOMENTS:
557 elif autoThresholdMethod == METHOD_OTSU:
559 elif autoThresholdMethod == METHOD_RENYI_ENTROPY:
561 elif autoThresholdMethod == METHOD_SHANBHAG:
563 elif autoThresholdMethod == METHOD_TRIANGLE:
565 elif autoThresholdMethod == METHOD_YEN:
568 logging.error(f
"Unknown AutoThresholdMethod {autoThresholdMethod}")
570 masterImageData = self.scriptedEffect.sourceVolumeImageData()
576 sourceVolumeMin, sourceVolumeMax = masterImageData.GetScalarRange()
578 if autoThresholdMode == MODE_SET_UPPER:
579 self.scriptedEffect.setParameter(
"MaximumThreshold", computedThreshold)
580 elif autoThresholdMode == MODE_SET_LOWER:
581 self.scriptedEffect.setParameter(
"MinimumThreshold", computedThreshold)
582 elif autoThresholdMode == MODE_SET_MIN_UPPER:
583 self.scriptedEffect.setParameter(
"MinimumThreshold", sourceVolumeMin)
584 self.scriptedEffect.setParameter(
"MaximumThreshold", computedThreshold)
585 elif autoThresholdMode == MODE_SET_LOWER_MAX:
586 self.scriptedEffect.setParameter(
"MinimumThreshold", computedThreshold)
587 self.scriptedEffect.setParameter(
"MaximumThreshold", sourceVolumeMax)
589 logging.error(f
"Unknown AutoThresholdMode {autoThresholdMode}")
592 if not self.scriptedEffect.confirmCurrentSegmentVisible():
597 masterImageData = self.scriptedEffect.sourceVolumeImageData()
599 modifierLabelmap = self.scriptedEffect.defaultModifierLabelmap()
600 originalImageToWorldMatrix = vtk.vtkMatrix4x4()
601 modifierLabelmap.GetImageToWorldMatrix(originalImageToWorldMatrix)
603 min = self.scriptedEffect.doubleParameter(
"MinimumThreshold")
604 max = self.scriptedEffect.doubleParameter(
"MaximumThreshold")
606 self.scriptedEffect.saveStateForUndo()
609 thresh = vtk.vtkImageThreshold()
610 thresh.SetInputData(masterImageData)
611 thresh.ThresholdBetween(min, max)
613 thresh.SetOutValue(0)
614 thresh.SetOutputScalarType(modifierLabelmap.GetScalarType())
616 modifierLabelmap.DeepCopy(thresh.GetOutput())
618 logging.error(
'apply: Failed to threshold source volume!')
622 self.scriptedEffect.modifySelectedSegmentByLabelmap(modifierLabelmap, slicer.qSlicerSegmentEditorAbstractEffect.ModificationModeSet)
625 self.scriptedEffect.selectEffect(
"")
629 self.scriptedEffect.removeActor2D(sliceWidget, pipeline.actor)
642 layoutManager = slicer.app.layoutManager()
643 if layoutManager
is None:
647 for sliceViewName
in layoutManager.sliceViewNames():
648 sliceWidget = layoutManager.sliceWidget(sliceViewName)
649 if not self.scriptedEffect.segmentationDisplayableInView(sliceWidget.mrmlSliceNode()):
651 renderer = self.scriptedEffect.renderer(sliceWidget)
653 logging.error(
"setupPreviewDisplay: Failed to get renderer!")
661 self.scriptedEffect.addActor2D(sliceWidget, pipeline.actor)
666 min = self.scriptedEffect.doubleParameter(
"MinimumThreshold")
667 max = self.scriptedEffect.doubleParameter(
"MaximumThreshold")
670 segmentationNode = self.scriptedEffect.parameterSetNode().GetSegmentationNode()
671 if not segmentationNode:
674 displayNode = segmentationNode.GetDisplayNode()
675 if displayNode
is None:
676 logging.error(
"preview: Invalid segmentation display node!")
677 color = [0.5, 0.5, 0.5]
678 segmentID = self.scriptedEffect.parameterSetNode().GetSelectedSegmentID()
684 r, g, b = segmentationNode.GetSegmentation().GetSegment(segmentID).GetColor()
689 pipeline.lookupTable.SetTableValue(1, r, g, b, opacity)
691 pipeline.thresholdFilter.SetInputConnection(layerLogic.GetReslice().GetOutputPort())
692 pipeline.thresholdFilter.ThresholdBetween(min, max)
693 pipeline.actor.VisibilityOn()
694 sliceWidget.sliceView().scheduleRender()
705 masterImageData = self.scriptedEffect.sourceVolumeImageData()
706 if masterImageData
is None:
710 if viewWidget.className() !=
"qMRMLSliceWidget":
713 anyModifierKeyPressed = callerInteractor.GetShiftKey()
or callerInteractor.GetControlKey()
or callerInteractor.GetAltKey()
716 if eventId == vtk.vtkCommand.LeftButtonPressEvent
and not anyModifierKeyPressed:
722 xy = callerInteractor.GetEventPosition()
723 ras = self.xyToRas(xy, viewWidget)
725 if eventId == vtk.vtkCommand.LeftButtonPressEvent
and not anyModifierKeyPressed:
730 elif eventId == vtk.vtkCommand.LeftButtonReleaseEvent:
734 elif eventId == vtk.vtkCommand.MouseMoveEvent:
741 brushType = HISTOGRAM_BRUSH_TYPE_CIRCLE
743 brushType = HISTOGRAM_BRUSH_TYPE_BOX
745 brushType = HISTOGRAM_BRUSH_TYPE_DRAW
747 brushType = HISTOGRAM_BRUSH_TYPE_LINE
758 if (button == qt.Qt.RightButton):
767 if (button == qt.Qt.RightButton):
773 if (button == qt.Qt.RightButton):
778 sourceVolumeNode = self.scriptedEffect.parameterSetNode().GetSourceVolumeNode()
779 sliceLogic = sliceWidget.sliceLogic()
781 backgroundLogic = sliceLogic.GetBackgroundLayer()
782 backgroundVolumeNode = backgroundLogic.GetVolumeNode()
783 if sourceVolumeNode == backgroundVolumeNode:
784 return backgroundLogic
786 foregroundLogic = sliceLogic.GetForegroundLayer()
787 foregroundVolumeNode = foregroundLogic.GetVolumeNode()
788 if sourceVolumeNode == foregroundVolumeNode:
789 return foregroundLogic
791 logging.warning(
"Source volume is not set as either the foreground or background")
793 foregroundOpacity = 0.0
794 if foregroundVolumeNode:
795 compositeNode = sliceLogic.GetSliceCompositeNode()
796 foregroundOpacity = compositeNode.GetForegroundOpacity()
798 if foregroundOpacity > 0.5:
799 return foregroundLogic
801 return backgroundLogic
804 masterImageData = self.scriptedEffect.sourceVolumeImageData()
816 brushBounds = brushPolydata.GetBounds()
817 brushExtent = [0, -1, 0, -1, 0, -1]
819 brushExtent[2 * i] = vtk.vtkMath.Floor(brushBounds[2 * i])
820 brushExtent[2 * i + 1] = vtk.vtkMath.Ceil(brushBounds[2 * i + 1])
821 if brushExtent[0] > brushExtent[1]
or brushExtent[2] > brushExtent[3]
or brushExtent[4] > brushExtent[5]:
826 self.
reslice.SetInputConnection(layerLogic.GetReslice().GetInputConnection(0, 0))
827 self.
reslice.SetResliceTransform(layerLogic.GetReslice().GetResliceTransform())
828 self.
reslice.SetInterpolationMode(layerLogic.GetReslice().GetInterpolationMode())
829 self.
reslice.SetOutputExtent(brushExtent)
831 maxNumberOfBins = 1000
832 masterImageData = self.scriptedEffect.sourceVolumeImageData()
833 scalarRange = masterImageData.GetScalarRange()
834 scalarType = masterImageData.GetScalarType()
835 if scalarType == vtk.VTK_FLOAT
or scalarType == vtk.VTK_DOUBLE:
836 numberOfBins = maxNumberOfBins
838 numberOfBins = int(scalarRange[1] - scalarRange[0]) + 1
839 if numberOfBins > maxNumberOfBins:
840 numberOfBins = maxNumberOfBins
841 binSpacing = (scalarRange[1] - scalarRange[0] + 1) / numberOfBins
843 self.
imageAccumulate.SetComponentExtent(0, numberOfBins - 1, 0, 0, 0, 0)
844 self.
imageAccumulate.SetComponentSpacing(binSpacing, binSpacing, binSpacing)
845 self.
imageAccumulate.SetComponentOrigin(scalarRange[0], scalarRange[0], scalarRange[0])
850 tableSize = self.
imageAccumulate.GetOutput().GetPointData().GetScalars().GetNumberOfTuples()
851 for i
in range(tableSize):
852 value = self.
imageAccumulate.GetOutput().GetPointData().GetScalars().GetTuple1(i)
867 lower = min(startX, endX)
868 average = (startX + endX) / 2.0
869 upper = max(startX, endX)
887 minimumThreshold = lower
888 maximumThreshold = upper
890 histogramSetModeLower = self.scriptedEffect.parameter(HISTOGRAM_SET_LOWER_PARAMETER_NAME)
891 if histogramSetModeLower == HISTOGRAM_SET_MINIMUM:
892 minimumThreshold = scalarRange[0]
893 elif histogramSetModeLower == HISTOGRAM_SET_LOWER:
894 minimumThreshold = lower
895 elif histogramSetModeLower == HISTOGRAM_SET_AVERAGE:
896 minimumThreshold = average
898 histogramSetModeUpper = self.scriptedEffect.parameter(HISTOGRAM_SET_UPPER_PARAMETER_NAME)
899 if histogramSetModeUpper == HISTOGRAM_SET_AVERAGE:
900 maximumThreshold = average
901 elif histogramSetModeUpper == HISTOGRAM_SET_UPPER:
902 maximumThreshold = upper
903 elif histogramSetModeUpper == HISTOGRAM_SET_MAXIMUM:
904 maximumThreshold = scalarRange[1]
906 self.scriptedEffect.setParameter(
"MinimumThreshold", minimumThreshold)
907 self.scriptedEffect.setParameter(
"MaximumThreshold", maximumThreshold)
912 masterImageData = self.scriptedEffect.sourceVolumeImageData()
913 if masterImageData
is None:
916 scalarRange = masterImageData.GetScalarRange()
919 low = self.scriptedEffect.doubleParameter(
"MinimumThreshold")
920 upper = self.scriptedEffect.doubleParameter(
"MaximumThreshold")
921 low = max(scalarRange[0] + epsilon, low)
922 upper = min(scalarRange[1] - epsilon, upper)
938 """ Visualization objects and pipeline for each slice view for threshold preview 958 self.
dummyImage.AllocateScalars(vtk.VTK_UNSIGNED_INT, 1)
961 self.
actor.VisibilityOff()
963 self.
mapper.SetColorWindow(255)
964 self.
mapper.SetColorLevel(128)
976 thresholdEffect =
None 985 if (event.type() == qt.QEvent.GraphicsSceneMousePress
or 986 event.type() == qt.QEvent.GraphicsSceneMouseMove
or 987 event.type() == qt.QEvent.GraphicsSceneMouseRelease):
988 transferFunction = object.transferFunction()
989 if transferFunction
is None:
992 representation = transferFunction.representation()
993 x = representation.mapXFromScene(event.pos().x())
994 y = representation.mapYFromScene(event.pos().y())
997 if event.type() == qt.QEvent.GraphicsSceneMousePress:
999 elif event.type() == qt.QEvent.GraphicsSceneMouseMove:
1001 elif event.type() == qt.QEvent.GraphicsSceneMouseRelease:
1002 self.
thresholdEffect.onHistogramMouseRelease(position, event.button())
1009 def __init__(self, thresholdEffect, scriptedEffect, sliceWidget, brushMode):
1061 lines = vtk.vtkCellArray()
1068 thinLines = vtk.vtkCellArray()
1074 self.
mapper.SetInputConnection(self.
cutter.GetOutputPort())
1079 actorProperty = self.
actor.GetProperty()
1080 actorProperty.SetColor(1, 1, 0)
1081 actorProperty.SetLineWidth(2)
1083 if renderer
is None:
1084 logging.error(
"pipelineForWidget: Failed to get renderer!")
1089 if self.
brushMode == HISTOGRAM_BRUSH_TYPE_DRAW:
1102 thinActorProperty = self.
thinActor.GetProperty()
1103 thinActorProperty.SetColor(1, 1, 0)
1104 thinActorProperty.SetLineWidth(1)
1106 elif self.
brushMode == HISTOGRAM_BRUSH_TYPE_LINE:
1110 if self.
actor is not None:
1124 if self.
brushMode == HISTOGRAM_BRUSH_TYPE_DRAW:
1125 newPointIndex = self.
rasPoints.InsertNextPoint(ras)
1126 previousPointIndex = newPointIndex - 1
1127 if (previousPointIndex >= 0):
1128 idList = vtk.vtkIdList()
1129 idList.InsertNextId(previousPointIndex)
1130 idList.InsertNextId(newPointIndex)
1131 self.
polyData.InsertNextCell(vtk.VTK_LINE, idList)
1134 thinLines.Initialize()
1135 idList = vtk.vtkIdList()
1136 idList.InsertNextId(newPointIndex)
1137 idList.InsertNextId(0)
1150 sliceXyToRas = self.
sliceWidget.sliceLogic().GetSliceNode().GetXYToRAS()
1151 rasToSliceXy = vtk.vtkMatrix4x4()
1152 vtk.vtkMatrix4x4.Invert(sliceXyToRas, rasToSliceXy)
1156 brushToWorldOriginTransformMatrix = vtk.vtkMatrix4x4()
1157 brushToWorldOriginTransformMatrix.DeepCopy(self.
sliceWidget.sliceLogic().GetSliceNode().GetSliceToRAS())
1158 brushToWorldOriginTransformMatrix.SetElement(0, 3, 0)
1159 brushToWorldOriginTransformMatrix.SetElement(1, 3, 0)
1160 brushToWorldOriginTransformMatrix.SetElement(2, 3, 0)
1169 if self.
brushMode == HISTOGRAM_BRUSH_TYPE_CIRCLE:
1172 point1ToPoint2 = [0, 0, 0]
1173 vtk.vtkMath.Subtract(self.
point1, self.
point2, point1ToPoint2)
1174 radius = vtk.vtkMath.Normalize(point1ToPoint2)
1180 elif self.
brushMode == HISTOGRAM_BRUSH_TYPE_BOX:
1188 xVector = [1, 0, 0, 0]
1190 xLength = abs(vtk.vtkMath.Dot(xVector[:3], length))
1193 zVector = [0, 0, 1, 0]
1195 zLength = abs(vtk.vtkMath.Dot(zVector[:3], length))
1199 elif self.
brushMode == HISTOGRAM_BRUSH_TYPE_LINE:
1210 HISTOGRAM_BRUSH_TYPE_PARAMETER_NAME =
"BrushType" 1212 HISTOGRAM_BRUSH_TYPE_BOX =
'BOX' 1213 HISTOGRAM_BRUSH_TYPE_CIRCLE =
'CIRCLE' 1214 HISTOGRAM_BRUSH_TYPE_DRAW =
'DRAW' 1215 HISTOGRAM_BRUSH_TYPE_LINE =
'LINE' 1217 HISTOGRAM_STATE_OFF =
'OFF' 1218 HISTOGRAM_STATE_MOVING =
'MOVING' 1219 HISTOGRAM_STATE_PLACED =
'PLACED' 1221 HISTOGRAM_SET_LOWER_PARAMETER_NAME =
'HistogramSetLower' 1222 HISTOGRAM_SET_UPPER_PARAMETER_NAME =
'HistogramSetUpper' 1224 HISTOGRAM_SET_MINIMUM =
'MINIMUM' 1225 HISTOGRAM_SET_LOWER =
'LOWER' 1226 HISTOGRAM_SET_AVERAGE =
'AVERAGE' 1227 HISTOGRAM_SET_UPPER =
'UPPER' 1228 HISTOGRAM_SET_MAXIMUM =
'MAXIMUM' 1232 METHOD_HUANG =
'HUANG' 1233 METHOD_INTERMODES =
'INTERMODES' 1234 METHOD_ISO_DATA =
'ISO_DATA' 1235 METHOD_KITTLER_ILLINGWORTH =
'KITTLER_ILLINGWORTH' 1237 METHOD_MAXIMUM_ENTROPY =
'MAXIMUM_ENTROPY' 1238 METHOD_MOMENTS =
'MOMENTS' 1239 METHOD_OTSU =
'OTSU' 1240 METHOD_RENYI_ENTROPY =
'RENYI_ENTROPY' 1241 METHOD_SHANBHAG =
'SHANBHAG' 1242 METHOD_TRIANGLE =
'TRIANGLE' 1245 MODE_SET_UPPER =
'SET_UPPER' 1246 MODE_SET_LOWER =
'SET_LOWER' 1247 MODE_SET_MIN_UPPER =
'SET_MIN_UPPER' 1248 MODE_SET_LOWER_MAX =
'SET_LOWER_MAX'
def setThresholdEffect(self, thresholdEffect)
histogramUpperMethodButtonGroup
Upper histogram threshold buttons.
histogramUpperThresholdMaximumButton
def updateMRMLFromGUI(self)
worldOriginToWorldTransform
def onSelectNextAutoThresholdMethod(self)
def setMRMLDefaults(self)
def onThresholdValuesChanged(self, min, max)
def onHistogramMouseRelease(self, pos, button)
def sourceVolumeNodeChanged(self)
def createHistogramPipeline(self, sliceWidget)
histogramLowerThresholdAverageButton
def eventFilter(self, object, event)
histogramLowerThresholdLowerButton
histogramUpperThresholdAverageButton
histogramLowerThresholdMinimumButton
def processViewNodeEvents(self, callerViewNode, eventId, viewWidget)
def onSelectedAutoThresholdMethod(self)
backgroundFunctionContainer
def updateBrushModel(self)
histogramLowerMethodButtonGroup
Lower histogram threshold buttons.
histogramUpperThresholdUpperButton
thinWorldToSliceTransformer
def setupOptionsFrame(self)
def clearPreviewDisplay(self)
def onHistogramMouseClick(self, pos, button)
selectPreviousAutoThresholdButton
def getSourceVolumeLayerLogic(self, sliceWidget)
def updateHistogramBackground(self)
brushToWorldOriginTransformer
def clearHistogramDisplay(self)
def updateHistogram(self)
def autoThreshold(self, autoThresholdMethod, autoThresholdMode)
def restorePreviewedSegmentTransparency(self)
def setupPreviewDisplay(self)
def __init__(self, scriptedEffect)
def onAutoThreshold(self)
def updateGUIFromMRML(self)
histogramFunctionContainer
selectNextAutoThresholdButton
def setCurrentSegmentTransparent(self)
autoThresholdModeSelectorComboBox
brushToWorldOriginTransform
worldOriginToWorldTransformer
def processInteractionEvents(self, callerInteractor, eventId, viewWidget)
def onSelectPreviousAutoThresholdMethod(self)
def __init__(self, thresholdEffect, scriptedEffect, sliceWidget, brushMode)
autoThresholdMethodSelectorComboBox
histogramBrushButtonGroup
def onHistogramMouseMove(self, pos, button)