Commit 6fdec144aa10b9ad26e03aea10ddc3f6d32db150
1 parent
34feaf7f
Exists in
master
and in
38 other branches
Added a option to clean the actual mask
Showing
4 changed files
with
36 additions
and
11 deletions
Show diff stats
invesalius/constants.py
invesalius/data/mask.py
| ... | ... | @@ -285,6 +285,12 @@ class Mask(): |
| 285 | 285 | shape = shape[0] + 1, shape[1] + 1, shape[2] + 1 |
| 286 | 286 | self.matrix = numpy.memmap(self.temp_file, mode='w+', dtype='uint8', shape=shape) |
| 287 | 287 | |
| 288 | + def clean(self): | |
| 289 | + self.matrix[1:, 1:, 1:] = 0 | |
| 290 | + self.matrix[0, :, :] = 1 | |
| 291 | + self.matrix[:, 0, :] = 1 | |
| 292 | + self.matrix[:, :, 0] = 1 | |
| 293 | + | |
| 288 | 294 | def copy(self, copy_name): |
| 289 | 295 | """ |
| 290 | 296 | creates and return a copy from the mask instance. | ... | ... |
invesalius/data/slice_.py
| ... | ... | @@ -142,6 +142,7 @@ class Slice(object): |
| 142 | 142 | Publisher.subscribe(self.__set_mask_name, 'Change mask name') |
| 143 | 143 | Publisher.subscribe(self.__show_mask, 'Show mask') |
| 144 | 144 | Publisher.subscribe(self.__hide_current_mask, 'Hide current mask') |
| 145 | + Publisher.subscribe(self.__clean_current_mask, 'Clean current mask') | |
| 145 | 146 | |
| 146 | 147 | Publisher.subscribe(self.__set_current_mask_threshold_limits, |
| 147 | 148 | 'Update threshold limits') |
| ... | ... | @@ -211,6 +212,7 @@ class Slice(object): |
| 211 | 212 | buffer_.discard_vtk_mask() |
| 212 | 213 | buffer_.discard_mask() |
| 213 | 214 | |
| 215 | + Publisher.sendMessage('Show mask', (item, 0)) | |
| 214 | 216 | Publisher.sendMessage('Reload actual slice') |
| 215 | 217 | |
| 216 | 218 | def OnDuplicateMasks(self, pubsub_evt): |
| ... | ... | @@ -385,6 +387,14 @@ class Slice(object): |
| 385 | 387 | value = False |
| 386 | 388 | Publisher.sendMessage('Show mask', (index, value)) |
| 387 | 389 | |
| 390 | + def __clean_current_mask(self, pubsub_evt): | |
| 391 | + if self.current_mask: | |
| 392 | + self.current_mask.clean() | |
| 393 | + for buffer_ in self.buffer_slices.values(): | |
| 394 | + buffer_.discard_vtk_mask() | |
| 395 | + buffer_.discard_mask() | |
| 396 | + self.current_mask.clear_history() | |
| 397 | + | |
| 388 | 398 | def create_temp_mask(self): |
| 389 | 399 | temp_file = tempfile.mktemp() |
| 390 | 400 | shape = self.matrix.shape |
| ... | ... | @@ -1012,6 +1022,7 @@ class Slice(object): |
| 1012 | 1022 | |
| 1013 | 1023 | if show: |
| 1014 | 1024 | self.current_mask = mask |
| 1025 | + Publisher.sendMessage('Show mask', (mask.index, 1)) | |
| 1015 | 1026 | Publisher.sendMessage('Change mask selected', mask.index) |
| 1016 | 1027 | Publisher.sendMessage('Update slice viewer') |
| 1017 | 1028 | ... | ... |
invesalius/gui/frame.py
| ... | ... | @@ -401,6 +401,8 @@ class Frame(wx.Frame): |
| 401 | 401 | |
| 402 | 402 | elif id == const.ID_BOOLEAN_MASK: |
| 403 | 403 | self.OnMaskBoolean() |
| 404 | + elif id == const.ID_CLEAN_MASK: | |
| 405 | + self.OnCleanMask() | |
| 404 | 406 | |
| 405 | 407 | def OnSize(self, evt): |
| 406 | 408 | """ |
| ... | ... | @@ -503,11 +505,13 @@ class Frame(wx.Frame): |
| 503 | 505 | print "Redo" |
| 504 | 506 | Publisher.sendMessage('Redo edition') |
| 505 | 507 | |
| 506 | - | |
| 507 | 508 | def OnMaskBoolean(self): |
| 508 | 509 | print "Mask boolean" |
| 509 | 510 | Publisher.sendMessage('Show boolean dialog') |
| 510 | - | |
| 511 | + | |
| 512 | + def OnCleanMask(self): | |
| 513 | + Publisher.sendMessage('Clean current mask') | |
| 514 | + Publisher.sendMessage('Reload actual slice') | |
| 511 | 515 | |
| 512 | 516 | # ------------------------------------------------------------------ |
| 513 | 517 | # ------------------------------------------------------------------ |
| ... | ... | @@ -548,6 +552,7 @@ class MenuBar(wx.MenuBar): |
| 548 | 552 | |
| 549 | 553 | sub(self.OnAddMask, "Add mask") |
| 550 | 554 | sub(self.OnRemoveMasks, "Remove masks") |
| 555 | + sub(self.OnShowMask, "Show mask") | |
| 551 | 556 | |
| 552 | 557 | self.num_masks = 0 |
| 553 | 558 | |
| ... | ... | @@ -629,6 +634,10 @@ class MenuBar(wx.MenuBar): |
| 629 | 634 | mask_menu = wx.Menu() |
| 630 | 635 | self.bool_op_menu = mask_menu.Append(const.ID_BOOLEAN_MASK, _(u"Boolean operations")) |
| 631 | 636 | self.bool_op_menu.Enable(False) |
| 637 | + | |
| 638 | + self.clean_mask_menu = mask_menu.Append(const.ID_CLEAN_MASK, _(u"Clean Mask\tCtrl+Shift+A")) | |
| 639 | + self.clean_mask_menu.Enable(False) | |
| 640 | + | |
| 632 | 641 | file_edit.AppendMenu(-1, _(u"Mask"), mask_menu) |
| 633 | 642 | |
| 634 | 643 | |
| ... | ... | @@ -725,19 +734,17 @@ class MenuBar(wx.MenuBar): |
| 725 | 734 | |
| 726 | 735 | def OnAddMask(self, pubsub_evt): |
| 727 | 736 | self.num_masks += 1 |
| 728 | - | |
| 729 | - if self.num_masks >= 2: | |
| 730 | - self.bool_op_menu.Enable(True) | |
| 731 | - else: | |
| 732 | - self.bool_op_menu.Enable(False) | |
| 737 | + self.bool_op_menu.Enable(self.num_masks >= 2) | |
| 733 | 738 | |
| 734 | 739 | def OnRemoveMasks(self, pubsub_evt): |
| 735 | 740 | self.num_masks -= len(pubsub_evt.data) |
| 741 | + self.bool_op_menu.Enable(self.num_masks >= 2) | |
| 742 | + | |
| 743 | + def OnShowMask(self, pubsub_evt): | |
| 744 | + index, value = pubsub_evt.data | |
| 745 | + self.clean_mask_menu.Enable(value) | |
| 746 | + | |
| 736 | 747 | |
| 737 | - if self.num_masks >= 2: | |
| 738 | - self.bool_op_menu.Enable(True) | |
| 739 | - else: | |
| 740 | - self.bool_op_menu.Enable(False) | |
| 741 | 748 | # ------------------------------------------------------------------ |
| 742 | 749 | # ------------------------------------------------------------------ |
| 743 | 750 | # ------------------------------------------------------------------ | ... | ... |