Compare View

switch
from
...
to
 
Commits (2)
  • Olli-Pekka Kahilakoski
     
  • * Doing some tests
    
    * Drawing texts on canvas scaled by GetContentScaleFactor
    
    * Created a method to get mouse position
    
    * Using GetMousePosition() on slice editor
    
    * Using GetMousePosition() on watershed style
    
    * Using GetMousePosition() on image reorientation
    
    * Using GetMousePosition() on mask filling
    
    * Using GetMousePosition() on mask crop
    
    * Using GetMousePosition() on cross
    
    * Using GetMousePosition() on WW&WL
    
    * Using GetMousePosition() on mouse scroll
    
    * Using GetMousePosition() on region growing
    
    * Using GetMousePosition() on editor
    
    * created a method to get vtk mouse position on viewer slice
    
    * using get_vtk_mouse_position on canvas renderer
    
    * using get_vtk_mouse_position on slice styles
    
    * Removed unneed prints
    
    * Using WX to get Mouse position on vtk renderer
    
    * Using get_vtk_mouse_position on viewer_volume
    
    * Added a comment to explain the problem with highdpi display on mac
    
    * Scalling WW&WL text on ViewerVolume
    Thiago Franco de Moraes
     
invesalius/data/styles.py
@@ -77,6 +77,8 @@ WATERSHED_OPERATIONS = {_("Erase"): BRUSH_ERASE, @@ -77,6 +77,8 @@ WATERSHED_OPERATIONS = {_("Erase"): BRUSH_ERASE,
77 77
78 class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): 78 class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage):
79 def __init__(self, viewer): 79 def __init__(self, viewer):
  80 + self.viewer = viewer
  81 +
80 self.right_pressed = False 82 self.right_pressed = False
81 self.left_pressed = False 83 self.left_pressed = False
82 self.middle_pressed = False 84 self.middle_pressed = False
@@ -110,6 +112,22 @@ class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): @@ -110,6 +112,22 @@ class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage):
110 def OnMiddleButtonReleaseEvent(self, evt, obj): 112 def OnMiddleButtonReleaseEvent(self, evt, obj):
111 self.middle_pressed = False 113 self.middle_pressed = False
112 114
  115 + def GetMousePosition(self):
  116 + mx, my = self.viewer.get_vtk_mouse_position()
  117 + return mx, my
  118 +
  119 + def GetPickPosition(self, mouse_position=None):
  120 + if mouse_position is None:
  121 + mx, my = self.GetMousePosition()
  122 + else:
  123 + mx, my = mouse_position
  124 + iren = self.viewer.interactor
  125 + render = iren.FindPokedRenderer(mx, my)
  126 + self.picker.Pick(mx, my, 0, render)
  127 + x, y, z = self.picker.GetPickPosition()
  128 + return (x, y, z)
  129 +
  130 +
