Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with open(tmp_segmentation_mha, 'wb') as f:
f.write(__base64_decode__( data['content'] ))
if sys.version_info.major == 2:
# returnNode is deprecated in newer Slicer versions
success, node = slicer.util.loadLabelVolume(tmp_segmentation_mha, properties={'show': False}, returnNode=True)
else:
node = slicer.util.loadLabelVolume(tmp_segmentation_mha, properties={'show': False})
os.remove(tmp_segmentation_mha)
logic = slicer.modules.volumerendering.logic()
volumeNode = slicer.util.getNode(node.GetName())
displayNode = logic.CreateVolumeRenderingDisplayNode()
slicer.mrmlScene.AddNode(displayNode)
displayNode.UnRegister(logic)
logic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)
volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())
layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)
threeDView = threeDWidget.threeDView()
threeDView.resetFocalPoint()
for view in ['Red', 'Green', 'Yellow']:
view_widget = slicer.app.layoutManager().sliceWidget(view)
view_logic = view_widget.sliceLogic()
view_logic.GetSliceCompositeNode().SetLabelVolumeID(node.GetID())
view_logic.GetSliceCompositeNode().SetLabelOpacity(0.5)
def createAndObserveDisplayNode(node, displayNodeClass=slicer.vtkMRMLDisplayNode):
displayNode = displayNodeClass()
slicer.mrmlScene.AddNode(displayNode)
node.SetAndObserveDisplayNodeID(displayNode.GetID())
return displayNode
(LeftNode, RightNode) = self.logic.PatientModel.ClassifyLeftRight()
# Update scene
PriorLeft = slicer.util.getNode(LeftNode.GetName())
if PriorLeft != None:
self.LeftSideSelector.setCurrentNode(None)
slicer.mrmlScene.RemoveNode(PriorLeft)
PriorRight = slicer.util.getNode(RightNode.GetName())
if PriorRight != None:
self.RightSideSelector.setCurrentNode(None)
slicer.mrmlScene.RemoveNode(PriorRight)
# Add new nodes to scene
slicer.mrmlScene.AddNode(LeftNode)
slicer.mrmlScene.AddNode(RightNode)
LeftNode.CreateDefaultDisplayNodes()
RightNode.CreateDefaultDisplayNodes()
# Update user interface
self.LeftSideSelector.setCurrentNode(LeftNode)
self.RightSideSelector.setCurrentNode(RightNode)
PriorSelectedSideNode = self.RepairSideSelector.currentNode()
if PriorSelectedSideNode != None:
self.RepairSideSelector.setCurrentNode(None)
slicer.mrmlScene.RemoveNode(PriorSelectedSideNode)
if PriorSelectedSideNode.GetName().__contains__("_Left"):
self.RepairSideSelector.setCurrentNode(LeftNode)
if PriorSelectedSideNode.GetName().__contains__("_Right"):
def setFOV2Largest2DRegion(self, widget, largestLabel=None, factor=1.5):
if not largestLabel:
largestLabel = self.findLargest2DRegion(self.segmentationNode)
slicer.mrmlScene.AddNode(largestLabel)
sliceLogic = widget.sliceLogic()
sliceNode = sliceLogic.GetSliceNode()
compositeNode = widget.mrmlSliceCompositeNode()
savedVolumeID = compositeNode.GetBackgroundVolumeID()
savedFOV = sliceNode.GetFieldOfView()
compositeNode.SetBackgroundVolumeID(largestLabel.GetID())
sliceLogic.FitSliceToAll()
compositeNode.SetBackgroundVolumeID(savedVolumeID)
FOV = sliceNode.GetFieldOfView()
ModuleWidgetMixin.setFOV(sliceLogic, [FOV[0] * factor, FOV[1] * factor, FOV[2]])
slicer.mrmlScene.RemoveNode(largestLabel)
return largestLabel
def createMarkupAndDisplayNodeForFiducials(self):
self.displayNode = slicer.vtkMRMLMarkupsDisplayNode()
slicer.mrmlScene.AddNode(self.displayNode)
self.inputMarkupNode = slicer.vtkMRMLMarkupsFiducialNode()
self.inputMarkupNode.SetName('inputMarkupNode')
slicer.mrmlScene.AddNode(self.inputMarkupNode)
self.inputMarkupNode.SetAndObserveDisplayNodeID(self.displayNode.GetID())
self.styleDisplayNode(self.displayNode)