How to use the slicer.util.getNode 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 Kitware / SlicerSALT / Modules / Scripted / ShapeAnalysisToolBox / DataImporter.py View on Github external
if len(freesurfer_found_segments) != len(self.freesurfer_wanted_segments):
        unpresent_segments = self.freesurfer_wanted_segments[:]
        for seg in freesurfer_found_segments:
          del unpresent_segments[unpresent_segments.index(seg)]
        unpresent_segments = map(lambda x: self.freesurfer_lut_dict[x.split('_')[-1]]['name'], unpresent_segments)
        logging.warning('Unable to find all segments, {} have not been found.'.format(unpresent_segments))
        logging.warning('LabelMap in path: {} has not been loaded into segmentationDict.'.format(path))
        return False

      for segmentId in to_remove_ids:
        segmentationNode.GetSegmentation().RemoveSegment(segmentId)

    elif self.color_table_id != 'None':
      segment_number = segmentationNode.GetSegmentation().GetNumberOfSegments()
      color_node = slicer.util.getNode(pattern=self.color_table_id)
      if (segment_number > 1):
        for segmentIndex in range(segment_number):
          segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(segmentIndex)
          label_id = int(segmentId.split('_')[-1])

          color = [.0, .0, .0, .0]
          color_node.GetColor(label_id, color)
          segment_name = color_node.GetColorName(label_id)

          segment = segmentationNode.GetSegmentation().GetSegment(segmentId)
          segment.SetName(segment_name)
          segment.SetColor(color[:3])

      elif (segment_number==1):
        segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)
        color = [.0, .0, .0, .0]
github Kitware / SlicerSALT / Modules / Scripted / ShapeAnalysisToolBox / DataImporter.py View on Github external
segmentIdList = vtk.vtkStringArray()
        segmentIdList.InsertNextValue(segmentId)

        full_segmentName = segmentation_node.GetName() + segmentName

        # save label map
        exported_labelmap = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode", full_segmentName+' LabelMap')

        if name in self.labelMapDict.keys():
          segmentationLogic.ExportSegmentsToLabelmapNode(segmentation_node, segmentIdList, exported_labelmap, self.labelMapDict[name])
        else:
          segmentationLogic.ExportSegmentsToLabelmapNode(segmentation_node, segmentIdList, exported_labelmap)

        slicer.util.saveNode(exported_labelmap, labelMap_filepath)
        slicer.mrmlScene.RemoveNode(slicer.util.getNode(pattern=full_segmentName+' LabelMap_ColorTable'))
        slicer.mrmlScene.RemoveNode(exported_labelmap)

        # save Polydata
        exported_hierarchy = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelHierarchyNode", full_segmentName+' Model')
        segmentationLogic.ExportSegmentsToModelHierarchy(segmentation_node, segmentIdList, exported_hierarchy)
        collec = vtk.vtkCollection()
        exported_hierarchy.GetChildrenModelNodes(collec)
        exported_model = collec.GetItemAsObject(0)
        slicer.util.saveNode(exported_model, polydata_filepath)
        slicer.mrmlScene.RemoveNode(exported_hierarchy)
        slicer.mrmlScene.RemoveNode(exported_model)

        # create output directory
        if not os.path.isdir(output_directory_path):
          os.mkdir(output_directory_path)
github SlicerIGT / SlicerIGT / Scoliosis / SlicerExtension / PostureAssessmentToolkit / AssessLandmarks / AssessLandmarks.py View on Github external
import urllib
    downloads = (
        ('http://slicer.kitware.com/midas3/download?items=5767', 'FA.nrrd', slicer.util.loadVolume),
        )

    for url,name,loader in downloads:
      filePath = slicer.app.temporaryPath + '/' + name
      if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
        logging.info('Requesting download %s from %s...\n' % (name, url))
        urllib.urlretrieve(url, filePath)
      if loader:
        logging.info('Loading %s...' % (name,))
        loader(filePath)
    self.delayDisplay('Finished with download and loading')

    volumeNode = slicer.util.getNode(pattern="FA")
    logic = AssessLandmarksLogic()
    self.assertIsNotNone( logic.hasImageData(volumeNode) )
    self.delayDisplay('Test passed!')