113 131
114 class DefaultInteractorStyle(BaseImageInteractorStyle): 132 class DefaultInteractorStyle(BaseImageInteractorStyle):
115 """ 133 """
@@ -277,7 +295,7 @@ class BaseImageEditionInteractorStyle(DefaultInteractorStyle): @@ -277,7 +295,7 @@ class BaseImageEditionInteractorStyle(DefaultInteractorStyle):
277 295
278 viewer._set_editor_cursor_visibility(1) 296 viewer._set_editor_cursor_visibility(1)
279 297
280 - mouse_x, mouse_y = iren.GetEventPosition() 298 + mouse_x, mouse_y = self.GetMousePosition()
281 render = iren.FindPokedRenderer(mouse_x, mouse_y) 299 render = iren.FindPokedRenderer(mouse_x, mouse_y)
282 slice_data = viewer.get_slice_data(render) 300 slice_data = viewer.get_slice_data(render)
283 301
@@ -316,7 +334,7 @@ class BaseImageEditionInteractorStyle(DefaultInteractorStyle): @@ -316,7 +334,7 @@ class BaseImageEditionInteractorStyle(DefaultInteractorStyle):
316 334
317 viewer._set_editor_cursor_visibility(1) 335 viewer._set_editor_cursor_visibility(1)
318 336
319 - mouse_x, mouse_y = iren.GetEventPosition() 337 + mouse_x, mouse_y = self.GetMousePosition()
320 render = iren.FindPokedRenderer(mouse_x, mouse_y) 338 render = iren.FindPokedRenderer(mouse_x, mouse_y)
321 slice_data = viewer.get_slice_data(render) 339 slice_data = viewer.get_slice_data(render)
322 operation = self.config.operation 340 operation = self.config.operation
@@ -486,7 +504,7 @@ class CrossInteractorStyle(DefaultInteractorStyle): @@ -486,7 +504,7 @@ class CrossInteractorStyle(DefaultInteractorStyle):
486 self.ChangeCrossPosition(iren) 504 self.ChangeCrossPosition(iren)
487 505
488 def ChangeCrossPosition(self, iren): 506 def ChangeCrossPosition(self, iren):
489 - mouse_x, mouse_y = iren.GetEventPosition() 507 + mouse_x, mouse_y = self.GetMousePosition()
490 x, y, z = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) 508 x, y, z = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker)
491 self.viewer.UpdateSlicesPosition([x, y, z]) 509 self.viewer.UpdateSlicesPosition([x, y, z])
492 # This "Set cross" message is needed to update the cross in the other slices 510 # This "Set cross" message is needed to update the cross in the other slices
@@ -626,7 +644,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle): @@ -626,7 +644,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle):
626 def OnWindowLevelMove(self, obj, evt): 644 def OnWindowLevelMove(self, obj, evt):
627 if (self.left_pressed): 645 if (self.left_pressed):
628 iren = obj.GetInteractor() 646 iren = obj.GetInteractor()
629 - mouse_x, mouse_y = iren.GetEventPosition() 647 + mouse_x, mouse_y = self.GetMousePosition()
630 self.acum_achange_window += mouse_x - self.last_x 648 self.acum_achange_window += mouse_x - self.last_x
631 self.acum_achange_level += mouse_y - self.last_y 649 self.acum_achange_level += mouse_y - self.last_y
632 self.last_x, self.last_y = mouse_x, mouse_y 650 self.last_x, self.last_y = mouse_x, mouse_y
@@ -713,7 +731,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): @@ -713,7 +731,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
713 def OnInsertMeasurePoint(self, obj, evt): 731 def OnInsertMeasurePoint(self, obj, evt):
714 slice_number = self.slice_data.number 732 slice_number = self.slice_data.number
715 x, y, z = self._get_pos_clicked() 733 x, y, z = self._get_pos_clicked()
716 - mx, my = self.viewer.interactor.GetEventPosition() 734 + mx, my = self.GetMousePosition()
717 735
718 if self.selected: 736 if self.selected:
719 self.selected = None 737 self.selected = None
@@ -784,7 +802,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): @@ -784,7 +802,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
784 self.viewer.UpdateCanvas() 802 self.viewer.UpdateCanvas()
785 803
786 else: 804 else:
787 - mx, my = self.viewer.interactor.GetEventPosition() 805 + mx, my = self.GetMousePosition()
788 if self._verify_clicked_display(mx, my): 806 if self._verify_clicked_display(mx, my):
789 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_HAND)) 807 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_HAND))
790 else: 808 else:
@@ -801,12 +819,8 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): @@ -801,12 +819,8 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
801 self.viewer.scroll_enabled = True 819 self.viewer.scroll_enabled = True
802 820
803 def _get_pos_clicked(self): 821 def _get_pos_clicked(self):
804 - iren = self.viewer.interactor  
805 - mx,my = iren.GetEventPosition()  
806 - render = iren.FindPokedRenderer(mx, my)  
807 self.picker.AddPickList(self.slice_data.actor) 822 self.picker.AddPickList(self.slice_data.actor)
808 - self.picker.Pick(mx, my, 0, render)  
809 - x, y, z = self.picker.GetPickPosition() 823 + x, y, z = self.GetPickPosition()
810 self.picker.DeletePickList(self.slice_data.actor) 824 self.picker.DeletePickList(self.slice_data.actor)
811 return (x, y, z) 825 return (x, y, z)
812 826
@@ -919,11 +933,11 @@ class DensityMeasureStyle(DefaultInteractorStyle): @@ -919,11 +933,11 @@ class DensityMeasureStyle(DefaultInteractorStyle):
919 933
920 def _pick_position(self): 934 def _pick_position(self):
921 iren = self.viewer.interactor 935 iren = self.viewer.interactor
922 - mx, my = iren.GetEventPosition() 936 + mx, my = self.GetMousePosition()
923 return (mx, my) 937 return (mx, my)
924 938
925 def _get_pos_clicked(self): 939 def _get_pos_clicked(self):
926 - mouse_x, mouse_y = self._pick_position() 940 + mouse_x, mouse_y = self.GetMousePosition()
927 position = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker) 941 position = self.viewer.get_coordinate_cursor(mouse_x, mouse_y, self.picker)
928 return position 942 return position
929 943
@@ -1232,15 +1246,14 @@ class EditorInteractorStyle(DefaultInteractorStyle): @@ -1232,15 +1246,14 @@ class EditorInteractorStyle(DefaultInteractorStyle):
1232 self.viewer.slice_data.cursor.Show(0) 1246 self.viewer.slice_data.cursor.Show(0)
1233 1247
1234 def SetUp(self): 1248 def SetUp(self):
1235 -  
1236 x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition()) 1249 x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition())
1237 if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE: 1250 if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE:
1238 self.viewer.slice_data.cursor.Show() 1251 self.viewer.slice_data.cursor.Show()
1239 - 1252 +
1240 y = self.viewer.interactor.GetSize()[1] - y 1253 y = self.viewer.interactor.GetSize()[1] - y
1241 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker) 1254 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker)
1242 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z)) 1255 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z))
1243 - 1256 +
1244 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK)) 1257 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
1245 self.viewer.interactor.Render() 1258 self.viewer.interactor.Render()
1246 1259
@@ -1319,7 +1332,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): @@ -1319,7 +1332,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
1319 1332
1320 viewer._set_editor_cursor_visibility(1) 1333 viewer._set_editor_cursor_visibility(1)
1321 1334
1322 - mouse_x, mouse_y = iren.GetEventPosition() 1335 + mouse_x, mouse_y = self.GetMousePosition()
1323 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1336 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1324 slice_data = viewer.get_slice_data(render) 1337 slice_data = viewer.get_slice_data(render)
1325 1338
@@ -1351,7 +1364,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): @@ -1351,7 +1364,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
1351 1364
1352 viewer._set_editor_cursor_visibility(1) 1365 viewer._set_editor_cursor_visibility(1)
1353 1366
1354 - mouse_x, mouse_y = iren.GetEventPosition() 1367 + mouse_x, mouse_y = self.GetMousePosition()
1355 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1368 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1356 slice_data = viewer.get_slice_data(render) 1369 slice_data = viewer.get_slice_data(render)
1357 1370
@@ -1402,7 +1415,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): @@ -1402,7 +1415,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
1402 iren = self.viewer.interactor 1415 iren = self.viewer.interactor
1403 viewer = self.viewer 1416 viewer = self.viewer
1404 if iren.GetControlKey(): 1417 if iren.GetControlKey():
1405 - mouse_x, mouse_y = iren.GetEventPosition() 1418 + mouse_x, mouse_y = self.GetMousePosition()
1406 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1419 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1407 slice_data = self.viewer.get_slice_data(render) 1420 slice_data = self.viewer.get_slice_data(render)
1408 cursor = slice_data.cursor 1421 cursor = slice_data.cursor
@@ -1420,7 +1433,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): @@ -1420,7 +1433,7 @@ class EditorInteractorStyle(DefaultInteractorStyle):
1420 iren = self.viewer.interactor 1433 iren = self.viewer.interactor
1421 viewer = self.viewer 1434 viewer = self.viewer
1422 if iren.GetControlKey(): 1435 if iren.GetControlKey():
1423 - mouse_x, mouse_y = iren.GetEventPosition() 1436 + mouse_x, mouse_y = self.GetMousePosition()
1424 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1437 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1425 slice_data = self.viewer.get_slice_data(render) 1438 slice_data = self.viewer.get_slice_data(render)
1426 cursor = slice_data.cursor 1439 cursor = slice_data.cursor
@@ -1545,11 +1558,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): @@ -1545,11 +1558,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1545 x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition()) 1558 x, y = self.viewer.interactor.ScreenToClient(wx.GetMousePosition())
1546 if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE: 1559 if self.viewer.interactor.HitTest((x, y)) == wx.HT_WINDOW_INSIDE:
1547 self.viewer.slice_data.cursor.Show() 1560 self.viewer.slice_data.cursor.Show()
1548 - 1561 +
1549 y = self.viewer.interactor.GetSize()[1] - y 1562 y = self.viewer.interactor.GetSize()[1] - y
1550 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker) 1563 w_x, w_y, w_z = self.viewer.get_coordinate_cursor(x, y, self.picker)
1551 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z)) 1564 self.viewer.slice_data.cursor.SetPosition((w_x, w_y, w_z))
1552 - 1565 +
1553 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK)) 1566 self.viewer.interactor.SetCursor(wx.Cursor(wx.CURSOR_BLANK))
1554 self.viewer.interactor.Render() 1567 self.viewer.interactor.Render()
1555 1568
@@ -1622,7 +1635,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): @@ -1622,7 +1635,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1622 iren = self.viewer.interactor 1635 iren = self.viewer.interactor
1623 viewer = self.viewer 1636 viewer = self.viewer
1624 if iren.GetControlKey(): 1637 if iren.GetControlKey():
1625 - mouse_x, mouse_y = iren.GetEventPosition() 1638 + mouse_x, mouse_y = self.GetMousePosition()
1626 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1639 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1627 slice_data = self.viewer.get_slice_data(render) 1640 slice_data = self.viewer.get_slice_data(render)
1628 cursor = slice_data.cursor 1641 cursor = slice_data.cursor
@@ -1640,7 +1653,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): @@ -1640,7 +1653,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1640 iren = self.viewer.interactor 1653 iren = self.viewer.interactor
1641 viewer = self.viewer 1654 viewer = self.viewer
1642 if iren.GetControlKey(): 1655 if iren.GetControlKey():
1643 - mouse_x, mouse_y = iren.GetEventPosition() 1656 + mouse_x, mouse_y = self.GetMousePosition()
1644 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1657 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1645 slice_data = self.viewer.get_slice_data(render) 1658 slice_data = self.viewer.get_slice_data(render)
1646 cursor = slice_data.cursor 1659 cursor = slice_data.cursor
@@ -1663,7 +1676,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): @@ -1663,7 +1676,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1663 1676
1664 viewer._set_editor_cursor_visibility(1) 1677 viewer._set_editor_cursor_visibility(1)
1665 1678
1666 - mouse_x, mouse_y = iren.GetEventPosition() 1679 + mouse_x, mouse_y = self.GetMousePosition()
1667 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1680 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1668 slice_data = viewer.get_slice_data(render) 1681 slice_data = viewer.get_slice_data(render)
1669 1682
@@ -1710,7 +1723,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): @@ -1710,7 +1723,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1710 1723
1711 viewer._set_editor_cursor_visibility(1) 1724 viewer._set_editor_cursor_visibility(1)
1712 1725
1713 - mouse_x, mouse_y = iren.GetEventPosition() 1726 + mouse_x, mouse_y = self.GetMousePosition()
1714 render = iren.FindPokedRenderer(mouse_x, mouse_y) 1727 render = iren.FindPokedRenderer(mouse_x, mouse_y)
1715 slice_data = viewer.get_slice_data(render) 1728 slice_data = viewer.get_slice_data(render)
1716 1729
@@ -2033,7 +2046,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -2033,7 +2046,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
2033 if self._over_center: 2046 if self._over_center:
2034 self.dragging = True 2047 self.dragging = True
2035 else: 2048 else:
2036 - x, y = self.viewer.interactor.GetEventPosition() 2049 + x, y = self.GetMousePosition()
2037 w, h = self.viewer.interactor.GetSize() 2050 w, h = self.viewer.interactor.GetSize()
2038 2051
2039 self.picker.Pick(h/2.0, w/2.0, 0, self.viewer.slice_data.renderer) 2052 self.picker.Pick(h/2.0, w/2.0, 0, self.viewer.slice_data.renderer)
@@ -2063,7 +2076,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -2063,7 +2076,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
2063 else: 2076 else:
2064 # Getting mouse position 2077 # Getting mouse position
2065 iren = self.viewer.interactor 2078 iren = self.viewer.interactor
2066 - mx, my = iren.GetEventPosition() 2079 + mx, my = self.GetMousePosition()
2067 2080
2068 # Getting center value 2081 # Getting center value
2069 center = self.viewer.slice_.center 2082 center = self.viewer.slice_.center
@@ -2109,7 +2122,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -2109,7 +2122,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
2109 2122
2110 def _move_center_rot(self): 2123 def _move_center_rot(self):
2111 iren = self.viewer.interactor 2124 iren = self.viewer.interactor
2112 - mx, my = iren.GetEventPosition() 2125 + mx, my = self.GetMousePosition()
2113 2126
2114 icx, icy, icz = self.viewer.slice_.center 2127 icx, icy, icz = self.viewer.slice_.center
2115 2128
@@ -2131,7 +2144,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): @@ -2131,7 +2144,7 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle):
2131 def _rotate(self): 2144 def _rotate(self):
2132 # Getting mouse position 2145 # Getting mouse position
2133 iren = self.viewer.interactor 2146 iren = self.viewer.interactor
2134 - mx, my = iren.GetEventPosition() 2147 + mx, my = self.GetMousePosition()
2135 2148
2136 cx, cy, cz = self.viewer.slice_.center 2149 cx, cy, cz = self.viewer.slice_.center
2137 2150
@@ -2294,7 +2307,7 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): @@ -2294,7 +2307,7 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle):
2294 2307
2295 viewer = self.viewer 2308 viewer = self.viewer
2296 iren = viewer.interactor 2309 iren = viewer.interactor
2297 - mouse_x, mouse_y = iren.GetEventPosition() 2310 + mouse_x, mouse_y = self.GetMousePosition()
2298 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) 2311 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
2299 2312
2300 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] 2313 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
@@ -2401,14 +2414,12 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): @@ -2401,14 +2414,12 @@ class CropMaskInteractorStyle(DefaultInteractorStyle):
2401 Publisher.subscribe(self.CropMask, "Crop mask") 2414 Publisher.subscribe(self.CropMask, "Crop mask")
2402 2415
2403 def OnMove(self, obj, evt): 2416 def OnMove(self, obj, evt):
2404 - iren = self.viewer.interactor  
2405 - x, y = iren.GetEventPosition() 2417 + x, y = self.GetMousePosition()
2406 self.draw_retangle.MouseMove(x,y) 2418 self.draw_retangle.MouseMove(x,y)
2407 2419
2408 def OnLeftPressed(self, obj, evt): 2420 def OnLeftPressed(self, obj, evt):
2409 self.draw_retangle.mouse_pressed = True 2421 self.draw_retangle.mouse_pressed = True
2410 - iren = self.viewer.interactor  
2411 - x, y = iren.GetEventPosition() 2422 + x, y = self.GetMousePosition()
2412 self.draw_retangle.LeftPressed(x,y) 2423 self.draw_retangle.LeftPressed(x,y)
2413 2424
2414 def OnReleaseLeftButton(self, obj, evt): 2425 def OnReleaseLeftButton(self, obj, evt):
@@ -2416,13 +2427,12 @@ class CropMaskInteractorStyle(DefaultInteractorStyle): @@ -2416,13 +2427,12 @@ class CropMaskInteractorStyle(DefaultInteractorStyle):
2416 self.draw_retangle.ReleaseLeft() 2427 self.draw_retangle.ReleaseLeft()
2417 2428
2418 def SetUp(self): 2429 def SetUp(self):
2419 -  
2420 self.draw_retangle = geom.DrawCrop2DRetangle() 2430 self.draw_retangle = geom.DrawCrop2DRetangle()
2421 self.draw_retangle.SetViewer(self.viewer) 2431 self.draw_retangle.SetViewer(self.viewer)
2422 2432
2423 self.viewer.canvas.draw_list.append(self.draw_retangle) 2433 self.viewer.canvas.draw_list.append(self.draw_retangle)
2424 self.viewer.UpdateCanvas() 2434 self.viewer.UpdateCanvas()
2425 - 2435 +
2426 if not(self.config.dlg_visible): 2436 if not(self.config.dlg_visible):
2427 self.config.dlg_visible = True 2437 self.config.dlg_visible = True
2428 2438
@@ -2550,7 +2560,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle): @@ -2550,7 +2560,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle):
2550 return 2560 return
2551 2561
2552 iren = self.viewer.interactor 2562 iren = self.viewer.interactor
2553 - mouse_x, mouse_y = iren.GetEventPosition() 2563 + mouse_x, mouse_y = self.GetMousePosition()
2554 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) 2564 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
2555 2565
2556 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] 2566 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
@@ -2670,7 +2680,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): @@ -2670,7 +2680,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
2670 def do_2d_seg(self): 2680 def do_2d_seg(self):
2671 viewer = self.viewer 2681 viewer = self.viewer
2672 iren = viewer.interactor 2682 iren = viewer.interactor
2673 - mouse_x, mouse_y = iren.GetEventPosition() 2683 + mouse_x, mouse_y = self.GetMousePosition()
2674 x, y = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) 2684 x, y = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
2675 2685
2676 mask = self.viewer.slice_.buffer_slices[self.orientation].mask.copy() 2686 mask = self.viewer.slice_.buffer_slices[self.orientation].mask.copy()
@@ -2736,7 +2746,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): @@ -2736,7 +2746,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
2736 def do_3d_seg(self): 2746 def do_3d_seg(self):
2737 viewer = self.viewer 2747 viewer = self.viewer
2738 iren = viewer.interactor 2748 iren = viewer.interactor
2739 - mouse_x, mouse_y = iren.GetEventPosition() 2749 + mouse_x, mouse_y = self.GetMousePosition()
2740 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) 2750 x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
2741 2751
2742 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] 2752 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
invesalius/data/styles_3d.py
@@ -300,8 +300,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle): @@ -300,8 +300,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle):
300 300
301 def OnWindowLevelMove(self, obj, evt): 301 def OnWindowLevelMove(self, obj, evt):
302 if self.changing_wwwl: 302 if self.changing_wwwl:
303 - iren = obj.GetInteractor()  
304 - mouse_x, mouse_y = iren.GetEventPosition() 303 + mouse_x, mouse_y = self.viewer.get_vtk_mouse_position()
305 diff_x = mouse_x - self.last_x 304 diff_x = mouse_x - self.last_x
306 diff_y = mouse_y - self.last_y 305 diff_y = mouse_y - self.last_y
307 self.last_x, self.last_y = mouse_x, mouse_y 306 self.last_x, self.last_y = mouse_x, mouse_y
@@ -311,8 +310,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle): @@ -311,8 +310,7 @@ class WWWLInteractorStyle(DefaultInteractorStyle):
311 Publisher.sendMessage('Render volume viewer') 310 Publisher.sendMessage('Render volume viewer')
312 311
313 def OnWindowLevelClick(self, obj, evt): 312 def OnWindowLevelClick(self, obj, evt):
314 - iren = obj.GetInteractor()  
315 - self.last_x, self.last_y = iren.GetLastEventPosition() 313 + self.last_x, self.last_y = self.viewer.get_vtk_mouse_position()
316 self.changing_wwwl = True 314 self.changing_wwwl = True
317 315
318 def OnWindowLevelRelease(self, obj, evt): 316 def OnWindowLevelRelease(self, obj, evt):
@@ -345,7 +343,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): @@ -345,7 +343,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
345 Publisher.sendMessage("Remove incomplete measurements") 343 Publisher.sendMessage("Remove incomplete measurements")
346 344
347 def OnInsertLinearMeasurePoint(self, obj, evt): 345 def OnInsertLinearMeasurePoint(self, obj, evt):
348 - x,y = self.viewer.interactor.GetEventPosition() 346 + x,y = self.viewer.get_vtk_mouse_position()
349 self.measure_picker.Pick(x, y, 0, self.viewer.ren) 347 self.measure_picker.Pick(x, y, 0, self.viewer.ren)
350 x, y, z = self.measure_picker.GetPickPosition() 348 x, y, z = self.measure_picker.GetPickPosition()
351 if self.measure_picker.GetActor(): 349 if self.measure_picker.GetActor():
@@ -384,7 +382,7 @@ class AngularMeasureInteractorStyle(DefaultInteractorStyle): @@ -384,7 +382,7 @@ class AngularMeasureInteractorStyle(DefaultInteractorStyle):
384 Publisher.sendMessage("Remove incomplete measurements") 382 Publisher.sendMessage("Remove incomplete measurements")
385 383
386 def OnInsertAngularMeasurePoint(self, obj, evt): 384 def OnInsertAngularMeasurePoint(self, obj, evt):
387 - x,y = self.viewer.interactor.GetEventPosition() 385 + x,y = self.viewer.get_vtk_mouse_position()
388 self.measure_picker.Pick(x, y, 0, self.viewer.ren) 386 self.measure_picker.Pick(x, y, 0, self.viewer.ren)
389 x, y, z = self.measure_picker.GetPickPosition() 387 x, y, z = self.measure_picker.GetPickPosition()
390 if self.measure_picker.GetActor(): 388 if self.measure_picker.GetActor():
@@ -412,7 +410,7 @@ class SeedInteractorStyle(DefaultInteractorStyle): @@ -412,7 +410,7 @@ class SeedInteractorStyle(DefaultInteractorStyle):
412 self.AddObserver("LeftButtonPressEvent", self.OnInsertSeed) 410 self.AddObserver("LeftButtonPressEvent", self.OnInsertSeed)
413 411
414 def OnInsertSeed(self, obj, evt): 412 def OnInsertSeed(self, obj, evt):
415 - x,y = self.viewer.interactor.GetEventPosition() 413 + x,y = self.viewer.get_vtk_mouse_position()
416 self.picker.Pick(x, y, 0, self.viewer.ren) 414 self.picker.Pick(x, y, 0, self.viewer.ren)
417 point_id = self.picker.GetPointId() 415 point_id = self.picker.GetPointId()
418 if point_id > -1: 416 if point_id > -1:
invesalius/data/viewer_slice.py
@@ -650,6 +650,27 @@ class Viewer(wx.Panel): @@ -650,6 +650,27 @@ class Viewer(wx.Panel):
650 my = round((z - zi)/self.slice_.spacing[2], 0) 650 my = round((z - zi)/self.slice_.spacing[2], 0)
651 return int(mx), int(my) 651 return int(mx), int(my)
652 652
  653 + def get_vtk_mouse_position(self):
  654 + """
  655 + Get Mouse position inside a wxVTKRenderWindowInteractorself. Return a
  656 + tuple with X and Y position.
  657 + Please use this instead of using iren.GetEventPosition because it's
  658 + not returning the correct values on Mac with HighDPI display, maybe
  659 + the same is happing with Windows and Linux, we need to test.
  660 + """
  661 + mposx, mposy = wx.GetMousePosition()
  662 + cposx, cposy = self.interactor.ScreenToClient((mposx, mposy))
  663 + mx, my = cposx, self.interactor.GetSize()[1] - cposy
  664 + if sys.platform == 'darwin':
  665 + # It's needed to mutiple by scale factor in HighDPI because of
  666 + # https://docs.wxpython.org/wx.glcanvas.GLCanvas.html
  667 + # For now we are doing this only on Mac but it may be needed on
  668 + # Windows and Linux too.
  669 + scale = self.interactor.GetContentScaleFactor()
  670 + mx *= scale
  671 + my *= scale
  672 + return int(mx), int(my)
  673 +
