Commit 89ea441d62d2397afb94f7692deb32f600f2e4c7

Authored by Thiago Franco de Moraes
1 parent 0439d030
Exists in get_pixel

Simplified get positions in viewer_slice

invesalius/data/styles.py
... ... @@ -1162,12 +1162,13 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1162 1162 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1163 1163 slice_data = viewer.get_slice_data(render)
1164 1164  
1165   - coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, picker=None)
  1165 + coord = self.viewer.get_coord_inside_volume(mouse_x, mouse_y, self.picker)
1166 1166 slice_data.cursor.SetPosition(coord)
1167 1167  
1168 1168 if (self.left_pressed):
1169 1169 cursor = slice_data.cursor
1170   - position = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
  1170 + position = self.viewer.get_slice_pixel_coord_by_world_pos(*coord)
  1171 + print ">>>", position
1171 1172 radius = cursor.radius
1172 1173  
1173 1174 if position < 0:
... ...
invesalius/data/viewer_slice.py
... ... @@ -940,25 +940,23 @@ class Viewer(wx.Panel):
940 940 # WARN: Return the only slice_data used in this slice_viewer.
941 941 return self.slice_data
942 942  
943   - def calcultate_scroll_position(self, position):
944   - # Based in the given coord (x, y, z), returns a list with the scroll positions for each
  943 + def calcultate_scroll_position(self, x, y):
  944 + # Based in the given coord (x, y), returns a list with the scroll positions for each
945 945 # orientation, being the first position the sagital, second the coronal
946 946 # and the last, axial.
947   - image_width = self.slice_.buffer_slices[self.orientation].image.shape[1]
948   -
949 947 if self.orientation == 'AXIAL':
950 948 axial = self.slice_data.number
951   - coronal = position / image_width
952   - sagital = position % image_width
  949 + coronal = y
  950 + sagital = x
953 951  
954 952 elif self.orientation == 'CORONAL':
955   - axial = position / image_width
  953 + axial = y
956 954 coronal = self.slice_data.number
957   - sagital = position % image_width
  955 + sagital = x
958 956  
959 957 elif self.orientation == 'SAGITAL':
960   - axial = position / image_width
961   - coronal = position % image_width
  958 + axial = y
  959 + coronal = x
962 960 sagital = self.slice_data.number
963 961  
964 962 return sagital, coronal, axial
... ... @@ -975,7 +973,7 @@ class Viewer(wx.Panel):
975 973 elif self.orientation == 'SAGITAL':
976 974 mx = round((y - yi)/self.slice_.spacing[1], 0)
977 975 my = round((z - zi)/self.slice_.spacing[2], 0)
978   - return my, mx
  976 + return mx, my
979 977  
980 978 def get_coordinate_cursor(self, picker=None):
981 979 # Find position
... ... @@ -1051,19 +1049,31 @@ class Viewer(wx.Panel):
1051 1049  
1052 1050 picker.Pick(mx, my, 0, renderer)
1053 1051  
1054   - coord = self.get_coordinate_cursor(picker)
1055   - position = slice_data.actor.GetInput().FindPoint(coord)
  1052 + wx, wy, wz = self.get_coordinate_cursor(picker)
  1053 + x, y, z = self.get_voxel_coord_by_world_pos(wx, wy, wz)
1056 1054  
1057   - if position != -1:
1058   - coord = slice_data.actor.GetInput().GetPoint(position)
  1055 + return (x, y, z)
  1056 +
  1057 + def get_voxel_coord_by_world_pos(self, wx, wy, wz):
  1058 + """
  1059 + Given the (x, my) screen position returns the voxel coordinate
  1060 + of the voxel at (that mx, my) position.
1059 1061  
1060   - if position < 0:
1061   - position = viewer.calculate_matrix_position(coord)
  1062 + Parameters:
  1063 + wx (float): x position.
  1064 + wy (float): y position
  1065 + wz (float): z position
1062 1066  
1063   - x, y, z = self.calcultate_scroll_position(position)
  1067 + Returns:
  1068 + voxel_coordinate (x, y, z): voxel coordinate inside the matrix. Can
  1069 + be used to access the voxel value inside the matrix.
  1070 + """
  1071 + px, py = self.get_slice_pixel_coord_by_world_pos(wx, wy, wz)
  1072 + x, y, z = self.calcultate_scroll_position(px, py)
1064 1073  
1065 1074 return (x, y, z)
1066 1075  
  1076 +
1067 1077 def get_slice_pixel_coord_by_screen_pos(self, mx, my, picker=None):
1068 1078 """
1069 1079 Given the (mx, my) screen position returns the pixel coordinate
... ... @@ -1086,32 +1096,27 @@ class Viewer(wx.Panel):
1086 1096  
1087 1097 picker.Pick(mx, my, 0, renderer)
1088 1098  
1089   - coord = self.get_coordinate_cursor(picker)
1090   - position = slice_data.actor.GetInput().FindPoint(coord)
  1099 + wx, wy, wz = self.get_coordinate_cursor(picker)
  1100 + return self.get_slice_pixel_coord_by_world_pos(wx, wy, wz)
1091 1101  
1092   - if position != -1:
1093   - coord = slice_data.actor.GetInput().GetPoint(position)
  1102 + return px, py
1094 1103  
1095   - if position < 0:
1096   - px, py = viewer.calculate_matrix_position(coord)
1097   - else:
1098   - spacing = self.slice_.spacing
1099   - image = self.slice_.buffer_slices[self.orientation].image
1100   - if self.orientation == 'AXIAL':
1101   - sx = spacing[0]
1102   - sy = spacing[1]
1103   - py = position / image.shape[1]
1104   - px = position % image.shape[1]
1105   - elif self.orientation == 'CORONAL':
1106   - sx = spacing[0]
1107   - sy = spacing[2]
1108   - py = position / image.shape[1]
1109   - px = position % image.shape[1]
1110   - elif self.orientation == 'SAGITAL':
1111   - sx = spacing[2]
1112   - sy = spacing[1]
1113   - py = position / image.shape[1]
1114   - px = position % image.shape[1]
  1104 + def get_slice_pixel_coord_by_world_pos(self, wx, wy, wz):
  1105 + """
  1106 + Given the (wx, wy, wz) world position returns the pixel coordinate
  1107 + of the slice at (that mx, my) position.
  1108 +
  1109 + Parameters:
  1110 + mx (int): x position.
  1111 + my (int): y position
  1112 + picker: the picker used to get calculate the pixel coordinate.
  1113 +
  1114 + Returns:
  1115 + voxel_coordinate (x, y): voxel coordinate inside the matrix. Can
  1116 + be used to access the voxel value inside the matrix.
  1117 + """
  1118 + coord = wx, wy, wz
  1119 + px, py = self.calculate_matrix_position(coord)
1115 1120  
1116 1121 return px, py
1117 1122  
... ...