How to use the slicer.mrmlScene.RemoveNode function in slicer

To help you get started, we’ve selected a few slicer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SlicerRt / SlicerRT / Segmentations / Testing / Python / SegmentationsModuleTest1.py View on Github external
modelSegmentTranformed.UnRegister(None) # Need to release ownership
    self.assertIsNotNone(modelSegmentTranformed)
    modelSegmentTransformedPolyData = modelSegmentTranformed.GetRepresentation(self.closedSurfaceReprName)
    self.assertIsNotNone(modelSegmentTransformedPolyData)
    self.assertEqual(int(modelSegmentTransformedPolyData.GetBounds()[0]), 1332)
    self.assertEqual(int(modelSegmentTransformedPolyData.GetBounds()[1]), 1675)

    # Clean up temporary nodes
    slicer.mrmlScene.RemoveNode(bodyModelNode)
    slicer.mrmlScene.RemoveNode(bodyLabelmapNode)
    slicer.mrmlScene.RemoveNode(allSegmentsLabelmapNode)
    slicer.mrmlScene.RemoveNode(modelImportSegmentationNode)
    slicer.mrmlScene.RemoveNode(multiLabelImportSegmentationNode)
    slicer.mrmlScene.RemoveNode(singleLabelImportSegmentationNode)
    slicer.mrmlScene.RemoveNode(bodyModelTransformNode)
    slicer.mrmlScene.RemoveNode(bodyModelNodeTransformed)
    slicer.mrmlScene.RemoveNode(bodyLabelmapNodeTransformed)
    slicer.mrmlScene.RemoveNode(modelTransformedImportSegmentationNode)
github SlicerIGT / SlicerIGT / Scoliosis / SlicerExtension / PostureAssessmentToolkit / UsSurfaceToLandmarks / UsSurfaceToLandmarks.py View on Github external
def OnGenerateLandmarksButtonClicked(self):
    logic = UsSurfaceToLandmarksLogic()
    
    LabelMapNode = self.WorkingLabelMapStorage.currentNode()
    if LabelMapNode == None:
      print "ERROR - Cannot generate landmarks without labelmap; at least threshold volume first"
      return False
      
    else:
      MarkupsNode = logic.LabelmapToMarkupsNode(LabelMapNode, self.UndersampleFractionSlider.value)
      MarkupsNodeName = LabelMapNode.GetName() + self.MarkupsTag
      MarkupsNode.SetName(MarkupsNodeName)
      
      OldMarkupsNode = slicer.util.getNode(MarkupsNodeName)
      if OldMarkupsNode != None:
        slicer.mrmlScene.RemoveNode(OldMarkupsNode)
      
      slicer.mrmlScene.AddNode(MarkupsNode)
      self.OutputMarkupsStorage.setCurrentNode(MarkupsNode)
      return True
github Kitware / SlicerSALT / Modules / Scripted / ShapeAnalysisToolBox / CommonUtilities / utility.py View on Github external
    @staticmethod
    def removeMRMLNode(node):
        if slicer.util.getNode(node.GetName()):
            slicer.mrmlScene.RemoveNode(node)
github SlicerIGT / SlicerIGT / Scoliosis / SlicerExtension / PostureAssessmentToolkit / PreProcessLandmarks / PreProcessLandmarks.py View on Github external
# Following logic check may be un-necessary as it is called when Widget.SingleNodeSelector.currentNode() changes
    if self.logic == None:
      self.logic = RepairLandmarksLogic(self.SingleNodeSelector.currentNode(), self.kmWindowSizeSlider.value, self.PolyFitDegreeSlider.value, self.BoundaryMultiplicitySlider.value, self.SpecificitySlider.value, self.ImputationSpecificitySlider.value)
      #self.SpecificitySlider.enabled = True
    else:
      self.logic.UpdateParameters(self.kmWindowSizeSlider.value, self.PolyFitDegreeSlider.value, self.BoundaryMultiplicitySlider.value, self.SpecificitySlider.value, self.ImputationSpecificitySlider.value)
    # Get Left and Right side markups nodes
    (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)
