From 94e17db75ad08fd522d76c4c7e6e7ccaade50f2c Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 20 Apr 2016 13:47:30 -0300 Subject: [PATCH] Starting to show reoriented image --- invesalius/constants.py | 11 +++++++---- invesalius/data/slice_.py | 2 +- invesalius/data/styles.py | 41 +++++++++++++++++++++++++++++++++++++++++ invesalius/gui/frame.py | 15 ++++++++++++++- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 287f7cc..4f726f9 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -494,16 +494,18 @@ SLICE_STATE_CROSS = 3006 SLICE_STATE_SCROLL = 3007 SLICE_STATE_EDITOR = 3008 SLICE_STATE_WATERSHED = 3009 +SLICE_STATE_REORIENT = 3010 VOLUME_STATE_SEED = 2001 -#STATE_LINEAR_MEASURE = 3001 -#STATE_ANGULAR_MEASURE = 3002 +# STATE_LINEAR_MEASURE = 3001 +# STATE_ANGULAR_MEASURE = 3002 TOOL_STATES = [STATE_WL, STATE_SPIN, STATE_ZOOM, STATE_ZOOM_SL, STATE_PAN, STATE_MEASURE_DISTANCE, - STATE_MEASURE_ANGLE]#, STATE_ANNOTATE] + STATE_MEASURE_ANGLE] #, STATE_ANNOTATE] -TOOL_SLICE_STATES = [SLICE_STATE_CROSS, SLICE_STATE_SCROLL] +TOOL_SLICE_STATES = [SLICE_STATE_CROSS, SLICE_STATE_SCROLL, + SLICE_STATE_REORIENT] SLICE_STYLES = TOOL_STATES + TOOL_SLICE_STATES @@ -520,6 +522,7 @@ STYLE_LEVEL = {SLICE_STATE_EDITOR: 1, SLICE_STATE_WATERSHED: 1, SLICE_STATE_CROSS: 2, SLICE_STATE_SCROLL: 2, + SLICE_STATE_REORIENT: 2, STATE_ANNOTATE: 2, STATE_DEFAULT: 0, STATE_MEASURE_ANGLE: 2, diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index eed0114..633da4a 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -584,7 +584,7 @@ class Slice(object): if orientation == 'AXIAL': tmp_array = np.array(self.matrix[slice_number:slice_number + number_slices]) if np.any(self.rotations): - transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, 1, self.matrix.min(), tmp_array) + transforms.apply_view_matrix_transform(self.matrix, self.spacing, M, slice_number, orientation, 2, self.matrix.min(), tmp_array) if self._type_projection == const.PROJECTION_NORMAL: n_image = tmp_array.squeeze() else: diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index c62f039..14a0e42 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -1405,6 +1405,46 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): session.ChangeProject() +class ReorientImageInteractorStyle(DefaultInteractorStyle): + """ + Interactor style responsible for image reorientation + """ + def __init__(self, viewer): + DefaultInteractorStyle.__init__(self, viewer) + + self.viewer = viewer + + self.AddObserver("KeyPressEvent", self.OnKeyPress) + + def SetUp(self): + self.viewer.slice_.current_mask.is_shown = False + Publisher.sendMessage('Reload actual slice') + + def OnKeyPress(self, evt, obj): + key = self.viewer.interactor.GetKeyCode() + if key == '+': + delta = 1 + elif key == '-': + delta = -1 + else: + return + + rx, ry, rz = self.viewer.slice_.rotations + orientation = self.viewer.orientation + if orientation == 'AXIAL': + rz += np.deg2rad(delta) + elif orientation == 'CORONAL': + ry += np.deg2rad(delta) + elif orientation == 'SAGITAL': + rx += np.deg2rad(delta) + + self.viewer.slice_.rotations = (rx, ry, rz) + + self.viewer.slice_.discard_all_buffers() + self.viewer.slice_.current_mask.clear_history() + Publisher.sendMessage('Reload actual slice') + + def get_style(style): STYLES = { const.STATE_DEFAULT: DefaultInteractorStyle, @@ -1419,5 +1459,6 @@ def get_style(style): const.SLICE_STATE_SCROLL: ChangeSliceInteractorStyle, const.SLICE_STATE_EDITOR: EditorInteractorStyle, const.SLICE_STATE_WATERSHED: WaterShedInteractorStyle, + const.SLICE_STATE_REORIENT: ReorientImageInteractorStyle, } return STYLES[style] diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index ebaaf07..8b67b49 100644 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -1278,7 +1278,8 @@ class SliceToolBar(AuiToolBar): self.parent = parent self.enable_items = [const.SLICE_STATE_SCROLL, - const.SLICE_STATE_CROSS] + const.SLICE_STATE_CROSS, + const.SLICE_STATE_REORIENT] self.__init_items() self.__bind_events() self.__bind_events_wx() @@ -1297,6 +1298,9 @@ class SliceToolBar(AuiToolBar): path = os.path.join(d,"cross_original.png") BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + + path = os.path.join(d, "tool_rotate_original.png") + BMP_REORIENT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) else: path = os.path.join(d, "slice.png") BMP_SLICE = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) @@ -1304,6 +1308,9 @@ class SliceToolBar(AuiToolBar): path = os.path.join(d,"cross.png") BMP_CROSS = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + path = os.path.join(d, "tool_rotate.png") + BMP_REORIENT = wx.Bitmap(path, wx.BITMAP_TYPE_PNG) + self.sst = self.AddToggleTool(const.SLICE_STATE_SCROLL, BMP_SLICE,#, kind=wx.ITEM_CHECK) wx.NullBitmap, @@ -1316,6 +1323,12 @@ class SliceToolBar(AuiToolBar): toggle=True, short_help_string=_("Slices' cross intersection")) + self.srt = self.AddToggleTool(const.SLICE_STATE_REORIENT, + BMP_REORIENT,#, kind=wx.ITEM_CHECK) + wx.NullBitmap, + toggle=True, + short_help_string=_("Reorient slices")) + def __bind_events(self): """ Bind events related to pubsub. -- libgit2 0.21.2