Example #1
0
  def proceedWithReferencedLoadablesSelection(self):
    if not self.warnUserIfLoadableWarningsAndProceed():
      return

    progressDialog = slicer.util.createProgressDialog(parent=self, value=0, maximum=100)

    def progressCallback(progressDialog, progressLabel, progressValue):
      progressDialog.labelText = '\nLoading %s' % progressLabel
      slicer.app.processEvents()
      progressDialog.setValue(progressValue)
      slicer.app.processEvents()
      cancelled = progressDialog.wasCanceled
      return cancelled

    qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)

    messages = []
    loadedNodeIDs = DICOMLib.loadLoadables(self.loadablesByPlugin, messages,
      lambda progressLabel, progressValue, progressDialog=progressDialog: progressCallback(progressDialog, progressLabel, progressValue))

    loadedFileParameters = {}
    loadedFileParameters['nodeIDs'] = loadedNodeIDs
    slicer.app.ioManager().emitNewFileLoaded(loadedFileParameters)

    qt.QApplication.restoreOverrideCursor()

    progressDialog.close()

    if messages:
      slicer.util.warningDisplay('\n'.join(messages), windowTitle='DICOM loading')

    self.onLoadingFinished()
    def load_dicom_archive(self, file_path):
        """
        Load unzipped DICOMs into Slicer.

        Args:
            file_path (str): path to the cached dicom archive.

        https://discourse.slicer.org/t/fastest-way-to-load-dicom/9317/2
        """
        with tempfile.TemporaryDirectory() as dicomDataDir:
            dicom_zip = ZipFile(file_path)
            dicom_zip.extractall(path=dicomDataDir)
            DICOMLib.importDicom(dicomDataDir)
            dicomFiles = slicer.util.getFilesInDirectory(dicomDataDir)
            loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists([dicomFiles])
            loadedNodeIDs = DICOMLib.loadLoadables(loadablesByPlugin)