653 def get_coordinate_cursor(self, mx, my, picker=None): 674 def get_coordinate_cursor(self, mx, my, picker=None):
654 """ 675 """
655 Given the mx, my screen position returns the x, y, z position in world 676 Given the mx, my screen position returns the x, y, z position in world
@@ -1028,7 +1049,7 @@ class Viewer(wx.Panel): @@ -1028,7 +1049,7 @@ class Viewer(wx.Panel):
1028 #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) 1049 #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease)
1029 self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) 1050 self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
1030 self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu) 1051 self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu)
1031 - # self.interactor.Bind(wx.EVT_SIZE, self.OnSize) 1052 + self.interactor.Bind(wx.EVT_SIZE, self.OnSize)
1032 1053
1033 def LoadImagedata(self, mask_dict): 1054 def LoadImagedata(self, mask_dict):
1034 self.SetInput(mask_dict) 1055 self.SetInput(mask_dict)
@@ -1413,12 +1434,13 @@ class Viewer(wx.Panel): @@ -1413,12 +1434,13 @@ class Viewer(wx.Panel):
1413 self.OnScrollBar() 1434 self.OnScrollBar()
1414 1435
1415 def OnSize(self, evt): 1436 def OnSize(self, evt):
1416 - w, h = evt.GetSize()  
1417 - w = float(w)  
1418 - h = float(h)  
1419 - if self.slice_data:  
1420 - self.slice_data.SetSize((w, h))  
1421 - evt.Skip() 1437 + print("OnSize")
  1438 + w, h = self.GetSize()
  1439 + rwin = self.interactor.GetRenderWindow()
  1440 + rwin.SetSize(w, h)
  1441 + # if self.slice_data:
  1442 + # self.slice_data.SetSize((w, h))
  1443 + # evt.Skip()
