Commit 14811233b42064ca742564c0ec197c837cfb46e8
1 parent
46111ecb
Exists in
watershed
Removing aux matrix when opening a new dicom dir
Showing
3 changed files
with
20 additions
and
25 deletions
Show diff stats
invesalius/control.py
@@ -128,6 +128,11 @@ class Controller(): | @@ -128,6 +128,11 @@ class Controller(): | ||
128 | answer = dialog.SaveChangesDialog2(filename) | 128 | answer = dialog.SaveChangesDialog2(filename) |
129 | if answer: | 129 | if answer: |
130 | self.ShowDialogSaveProject() | 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 | # Import project | 136 | # Import project |
132 | dirpath = dialog.ShowImportDirDialog() | 137 | dirpath = dialog.ShowImportDirDialog() |
133 | if dirpath and not os.listdir(dirpath): | 138 | if dirpath and not os.listdir(dirpath): |
invesalius/data/slice_.py
@@ -246,6 +246,7 @@ class Slice(object): | @@ -246,6 +246,7 @@ class Slice(object): | ||
246 | 246 | ||
247 | if (state == const.SLICE_STATE_EDITOR): | 247 | if (state == const.SLICE_STATE_EDITOR): |
248 | Publisher.sendMessage('Set interactor default cursor') | 248 | Publisher.sendMessage('Set interactor default cursor') |
249 | + self.state = new_state | ||
249 | 250 | ||
250 | def OnCloseProject(self, pubsub_evt): | 251 | def OnCloseProject(self, pubsub_evt): |
251 | self.CloseProject() | 252 | self.CloseProject() |
@@ -258,9 +259,18 @@ class Slice(object): | @@ -258,9 +259,18 @@ class Slice(object): | ||
258 | os.remove(f) | 259 | os.remove(f) |
259 | self.current_mask = None | 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 | self.values = None | 270 | self.values = None |
262 | self.nodes = None | 271 | self.nodes = None |
263 | self.from_= OTHER | 272 | self.from_= OTHER |
273 | + self.state = const.STATE_DEFAULT | ||
264 | 274 | ||
265 | self.number_of_colours = 256 | 275 | self.number_of_colours = 256 |
266 | self.saturation_range = (0, 0) | 276 | self.saturation_range = (0, 0) |
@@ -392,7 +402,7 @@ class Slice(object): | @@ -392,7 +402,7 @@ class Slice(object): | ||
392 | def create_temp_mask(self): | 402 | def create_temp_mask(self): |
393 | temp_file = tempfile.mktemp() | 403 | temp_file = tempfile.mktemp() |
394 | shape = self.matrix.shape | 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 | return temp_file, matrix | 406 | return temp_file, matrix |
397 | 407 | ||
398 | def edit_mask_pixel(self, operation, index, position, radius, orientation): | 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,6 +281,7 @@ class InnerFoldPanel(wx.Panel): | ||
281 | def __bind_pubsub_evt(self): | 281 | def __bind_pubsub_evt(self): |
282 | Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') | 282 | Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') |
283 | Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style') | 283 | Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style') |
284 | + Publisher.subscribe(self.OnCloseProject, 'Close project data') | ||
284 | 285 | ||
285 | def OnFoldPressCaption(self, evt): | 286 | def OnFoldPressCaption(self, evt): |
286 | id = evt.GetTag().GetId() | 287 | id = evt.GetTag().GetId() |
@@ -317,6 +318,9 @@ class InnerFoldPanel(wx.Panel): | @@ -317,6 +318,9 @@ class InnerFoldPanel(wx.Panel): | ||
317 | if (self.last_style == const.SLICE_STATE_EDITOR): | 318 | if (self.last_style == const.SLICE_STATE_EDITOR): |
318 | Publisher.sendMessage('Disable style', const.SLICE_STATE_EDITOR) | 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 | def GetMaskSelected(self): | 324 | def GetMaskSelected(self): |
321 | x= self.mask_prop_panel.GetMaskSelected() | 325 | x= self.mask_prop_panel.GetMaskSelected() |
322 | return self.mask_prop_panel.GetMaskSelected() | 326 | return self.mask_prop_panel.GetMaskSelected() |
@@ -758,13 +762,8 @@ class WatershedTool(EditionTools): | @@ -758,13 +762,8 @@ class WatershedTool(EditionTools): | ||
758 | line2.Add(combo_brush_op, 1, wx.EXPAND|wx.TOP|wx.RIGHT|wx.LEFT, 5) | 762 | line2.Add(combo_brush_op, 1, wx.EXPAND|wx.TOP|wx.RIGHT|wx.LEFT, 5) |
759 | 763 | ||
760 | ## LINE 3 | 764 | ## LINE 3 |
761 | - text_thresh = wx.StaticText(self, -1, _("Brush threshold range:")) | ||
762 | 765 | ||
763 | ## LINE 4 | 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 | # LINE 5 | 768 | # LINE 5 |
770 | check_box = wx.CheckBox(self, -1, _("Overwrite mask")) | 769 | check_box = wx.CheckBox(self, -1, _("Overwrite mask")) |
@@ -777,9 +776,6 @@ class WatershedTool(EditionTools): | @@ -777,9 +776,6 @@ class WatershedTool(EditionTools): | ||
777 | sizer = wx.BoxSizer(wx.VERTICAL) | 776 | sizer = wx.BoxSizer(wx.VERTICAL) |
778 | sizer.Add(text1, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 777 | sizer.Add(text1, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
779 | sizer.Add(line2, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 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 | sizer.Add(check_box, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 779 | sizer.Add(check_box, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
784 | sizer.Add(self.btn_exp_watershed, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) | 780 | sizer.Add(self.btn_exp_watershed, 0, wx.GROW|wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5) |
785 | sizer.Fit(self) | 781 | sizer.Fit(self) |
@@ -788,24 +784,15 @@ class WatershedTool(EditionTools): | @@ -788,24 +784,15 @@ class WatershedTool(EditionTools): | ||
788 | self.Update() | 784 | self.Update() |
789 | self.SetAutoLayout(1) | 785 | self.SetAutoLayout(1) |
790 | 786 | ||
791 | - self.__bind_events() | ||
792 | self.__bind_events_wx() | 787 | self.__bind_events_wx() |
793 | 788 | ||
794 | 789 | ||
795 | def __bind_events_wx(self): | 790 | def __bind_events_wx(self): |
796 | self.Bind(wx.EVT_MENU, self.OnMenu) | 791 | self.Bind(wx.EVT_MENU, self.OnMenu) |
797 | - self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnGradientChanged, | ||
798 | - self.gradient_thresh) | ||
799 | self.combo_brush_op.Bind(wx.EVT_COMBOBOX, self.OnComboBrushOp) | 792 | self.combo_brush_op.Bind(wx.EVT_COMBOBOX, self.OnComboBrushOp) |
800 | self.check_box.Bind(wx.EVT_CHECKBOX, self.OnCheckOverwriteMask) | 793 | self.check_box.Bind(wx.EVT_CHECKBOX, self.OnCheckOverwriteMask) |
801 | self.btn_exp_watershed.Bind(wx.EVT_BUTTON, self.OnExpandWatershed) | 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 | def ChangeMaskColour(self, pubsub_evt): | 796 | def ChangeMaskColour(self, pubsub_evt): |
810 | colour = pubsub_evt.data | 797 | colour = pubsub_evt.data |
811 | self.gradient_thresh.SetColour(colour) | 798 | self.gradient_thresh.SetColour(colour) |
@@ -830,13 +817,6 @@ class WatershedTool(EditionTools): | @@ -830,13 +817,6 @@ class WatershedTool(EditionTools): | ||
830 | self.gradient_thresh.SetMinValue(thresh_min) | 817 | self.gradient_thresh.SetMinValue(thresh_min) |
831 | self.gradient_thresh.SetMaxValue(thresh_max) | 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 | def OnMenu(self, evt): | 820 | def OnMenu(self, evt): |
841 | SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) | 821 | SQUARE_BMP = wx.Bitmap("../icons/brush_square.jpg", wx.BITMAP_TYPE_JPEG) |
842 | CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) | 822 | CIRCLE_BMP = wx.Bitmap("../icons/brush_circle.jpg", wx.BITMAP_TYPE_JPEG) |