def SetThresholdModes(self, thresh_modes_names, default_thresh): self.combo_thresh.SetItems(thresh_modes_names) self.threshold_modes_names = thresh_modes_names proj = Project() if isinstance(default_thresh, int): self.combo_thresh.SetSelection(default_thresh) (thresh_min, thresh_max) =\ self.threshold_modes[thresh_modes_names[default_thresh]] elif default_thresh in proj.threshold_modes.keys(): index = self.threshold_modes_names.index(default_thresh) self.combo_thresh.SetSelection(index) thresh_min, thresh_max = self.threshold_modes[default_thresh] elif default_thresh in proj.threshold_modes.values(): preset_name = proj.threshold_modes.get_key(default_thresh)[0] index = self.threshold_modes_names.index(preset_name) self.combo_thresh.SetSelection(index) thresh_min, thresh_max = default_thresh else: index = self.threshold_modes_names.index(_("Custom")) self.combo_thresh.SetSelection(index) thresh_min, thresh_max = default_thresh proj.threshold_modes[_("Custom")] = (thresh_min, thresh_max) self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max)
def SetThresholdValues2(self, threshold_range): thresh_min, thresh_max = threshold_range self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) thresh = (thresh_min, thresh_max) if thresh in Project().threshold_modes.values(): preset_name = Project().threshold_modes.get_key(thresh)[0] index = self.threshold_modes_names.index(preset_name) self.combo_thresh.SetSelection(index) else: index = self.threshold_modes_names.index(_("Custom")) self.combo_thresh.SetSelection(index) Project().threshold_modes[_("Custom")] = (thresh_min, thresh_max)
def check_for_export(options, suffix='', remove_surfaces=False): suffix = sanitize(suffix) if options.export: if not options.threshold: print("Need option --threshold when using --export.") exit(1) threshold_range = tuple([int(n) for n in options.threshold.split(',')]) if suffix: if options.export.endswith('.stl'): path_ = '{}-{}.stl'.format(options.export[:-4], suffix) else: path_ = '{}-{}.stl'.format(options.export, suffix) else: path_ = options.export export(path_, threshold_range, remove_surface=remove_surfaces) elif options.export_to_all: # noinspection PyBroadException try: from invesalius.project import Project for threshold_name, threshold_range in Project( ).presets.thresh_ct.iteritems(): if isinstance(threshold_range[0], int): path_ = u'{}-{}-{}.stl'.format(options.export_to_all, suffix, threshold_name) export(path_, threshold_range, remove_surface=True) except: traceback.print_exc() finally: exit(0)
def SetThresholdValues(self, pubsub_evt): thresh_min, thresh_max = pubsub_evt.data self.bind_evt_gradient = False self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) self.bind_evt_gradient = True thresh = (thresh_min, thresh_max) if thresh in Project().threshold_modes.values(): preset_name = Project().threshold_modes.get_key(thresh)[0] index = self.threshold_modes_names.index(preset_name) self.combo_thresh.SetSelection(index) else: index = self.threshold_modes_names.index(_("Custom")) self.combo_thresh.SetSelection(index) Project().threshold_modes[_("Custom")] = (thresh_min, thresh_max)
def new_name_by_pattern(pattern): from invesalius.project import Project proj = Project() mask_dict = proj.mask_dict names_list = [i.name for i in mask_dict.values() if i.name.startswith(pattern + "_")] count = len(names_list) + 1 return "{}_{}".format(pattern, count)
def check_for_export(args, suffix='', remove_surfaces=False): suffix = sanitize(suffix) if args.export: if not args.threshold: print("Need option --threshold when using --export.") exit(1) threshold_range = tuple([int(n) for n in args.threshold.split(',')]) if suffix: if args.export.endswith('.stl'): path_ = '{}-{}.stl'.format(args.export[:-4], suffix) else: path_ = '{}-{}.stl'.format(args.export, suffix) else: path_ = args.export export(path_, threshold_range, remove_surface=remove_surfaces) elif args.export_to_all: # noinspection PyBroadException try: from invesalius.project import Project for threshold_name, threshold_range in Project( ).presets.thresh_ct.items(): if isinstance(threshold_range[0], int): path_ = u'{}-{}-{}.stl'.format(args.export_to_all, suffix, threshold_name) export(path_, threshold_range, remove_surface=True) except: traceback.print_exc() finally: exit(0) if args.export_project: from invesalius.project import Project prj = Project() export_filename = args.export_project if suffix: export_filename, ext = os.path.splitext(export_filename) export_filename = u'{}-{}{}'.format(export_filename, suffix, ext) prj.export_project(export_filename, save_masks=args.save_masks) print("Saved {}".format(export_filename))
def check_for_export(options, suffix='', remove_surfaces=False): suffix = sanitize(suffix) if options.export: if not options.threshold: print("Need option --threshold when using --export.") exit(1) threshold_range = tuple([int(n) for n in options.threshold.split(',')]) if suffix: if options.export.endswith('.stl'): path_ = '{}-{}.stl'.format(options.export[:-4], suffix) else: path_ = '{}-{}.stl'.format(options.export, suffix) else: path_ = options.export export(path_, threshold_range, remove_surface=remove_surfaces) elif options.export_to_all: # noinspection PyBroadException try: from invesalius.project import Project for threshold_name, threshold_range in Project().presets.thresh_ct.iteritems(): if isinstance(threshold_range[0], int): path_ = u'{}-{}-{}.stl'.format(options.export_to_all, suffix, threshold_name) export(path_, threshold_range, remove_surface=True) except: traceback.print_exc() finally: exit(0) if options.export_project: from invesalius.project import Project prj = Project() export_filename = options.export_project if suffix: export_filename, ext = os.path.splitext(export_filename) export_filename = u'{}-{}{}'.format(export_filename, suffix, ext) prj.export_project(export_filename, save_masks=options.save_masks) print("Saved {}".format(export_filename))
def OnButtonNextTask(self, evt): overwrite = self.check_box.IsChecked() algorithm = 'Default' options = {} to_generate = True if self.GetMaskSelected() != -1: sl = slice_.Slice() if sl.current_mask.was_edited: dlgs = dlg.SurfaceDialog() if dlgs.ShowModal() == wx.ID_OK: algorithm = dlgs.GetAlgorithmSelected() options = dlgs.GetOptions() else: to_generate = False dlgs.Destroy() if to_generate: proj = Project() for idx in proj.mask_dict: if proj.mask_dict[idx] is sl.current_mask: mask_index = idx break else: return method = {'algorithm': algorithm, 'options': options} srf_options = { "index": mask_index, "name": '', "quality": _('Optimal *'), "fill": False, "keep_largest": False, "overwrite": overwrite } Publisher.sendMessage('Create surface from index', surface_parameters={ 'method': method, 'options': srf_options }) Publisher.sendMessage('Fold surface task') else: dlg.InexistentMask()
def OnComboThresh(self, evt): (thresh_min, thresh_max) = Project().threshold_modes[evt.GetString()] self.gradient.SetMinValue(thresh_min) self.gradient.SetMaxValue(thresh_max) self.OnSlideChanging(None) self.OnSlideChanged(None)
def __init__(self, parent): wx.Panel.__init__(self, parent) ## LINE 1 # Combo related to mask naem combo_mask_name = wx.ComboBox(self, -1, "", choices=MASK_LIST, style=wx.CB_DROPDOWN | wx.CB_READONLY) #combo_mask_name.SetSelection(0) # wx.CB_SORT if sys.platform != 'win32': combo_mask_name.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.combo_mask_name = combo_mask_name # Mask colour button_colour = csel.ColourSelect(self, 111, colour=(0, 255, 0), size=(22, -1)) self.button_colour = button_colour # Sizer which represents the first line line1 = wx.BoxSizer(wx.HORIZONTAL) line1.Add(combo_mask_name, 1, wx.EXPAND | wx.GROW | wx.TOP | wx.RIGHT, 2) line1.Add(button_colour, 0, wx.TOP | wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 2) ### LINE 2 text_thresh = wx.StaticText(self, -1, _("Set predefined or manual threshold:")) ### LINE 3 THRESHOLD_LIST = [ "", ] combo_thresh = wx.ComboBox( self, -1, "", #size=(15,-1), choices=THRESHOLD_LIST, style=wx.CB_DROPDOWN | wx.CB_READONLY) combo_thresh.SetSelection(0) if sys.platform != 'win32': combo_thresh.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) self.combo_thresh = combo_thresh ## LINE 4 gradient = grad.GradientCtrl(self, -1, -5000, 5000, 0, 5000, (0, 255, 0, 100)) self.gradient = gradient # Add all lines into main sizer sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSpacer(7) sizer.Add(line1, 0, wx.GROW | wx.EXPAND | wx.LEFT | wx.RIGHT, 5) sizer.AddSpacer(5) sizer.Add(text_thresh, 0, wx.GROW | wx.EXPAND | wx.LEFT | wx.RIGHT, 5) sizer.AddSpacer(2) sizer.Add(combo_thresh, 0, wx.EXPAND | wx.GROW | wx.LEFT | wx.RIGHT, 5) sizer.AddSpacer(5) sizer.Add(gradient, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 5) sizer.AddSpacer(7) sizer.Fit(self) self.SetSizerAndFit(sizer) self.Update() self.SetAutoLayout(1) # Non GUI stuff proj = Project() self.threshold_modes = proj.threshold_modes self.threshold_modes_names = [] self.bind_evt_gradient = True self.__bind_events() self.__bind_events_wx()