Commit 14811233b42064ca742564c0ec197c837cfb46e8

Authored by Thiago Franco de Moraes
1 parent 46111ecb
Exists in watershed

Removing aux matrix when opening a new dicom dir

invesalius/control.py
... ... @@ -128,6 +128,11 @@ class Controller():
128 128 answer = dialog.SaveChangesDialog2(filename)
129 129 if answer:
130 130 self.ShowDialogSaveProject()
  131 + self.CloseProject()
  132 + #Publisher.sendMessage("Enable state project", False)
  133 + Publisher.sendMessage('Set project name')
  134 + Publisher.sendMessage("Stop Config Recording")
  135 + Publisher.sendMessage("Set slice interaction style", const.STATE_DEFAULT)
131 136 # Import project
132 137 dirpath = dialog.ShowImportDirDialog()
133 138 if dirpath and not os.listdir(dirpath):
... ...
invesalius/data/slice_.py
... ... @@ -246,6 +246,7 @@ class Slice(object):
246 246  
247 247 if (state == const.SLICE_STATE_EDITOR):
248 248 Publisher.sendMessage('Set interactor default cursor')
  249 + self.state = new_state
249 250  
250 251 def OnCloseProject(self, pubsub_evt):
251 252 self.CloseProject()
... ... @@ -258,9 +259,18 @@ class Slice(object):
258 259 os.remove(f)
259 260 self.current_mask = None
260 261  
  262 + for name in self.aux_matrices:
  263 + m = self.aux_matrices[name]
  264 + f = m.filename
  265 + m._mmap.close()
  266 + m = None
  267 + os.remove(f)
  268 + self.aux_matrices = {}
  269 +
261 270 self.values = None
262 271 self.nodes = None
263 272 self.from_= OTHER
  273 + self.state = const.STATE_DEFAULT
264 274  
265 275 self.number_of_colours = 256
266 276 self.saturation_range = (0, 0)
... ... @@ -392,7 +402,7 @@ class Slice(object):
392 402 def create_temp_mask(self):
393 403 temp_file = tempfile.mktemp()
394 404 shape = self.matrix.shape
395   - matrix = numpy.memmap(temp_file, mode='w+', dtype='int8', shape=shape)
  405 + matrix = numpy.memmap(temp_file, mode='w+', dtype='uint8', shape=shape)
396 406 return temp_file, matrix
397 407  
398 408 def edit_mask_pixel(self, operation, index, position, radius, orientation):
... ...
invesalius/gui/task_slice.py
... ... @@ -281,6 +281,7 @@ class InnerFoldPanel(wx.Panel):
281 281 def __bind_pubsub_evt(self):
282 282 Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style')
283 283 Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style')
  284 + Publisher.subscribe(self.OnCloseProject, 'Close project data')
284 285  
285 286 def OnFoldPressCaption(self, evt):
286 287 id = evt.GetTag().GetId()
... ... @@ -317,6 +318,9 @@ class InnerFoldPanel(wx.Panel):
317 318 if (self.last_style == const.SLICE_STATE_EDITOR):
318 319 Publisher.sendMessage('Disable style', const.SLICE_STATE_EDITOR)
319 320  
  321 + def OnCloseProject(self, pubsub_evt):
  322 + self.fold_panel.Expand(self.fold_panel.GetFoldPanel(0))
  323 +
320 324 def GetMaskSelected(self):
321 325 x= self.mask_prop_panel.GetMaskSelected()
322 326 return self.mask_prop_panel.GetMaskSelected()
... ... @@ -758,13 +762,8 @@ class WatershedTool(EditionTools):
758 762 line2.Add(combo_brush_op, 1, wx.EXPAND|wx.TOP|wx.RIGHT|wx.LEFT, 5)
759 763  
760 764 ## LINE 3
761   - text_thresh = wx.StaticText(self, -1, _("Brush threshold range:"))
762 765  
763 766 ## LINE 4
764   - gradient_thresh = grad.GradientCtrl(self, -1, 0, 5000, 0, 5000,
765   - (0, 0, 255, 100))
766   - self.gradient_thresh = gradient_thresh
767   - self.bind_evt_gradient = True
768 767  
769 768 # LINE 5
770 769 check_box = wx.CheckBox(self, -1, _("Overwrite mask"))
... ... @@ -777,9 +776,6 @@ class WatershedTool(EditionTools):
777 776 sizer = wx.BoxSizer(wx.VERTICAL)
778 777 sizer.Add(text1, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
779 778 sizer.Add(line2, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
780   - sizer.Add(text_thresh, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
781   - sizer.Add(gradient_thresh, 0, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT|
782   - wx.BOTTOM, 6)
783 779 sizer.Add(check_box, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
784 780 sizer.Add(self.btn_exp_watershed, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
785 781 sizer.Fit(self)
... ... @@ -788,24 +784,15 @@ class WatershedTool(EditionTools):
788 784 self.Update()
789 785 self.SetAutoLayout(1)
790 786  
791   - self.__bind_events()
792 787 self.__bind_events_wx()
793 788  
794 789  
795 790 def __bind_events_wx(self):
796 791 self.Bind(wx.EVT_MENU, self.OnMenu)
797   - self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnGradientChanged,
798   - self.gradient_thresh)
799 792 self.combo_brush_op.Bind(wx.EVT_COMBOBOX, self.OnComboBrushOp)
800 793 self.check_box.Bind(wx.EVT_CHECKBOX, self.OnCheckOverwriteMask)
801 794 self.btn_exp_watershed.Bind(wx.EVT_BUTTON, self.OnExpandWatershed)
802 795  
803   - def __bind_events(self):
804   - Publisher.subscribe(self.SetThresholdBounds,
805   - 'Update threshold limits')
806   - Publisher.subscribe(self.ChangeMaskColour, 'Change mask colour')
807   - Publisher.subscribe(self.SetGradientColour, 'Add mask')
808   -
809 796 def ChangeMaskColour(self, pubsub_evt):
810 797 colour = pubsub_evt.data
811 798 self.gradient_thresh.SetColour(colour)
... ... @@ -830,13 +817,6 @@ class WatershedTool(EditionTools):
830 817 self.gradient_thresh.SetMinValue(thresh_min)
831 818 self.gradient_thresh.SetMaxValue(thresh_max)
832 819  
833   - def OnGradientChanged(self, evt):
834   - thresh_min = self.gradient_thresh.GetMinValue()
835   - thresh_max = self.gradient_thresh.GetMaxValue()
836   - if self.bind_evt_gradient:
837   - Publisher.sendMessage('Set edition threshold values',
838   - (thresh_min, thresh_max))
839   -
840 820 def OnMenu(self, evt):
841 821 SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG)
842 822 CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG)
... ...