1422 1444
1423 def OnSetMIPSize(self, number_slices): 1445 def OnSetMIPSize(self, number_slices):
1424 self.number_slices = number_slices 1446 self.number_slices = number_slices
invesalius/data/viewer_volume.py
@@ -116,6 +116,9 @@ class Viewer(wx.Panel): @@ -116,6 +116,9 @@ class Viewer(wx.Panel):
116 self.text = vtku.TextZero() 116 self.text = vtku.TextZero()
117 self.text.SetValue("") 117 self.text.SetValue("")
118 self.text.SetPosition(const.TEXT_POS_LEFT_UP) 118 self.text.SetPosition(const.TEXT_POS_LEFT_UP)
  119 + if sys.platform == 'darwin':
  120 + font_size = const.TEXT_SIZE_LARGE * self.GetContentScaleFactor()
  121 + self.text.SetSize(int(round(font_size, 0)))
119 self.ren.AddActor(self.text.actor) 122 self.ren.AddActor(self.text.actor)
120 123
121 # self.polygon = Polygon(None, is_3d=False) 124 # self.polygon = Polygon(None, is_3d=False)
@@ -318,6 +321,27 @@ class Viewer(wx.Panel): @@ -318,6 +321,27 @@ class Viewer(wx.Panel):
318 Publisher.subscribe(self.ActivateRobotMode, 'Robot navigation mode') 321 Publisher.subscribe(self.ActivateRobotMode, 'Robot navigation mode')
319 Publisher.subscribe(self.OnUpdateRobotStatus, 'Update robot status') 322 Publisher.subscribe(self.OnUpdateRobotStatus, 'Update robot status')
320 323
  324 + def get_vtk_mouse_position(self):
  325 + """
  326 + Get Mouse position inside a wxVTKRenderWindowInteractorself. Return a
  327 + tuple with X and Y position.
  328 + Please use this instead of using iren.GetEventPosition because it's
  329 + not returning the correct values on Mac with HighDPI display, maybe
  330 + the same is happing with Windows and Linux, we need to test.
  331 + """
  332 + mposx, mposy = wx.GetMousePosition()
  333 + cposx, cposy = self.interactor.ScreenToClient((mposx, mposy))
  334 + mx, my = cposx, self.interactor.GetSize()[1] - cposy
  335 + if sys.platform == 'darwin':
  336 + # It's needed to mutiple by scale factor in HighDPI because of
  337 + # https://docs.wxpython.org/wx.glcanvas.GLCanvas.html
  338 + # For now we are doing this only on Mac but it may be needed on
  339 + # Windows and Linux too.
  340 + scale = self.interactor.GetContentScaleFactor()
  341 + mx *= scale
  342 + my *= scale
  343 + return int(mx), int(my)
  344 +