github SlicerIGT / SlicerIGT / Scoliosis / SlicerExtension / PostureAssessmentToolkit / PreProcessLandmarks / PreProcessLandmarks.py View on Github external
def OnAutoGenPatchButton(self):
    
    # Probably should necessitate continuity of data on the user's end
    #if self.logic == None:
    #  self.logic = PreProcessLandmarksLogic(self.SingleNodeSelector.currentNode(), self.PolynomialDegree)
    #  (LS, RS) = self.logic.CategorizeLeftRight(4)
    
    NodeToPatch = self.RepairSideSelector.currentNode()
    OldPatchNode = slicer.util.getNode(NodeToPatch.GetName() + "_Patch")
    if OldPatchNode != None:
      slicer.mrmlScene.RemoveNode(OldPatchNode)
    
    if NodeToPatch.GetName().__contains__("Left"):
      # Get patch
      PatchNode = self.logic.PatientModel.LeftSide.GeneratePatchNode()
      
      # Update scene
      slicer.mrmlScene.AddNode(PatchNode)
      PatchNode.CreateDefaultDisplayNodes()
      
      # Update UI
      self.LeftPatchSelector.setCurrentNode(PatchNode)
      
    elif NodeToPatch.GetName().__contains__("Right"):
      # Get patch
github SlicerIGT / SlicerIGT / ScreenCapture / ScreenCapture.py View on Github external
import urllib
    downloads = (
        ('http://slicer.kitware.com/midas3/download?items=5767', 'FA.nrrd', slicer.util.loadVolume),
        )

    for url,name,loader in downloads:
      filePath = slicer.app.temporaryPath + '/' + name
      if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
        logging.info('Requesting download %s from %s...\n' % (name, url))
        urllib.urlretrieve(url, filePath)
      if loader:
        logging.info('Loading %s...' % (name,))
        loader(filePath)
    self.delayDisplay('Finished with download and loading')

    volumeNode = slicer.util.getNode(pattern="FA")
    logic = ScreenCaptureLogic()
    self.assertIsNotNone( logic.hasImageData(volumeNode) )
    self.delayDisplay('Test passed!')
github Radiomics / SlicerRadiomics / SlicerRadiomics / SlicerRadiomics.py View on Github external
('Params.yaml', None))

    for item, loader in dataItems:
      url = dataURLPrefix + '-' + dataRelease + '/' + item
      filePath = os.path.join(slicer.app.temporaryPath, item)
      if not os.path.exists(filePath) or os.stat(filePath).st_size == 0:
        self.logger.info('Requesting download %s from %s...\n' % (item, url))
        self.assertTrue(urlretrieve(url, filePath), 'Failed to download from ' + url)
      if loader:
        self.logger.info('Loading %s from %s...' % (item, filePath))
        self.assertTrue(loader(filePath), 'Failed to load ' + item)

    self.delayDisplay(
      'Finished with download and loading %d volumes' % (slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLVolumeNode')))

    grayscaleNode = slicer.util.getNode(pattern='lung1_image')
    labelmapNode = slicer.util.getNode(pattern='lung1_label')
    binaryNode = slicer.util.getNode(pattern='lung1_binary')
    surfaceNode = slicer.util.getNode(pattern='lung1_surface')

    parameterFile = os.path.join(slicer.app.temporaryPath, 'Params.yaml')

    logic = SlicerRadiomicsLogic()
    logic.runSync = True  # Block Thread until each extraction is done (i.e. run synchronously)
    self.assertIsNotNone(logic.hasImageData(grayscaleNode))
    self.assertIsNotNone(logic.hasImageData(labelmapNode))

    featureClasses = ['firstorder']
    settings = {
      'binWidth': 25,
      'symmetricalGLCM': False,
      'label': 1