示例#1
0
  def section_LoadDicomDataWitchBatchProcessing(self):
    try:
      # Open Data module so that a subject hierarchy scene model is active
      # (which caused problems with batch processing)
      slicer.util.selectModule('Data')

      # Open test database and empty it
      with DICOMUtils.TemporaryDICOMDatabase(self.dicomDatabaseDir) as db:
        self.assertTrue( db.isOpen )
        self.assertEqual( slicer.dicomDatabase, db)

        slicer.mrmlScene.StartState(slicer.vtkMRMLScene.BatchProcessState)

        # Download, unzip, import, and load data. Verify loaded nodes.
        loadedNodes = {'vtkMRMLScalarVolumeNode':1}
        with DICOMUtils.LoadDICOMFilesToDatabase( \
            self.dicomZipFileUrl, self.dicomZipFilePath, \
            self.dicomDataDir, self.expectedNumOfFilesInDicomDataDir, \
            {}, loadedNodes, checksum=self.dicomZipChecksum) as success:
          self.assertTrue(success)

        slicer.mrmlScene.EndState(slicer.vtkMRMLScene.BatchProcessState)

      self.assertEqual( len( slicer.util.getNodes('vtkMRMLSubjectHierarchyNode*') ), 1 )

      shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
      self.assertIsNotNone( shNode )
      loadedDicomVolumeItemID = shNode.GetItemByName(self.loadedDicomVolumeName)
      loadedDicomStudyItemID = shNode.GetItemByName(self.loadedDicomStudyName)
      self.assertEqual( shNode.GetItemParent(loadedDicomVolumeItemID), loadedDicomStudyItemID )

    except Exception as e:
      import traceback
      traceback.print_exc()
      self.delayDisplay('Test caused exception!\n' + str(e),self.delayMs*2)
示例#2
0
    def loadTestData(self):
        #download data and add to dicom database
        zipFileUrl = 'http://slicer.kitware.com/midas3/download/item/257234/QIN-HEADNECK-01-0139-PET.zip'
        zipFilePath = self.tempDataDir + '/dicom.zip'
        zipFileData = self.tempDataDir + '/dicom'
        expectedNumOfFiles = 545
        if not os.access(self.tempDataDir, os.F_OK):
            os.mkdir(self.tempDataDir)
        if not os.access(zipFileData, os.F_OK):
            os.mkdir(zipFileData)

        dicomWidget = slicer.modules.dicom.widgetRepresentation().self()
        dicomPluginCheckbox = dicomWidget.detailsPopup.pluginSelector.checkBoxByPlugin
        dicomPluginStates = {(key, value.checked)
                             for key, value in dicomPluginCheckbox.iteritems()}
        for cb in dicomPluginCheckbox.itervalues():
            cb.checked = False
        dicomPluginCheckbox['DICOMScalarVolumePlugin'].checked = True

        # Download, unzip, import, and load data. Verify loaded nodes.
        loadedNodes = {'vtkMRMLScalarVolumeNode': 1}
        with DICOMUtils.LoadDICOMFilesToDatabase(zipFileUrl, zipFilePath,
                                                 zipFileData,
                                                 expectedNumOfFiles, {},
                                                 loadedNodes) as success:
            self.assertTrue(success)
            print('loading returned true')

        self.assertEqual(
            len(slicer.util.getNodes('vtkMRMLSubjectHierarchyNode*')), 1)
        imageNode = slicer.mrmlScene.GetFirstNodeByClass(
            'vtkMRMLScalarVolumeNode')

        for key, value in dicomPluginStates:
            dicomPluginCheckbox[key].checked = value

        # apply the SUVbw conversion factor and set units and quantity
        suvNormalizationFactor = 0.00040166400000000007
        quantity = slicer.vtkCodedEntry()
        quantity.SetFromString(
            'CodeValue:126400|CodingSchemeDesignator:DCM|CodeMeaning:Standardized Uptake Value'
        )
        units = slicer.vtkCodedEntry()
        units.SetFromString(
            'CodeValue:{SUVbw}g/ml|CodingSchemeDesignator:UCUM|CodeMeaning:Standardized Uptake Value body weight'
        )
        multiplier = vtk.vtkImageMathematics()
        multiplier.SetOperationToMultiplyByK()
        multiplier.SetConstantK(suvNormalizationFactor)
        multiplier.SetInput1Data(imageNode.GetImageData())
        multiplier.Update()
        imageNode.GetImageData().DeepCopy(multiplier.GetOutput())
        imageNode.GetVolumeDisplayNode().SetWindowLevel(6, 3)
        imageNode.GetVolumeDisplayNode().SetAndObserveColorNodeID(
            'vtkMRMLColorTableNodeInvertedGrey')
        imageNode.SetVoxelValueQuantity(quantity)
        imageNode.SetVoxelValueUnits(units)

        return imageNode
示例#3
0
  def TestSection_1_LoadDicomData(self):
    try:
      self.assertTrue( self.db.isOpen )
      self.assertEqual( slicer.dicomDatabase, self.db)

      # Download, unzip, import, and load data. Verify selected plugins and loaded nodes.
      selectedPlugins = { 'Scalar Volume':1, 'RT':2 }
      loadedNodes = { 'vtkMRMLScalarVolumeNode':2, \
                      'vtkMRMLSegmentationNode':1 }
      with DICOMUtils.LoadDICOMFilesToDatabase( \
          self.dicomZipFileUrl, self.dicomZipFilePath, \
          self.dicomDataDir, self.expectedNumOfFilesInDicomDataDir, \
          {}, loadedNodes) as success:
        self.assertTrue(success)

    except Exception as e:
      import traceback
      traceback.print_exc()
      self.delayDisplay('Test caused exception!\n' + str(e),self.delayMs*2)
  def section_LoadDicomData(self):
    try:
      # Open test database and empty it
      with DICOMUtils.TemporaryDICOMDatabase(self.dicomDatabaseDir) as db:
        self.assertTrue( db.isOpen )
        self.assertEqual( slicer.dicomDatabase, db)

        # Download, unzip, import, and load data. Verify loaded nodes.
        loadedNodes = {'vtkMRMLScalarVolumeNode':1}
        with DICOMUtils.LoadDICOMFilesToDatabase( \
            self.dicomZipFileUrl, self.dicomZipFilePath, \
            self.dicomDataDir, self.expectedNumOfFilesInDicomDataDir, \
            {}, loadedNodes, checksum=self.dicomZipChecksum) as success:
          self.assertTrue(success)

      self.assertEqual( len( slicer.util.getNodes('vtkMRMLSubjectHierarchyNode*') ), 1 )

    except Exception as e:
      import traceback
      traceback.print_exc()
      self.delayDisplay('Test caused exception!\n' + str(e),self.delayMs*2)