Commit 0354b116abaceb19c785866b2db19aebd3cc5410

Authored by tatiana
1 parent def86810

FIX: Threshold bounds (fix #54)/ combo-gradient consistency

invesalius/control.py
@@ -427,11 +427,20 @@ class Controller(): @@ -427,11 +427,20 @@ class Controller():
427 427
428 thresh_modes = proj.threshold_modes.keys() 428 thresh_modes = proj.threshold_modes.keys()
429 thresh_modes.sort() 429 thresh_modes.sort()
430 -  
431 default_threshold = const.THRESHOLD_PRESETS_INDEX 430 default_threshold = const.THRESHOLD_PRESETS_INDEX
432 if proj.mask_dict: 431 if proj.mask_dict:
433 - last = max(proj.mask_dict.keys())  
434 - default_threshold = proj.mask_dict[last].threshold_range 432 + keys = proj.mask_dict.keys()
  433 + last = max(keys)
  434 + (a,b) = proj.mask_dict[last].threshold_range
  435 + default_threshold = [a,b]
  436 + min_ = proj.threshold_range[0]
  437 + max_ = proj.threshold_range[1]
  438 + if default_threshold[0] < min_:
  439 + default_threshold[0] = min_
  440 + if default_threshold[1] > max_:
  441 + default_threshold[1] = max_
  442 + [a,b] = default_threshold
  443 + default_threshold = (a,b)
435 ps.Publisher().sendMessage('Set threshold modes', 444 ps.Publisher().sendMessage('Set threshold modes',
436 (thresh_modes,default_threshold)) 445 (thresh_modes,default_threshold))
437 446
invesalius/gui/task_slice.py
@@ -336,10 +336,12 @@ class MaskProperties(wx.Panel): @@ -336,10 +336,12 @@ class MaskProperties(wx.Panel):
336 336
337 proj = Project() 337 proj = Project()
338 self.threshold_modes = proj.threshold_modes 338 self.threshold_modes = proj.threshold_modes
  339 + self.threshold_modes_names = []
339 self.bind_evt_gradient = True 340 self.bind_evt_gradient = True
340 self.__bind_events() 341 self.__bind_events()
341 self.__bind_events_wx() 342 self.__bind_events_wx()
342 343
  344 +
343 def __bind_events(self): 345 def __bind_events(self):
344 ps.Publisher().subscribe(self.AddMask, 'Add mask') 346 ps.Publisher().subscribe(self.AddMask, 'Add mask')
345 # TODO: Uncomment 347 # TODO: Uncomment
@@ -352,6 +354,7 @@ class MaskProperties(wx.Panel): @@ -352,6 +354,7 @@ class MaskProperties(wx.Panel):
352 ps.Publisher().subscribe(self.SelectMaskName, 'Select mask name in combo') 354 ps.Publisher().subscribe(self.SelectMaskName, 'Select mask name in combo')
353 ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name') 355 ps.Publisher().subscribe(self.ChangeMaskName, 'Change mask name')
354 ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') 356 ps.Publisher().subscribe(self.OnCloseProject, 'Close project data')
  357 + ps.Publisher().subscribe(self.SetThresholdValues2, 'Set threshold values')
355 358
356 def OnCloseProject(self, pubsub_evt): 359 def OnCloseProject(self, pubsub_evt):
357 self.CloseProject() 360 self.CloseProject()
@@ -387,6 +390,19 @@ class MaskProperties(wx.Panel): @@ -387,6 +390,19 @@ class MaskProperties(wx.Panel):
387 self.gradient.SetMaxValue(thresh_max) 390 self.gradient.SetMaxValue(thresh_max)
388 self.bind_evt_gradient = True 391 self.bind_evt_gradient = True
389 392
  393 + def SetThresholdValues2(self, pubsub_evt):
  394 + thresh_min, thresh_max = pubsub_evt.data
  395 + self.gradient.SetMinValue(thresh_min)
  396 + self.gradient.SetMaxValue(thresh_max)
  397 + thresh = (thresh_min, thresh_max)
  398 + if thresh in Project().presets.thresh_ct.values():
  399 + preset_name = Project().presets.thresh_ct.get_key(thresh)[0]
  400 + index = self.threshold_modes_names.index(preset_name)
  401 + self.combo_thresh.SetSelection(index)
  402 + else:
  403 + index = self.threshold_modes_names.index(_("Custom"))
  404 + self.combo_thresh.SetSelection(index)
  405 +
390 def SetItemsColour(self, evt_pubsub): 406 def SetItemsColour(self, evt_pubsub):
391 colour = evt_pubsub.data 407 colour = evt_pubsub.data
392 self.gradient.SetColour(colour) 408 self.gradient.SetColour(colour)
@@ -408,17 +424,24 @@ class MaskProperties(wx.Panel): @@ -408,17 +424,24 @@ class MaskProperties(wx.Panel):
408 424
409 def SetThresholdModes(self, pubsub_evt): 425 def SetThresholdModes(self, pubsub_evt):
410 (thresh_modes_names, default_thresh) = pubsub_evt.data 426 (thresh_modes_names, default_thresh) = pubsub_evt.data
411 - print pubsub_evt.data  
412 self.combo_thresh.SetItems(thresh_modes_names) 427 self.combo_thresh.SetItems(thresh_modes_names)
  428 + self.threshold_modes_names = thresh_modes_names
  429 + proj = Project()
  430 +
413 if isinstance(default_thresh, int): 431 if isinstance(default_thresh, int):
414 self.combo_thresh.SetSelection(default_thresh) 432 self.combo_thresh.SetSelection(default_thresh)
415 (thresh_min, thresh_max) =\ 433 (thresh_min, thresh_max) =\
416 self.threshold_modes[thresh_modes_names[default_thresh]] 434 self.threshold_modes[thresh_modes_names[default_thresh]]
  435 + elif default_thresh in proj.presets.thresh_ct.values():
  436 + preset_name = proj.presets.thresh_ct.get_key(default_thresh)[0]
  437 + index = self.threshold_modes_names.index(preset_name)
  438 + self.combo_thresh.SetSelection(index)
  439 + thresh_min, thresh_max = default_thresh
417 else: 440 else:
418 - self.combo_thresh.SetSelection(3)  
419 - thresh_min, thresh_max = default_thresh 441 + index = self.threshold_modes_names.index(_("Custom"))
  442 + self.combo_thresh.SetSelection(index)
  443 + thresh_min, thresh_max = default_thresh
420 444
421 - print "Este e threshold", thresh_min, thresh_max  
422 self.gradient.SetMinValue(thresh_min) 445 self.gradient.SetMinValue(thresh_min)
423 self.gradient.SetMaxValue(thresh_max) 446 self.gradient.SetMaxValue(thresh_max)
424 447