github SlicerProstate / SliceTracker / SliceTracker / SliceTrackerZFrameRegistration.py View on Github external
def loadZFrameModel(self):
    collection = slicer.mrmlScene.GetNodesByName(self.ZFRAME_MODEL_NAME)
    for index in range(collection.GetNumberOfItems()):
      slicer.mrmlScene.RemoveNode(collection.GetItemAsObject(index))
    self.modulePath = os.path.dirname(slicer.util.modulePath(self.moduleName))
    zFrameModelPath = os.path.join(self.modulePath, self.ZFRAME_MODEL_PATH)
    if not self.zFrameModelNode:
      _, self.zFrameModelNode = slicer.util.loadModel(zFrameModelPath, returnNode=True)
      self.zFrameModelNode.SetName(self.ZFRAME_MODEL_NAME)
      slicer.mrmlScene.AddNode(self.zFrameModelNode)
      modelDisplayNode = self.zFrameModelNode.GetDisplayNode()
      modelDisplayNode.SetColor(1, 1, 0)
github SlicerIGT / SlicerIGT / Scoliosis / SlicerExtension / PostureAssessmentToolkit / AssessLandmarks / AssessLandmarks.py View on Github external
# Clear average spine surface model
    slicer.mrmlScene.RemoveNode(slicer.util.getNode('AverageModel'))
    
    # Clear visualizations generated
    ModelNodes = slicer.util.getNodesByClass('vtkMRMLModelNode')
    IsVisualizationNode = [ModelNodes[i].GetName().__contains__("_Visualization") for i in range(len(ModelNodes))]
    for i, ShouldDeleteNode in enumerate(IsVisualizationNode):
      if ShouldDeleteNode:
        slicer.mrmlScene.RemoveNode(ModelNodes[i])
    
    TransformNodes = slicer.util.getNodesByClass('vtkMRMLTransformNode')
    if len(TransformNodes) > 0:
      IsVisualizedTransform = [TransformNodes[i].GetName().__contains__("L5ToT7OffsetInAxialPlane") for i in range(len(TransformNodes))]
      for i, ShouldDeleteNode in enumerate(IsVisualizedTransform):
        if ShouldDeleteNode:
          slicer.mrmlScene.RemoveNode(TransformNodes[i])
    
    """
    # Clear vertebra surface models
    VertebraLabels = ['T01','T02','T03','T04','T05','T06','T07','T08','T09','T10','T11','T12','L01','L02','L03','L04','L05']
    for Label in VertebraLabels:
      slicer.mrmlScene.RemoveNode(slicer.util.getNode(Label))
    """
github Kitware / SlicerSALT / Modules / Scripted / ShapeAnalysisToolBox / DataImporter.py View on Github external
def cleanup(self):
    logging.debug('Deleting nodes')
    if self.labelMapDict is not None:
      for nodeName in self.labelMapDict:
        logging.debug('Deleting label map node: ' + nodeName)
        slicer.mrmlScene.RemoveNode(self.labelMapDict[nodeName])

    if self.modelDict is not None:
      for nodeName in self.modelDict:
        logging.debug('Deleting model node: ' + nodeName)
        slicer.mrmlScene.RemoveNode(self.modelDict[nodeName])

    if self.segmentationDict is not None:
      for nodeName in self.segmentationDict:
        logging.debug('Deleting segmentation node: ' + nodeName)
        slicer.mrmlScene.RemoveNode(self.segmentationDict[nodeName])

    self.labelMapDict = {}
    self.modelDict = {}
    self.segmentationDict = {}
    self.labelRangeInCohort = (-1, -1)
    self.topologyDict = {}
    self.polyDataDict = {}
    self.expectedTopologiesBySegment = {}
    self.inconsistentTopologyDict = {}

    self.numberOfDifferentSegments = 0