def closeCase(self, save_loaded_masks=False, save_new_masks=False, reader_name=None):

    # Save the results (label maps reviewed or created)
    if reader_name == '':
      reader_name = None

    loaded_masks = {node.GetName(): node for node in self.mask_nodes.values()}
    new_masks = {node.GetName(): node for node in slicer.util.getNodesByClass('vtkMRMLLabelMapVolumeNode')
                 if node.GetName() not in loaded_masks.keys()}

    # If enabled, save label maps
    if save_loaded_masks:
      if len(loaded_masks) == 0:
        self.logger.debug('No loaded masks to save...')
      else:
        self.logger.info('Saving %d loaded masks...', len(loaded_masks))
        self._saveMasks(loaded_masks, self.image_root, reader_name)
    if save_new_masks:
      if len(new_masks) == 0:
        self.logger.debug('No new masks to save...')
      else:
        self.logger.info('Saving %d new masks...', len(new_masks))
        self._saveMasks(new_masks, self.image_root, reader_name)

    # Close the scene and start a fresh one
    if slicer.util.selectedModule() == 'Editor':
      slicer.modules.EditorWidget.exit()

    slicer.mrmlScene.Clear(0)
    node = slicer.vtkMRMLViewNode()
    slicer.mrmlScene.AddNode(node)
Beispiel #2
0
    def onLayoutSelectButton(self):
        layoutManager = slicer.app.layoutManager()
        currentLayout = layoutManager.layout

        # place skeleton model in first 3d view
        skeleton_volume = slicer.util.getFirstNodeByName("SkeletonModel")
        viewNode = layoutManager.threeDWidget(0).mrmlViewNode()

        if skeleton_volume is not None:
            displayNode = skeleton_volume.GetDisplayNode()
            displayNode.SetViewNodeIDs([viewNode.GetID()])

        # place reconstructed volume in second 3d view

        # hacky but necessary way to ensure that we grab the correct browser node
        i = 1
        found = False
        browser = slicer.util.getFirstNodeByClassByName(
            'vtkMRMLSequenceBrowserNode', 'LandmarkingScan')
        while not found and i < 6:
            if browser == None:
                browser = slicer.util.getFirstNodeByClassByName(
                    'vtkMRMLSequenceBrowserNode',
                    'LandmarkingScan_{}'.format(str(i)))
                if browser != None:
                    found = True
            else:
                found = True

            i += 1

        if browser is not None:
            spine_volume = slicer.util.getFirstNodeByName(
                browser.GetName() + 'ReconstructionResults')
            if layoutManager.threeDWidget(1) is not None:
                viewNode = layoutManager.threeDWidget(1).mrmlViewNode()
            else:
                newView = slicer.vtkMRMLViewNode()
                newView = slicer.mrmlScene.AddNode(newView)
                newWidget = slicer.qMRMLThreeDWidget()
                newWidget.setMRMLScene(slicer.mrmlScene)
                newWidget.setMRMLViewNode(newView)

            if spine_volume is not None:
                displayNode = slicer.modules.volumerendering.logic(
                ).GetFirstVolumeRenderingDisplayNode(spine_volume)
                displayNode.SetViewNodeIDs([viewNode.GetID()])
                spine_volume.SetDisplayVisibility(1)

        if currentLayout == 501:
            layoutManager.setLayout(
                502)  # switch to dual 3d + red slice layout
        elif currentLayout == 502:
            layoutManager.setLayout(6)  # switch to red slice only layout
        else:
            layoutManager.setLayout(
                501)  # switch to custom layout with 3d viewer
    def TestSection_InitializeTest(self):
        #
        # Define variables
        #

        # A certain model to test that is both in the brain and the midbrain folders
        self.testModelNodeName = 'Model_79_left_red_nucleus'
        self.testModelNode = None
        self.overrideColor = [255, 255, 0]

        # Get subject hierarchy node
        self.shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(
            slicer.mrmlScene)
        self.assertIsNotNone(self.shNode)
        # Get folder plugin
        pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler().instance(
        )
        self.assertIsNotNone(pluginHandler)
        self.folderPlugin = pluginHandler.pluginByName('Folder')
        self.assertIsNotNone(self.folderPlugin)

        #
        # Initialize test
        #

        # Create 3D view
        self.layoutName = "Test3DView"
        # ownerNode manages this view instead of the layout manager (it can be any node in the scene)
        self.viewOwnerNode = slicer.mrmlScene.AddNewNodeByClass(
            "vtkMRMLScriptedModuleNode")
        self.viewNode = slicer.vtkMRMLViewNode()
        self.viewNode.SetName(self.layoutName)
        self.viewNode.SetLayoutName(self.layoutName)
        self.viewNode.SetLayoutColor(1, 1, 0)
        self.viewNode.SetAndObserveParentLayoutNodeID(
            self.viewOwnerNode.GetID())
        self.viewNode = slicer.mrmlScene.AddNode(self.viewNode)
        self.viewWidget = slicer.qMRMLThreeDWidget()
        self.viewWidget.setMRMLScene(slicer.mrmlScene)
        self.viewWidget.setMRMLViewNode(self.viewNode)
        self.viewWidget.show()

        # Get model displayable manager for the 3D view
        self.modelDisplayableManager = self.getModelDisplayableManager()
        self.assertIsNotNone(self.modelDisplayableManager)
  def _closeCase(self):
    _, mask, _, additionalMasks = self.currentCase
    if self.saveLoaded:
      if mask is not None:
        self.iterator.saveMask(mask, self.reader)
      for ma in additionalMasks:
        self.iterator.saveMask(ma, self.reader)
    if self.saveNew:
      nodes = [n for n in slicer.util.getNodesByClass('vtkMRMLSegmentationNode')
               if n not in additionalMasks and n != mask]
      for n in nodes:
        self.iterator.saveMask(n, self.reader)

    # Remove reference to current case, signalling it is closed
    self.currentCase = None

    # Close the scene and start a fresh one
    slicer.mrmlScene.Clear(0)

    if slicer.util.selectedModule() == 'SegmentEditor':
      slicer.modules.SegmentEditorWidget.exit()

    node = slicer.vtkMRMLViewNode()
    slicer.mrmlScene.AddNode(node)
#     \version   0.1
# */
# //==============================================================================
import slicer

# Load the scene first
slicer.util.loadScene(
    '/home/adnan/NewWorkingHamlynDemo/AnatomicalMRIRegisteredToDTI.mrml')

# Create a Widget for Right Window
#
#
layout_name_right = "Right_Window"
layout_label = "T3"
# Create MRML node
view_node_right = slicer.vtkMRMLViewNode()
view_node_right.SetName(layout_name_right)
view_node_right.SetLayoutName(layout_name_right)
view_node_right.SetLayoutLabel(layout_label)
view_node_right = slicer.mrmlScene.AddNode(view_node_right)
view_node_right.SetName(layout_name_right)

# Create widget
view_widget_right = slicer.qMRMLThreeDWidget()
view_widget_right.setMRMLScene(slicer.mrmlScene)
view_widget_right.setMRMLViewNode(view_node_right)
view_widget_right.setWindowTitle(
    layout_name_right)  # Make sure to name the window
view_widget_right.show()

# Create a Widget for Right Window