From 628fec8e95cb9e1f9320a888f492df59c4aa0298 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Fri, 5 Feb 2010 14:08:56 +0000 Subject: [PATCH] FIX: The scrolls in viewer_slice sync between all orientations are correct. Related to ticket #147 --- invesalius/data/viewer_slice.py | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 92045cc..472d25a 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -18,7 +18,6 @@ #-------------------------------------------------------------------------- import itertools -import os.path import numpy @@ -84,7 +83,6 @@ class Viewer(wx.Panel): def __init_gui(self): - interactor = wxVTKRenderWindowInteractor(self, -1, size=self.GetSize()) scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL) @@ -99,14 +97,12 @@ class Viewer(wx.Panel): self.SetSizer(background_sizer) background_sizer.Fit(self) - self.Layout() self.Update() self.SetAutoLayout(1) self.interactor = interactor - def OnContextMenu(self, evt): self.right_pressed = 0 if (self.last_position_mouse_move ==\ @@ -306,9 +302,6 @@ class Viewer(wx.Panel): def OnReleaseLeftButton(self, evt, obj): self.left_pressed = 0 ps.Publisher().sendMessage('Update slice viewer') - - - def OnWindowLevelMove(self, evt, obj): if (self.left_pressed): @@ -321,10 +314,8 @@ class Viewer(wx.Panel): ps.Publisher().sendMessage('Bright and contrast adjustment image', (self.acum_achange_window, self.acum_achange_level)) - - self.SetWLText(self.acum_achange_level, - self.acum_achange_window) - + #self.SetWLText(self.acum_achange_level, + # self.acum_achange_window) const.WINDOW_LEVEL['Manual'] = (self.acum_achange_window,\ self.acum_achange_level) @@ -332,9 +323,8 @@ class Viewer(wx.Panel): ps.Publisher().sendMessage('Update window level value',(self.acum_achange_window, self.acum_achange_level)) #Necessary update the slice plane in the volume case exists + ps.Publisher().sendMessage('Update slice viewer') ps.Publisher().sendMessage('Render volume viewer') - - self.interactor.Render() def OnWindowLevelClick(self, evt, obj): @@ -419,7 +409,7 @@ class Viewer(wx.Panel): value = STR_WL%(window_width, window_level) if (self.wl_text): self.wl_text.SetValue(value) - self.interactor.Render() + #self.interactor.Render() def EnableText(self): if not (self.wl_text): @@ -673,28 +663,45 @@ class Viewer(wx.Panel): self.interactor.Render() - + def OnCrossMouseClick(self, evt, obj): + self.ChangeCrossPosition() def OnCrossMove(self, evt, obj): - # Update position in other slices + # The user moved the mouse with left button pressed if (self.left_pressed): - mouse_x, mouse_y = self.interactor.GetEventPosition() - renderer = self.slice_data_list[0].renderer - self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) - coord_cross = self.get_coordinate_cursor() - coord = self.get_coordinate() - ps.Publisher().sendMessage('Update cross position', - (self.orientation, coord_cross)) + self.ChangeCrossPosition() + + def ChangeCrossPosition(self): + mouse_x, mouse_y = self.interactor.GetEventPosition() + # Get in what slice data the click occurred + renderer = self.slice_data_list[0].renderer + # pick to get click position in the 3d world + self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) + coord_cross = self.get_coordinate_cursor() + coord = self.CalcultateScrollPosition(coord_cross) + ps.Publisher().sendMessage('Update cross position', + (self.orientation, coord_cross)) + self.ScrollSlice(coord) + self.interactor.Render() + + def ScrollSlice(self, coord): + if self.orientation == "AXIAL": ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), coord[0]) ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), coord[1]) + elif self.orientation == "SAGITAL": + ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), + coord[2]) + ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), + coord[1]) + elif self.orientation == "CORONAL": ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), coord[2]) + ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), + coord[0]) def OnZoomMoveRight(self, evt, obj): - - if (self.right_pressed): evt.Dolly() evt.OnRightButtonDown() @@ -702,31 +709,16 @@ class Viewer(wx.Panel): def OnZoomRightClick(self, evt, obj): evt.StartDolly() - - def OnCrossMouseClick(self, evt, obj): - mouse_x, mouse_y = self.interactor.GetEventPosition() - renderer = self.slice_data_list[0].renderer - self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) - coord_cross = self.get_coordinate_cursor() - coord = self.get_coordinate() - ps.Publisher().sendMessage('Update cross position', - (self.orientation, 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]) - - def get_slice_data(self, render): for slice_data in self.slice_data_list: if slice_data.renderer is render: return slice_data - def get_coordinate(self): - # Find position - x, y, z = self.pick.GetPickPosition() + def CalcultateScrollPosition(self, coord): + # Based in the given coord (x, y, z), returns a list with the scroll positions for each + # orientation, being the first position the sagital, second the coronal + # and the last, axial. + x, y, z = coord # First we fix the position origin, based on vtkActor bounds bounds = self.actor.GetBounds() @@ -737,15 +729,20 @@ class Viewer(wx.Panel): # Then we fix the porpotion, based on vtkImageData spacing spacing_x, spacing_y, spacing_z = self.imagedata.GetSpacing() + x = x/spacing_x y = y/spacing_y z = z/spacing_z + proj = project.Project() + orig_orien = proj.original_orientation # Based on the current orientation, we define 3D position - coordinates = {"SAGITAL": [self.slice_number, y, z], - "CORONAL": [x, self.slice_number, z], - "AXIAL": [x, y, self.slice_number]} - coord = [int(coord) for coord in coordinates[self.orientation]] + # Sagita, coronal, axial + coordinates = {const.AXIAL: [x, y, z], + const.SAGITAL: [z, x, y], + const.CORONAL: [x, z, y]} + + coord = [int(i) for i in coordinates[orig_orien]] # According to vtkImageData extent, we limit min and max value # If this is not done, a VTK Error occurs when mouse is pressed outside @@ -763,6 +760,13 @@ class Viewer(wx.Panel): def get_coordinate_cursor(self): # Find position x, y, z = self.pick.GetPickPosition() + bounds = self.actor.GetBounds() + if bounds[0] == bounds[1]: + x = bounds[0] + elif bounds[2] == bounds[3]: + y = bounds[2] + elif bounds[4] == bounds[5]: + z = bounds[4] return x, y, z def get_coordinate_cursor_edition(self, slice_data): @@ -1128,8 +1132,8 @@ class Viewer(wx.Panel): #xz = [x, y - abs(y * 0.001), z] #xy = [x, y, z + abs(z * 0.001)] - #proj = project.Project() - #orig_orien = proj.original_orientation + proj = project.Project() + orig_orien = proj.original_orientation #pos = [x, y, z] #if (orig_orien == const.SAGITAL): -- libgit2 0.21.2