From 1aea71561f1f115abf940dc090e97767ce9d4ff5 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Thu, 18 Aug 2016 15:52:09 -0300 Subject: [PATCH] Undo and Redo --- invesalius/constants.py | 2 +- invesalius/data/mask.py | 19 +++++++++++++++++-- invesalius/data/slice_.py | 6 ++++-- invesalius/data/styles.py | 24 ++++++++++++++++++++---- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 4c1e06f..d9a1717 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -538,7 +538,7 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, STATE_DEFAULT: 0, STATE_MEASURE_ANGLE: 2, STATE_MEASURE_DISTANCE: 2, - STATE_WL: 2, + STATE_WL: 3, STATE_SPIN: 2, STATE_ZOOM: 2, STATE_ZOOM_SL: 2, diff --git a/invesalius/data/mask.py b/invesalius/data/mask.py index 63c04c4..96df501 100644 --- a/invesalius/data/mask.py +++ b/invesalius/data/mask.py @@ -60,6 +60,8 @@ class EditionHistoryNode(object): mvolume[1:, 1:, self.index+1] = array if self.clean: mvolume[0, 0, self.index+1] = 1 + elif self.orientation == 'VOLUME': + mvolume[:] = array print "applying to", self.orientation, "at slice", self.index @@ -106,7 +108,15 @@ class EditionHistory(object): ##self.index -= 1 ##h[self.index].commit_history(mvolume) #self._reload_slice(self.index - 1) - if actual_slices and actual_slices[h[self.index - 1].orientation] != h[self.index - 1].index: + if h[self.index - 1].orientation == 'VOLUME': + self.index -= 1 + print "================================" + print mvolume.shape + print "================================" + h[self.index].commit_history(mvolume) + self._reload_slice(self.index) + Publisher.sendMessage("Enable redo", True) + elif actual_slices and actual_slices[h[self.index - 1].orientation] != h[self.index - 1].index: self._reload_slice(self.index - 1) else: self.index -= 1 @@ -129,7 +139,12 @@ class EditionHistory(object): ##h[self.index].commit_history(mvolume) #self._reload_slice(self.index + 1) - if actual_slices and actual_slices[h[self.index + 1].orientation] != h[self.index + 1].index: + if h[self.index + 1].orientation == 'VOLUME': + self.index += 1 + h[self.index].commit_history(mvolume) + self._reload_slice(self.index) + Publisher.sendMessage("Enable undo", True) + elif actual_slices and actual_slices[h[self.index + 1].orientation] != h[self.index + 1].index: self._reload_slice(self.index + 1) else: self.index += 1 diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 8690ada..1adead7 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -1402,7 +1402,8 @@ class Slice(object): buffer_slices = self.buffer_slices actual_slices = {"AXIAL": buffer_slices["AXIAL"].index, "CORONAL": buffer_slices["CORONAL"].index, - "SAGITAL": buffer_slices["SAGITAL"].index,} + "SAGITAL": buffer_slices["SAGITAL"].index, + "VOLUME": 0} self.current_mask.undo_history(actual_slices) for o in self.buffer_slices: self.buffer_slices[o].discard_mask() @@ -1413,7 +1414,8 @@ class Slice(object): buffer_slices = self.buffer_slices actual_slices = {"AXIAL": buffer_slices["AXIAL"].index, "CORONAL": buffer_slices["CORONAL"].index, - "SAGITAL": buffer_slices["SAGITAL"].index,} + "SAGITAL": buffer_slices["SAGITAL"].index, + "VOLUME": 0} self.current_mask.redo_history(actual_slices) for o in self.buffer_slices: self.buffer_slices[o].discard_mask() diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 4b858bf..385726d 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -1814,11 +1814,15 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): if position < 0: position = viewer.calculate_matrix_position(coord) + mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] x, y, z = self.calcultate_scroll_position(position) + if mask[z, y, x] < self.t0 or mask[z, y, x] > self.t1: + return if self.config.target == "3D": bstruct = np.array(generate_binary_structure(3, CON3D[self.config.con_3d]), dtype='uint8') self.viewer.slice_.do_threshold_to_all_slices() + cp_mask = self.viewer.slice_.current_mask.matrix.copy() else: _bstruct = generate_binary_structure(2, CON2D[self.config.con_2d]) if self.orientation == 'AXIAL': @@ -1831,11 +1835,23 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): bstruct = np.zeros((3, 3, 1), dtype='uint8') bstruct[:, :, 0] = _bstruct - print bstruct - mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] - cp_mask = mask - floodfill.floodfill_threshold(cp_mask, [[x, y, z]], self.t0, self.t1, self.fill_value, bstruct, mask) + floodfill.floodfill_threshold(mask, [[x, y, z]], self.t0, self.t1, self.fill_value, bstruct, mask) + + if self.config.target == '2D': + b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask + index = self.viewer.slice_.buffer_slices[self.orientation].index + + if self.orientation == 'AXIAL': + p_mask = mask[index,:,:].copy() + elif self.orientation == 'CORONAL': + p_mask = mask[:, index, :].copy() + elif self.orientation == 'SAGITAL': + p_mask = mask[:, :, index].copy() + + self.viewer.slice_.current_mask.save_history(index, self.orientation, p_mask, b_mask) + else: + self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask) self.viewer.slice_.buffer_slices['AXIAL'].discard_mask() self.viewer.slice_.buffer_slices['CORONAL'].discard_mask() -- libgit2 0.21.2