321 def SetStereoMode(self, mode): 345 def SetStereoMode(self, mode):
322 ren_win = self.interactor.GetRenderWindow() 346 ren_win = self.interactor.GetRenderWindow()
323 347
invesalius/data/vtk_utils.py
@@ -233,6 +233,7 @@ class TextZero(object): @@ -233,6 +233,7 @@ class TextZero(object):
233 233
234 def SetSize(self, size): 234 def SetSize(self, size):
235 self.property.SetFontSize(size) 235 self.property.SetFontSize(size)
  236 + self.actor.GetTextProperty().ShallowCopy(self.property)
236 237
237 def SetSymbolicSize(self, size): 238 def SetSymbolicSize(self, size):
238 self.symbolic_syze = size 239 self.symbolic_syze = size
@@ -288,8 +289,8 @@ class TextZero(object): @@ -288,8 +289,8 @@ class TextZero(object):
288 coord.SetValue(*self.position) 289 coord.SetValue(*self.position)
289 x, y = coord.GetComputedDisplayValue(canvas.evt_renderer) 290 x, y = coord.GetComputedDisplayValue(canvas.evt_renderer)
290 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) 291 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
291 - # font.SetWeight(wx.FONTWEIGHT_BOLD)  
292 font.SetSymbolicSize(self.symbolic_syze) 292 font.SetSymbolicSize(self.symbolic_syze)
  293 + font.Scale(canvas.viewer.GetContentScaleFactor())
