Commit 45c7f6a48166bbc99af4b9cc59b5164f0af56e2b
1 parent
89ea441d
Exists in
get_pixel
Updated scroll interactor style to new get position methods
Showing
2 changed files
with
17 additions
and
33 deletions
Show diff stats
invesalius/data/styles.py
| @@ -213,22 +213,14 @@ class CrossInteractorStyle(DefaultInteractorStyle): | @@ -213,22 +213,14 @@ class CrossInteractorStyle(DefaultInteractorStyle): | ||
| 213 | 213 | ||
| 214 | def ChangeCrossPosition(self, iren): | 214 | def ChangeCrossPosition(self, iren): |
| 215 | mouse_x, mouse_y = iren.GetEventPosition() | 215 | mouse_x, mouse_y = iren.GetEventPosition() |
| 216 | - ren = iren.GetRenderWindow().GetRenderers().GetFirstRenderer() | ||
| 217 | - self.picker.Pick(mouse_x, mouse_y, 0, ren) | ||
| 218 | - | ||
| 219 | - # Get in what slice data the click occurred | ||
| 220 | - # pick to get click position in the 3d world | ||
| 221 | - coord_cross = self.viewer.get_coordinate_cursor(self.picker) | ||
| 222 | - position = self.slice_actor.GetInput().FindPoint(coord_cross) | ||
| 223 | - # Forcing focal point to be setted in the center of the pixel. | ||
| 224 | - coord_cross = self.slice_actor.GetInput().GetPoint(position) | ||
| 225 | - | ||
| 226 | - coord = self.viewer.calcultate_scroll_position(position) | ||
| 227 | - Publisher.sendMessage('Update cross position', coord_cross) | 216 | + wx, wy, wz = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) |
| 217 | + px, py = self.viewer.get_slice_pixel_coord_by_world_pos(wx, wy, wz) | ||
| 218 | + coord = self.viewer.calcultate_scroll_position(px, py) | ||
| 219 | + Publisher.sendMessage('Update cross position', (wx, wy, wz)) | ||
| 228 | self.ScrollSlice(coord) | 220 | self.ScrollSlice(coord) |
| 229 | Publisher.sendMessage('Set ball reference position based on bound', | 221 | Publisher.sendMessage('Set ball reference position based on bound', |
| 230 | - coord_cross) | ||
| 231 | - Publisher.sendMessage('Set camera in volume', coord_cross) | 222 | + (wx, wy, wz)) |
| 223 | + Publisher.sendMessage('Set camera in volume', (wx, wy, wz)) | ||
| 232 | Publisher.sendMessage('Render volume viewer') | 224 | Publisher.sendMessage('Render volume viewer') |
| 233 | 225 | ||
| 234 | iren.Render() | 226 | iren.Render() |
| @@ -1115,7 +1107,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -1115,7 +1107,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
| 1115 | render = iren.FindPokedRenderer(mouse_x, mouse_y) | 1107 | render = iren.FindPokedRenderer(mouse_x, mouse_y) |
| 1116 | slice_data = viewer.get_slice_data(render) | 1108 | slice_data = viewer.get_slice_data(render) |
| 1117 | 1109 | ||
| 1118 | - coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, picker=None) | 1110 | + coord = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, picker=None) |
| 1119 | position = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) | 1111 | position = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) |
| 1120 | 1112 | ||
| 1121 | slice_data.cursor.Show() | 1113 | slice_data.cursor.Show() |
| @@ -1162,7 +1154,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -1162,7 +1154,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
| 1162 | render = iren.FindPokedRenderer(mouse_x, mouse_y) | 1154 | render = iren.FindPokedRenderer(mouse_x, mouse_y) |
| 1163 | slice_data = viewer.get_slice_data(render) | 1155 | slice_data = viewer.get_slice_data(render) |
| 1164 | 1156 | ||
| 1165 | - coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, self.picker) | 1157 | + coord = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) |
| 1166 | slice_data.cursor.SetPosition(coord) | 1158 | slice_data.cursor.SetPosition(coord) |
| 1167 | 1159 | ||
| 1168 | if (self.left_pressed): | 1160 | if (self.left_pressed): |
invesalius/data/viewer_slice.py
| @@ -975,11 +975,15 @@ class Viewer(wx.Panel): | @@ -975,11 +975,15 @@ class Viewer(wx.Panel): | ||
| 975 | my = round((z - zi)/self.slice_.spacing[2], 0) | 975 | my = round((z - zi)/self.slice_.spacing[2], 0) |
| 976 | return mx, my | 976 | return mx, my |
| 977 | 977 | ||
| 978 | - def get_coordinate_cursor(self, picker=None): | 978 | + def get_coordinate_cursor(self, mx, my, picker=None): |
| 979 | # Find position | 979 | # Find position |
| 980 | if picker is None: | 980 | if picker is None: |
| 981 | picker = self.pick | 981 | picker = self.pick |
| 982 | 982 | ||
| 983 | + slice_data = self.slice_data | ||
| 984 | + renderer = slice_data.renderer | ||
| 985 | + | ||
| 986 | + picker.Pick(mx, my, 0, renderer) | ||
| 983 | x, y, z = picker.GetPickPosition() | 987 | x, y, z = picker.GetPickPosition() |
| 984 | bounds = self.slice_data.actor.GetBounds() | 988 | bounds = self.slice_data.actor.GetBounds() |
| 985 | if bounds[0] == bounds[1]: | 989 | if bounds[0] == bounds[1]: |
| @@ -1030,7 +1034,7 @@ class Viewer(wx.Panel): | @@ -1030,7 +1034,7 @@ class Viewer(wx.Panel): | ||
| 1030 | def get_voxel_coord_by_screen_pos(self, mx, my, picker=None): | 1034 | def get_voxel_coord_by_screen_pos(self, mx, my, picker=None): |
| 1031 | """ | 1035 | """ |
| 1032 | Given the (mx, my) screen position returns the voxel coordinate | 1036 | Given the (mx, my) screen position returns the voxel coordinate |
| 1033 | - of the voxel at (that mx, my) position. | 1037 | + of the volume at (that mx, my) position. |
| 1034 | 1038 | ||
| 1035 | Parameters: | 1039 | Parameters: |
| 1036 | mx (int): x position. | 1040 | mx (int): x position. |
| @@ -1044,12 +1048,7 @@ class Viewer(wx.Panel): | @@ -1044,12 +1048,7 @@ class Viewer(wx.Panel): | ||
| 1044 | if picker is None: | 1048 | if picker is None: |
| 1045 | picker = self.pick | 1049 | picker = self.pick |
| 1046 | 1050 | ||
| 1047 | - slice_data = self.slice_data | ||
| 1048 | - renderer = slice_data.renderer | ||
| 1049 | - | ||
| 1050 | - picker.Pick(mx, my, 0, renderer) | ||
| 1051 | - | ||
| 1052 | - wx, wy, wz = self.get_coordinate_cursor(picker) | 1051 | + wx, wy, wz = self.get_coordinate_cursor(mx, my, picker) |
| 1053 | x, y, z = self.get_voxel_coord_by_world_pos(wx, wy, wz) | 1052 | x, y, z = self.get_voxel_coord_by_world_pos(wx, wy, wz) |
| 1054 | 1053 | ||
| 1055 | return (x, y, z) | 1054 | return (x, y, z) |
| @@ -1057,7 +1056,7 @@ class Viewer(wx.Panel): | @@ -1057,7 +1056,7 @@ class Viewer(wx.Panel): | ||
| 1057 | def get_voxel_coord_by_world_pos(self, wx, wy, wz): | 1056 | def get_voxel_coord_by_world_pos(self, wx, wy, wz): |
| 1058 | """ | 1057 | """ |
| 1059 | Given the (x, my) screen position returns the voxel coordinate | 1058 | Given the (x, my) screen position returns the voxel coordinate |
| 1060 | - of the voxel at (that mx, my) position. | 1059 | + of the volume at (that mx, my) position. |
| 1061 | 1060 | ||
| 1062 | Parameters: | 1061 | Parameters: |
| 1063 | wx (float): x position. | 1062 | wx (float): x position. |
| @@ -1091,12 +1090,7 @@ class Viewer(wx.Panel): | @@ -1091,12 +1090,7 @@ class Viewer(wx.Panel): | ||
| 1091 | if picker is None: | 1090 | if picker is None: |
| 1092 | picker = self.pick | 1091 | picker = self.pick |
| 1093 | 1092 | ||
| 1094 | - slice_data = self.slice_data | ||
| 1095 | - renderer = slice_data.renderer | ||
| 1096 | - | ||
| 1097 | - picker.Pick(mx, my, 0, renderer) | ||
| 1098 | - | ||
| 1099 | - wx, wy, wz = self.get_coordinate_cursor(picker) | 1093 | + wx, wy, wz = self.get_coordinate_cursor(mx, my, picker) |
| 1100 | return self.get_slice_pixel_coord_by_world_pos(wx, wy, wz) | 1094 | return self.get_slice_pixel_coord_by_world_pos(wx, wy, wz) |
| 1101 | 1095 | ||
| 1102 | return px, py | 1096 | return px, py |
| @@ -1127,8 +1121,6 @@ class Viewer(wx.Panel): | @@ -1127,8 +1121,6 @@ class Viewer(wx.Panel): | ||
| 1127 | slice_data = self.slice_data | 1121 | slice_data = self.slice_data |
| 1128 | renderer = slice_data.renderer | 1122 | renderer = slice_data.renderer |
| 1129 | 1123 | ||
| 1130 | - picker.Pick(mx, my, 0, renderer) | ||
| 1131 | - | ||
| 1132 | coord = self.get_coordinate_cursor(picker) | 1124 | coord = self.get_coordinate_cursor(picker) |
| 1133 | position = slice_data.actor.GetInput().FindPoint(coord) | 1125 | position = slice_data.actor.GetInput().FindPoint(coord) |
| 1134 | 1126 |