Ejemplo n.º 1
0
    def SaveProject(self, path=None, compress=False):
        Publisher.sendMessage('Begin busy cursor')
        session = ses.Session()
        if path:
            dirpath, filename = os.path.split(path)
        else:
            dirpath, filename = session.project_path

        if isinstance(filename, str):
            filename = utils.decode(filename, const.FS_ENCODE)

        proj = prj.Project()
        try:
            prj.Project().SavePlistProject(dirpath, filename, compress)
        except PermissionError as err:
            if wx.GetApp() is None:
                print(
                    "Error: Permission denied, you don't have permission to write at {}"
                    .format(dirpath))
            else:
                dlg = dialogs.ErrorMessageBox(
                    None, "Save project error",
                    "It was not possible to save because you don't have permission to write at {}\n{}"
                    .format(dirpath, err))
                dlg.ShowModal()
                dlg.Destroy()
        else:
            session.SaveProject((dirpath, filename))

        Publisher.sendMessage('End busy cursor')
Ejemplo n.º 2
0
    def OnTickTimer(self, evt):
        fmt = "%H:%M:%S"
        self.lbl_time.SetLabel(
            time.strftime(fmt, time.gmtime(time.time() - self.t0)))
        if self.ps is not None:
            if not self.ps.is_alive() and self.ps.exception is not None:
                error, traceback = self.ps.exception
                self.OnStop(None)
                self.HideProgress()
                dlg = dialogs.ErrorMessageBox(
                    None,
                    "Brain segmentation error",
                    "It was not possible to use brain segmentation because:" +
                    "\n" + str(error) + "\n" + traceback,
                    #  wx.ICON_ERROR | wx.OK,
                )
                dlg.ShowModal()
                return

            progress = self.ps.get_completion()
            if progress == np.Inf:
                progress = 1
                self.AfterSegment()
            if progress < 0:
                progress = 0
            if progress > 1:
                progress = 1
            self.SetProgress(float(progress))
Ejemplo n.º 3
0
    def OnSegment(self, evt):
        self.ShowProgress()
        self.t0 = time.time()
        self.elapsed_time_timer.Start(1000)
        image = slc.Slice().matrix
        backend = self.cb_backends.GetValue()
        if backend.lower() == "pytorch":
            try:
                device_id = self.torch_devices[self.cb_devices.GetValue()]
            except (KeyError, AttributeError):
                device_id = "cpu"
        else:
            try:
                device_id = self.plaidml_devices[self.cb_devices.GetValue()]
            except (KeyError, AttributeError):
                device_id = "llvm_cpu.0"
        apply_wwwl = self.chk_apply_wwwl.GetValue()
        create_new_mask = self.chk_new_mask.GetValue()
        use_gpu = self.chk_use_gpu.GetValue()
        prob_threshold = self.sld_threshold.GetValue() / 100.0
        self.btn_close.Disable()
        self.btn_stop.Enable()
        self.btn_segment.Disable()
        self.chk_new_mask.Disable()

        window_width = slc.Slice().window_width
        window_level = slc.Slice().window_level

        overlap = self.overlap_options[self.overlap.GetSelection()]

        try:
            self.ps = self.segmenter(
                image,
                create_new_mask,
                backend,
                device_id,
                use_gpu,
                overlap,
                apply_wwwl,
                window_width,
                window_level,
            )
            self.ps.start()
        except (multiprocessing.ProcessError, OSError, ValueError) as err:
            self.OnStop(None)
            self.HideProgress()
            dlg = dialogs.ErrorMessageBox(
                None,
                "It was not possible to start brain segmentation because:" +
                "\n" + str(err),
                "Brain segmentation error",
                #  wx.ICON_ERROR | wx.OK,
            )
            dlg.ShowModal()
Ejemplo n.º 4
0
    def OnExportSurface(self, filename, filetype):
        ftype_prefix = {
            const.FILETYPE_STL: '.stl',
            const.FILETYPE_VTP: '.vtp',
            const.FILETYPE_PLY: '.ply',
            const.FILETYPE_STL_ASCII: '.stl',
        }
        if filetype in ftype_prefix:
            temp_file = tempfile.mktemp(suffix=ftype_prefix[filetype])

            if _has_win32api:
                utl.touch(temp_file)
                _temp_file = temp_file
                temp_file = win32api.GetShortPathName(temp_file)
                os.remove(_temp_file)

            temp_file = utl.decode(temp_file, const.FS_ENCODE)
            try:
                self._export_surface(temp_file, filetype)
            except ValueError:
                if wx.GetApp() is None:
                    print(
                        "It was not possible to export the surface because the surface is empty"
                    )
                else:
                    wx.MessageBox(
                        _("It was not possible to export the surface because the surface is empty"
                          ), _("Export surface error"))
                return

            try:
                shutil.move(temp_file, filename)
            except PermissionError as err:
                dirpath = os.path.split(filename)[0]
                if wx.GetApp() is None:
                    print(
                        _("It was not possible to export the surface because you don't have permission to write to {} folder: {}"
                          .format(dirpath, err)))
                else:
                    dlg = dialogs.ErrorMessageBox(
                        None, _("Export surface error"),
                        "It was not possible to export the surface because you don't have permission to write to {}:\n{}"
                        .format(dirpath, err))
                    dlg.ShowModal()
                    dlg.Destroy()
                os.remove(temp_file)