Esempio n. 1
0
    def write(self, properties):
        print("parent", self.parent)
        print("Write", properties)

        if (not "nodeID" in properties or not "fileName" in properties):
            logging.error(
                "Bad properties passed to MarkupsFcsvFileWriter.write")
            return False
        markupNode = slicer.mrmlScene.GetNodeByID(properties["nodeID"])
        if not markupNode or not self.canWriteObject(markupNode):
            logging.error(
                "Bad MarkupNode passed to MarkupsFcsvFileWriter.write")
            return False
        storageNode = slicer.vtkMRMLMarkupsFiducialStorageNode()
        slicer.mrmlScene.AddNode(storageNode)
        fileName = properties["fileName"]
        if fileName.endswith(".fcsv.fcsv"):
            fileName = fileName[:-5]
        properties["fileName"] = fileName
        storageNode.SetFileName(fileName)
        storageNode.SetURI(None)
        result = storageNode.WriteData(markupNode)
        if result:
            self.parent.writtenNodes = [markupNode.GetID()]
        return bool(result)
Esempio n. 2
0
    def section_CloneNode(self):
        self.delayDisplay("Clone node", self.delayMs)

        shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(
            slicer.mrmlScene)
        self.assertIsNotNone(shNode)

        markupsNode = slicer.util.getNode(self.sampleMarkupName)
        markupsShItemID = shNode.GetItemByDataNode(markupsNode)

        self.assertIsNotNone(markupsShItemID)
        self.assertIsNotNone(shNode.GetItemDataNode(markupsShItemID))

        # Add storage node for markups node to test cloning those
        markupsStorageNode = slicer.vtkMRMLMarkupsFiducialStorageNode()
        slicer.mrmlScene.AddNode(markupsStorageNode)
        markupsNode.SetAndObserveStorageNodeID(markupsStorageNode.GetID())

        # Get clone node plugin
        pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler().instance(
        )
        self.assertIsNotNone(pluginHandler)

        cloneNodePlugin = pluginHandler.pluginByName('CloneNode')
        self.assertIsNotNone(cloneNodePlugin)

        # Set markup node as current (i.e. selected in the tree) for clone
        pluginHandler.setCurrentItem(markupsShItemID)

        # Get clone node context menu action and trigger
        cloneNodePlugin.itemContextMenuActions()[0].activate(
            qt.QAction.Trigger)

        self.assertEqual(
            slicer.mrmlScene.GetNumberOfNodesByClass(
                'vtkMRMLMarkupsFiducialNode'), 2)
        self.assertEqual(
            slicer.mrmlScene.GetNumberOfNodesByClass(
                'vtkMRMLMarkupsDisplayNode'), 2)
        self.assertEqual(
            slicer.mrmlScene.GetNumberOfNodesByClass(
                'vtkMRMLMarkupsFiducialStorageNode'), 2)

        clonedMarkupsName = self.sampleMarkupName + self.cloneNodeNamePostfix
        clonedMarkupsNode = slicer.util.getNode(clonedMarkupsName)
        self.assertIsNotNone(clonedMarkupsNode)
        clonedMarkupsShItemID = shNode.GetItemChildWithName(
            self.studyItemID, clonedMarkupsName)
        self.assertIsNotNone(clonedMarkupsShItemID)
        self.assertIsNotNone(clonedMarkupsNode.GetDisplayNode())
        self.assertIsNotNone(clonedMarkupsNode.GetStorageNode())

        inSameStudy = slicer.vtkSlicerSubjectHierarchyModuleLogic.AreItemsInSameBranch(
            shNode, markupsShItemID, clonedMarkupsShItemID,
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy())
        self.assertTrue(inSameStudy)
    def section_CloneNode(self):
        self.delayDisplay("Clone node", self.delayMs)

        markupsShNode = slicer.util.getNode(
            self.sampleMarkupName + slicer.vtkMRMLSubjectHierarchyConstants.GetSubjectHierarchyNodeNamePostfix()
        )
        self.assertTrue(markupsShNode != None)
        markupsNode = markupsShNode.GetAssociatedNode()
        self.assertTrue(markupsNode != None)

        # Add storage node for markups node to test cloning those
        markupsStorageNode = slicer.vtkMRMLMarkupsFiducialStorageNode()
        slicer.mrmlScene.AddNode(markupsStorageNode)
        markupsNode.SetAndObserveStorageNodeID(markupsStorageNode.GetID())

        # Get clone node plugin
        import qSlicerSubjectHierarchyModuleWidgetsPythonQt

        subjectHierarchyWidget = slicer.modules.subjecthierarchy.widgetRepresentation()
        self.assertTrue(subjectHierarchyWidget != None)
        subjectHierarchyPluginLogic = subjectHierarchyWidget.pluginLogic()
        self.assertTrue(subjectHierarchyPluginLogic != None)

        cloneNodePlugin = subjectHierarchyPluginLogic.subjectHierarchyPluginByName("CloneNode")
        self.assertTrue(cloneNodePlugin != None)

        # Set markup node as current (i.e. selected in the tree) for clone
        subjectHierarchyPluginLogic.setCurrentSubjectHierarchyNode(markupsShNode)

        # Get clone node context menu action and trigger
        cloneNodePlugin.nodeContextMenuActions()[0].activate(qt.QAction.Trigger)

        self.assertTrue(slicer.mrmlScene.GetNumberOfNodesByClass("vtkMRMLMarkupsFiducialNode") == 2)
        self.assertTrue(slicer.mrmlScene.GetNumberOfNodesByClass("vtkMRMLMarkupsDisplayNode") == 2)
        self.assertTrue(slicer.mrmlScene.GetNumberOfNodesByClass("vtkMRMLMarkupsFiducialStorageNode") == 2)

        clonedMarkupShNode = slicer.util.getNode(
            self.sampleMarkupName
            + " Copy"
            + slicer.vtkMRMLSubjectHierarchyConstants.GetSubjectHierarchyNodeNamePostfix()
        )
        self.assertTrue(clonedMarkupShNode != None)
        clonedMarkupNode = clonedMarkupShNode.GetAssociatedNode()
        self.assertTrue(clonedMarkupNode != None)
        self.assertTrue(clonedMarkupNode.GetName != self.sampleMarkupName + " Copy")
        self.assertTrue(clonedMarkupNode.GetDisplayNode() != None)
        self.assertTrue(clonedMarkupNode.GetStorageNode() != None)

        from vtkSlicerSubjectHierarchyModuleLogic import vtkSlicerSubjectHierarchyModuleLogic

        inSameStudy = vtkSlicerSubjectHierarchyModuleLogic.AreNodesInSameBranch(
            markupsShNode, clonedMarkupShNode, slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy()
        )
        self.assertTrue(inSameStudy)
  def section_CloneNode(self):
    self.delayDisplay("Clone node",self.delayMs)

    shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
    self.assertIsNotNone( shNode )

    markupsNode = slicer.util.getNode(self.sampleMarkupName)
    markupsShItemID = shNode.GetItemByDataNode(markupsNode)

    self.assertIsNotNone( markupsShItemID )
    self.assertIsNotNone( shNode.GetItemDataNode(markupsShItemID) )

    # Add storage node for markups node to test cloning those
    markupsStorageNode = slicer.vtkMRMLMarkupsFiducialStorageNode()
    slicer.mrmlScene.AddNode(markupsStorageNode)
    markupsNode.SetAndObserveStorageNodeID(markupsStorageNode.GetID())

    # Get clone node plugin
    pluginHandler = slicer.qSlicerSubjectHierarchyPluginHandler().instance()
    self.assertIsNotNone( pluginHandler )

    cloneNodePlugin = pluginHandler.pluginByName('CloneNode')
    self.assertIsNotNone( cloneNodePlugin )

    # Set markup node as current (i.e. selected in the tree) for clone
    pluginHandler.setCurrentItem(markupsShItemID)

    # Get clone node context menu action and trigger
    cloneNodePlugin.itemContextMenuActions()[0].activate(qt.QAction.Trigger)

    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsFiducialNode'), 2 )
    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsDisplayNode'), 2 )
    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsFiducialStorageNode'), 2 )

    clonedMarkupsName = self.sampleMarkupName + self.cloneNodeNamePostfix
    clonedMarkupsNode = slicer.util.getNode(clonedMarkupsName)
    self.assertIsNotNone( clonedMarkupsNode )
    clonedMarkupsShItemID = shNode.GetItemChildWithName(self.studyItemID, clonedMarkupsName)
    self.assertIsNotNone( clonedMarkupsShItemID )
    self.assertIsNotNone( clonedMarkupsNode.GetDisplayNode() )
    self.assertIsNotNone( clonedMarkupsNode.GetStorageNode() )

    inSameStudy = slicer.vtkSlicerSubjectHierarchyModuleLogic.AreItemsInSameBranch(
      shNode, markupsShItemID, clonedMarkupsShItemID, slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy())
    self.assertTrue( inSameStudy )
  def section_CloneNode(self):
    self.delayDisplay("Clone node",self.delayMs)

    markupsShNode = slicer.util.getNode(self.sampleMarkupName + slicer.vtkMRMLSubjectHierarchyConstants.GetSubjectHierarchyNodeNamePostfix())
    self.assertIsNotNone( markupsShNode )
    markupsNode = markupsShNode.GetAssociatedNode()
    self.assertIsNotNone( markupsNode )

    # Add storage node for markups node to test cloning those
    markupsStorageNode = slicer.vtkMRMLMarkupsFiducialStorageNode()
    slicer.mrmlScene.AddNode(markupsStorageNode)
    markupsNode.SetAndObserveStorageNodeID(markupsStorageNode.GetID())

    # Get clone node plugin
    subjectHierarchyWidget = slicer.modules.subjecthierarchy.widgetRepresentation()
    self.assertIsNotNone( subjectHierarchyWidget )
    subjectHierarchyPluginLogic = subjectHierarchyWidget.pluginLogic()
    self.assertIsNotNone( subjectHierarchyPluginLogic )

    cloneNodePlugin = subjectHierarchyPluginLogic.subjectHierarchyPluginByName('CloneNode')
    self.assertIsNotNone( cloneNodePlugin )

    # Set markup node as current (i.e. selected in the tree) for clone
    subjectHierarchyPluginLogic.setCurrentSubjectHierarchyNode(markupsShNode)

    # Get clone node context menu action and trigger
    cloneNodePlugin.nodeContextMenuActions()[0].activate(qt.QAction.Trigger)

    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsFiducialNode'), 2 )
    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsDisplayNode'), 2 )
    self.assertEqual( slicer.mrmlScene.GetNumberOfNodesByClass('vtkMRMLMarkupsFiducialStorageNode'), 2 )

    clonedMarkupShNode = slicer.util.getNode(self.sampleMarkupName + self.cloneNodeNamePostfix + slicer.vtkMRMLSubjectHierarchyConstants.GetSubjectHierarchyNodeNamePostfix())
    self.assertIsNotNone( clonedMarkupShNode )
    clonedMarkupNode = clonedMarkupShNode.GetAssociatedNode()
    self.assertIsNotNone( clonedMarkupNode )
    self.assertEqual( clonedMarkupNode.GetName(), self.sampleMarkupName + self.cloneNodeNamePostfix )
    self.assertIsNotNone( clonedMarkupNode.GetDisplayNode() )
    self.assertIsNotNone( clonedMarkupNode.GetStorageNode() )

    inSameStudy = slicer.vtkSlicerSubjectHierarchyModuleLogic.AreNodesInSameBranch(markupsShNode, clonedMarkupShNode, slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy())
    self.assertTrue( inSameStudy )