def jumpToSegmentAndCreateScreenShot(segmentationNode, segment, widgets, center=False, crosshair=False): imageData = vtkSegmentationCore.vtkOrientedImageData() segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegment(segment) segmentationsLogic = slicer.modules.segmentations.logic() segmentationsLogic.GetSegmentBinaryLabelmapRepresentation(segmentationNode, segmentID, imageData) extent = imageData.GetExtent() if extent[1] != -1 and extent[3] != -1 and extent[5] != -1: tempLabel = slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(tempLabel) tempLabel.SetName(segment.GetName() + "CentroidHelper") segmentationsLogic.CreateLabelmapVolumeFromOrientedImageData(imageData, tempLabel) CustomSegmentEditorLogic.applyThreshold(tempLabel, 1) centroid = ModuleLogicMixin.getCentroidForLabel(tempLabel, 1) slicer.mrmlScene.RemoveNode(tempLabel) annotationNodes = [] crosshairButton = None if crosshair: crosshairButton = CrosshairButton() crosshairButton.setSliceIntersectionEnabled(True) crosshairButton.checked = True for widget in widgets: sliceLogic = widget.sliceLogic() sliceNode = sliceLogic.GetSliceNode() if not center: sliceNode.JumpSliceByOffsetting(centroid[0], centroid[1], centroid[2]) else: markupsLogic = slicer.modules.markups.logic() markupsLogic.JumpSlicesToLocation(centroid[0], centroid[1], centroid[2], True) dNodeProperties = ScreenShotHelper.saveSegmentDisplayProperties(segmentationNode, segment) segmentationNode.GetDisplayNode().SetAllSegmentsVisibility(False) ScreenShotHelper.setDisplayNodeProperties(segmentationNode, segment, properties={'fill': True, 'outline': True, 'visible': True}) if crosshairButton: crosshairButton.crosshairNode.SetCrosshairRAS(centroid) annotationNode = ScreenShotHelper.takeScreenShot("{}_Screenshot_{}_{}".format(segment.GetName(), sliceNode.GetName(), sliceNode.GetOrientation()), "", widget) segmentationNode.GetDisplayNode().SetAllSegmentsVisibility(True) ScreenShotHelper.setDisplayNodeProperties(segmentationNode, segment, dNodeProperties) annotationNodes.append(annotationNode) if crosshairButton: crosshairButton.checked = False return annotationNodes[0] if len(annotationNodes) == 1 else annotationNodes
def getSegmentCentroid(segmentationNode, segment): imageData = vtkSegmentationCore.vtkOrientedImageData() segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegment(segment) segmentationsLogic = slicer.modules.segmentations.logic() segmentationsLogic.GetSegmentBinaryLabelmapRepresentation(segmentationNode, segmentID, imageData) extent = imageData.GetExtent() if extent[1] != -1 and extent[3] != -1 and extent[5] != -1: tempLabel = slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(tempLabel) tempLabel.SetName(segment.GetName() + "CentroidHelper") segmentationsLogic.CreateLabelmapVolumeFromOrientedImageData(imageData, tempLabel) CustomSegmentEditorLogic.applyThreshold(tempLabel, 1) centroid = ModuleLogicMixin.getCentroidForLabel(tempLabel, 1) slicer.mrmlScene.RemoveNode(tempLabel) return centroid return None
def getSegmentCentroid(segmentationNode, segment): imageData = vtkSegmentationCore.vtkOrientedImageData() segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegment(segment) segmentationsLogic = slicer.modules.segmentations.logic() segmentationsLogic.GetSegmentBinaryLabelmapRepresentation(segmentationNode, segmentID, imageData) extent = imageData.GetExtent() if extent[1] != -1 and extent[3] != -1 and extent[5] != -1: tempLabel = slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(tempLabel) tempLabel.SetName(segment.GetName() + "CentroidHelper") segmentationsLogic.CreateLabelmapVolumeFromOrientedImageData(imageData, tempLabel) CustomSegmentEditorLogic.applyThreshold(tempLabel, 1) centroid = ModuleLogicMixin.getCentroidForLabel(tempLabel, 1) slicer.mrmlScene.RemoveNode(tempLabel) return centroid return None
def jumpToSegmentAndCreateScreenShot(segmentationNode, segment, widgets, center=False, crosshair=False): imageData = vtkSegmentationCore.vtkOrientedImageData() segmentID = segmentationNode.GetSegmentation().GetSegmentIdBySegment( segment) segmentationsLogic = slicer.modules.segmentations.logic() segmentationsLogic.GetSegmentBinaryLabelmapRepresentation( segmentationNode, segmentID, imageData) extent = imageData.GetExtent() if extent[1] != -1 and extent[3] != -1 and extent[5] != -1: tempLabel = slicer.vtkMRMLLabelMapVolumeNode() slicer.mrmlScene.AddNode(tempLabel) tempLabel.SetName(segment.GetName() + "CentroidHelper") segmentationsLogic.CreateLabelmapVolumeFromOrientedImageData( imageData, tempLabel) CustomSegmentEditorLogic.applyThreshold(tempLabel, 1) centroid = ModuleLogicMixin.getCentroidForLabel(tempLabel, 1) slicer.mrmlScene.RemoveNode(tempLabel) annotationNodes = [] crosshairButton = None if crosshair: crosshairButton = CrosshairButton() crosshairButton.setSliceIntersectionEnabled(True) crosshairButton.checked = True for widget in widgets: sliceLogic = widget.sliceLogic() sliceNode = sliceLogic.GetSliceNode() if not center: sliceNode.JumpSliceByOffsetting(centroid[0], centroid[1], centroid[2]) else: markupsLogic = slicer.modules.markups.logic() markupsLogic.JumpSlicesToLocation(centroid[0], centroid[1], centroid[2], True) dNodeProperties = ScreenShotHelper.saveSegmentDisplayProperties( segmentationNode, segment) segmentationNode.GetDisplayNode().SetAllSegmentsVisibility( False) ScreenShotHelper.setDisplayNodeProperties(segmentationNode, segment, properties={ 'fill': True, 'outline': True, 'visible': True }) if crosshairButton: crosshairButton.crosshairNode.SetCrosshairRAS(centroid) annotationNode = ScreenShotHelper.takeScreenShot( "{}_Screenshot_{}_{}".format(segment.GetName(), sliceNode.GetName(), sliceNode.GetOrientation()), "", widget) segmentationNode.GetDisplayNode().SetAllSegmentsVisibility( True) ScreenShotHelper.setDisplayNodeProperties( segmentationNode, segment, dNodeProperties) annotationNodes.append(annotationNode) if crosshairButton: crosshairButton.checked = False return annotationNodes[0] if len( annotationNodes) == 1 else annotationNodes