diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 8354e78..ea654a2 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -213,22 +213,14 @@ class CrossInteractorStyle(DefaultInteractorStyle): def ChangeCrossPosition(self, iren): mouse_x, mouse_y = iren.GetEventPosition() - ren = iren.GetRenderWindow().GetRenderers().GetFirstRenderer() - self.picker.Pick(mouse_x, mouse_y, 0, ren) - - # Get in what slice data the click occurred - # pick to get click position in the 3d world - coord_cross = self.viewer.get_coordinate_cursor(self.picker) - position = self.slice_actor.GetInput().FindPoint(coord_cross) - # Forcing focal point to be setted in the center of the pixel. - coord_cross = self.slice_actor.GetInput().GetPoint(position) - - coord = self.viewer.calcultate_scroll_position(position) - Publisher.sendMessage('Update cross position', coord_cross) + wx, wy, wz = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) + px, py = self.viewer.get_slice_pixel_coord_by_world_pos(wx, wy, wz) + coord = self.viewer.calcultate_scroll_position(px, py) + Publisher.sendMessage('Update cross position', (wx, wy, wz)) self.ScrollSlice(coord) Publisher.sendMessage('Set ball reference position based on bound', - coord_cross) - Publisher.sendMessage('Set camera in volume', coord_cross) + (wx, wy, wz)) + Publisher.sendMessage('Set camera in volume', (wx, wy, wz)) Publisher.sendMessage('Render volume viewer') iren.Render() @@ -1115,7 +1107,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): render = iren.FindPokedRenderer(mouse_x, mouse_y) slice_data = viewer.get_slice_data(render) - coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, picker=None) + coord = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, picker=None) position = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) slice_data.cursor.Show() @@ -1162,7 +1154,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): render = iren.FindPokedRenderer(mouse_x, mouse_y) slice_data = viewer.get_slice_data(render) - coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, self.picker) + coord = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) slice_data.cursor.SetPosition(coord) if (self.left_pressed): diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index a5f2ae6..8de79e2 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -975,11 +975,15 @@ class Viewer(wx.Panel): my = round((z - zi)/self.slice_.spacing[2], 0) return mx, my - def get_coordinate_cursor(self, picker=None): + def get_coordinate_cursor(self, mx, my, picker=None): # Find position if picker is None: picker = self.pick + slice_data = self.slice_data + renderer = slice_data.renderer + + picker.Pick(mx, my, 0, renderer) x, y, z = picker.GetPickPosition() bounds = self.slice_data.actor.GetBounds() if bounds[0] == bounds[1]: @@ -1030,7 +1034,7 @@ class Viewer(wx.Panel): def get_voxel_coord_by_screen_pos(self, mx, my, picker=None): """ Given the (mx, my) screen position returns the voxel coordinate - of the voxel at (that mx, my) position. + of the volume at (that mx, my) position. Parameters: mx (int): x position. @@ -1044,12 +1048,7 @@ class Viewer(wx.Panel): if picker is None: picker = self.pick - slice_data = self.slice_data - renderer = slice_data.renderer - - picker.Pick(mx, my, 0, renderer) - - wx, wy, wz = self.get_coordinate_cursor(picker) + wx, wy, wz = self.get_coordinate_cursor(mx, my, picker) x, y, z = self.get_voxel_coord_by_world_pos(wx, wy, wz) return (x, y, z) @@ -1057,7 +1056,7 @@ class Viewer(wx.Panel): def get_voxel_coord_by_world_pos(self, wx, wy, wz): """ Given the (x, my) screen position returns the voxel coordinate - of the voxel at (that mx, my) position. + of the volume at (that mx, my) position. Parameters: wx (float): x position. @@ -1091,12 +1090,7 @@ class Viewer(wx.Panel): if picker is None: picker = self.pick - slice_data = self.slice_data - renderer = slice_data.renderer - - picker.Pick(mx, my, 0, renderer) - - wx, wy, wz = self.get_coordinate_cursor(picker) + wx, wy, wz = self.get_coordinate_cursor(mx, my, picker) return self.get_slice_pixel_coord_by_world_pos(wx, wy, wz) return px, py @@ -1127,8 +1121,6 @@ class Viewer(wx.Panel): slice_data = self.slice_data renderer = slice_data.renderer - picker.Pick(mx, my, 0, renderer) - coord = self.get_coordinate_cursor(picker) position = slice_data.actor.GetInput().FindPoint(coord) -- libgit2 0.21.2