293 if self.bottom_pos or self.right_pos: 294 if self.bottom_pos or self.right_pos:
294 w, h = canvas.calc_text_size(self.text, font) 295 w, h = canvas.calc_text_size(self.text, font)
295 if self.right_pos: 296 if self.right_pos:
invesalius/gui/widgets/canvas_renderer.py
@@ -180,13 +180,11 @@ class CanvasRendererCTX: @@ -180,13 +180,11 @@ class CanvasRendererCTX:
180 return False 180 return False
181 181
182 def Refresh(self): 182 def Refresh(self):
183 - print('Refresh')  
184 self.modified = True 183 self.modified = True
185 self.viewer.interactor.Render() 184 self.viewer.interactor.Render()
186 185
187 def OnMouseMove(self, evt): 186 def OnMouseMove(self, evt):
188 - x, y = evt.GetPosition()  
189 - y = self.viewer.interactor.GetSize()[1] - y 187 + x, y = self.viewer.get_vtk_mouse_position()
190 redraw = False 188 redraw = False
191 189
192 if self._drag_obj: 190 if self._drag_obj:
@@ -230,8 +228,7 @@ class CanvasRendererCTX: @@ -230,8 +228,7 @@ class CanvasRendererCTX:
230 evt.Skip() 228 evt.Skip()
231 229
232 def OnLeftButtonPress(self, evt): 230 def OnLeftButtonPress(self, evt):
233 - x, y = evt.GetPosition()  
234 - y = self.viewer.interactor.GetSize()[1] - y 231 + x, y = self.viewer.get_vtk_mouse_position()
235 if self._over_obj and hasattr(self._over_obj, 'on_mouse_move'): 232 if self._over_obj and hasattr(self._over_obj, 'on_mouse_move'):
236 if hasattr(self._over_obj, 'on_select'): 233 if hasattr(self._over_obj, 'on_select'):
237 try: 234 try:
@@ -286,8 +283,7 @@ class CanvasRendererCTX: @@ -286,8 +283,7 @@ class CanvasRendererCTX:
286 evt.Skip() 283 evt.Skip()
287 284
288 def OnDoubleClick(self, evt): 285 def OnDoubleClick(self, evt):
289 - x, y = evt.GetPosition()  
290 - y = self.viewer.interactor.GetSize()[1] - y 286 + x, y = self.viewer.get_vtk_mouse_position()
291 evt_obj = CanvasEvent('double_left_click', None, (x, y), self.viewer, self.evt_renderer, 287 evt_obj = CanvasEvent('double_left_click', None, (x, y), self.viewer, self.evt_renderer,
292 control_down=evt.ControlDown(), 288 control_down=evt.ControlDown(),
293 alt_down=evt.AltDown(), 289 alt_down=evt.AltDown(),
@@ -301,6 +297,7 @@ class CanvasRendererCTX: @@ -301,6 +297,7 @@ class CanvasRendererCTX:
301 def OnPaint(self, evt, obj): 297 def OnPaint(self, evt, obj):
302 size = self.canvas_renderer.GetSize() 298 size = self.canvas_renderer.GetSize()
303 w, h = size 299 w, h = size
  300 + ew, eh = self.evt_renderer.GetSize()
304 if self._size != size: 301 if self._size != size:
305 self._size = size 302 self._size = size
306 self._resize_canvas(w, h) 303 self._resize_canvas(w, h)
@@ -628,17 +625,18 @@ class CanvasRendererCTX: @@ -628,17 +625,18 @@ class CanvasRendererCTX:
628 625
629 if font is None: 626 if font is None:
630 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) 627 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
  628 + font.Scale(self.viewer.GetContentScaleFactor())
631 629
632 - font = gc.CreateFont(font, txt_colour) 630 + _font = gc.CreateFont(font, txt_colour)
633 px, py = pos 631 px, py = pos
634 for t in text.split('\n'): 632 for t in text.split('\n'):
635 t = t.strip() 633 t = t.strip()
636 _py = -py 634 _py = -py
637 _px = px 635 _px = px
638 - gc.SetFont(font) 636 + gc.SetFont(_font)
639 gc.DrawText(t, _px, _py) 637 gc.DrawText(t, _px, _py)
640 638
641 - w, h = self.calc_text_size(t) 639 + w, h = self.calc_text_size(t, font)
642 py -= h 640 py -= h
643 641
644 self._drawn = True 642 self._drawn = True
@@ -661,10 +659,11 @@ class CanvasRendererCTX: @@ -661,10 +659,11 @@ class CanvasRendererCTX:
661 659
662 if font is None: 660 if font is None:
663 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) 661 font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
  662 + font.Scale(self.viewer.GetContentScaleFactor())
