From 22434229e7193fec2b24e511f44f8cfb0e0d035c Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Tue, 1 Sep 2009 17:18:52 +0000 Subject: [PATCH] ADD: Cross reference between slices --- invesalius/constants.py | 1 + invesalius/data/viewer_slice.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- invesalius/gui/frame.py | 11 +++++++++-- 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 4817195..fb774ff 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -200,6 +200,7 @@ MODE_WW_WL = 4#:"Bright and contrast adjustment"} #### MODE_SLICE_SCROLL = -1 MODE_SLICE_EDITOR = -2 +MODE_SLICE_CROSS = -3 ############ diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 15f74cf..5096453 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -44,7 +44,7 @@ class Viewer(wx.Panel): self.SetBackgroundColour(colour) # Interactor additional style - self.modes = [] #['DEFAULT'] + self.modes = []#['DEFAULT'] self.mouse_pressed = 0 # All renderers and image actors in this viewer @@ -105,7 +105,7 @@ class Viewer(wx.Panel): def SetLayout(self, layout): self.layout = layout slice_ = sl.Slice() - self.load_renderers(slice_.GetOutput()) + self.LoadRenderers(slice_.GetOutput()) self.__configure_renderers() self.__configure_scroll() @@ -132,10 +132,10 @@ class Viewer(wx.Panel): self.modes.append(mode) # All modes and bindings - action = {'DEFAULT': { + action = {'CROSS': { "MouseMoveEvent": self.OnCrossMove, - "LeftButtonPressEvent": self.OnMouseClick, - "LeftButtonReleaseEvent": self.OnMouseRelease + "LeftButtonPressEvent": self.OnCrossMouseClick, + "LeftButtonReleaseEvent": self.OnCrossMouseRelease }, 'EDITOR': { "MouseMoveEvent": self.OnBrushMove, @@ -229,6 +229,11 @@ class Viewer(wx.Panel): self.mouse_pressed = 0 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) + def __set_mode_cross(self, pubsub_evt): + self.append_mode('CROSS') + self.mouse_pressed = 0 + self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_NONE)) + def OnWindowLevelMove(self, evt, obj): if self.mouse_pressed: position = self.interactor.GetLastEventPosition() @@ -523,7 +528,6 @@ class Viewer(wx.Panel): elif self._brush_cursor_op == const.BRUSH_THRESH: evt_msg = 'Edit mask pixel' - self.__update_cross_position(*coord) if self.mouse_pressed: pixels = itertools.ifilter(self.test_operation_position, @@ -533,17 +537,38 @@ class Viewer(wx.Panel): self.interactor.Render() def OnCrossMove(self, obj, evt_vtk): - coord = self.get_coordinate() # Update position in other slices if self.mouse_pressed: - ps.Publisher().sendMessage('Update cursor position in slice', - coord) + mouse_x, mouse_y = self.interactor.GetEventPosition() + renderer = self.slice_data_list[0].renderer + self.pick.Pick(mouse_x, mouse_y, 0, renderer) + coord_cross = self.get_coordinate_cursor() + coord = self.get_coordinate() + ps.Publisher().sendMessage('Update cross position', coord_cross) ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), - coord[0]) + coord[0]) ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), - coord[1]) + coord[1]) ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), - coord[2]) + coord[2]) + + def OnCrossMouseClick(self, obj, evt_vtk): + mouse_x, mouse_y = self.interactor.GetEventPosition() + renderer = self.slice_data_list[0].renderer + self.pick.Pick(mouse_x, mouse_y, 0, renderer) + coord_cross = self.get_coordinate_cursor() + coord = self.get_coordinate() + ps.Publisher().sendMessage('Update cross position', coord_cross) + ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), + coord[0]) + ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), + coord[1]) + ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), + coord[2]) + self.mouse_pressed = 1 + + def OnCrossMouseRelease(self, obj, evt_vtk): + self.mouse_pressed = 0 def get_slice_data(self, render): for slice_data in self.slice_data_list: @@ -637,6 +662,8 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.ChangeSliceNumber, ('Set scroll position', self.orientation)) + ps.Publisher().subscribe(self.__update_cross_position, + 'Update cross position') ### ps.Publisher().subscribe(self.ChangeBrushSize, 'Set edition brush size') @@ -669,6 +696,9 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.__set_mode_window_level, ('Set interaction mode', const.MODE_WW_WL)) + ps.Publisher().subscribe(self.__set_mode_cross, + ('Set interaction mode', + const.MODE_SLICE_CROSS)) #### ps.Publisher().subscribe(self.UpdateText,\ 'Update window and level text') @@ -692,7 +722,7 @@ class Viewer(wx.Panel): imagedata = pubsub_evt.data self.SetInput(imagedata) - def load_renderers(self, image): + def LoadRenderers(self, image): number_renderers = self.layout[0] * self.layout[1] diff = number_renderers - len(self.slice_data_list) if diff > 0: @@ -744,7 +774,7 @@ class Viewer(wx.Panel): #actor = vtk.vtkImageActor() #actor.SetInput(slice_.GetOutput()) - self.load_renderers(slice_.GetOutput()) + self.LoadRenderers(slice_.GetOutput()) self.__configure_renderers() ren = self.slice_data_list[0].renderer actor = self.slice_data_list[0].actor @@ -830,10 +860,12 @@ class Viewer(wx.Panel): cross_actor.SetProperty(property) # Only the slices are pickable cross_actor.PickableOff() + self.cross_actor = cross_actor renderer.AddActor(cross_actor) - def __update_cross_position(self, x, y, z): + def __update_cross_position(self, pubsub_evt): + x, y, z = pubsub_evt.data #xi, yi, zi = self.vline.GetPoint1() #xf, yf, zf = self.vline.GetPoint2() #self.vline.SetPoint1(x, yi, z) @@ -863,7 +895,7 @@ class Viewer(wx.Panel): else: coordinates = {"SAGITAL": yz, "CORONAL": xz, "AXIAL": xy} - self.cross.SetFocalPoint(coordinates[self.orientation]) + self.cross.SetFocalPoint(x, y, z) #print #print slice_number @@ -1012,10 +1044,10 @@ class Viewer(wx.Panel): "CORONAL": {1: slice_data.number}, "AXIAL": {2: slice_data.number}} - if 'DEFAULT' in self.modes: - ps.Publisher().sendMessage( - 'Update cursor single position in slice', - position[self.orientation]) + #if 'DEFAULT' in self.modes: + # ps.Publisher().sendMessage( + # 'Update cursor single position in slice', + # position[self.orientation]) def ChangeSliceNumber(self, pubsub_evt): index = pubsub_evt.data diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index b99dcf0..f6d2c37 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -43,8 +43,9 @@ MODE_BY_ID = {ID_ZOOM: const.MODE_ZOOM, ID_CONTRAST: const.MODE_WW_WL} # Slice toolbar -SLICE_TOOLS = [ID_SLICE_SCROLL] = [wx.NewId() for number in range(1)] -SLICE_MODE_BY_ID = {ID_SLICE_SCROLL: const.MODE_SLICE_SCROLL} +SLICE_TOOLS = [ID_SLICE_SCROLL, ID_CROSS] = [wx.NewId() for number in range(2)] +SLICE_MODE_BY_ID = {ID_SLICE_SCROLL: const.MODE_SLICE_SCROLL, + ID_CROSS: const.MODE_SLICE_CROSS} class Frame(wx.Frame): def __init__(self, prnt): @@ -508,9 +509,15 @@ class SliceToolBar(wx.ToolBar): BMP_SLICE = wx.Bitmap("../icons/slice.png", wx.BITMAP_TYPE_PNG) + BMP_CROSS = wx.Bitmap("../icons/cross.png", + wx.BITMAP_TYPE_PNG) + self.AddLabelTool(ID_SLICE_SCROLL, "Scroll slice", BMP_SLICE, kind = wx.ITEM_CHECK) + self.AddLabelTool(ID_CROSS, "Cross", + BMP_CROSS, kind = wx.ITEM_CHECK) + self.Realize() def __bind_events_wx(self): -- libgit2 0.21.2