コード例 #1
0
ファイル: DICOMBrowser.py プロジェクト: neuracle/Slicer
    def getLoadablesFromFileLists(self, fileLists):
        """Take list of file lists, return loadables by plugin dictionary
    """

        loadablesByPlugin = {}
        loadEnabled = False

        allFileCount = missingFileCount = 0
        for fileList in fileLists:
            for filePath in fileList:
                allFileCount += 1
                if not os.path.exists(filePath):
                    missingFileCount += 1

        if missingFileCount > 0:
            messages.appendslicer.util.warningDisplay(
                "Warning: %d of %d selected files listed in the database cannot be found on disk."
                % (missingFileCount, allFileCount),
                windowTitle="DICOM")

        if missingFileCount == allFileCount:
            # Nothing to load
            return loadablesByPlugin, loadEnabled

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

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

        messages = []
        loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists(
            fileLists,
            self.pluginSelector.selectedPlugins(),
            messages,
            lambda progressLabel, progressValue, progressDialog=progressDialog:
            progressCallback(progressDialog, progressLabel, progressValue),
            self.pluginInstances)

        progressDialog.close()

        if messages:
            slicer.util.warningDisplay(
                "Warning: %s\n\nSee python console for error message." %
                ' '.join(messages),
                windowTitle="DICOM",
                parent=self)

        return loadablesByPlugin, loadEnabled
コード例 #2
0
    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)
コード例 #3
0
ファイル: DICOMBrowser.py プロジェクト: Leengit/Slicer
    def getLoadablesFromFileLists(self, fileLists):
        """Take list of file lists, return loadables by plugin dictionary
        """

        loadablesByPlugin = {}
        loadEnabled = False

        # Get selected plugins from application settings
        # Settings are filled in DICOMWidget using DICOMPluginSelector
        settings = qt.QSettings()
        selectedPlugins = []
        if settings.contains('DICOM/disabledPlugins/size'):
            size = settings.beginReadArray('DICOM/disabledPlugins')
            disabledPlugins = []

            for i in range(size):
                settings.setArrayIndex(i)
                disabledPlugins.append(str(settings.allKeys()[0]))
            settings.endArray()

            for pluginClass in slicer.modules.dicomPlugins:
                if pluginClass not in disabledPlugins:
                    selectedPlugins.append(pluginClass)
        else:
            # All DICOM plugins would be enabled by default
            for pluginClass in slicer.modules.dicomPlugins:
                selectedPlugins.append(pluginClass)

        allFileCount = missingFileCount = 0
        for fileList in fileLists:
            for filePath in fileList:
                allFileCount += 1
                if not os.path.exists(filePath):
                    missingFileCount += 1

        messages = []
        if missingFileCount > 0:
            messages.append(
                "Warning: %d of %d selected files listed in the database cannot be found on disk."
                % (missingFileCount, allFileCount))

        if missingFileCount < allFileCount:
            progressDialog = slicer.util.createProgressDialog(parent=self,
                                                              value=0,
                                                              maximum=100)

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

            loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists(
                fileLists,
                selectedPlugins,
                messages,
                lambda progressLabel, progressValue,
                progressDialog=progressDialog: progressCallback(
                    progressDialog, progressLabel, progressValue),
                self.pluginInstances)

            progressDialog.close()

        if messages:
            slicer.util.warningDisplay(
                "Warning: %s\n\nSee python console for error message." %
                ' '.join(messages),
                windowTitle="DICOM",
                parent=self)

        return loadablesByPlugin, loadEnabled