664 663
665 _font = gc.CreateFont(font, txt_colour) 664 _font = gc.CreateFont(font, txt_colour)
666 gc.SetFont(_font) 665 gc.SetFont(_font)
667 - w, h = self.calc_text_size(text) 666 + w, h = self.calc_text_size(text, font)
668 667
669 px, py = pos 668 px, py = pos
670 669
@@ -880,11 +879,13 @@ class CircleHandler(CanvasHandlerBase): @@ -880,11 +879,13 @@ class CircleHandler(CanvasHandlerBase):
880 879
881 def draw_to_canvas(self, gc, canvas): 880 def draw_to_canvas(self, gc, canvas):
882 if self.visible: 881 if self.visible:
  882 + viewer = canvas.viewer
  883 + scale = viewer.GetContentScaleFactor()
883 if self.is_3d: 884 if self.is_3d:
884 px, py = self._3d_to_2d(canvas.evt_renderer, self.position) 885 px, py = self._3d_to_2d(canvas.evt_renderer, self.position)
885 else: 886 else:
886 px, py = self.position 887 px, py = self.position
887 - x, y, w, h = canvas.draw_circle((px, py), self.radius, 888 + x, y, w, h = canvas.draw_circle((px, py), self.radius * scale,
888 line_colour=self.line_colour, 889 line_colour=self.line_colour,
889 fill_colour=self.fill_colour) 890 fill_colour=self.fill_colour)
890 self.bbox = (x - w/2, y - h/2, x + w/2, y + h/2) 891 self.bbox = (x - w/2, y - h/2, x + w/2, y + h/2)
invesalius/net/neuronavigation_api.py
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 # detalhes. 17 # detalhes.
18 #-------------------------------------------------------------------------- 18 #--------------------------------------------------------------------------
19 19
  20 +from invesalius.pubsub import pub as Publisher
20 from invesalius.utils import Singleton 21 from invesalius.utils import Singleton
21 22
22 class NeuronavigationApi(metaclass=Singleton): 23 class NeuronavigationApi(metaclass=Singleton):