コード例 #1
0
    def section_AddNodeToSubjectHierarchy(self):
        self.delayDisplay("Add node to subject hierarchy", self.delayMs)

        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode
        import qSlicerSubjectHierarchyModuleWidgetsPythonQt

        # Get volume previously loaded from DICOM
        ctVolumeNode = slicer.util.getNode('vtkMRMLScalarVolumeNode*')
        self.assertTrue(ctVolumeNode != None)

        # Create sample labelmap and model and add them in subject hierarchy
        sampleLabelmapNode = self.createSampleLabelmapVolumeNode(
            ctVolumeNode, self.sampleLabelmapName, 2)

        sampleModelColor = [0.0, 1.0, 0.0]
        sampleModelNode = self.createSampleModelVolume(ctVolumeNode,
                                                       self.sampleModelName,
                                                       sampleModelColor)

        # Get subject hierarchy scene model
        subjectHierarchyWidget = slicer.modules.subjecthierarchy.widgetRepresentation(
        )
        self.assertTrue(subjectHierarchyWidget != None)
        subjectHierarchySceneModel = subjectHierarchyWidget.subjectHierarchySceneModel(
        )
        self.assertTrue(subjectHierarchySceneModel != None)

        # Get study node
        ctVolumeShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            ctVolumeNode)
        self.assertTrue(ctVolumeShNode != None)
        studyNode = ctVolumeShNode.GetParentNode()
        self.assertTrue(studyNode != None)

        # Verify DICOM levels
        self.assertTrue(studyNode.GetParentNode().GetLevel() == 'Subject')
        self.assertTrue(studyNode.GetLevel() == 'Study')
        self.assertTrue(ctVolumeShNode.GetLevel() == 'Series')

        # Add model and labelmap to the created study
        subjectHierarchySceneModel.reparent(sampleLabelmapNode, studyNode)
        subjectHierarchySceneModel.reparent(sampleModelNode, studyNode)

        sampleLabelmapShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            sampleLabelmapNode)
        self.assertTrue(sampleLabelmapShNode != None)
        self.assertTrue(sampleLabelmapShNode.GetParentNode() == studyNode)
        self.assertTrue(sampleLabelmapShNode.GetOwnerPluginName() == 'Volumes')

        sampleModelShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            sampleModelNode)
        self.assertTrue(sampleModelShNode != None)
        self.assertTrue(sampleModelShNode.GetParentNode() == studyNode)
        self.assertTrue(sampleModelShNode.GetOwnerPluginName() == 'Models')
コード例 #2
0
    def section_AddNodeToSubjectHierarchy(self):
        self.delayDisplay("Add node to subject hierarchy", self.delayMs)

        from vtkSlicerSubjectHierarchyModuleMRML import vtkMRMLSubjectHierarchyNode
        import qSlicerSubjectHierarchyModuleWidgetsPythonQt

        # Get volume previously loaded from DICOM
        ctVolumeNode = slicer.util.getNode('vtkMRMLScalarVolumeNode*')
        self.assertIsNotNone(ctVolumeNode)

        # Create sample labelmap and model and add them in subject hierarchy
        sampleLabelmapNode = self.createSampleLabelmapVolumeNode(
            ctVolumeNode, self.sampleLabelmapName, 2)
        sampleModelColor = [0.0, 1.0, 0.0]
        sampleModelNode = self.createSampleModelVolume(self.sampleModelName,
                                                       sampleModelColor,
                                                       ctVolumeNode)

        # Get subject hierarchy scene model
        subjectHierarchyWidget = slicer.modules.subjecthierarchy.widgetRepresentation(
        )
        self.assertIsNotNone(subjectHierarchyWidget)
        subjectHierarchySceneModel = subjectHierarchyWidget.subjectHierarchySceneModel(
        )
        self.assertIsNotNone(subjectHierarchySceneModel)

        # Get subject hierarchy nodes and study node
        ctVolumeShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            ctVolumeNode)
        self.assertIsNotNone(ctVolumeShNode)
        sampleLabelmapShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            sampleLabelmapNode)
        self.assertIsNotNone(sampleLabelmapShNode)
        sampleModelShNode = vtkMRMLSubjectHierarchyNode.GetAssociatedSubjectHierarchyNode(
            sampleModelNode)
        self.assertIsNotNone(sampleModelShNode)
        studyNode = ctVolumeShNode.GetParentNode()
        self.assertIsNotNone(studyNode)

        # Save node names for scene load testing
        self.patientNodeName = studyNode.GetParentNode().GetName()
        self.studyNodeName = studyNode.GetName()
        self.ctVolumeShNodeName = ctVolumeShNode.GetName()

        # Verify DICOM levels
        self.assertEqual(
            studyNode.GetParentNode().GetLevel(),
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelPatient())
        self.assertEqual(
            studyNode.GetLevel(),
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelStudy())
        self.assertEqual(
            ctVolumeShNode.GetLevel(),
            slicer.vtkMRMLSubjectHierarchyConstants.GetDICOMLevelSeries())

        # Add model and labelmap to the created study
        subjectHierarchySceneModel.reparent(sampleLabelmapShNode, studyNode)
        subjectHierarchySceneModel.reparent(sampleModelShNode, studyNode)
        qt.QApplication.processEvents()

        self.assertEqual(sampleLabelmapShNode.GetParentNode(), studyNode)
        self.assertEqual(sampleLabelmapShNode.GetOwnerPluginName(),
                         'LabelMaps')

        self.assertEqual(sampleModelShNode.GetParentNode(), studyNode)
        self.assertEqual(sampleModelShNode.GetOwnerPluginName(), 'Models')