Commit 628fec8e95cb9e1f9320a888f492df59c4aa0298
1 parent
3915e1bb
Exists in
master
and in
68 other branches
FIX: The scrolls in viewer_slice sync between all orientations are correct. Related to ticket #147
Showing
1 changed file
with
55 additions
and
51 deletions
Show diff stats
invesalius/data/viewer_slice.py
@@ -18,7 +18,6 @@ | @@ -18,7 +18,6 @@ | ||
18 | #-------------------------------------------------------------------------- | 18 | #-------------------------------------------------------------------------- |
19 | 19 | ||
20 | import itertools | 20 | import itertools |
21 | -import os.path | ||
22 | 21 | ||
23 | import numpy | 22 | import numpy |
24 | 23 | ||
@@ -84,7 +83,6 @@ class Viewer(wx.Panel): | @@ -84,7 +83,6 @@ class Viewer(wx.Panel): | ||
84 | 83 | ||
85 | 84 | ||
86 | def __init_gui(self): | 85 | def __init_gui(self): |
87 | - | ||
88 | interactor = wxVTKRenderWindowInteractor(self, -1, size=self.GetSize()) | 86 | interactor = wxVTKRenderWindowInteractor(self, -1, size=self.GetSize()) |
89 | 87 | ||
90 | scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL) | 88 | scroll = wx.ScrollBar(self, -1, style=wx.SB_VERTICAL) |
@@ -99,14 +97,12 @@ class Viewer(wx.Panel): | @@ -99,14 +97,12 @@ class Viewer(wx.Panel): | ||
99 | self.SetSizer(background_sizer) | 97 | self.SetSizer(background_sizer) |
100 | background_sizer.Fit(self) | 98 | background_sizer.Fit(self) |
101 | 99 | ||
102 | - | ||
103 | self.Layout() | 100 | self.Layout() |
104 | self.Update() | 101 | self.Update() |
105 | self.SetAutoLayout(1) | 102 | self.SetAutoLayout(1) |
106 | 103 | ||
107 | self.interactor = interactor | 104 | self.interactor = interactor |
108 | 105 | ||
109 | - | ||
110 | def OnContextMenu(self, evt): | 106 | def OnContextMenu(self, evt): |
111 | self.right_pressed = 0 | 107 | self.right_pressed = 0 |
112 | if (self.last_position_mouse_move ==\ | 108 | if (self.last_position_mouse_move ==\ |
@@ -306,9 +302,6 @@ class Viewer(wx.Panel): | @@ -306,9 +302,6 @@ class Viewer(wx.Panel): | ||
306 | def OnReleaseLeftButton(self, evt, obj): | 302 | def OnReleaseLeftButton(self, evt, obj): |
307 | self.left_pressed = 0 | 303 | self.left_pressed = 0 |
308 | ps.Publisher().sendMessage('Update slice viewer') | 304 | ps.Publisher().sendMessage('Update slice viewer') |
309 | - | ||
310 | - | ||
311 | - | ||
312 | 305 | ||
313 | def OnWindowLevelMove(self, evt, obj): | 306 | def OnWindowLevelMove(self, evt, obj): |
314 | if (self.left_pressed): | 307 | if (self.left_pressed): |
@@ -321,10 +314,8 @@ class Viewer(wx.Panel): | @@ -321,10 +314,8 @@ class Viewer(wx.Panel): | ||
321 | ps.Publisher().sendMessage('Bright and contrast adjustment image', | 314 | ps.Publisher().sendMessage('Bright and contrast adjustment image', |
322 | (self.acum_achange_window, self.acum_achange_level)) | 315 | (self.acum_achange_window, self.acum_achange_level)) |
323 | 316 | ||
324 | - | ||
325 | - self.SetWLText(self.acum_achange_level, | ||
326 | - self.acum_achange_window) | ||
327 | - | 317 | + #self.SetWLText(self.acum_achange_level, |
318 | + # self.acum_achange_window) | ||
328 | 319 | ||
329 | const.WINDOW_LEVEL['Manual'] = (self.acum_achange_window,\ | 320 | const.WINDOW_LEVEL['Manual'] = (self.acum_achange_window,\ |
330 | self.acum_achange_level) | 321 | self.acum_achange_level) |
@@ -332,9 +323,8 @@ class Viewer(wx.Panel): | @@ -332,9 +323,8 @@ class Viewer(wx.Panel): | ||
332 | ps.Publisher().sendMessage('Update window level value',(self.acum_achange_window, | 323 | ps.Publisher().sendMessage('Update window level value',(self.acum_achange_window, |
333 | self.acum_achange_level)) | 324 | self.acum_achange_level)) |
334 | #Necessary update the slice plane in the volume case exists | 325 | #Necessary update the slice plane in the volume case exists |
326 | + ps.Publisher().sendMessage('Update slice viewer') | ||
335 | ps.Publisher().sendMessage('Render volume viewer') | 327 | ps.Publisher().sendMessage('Render volume viewer') |
336 | - | ||
337 | - self.interactor.Render() | ||
338 | 328 | ||
339 | 329 | ||
340 | def OnWindowLevelClick(self, evt, obj): | 330 | def OnWindowLevelClick(self, evt, obj): |
@@ -419,7 +409,7 @@ class Viewer(wx.Panel): | @@ -419,7 +409,7 @@ class Viewer(wx.Panel): | ||
419 | value = STR_WL%(window_width, window_level) | 409 | value = STR_WL%(window_width, window_level) |
420 | if (self.wl_text): | 410 | if (self.wl_text): |
421 | self.wl_text.SetValue(value) | 411 | self.wl_text.SetValue(value) |
422 | - self.interactor.Render() | 412 | + #self.interactor.Render() |
423 | 413 | ||
424 | def EnableText(self): | 414 | def EnableText(self): |
425 | if not (self.wl_text): | 415 | if not (self.wl_text): |
@@ -673,28 +663,45 @@ class Viewer(wx.Panel): | @@ -673,28 +663,45 @@ class Viewer(wx.Panel): | ||
673 | 663 | ||
674 | self.interactor.Render() | 664 | self.interactor.Render() |
675 | 665 | ||
676 | - | 666 | + def OnCrossMouseClick(self, evt, obj): |
667 | + self.ChangeCrossPosition() | ||
677 | 668 | ||
678 | def OnCrossMove(self, evt, obj): | 669 | def OnCrossMove(self, evt, obj): |
679 | - # Update position in other slices | 670 | + # The user moved the mouse with left button pressed |
680 | if (self.left_pressed): | 671 | if (self.left_pressed): |
681 | - mouse_x, mouse_y = self.interactor.GetEventPosition() | ||
682 | - renderer = self.slice_data_list[0].renderer | ||
683 | - self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) | ||
684 | - coord_cross = self.get_coordinate_cursor() | ||
685 | - coord = self.get_coordinate() | ||
686 | - ps.Publisher().sendMessage('Update cross position', | ||
687 | - (self.orientation, coord_cross)) | 672 | + self.ChangeCrossPosition() |
673 | + | ||
674 | + def ChangeCrossPosition(self): | ||
675 | + mouse_x, mouse_y = self.interactor.GetEventPosition() | ||
676 | + # Get in what slice data the click occurred | ||
677 | + renderer = self.slice_data_list[0].renderer | ||
678 | + # pick to get click position in the 3d world | ||
679 | + self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) | ||
680 | + coord_cross = self.get_coordinate_cursor() | ||
681 | + coord = self.CalcultateScrollPosition(coord_cross) | ||
682 | + ps.Publisher().sendMessage('Update cross position', | ||
683 | + (self.orientation, coord_cross)) | ||
684 | + self.ScrollSlice(coord) | ||
685 | + self.interactor.Render() | ||
686 | + | ||
687 | + def ScrollSlice(self, coord): | ||
688 | + if self.orientation == "AXIAL": | ||
688 | ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), | 689 | ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), |
689 | coord[0]) | 690 | coord[0]) |
690 | ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), | 691 | ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), |
691 | coord[1]) | 692 | coord[1]) |
693 | + elif self.orientation == "SAGITAL": | ||
694 | + ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), | ||
695 | + coord[2]) | ||
696 | + ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), | ||
697 | + coord[1]) | ||
698 | + elif self.orientation == "CORONAL": | ||
692 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), | 699 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), |
693 | coord[2]) | 700 | coord[2]) |
701 | + ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), | ||
702 | + coord[0]) | ||
694 | 703 | ||
695 | def OnZoomMoveRight(self, evt, obj): | 704 | def OnZoomMoveRight(self, evt, obj): |
696 | - | ||
697 | - | ||
698 | if (self.right_pressed): | 705 | if (self.right_pressed): |
699 | evt.Dolly() | 706 | evt.Dolly() |
700 | evt.OnRightButtonDown() | 707 | evt.OnRightButtonDown() |
@@ -702,31 +709,16 @@ class Viewer(wx.Panel): | @@ -702,31 +709,16 @@ class Viewer(wx.Panel): | ||
702 | def OnZoomRightClick(self, evt, obj): | 709 | def OnZoomRightClick(self, evt, obj): |
703 | evt.StartDolly() | 710 | evt.StartDolly() |
704 | 711 | ||
705 | - | ||
706 | - def OnCrossMouseClick(self, evt, obj): | ||
707 | - mouse_x, mouse_y = self.interactor.GetEventPosition() | ||
708 | - renderer = self.slice_data_list[0].renderer | ||
709 | - self.pick.Pick(mouse_x, mouse_y, self.slice_data_list[0].number, renderer) | ||
710 | - coord_cross = self.get_coordinate_cursor() | ||
711 | - coord = self.get_coordinate() | ||
712 | - ps.Publisher().sendMessage('Update cross position', | ||
713 | - (self.orientation, coord_cross)) | ||
714 | - ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), | ||
715 | - coord[0]) | ||
716 | - ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), | ||
717 | - coord[1]) | ||
718 | - ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), | ||
719 | - coord[2]) | ||
720 | - | ||
721 | - | ||
722 | def get_slice_data(self, render): | 712 | def get_slice_data(self, render): |
723 | for slice_data in self.slice_data_list: | 713 | for slice_data in self.slice_data_list: |
724 | if slice_data.renderer is render: | 714 | if slice_data.renderer is render: |
725 | return slice_data | 715 | return slice_data |
726 | 716 | ||
727 | - def get_coordinate(self): | ||
728 | - # Find position | ||
729 | - x, y, z = self.pick.GetPickPosition() | 717 | + def CalcultateScrollPosition(self, coord): |
718 | + # Based in the given coord (x, y, z), returns a list with the scroll positions for each | ||
719 | + # orientation, being the first position the sagital, second the coronal | ||
720 | + # and the last, axial. | ||
721 | + x, y, z = coord | ||
730 | 722 | ||
731 | # First we fix the position origin, based on vtkActor bounds | 723 | # First we fix the position origin, based on vtkActor bounds |
732 | bounds = self.actor.GetBounds() | 724 | bounds = self.actor.GetBounds() |
@@ -737,15 +729,20 @@ class Viewer(wx.Panel): | @@ -737,15 +729,20 @@ class Viewer(wx.Panel): | ||
737 | 729 | ||
738 | # Then we fix the porpotion, based on vtkImageData spacing | 730 | # Then we fix the porpotion, based on vtkImageData spacing |
739 | spacing_x, spacing_y, spacing_z = self.imagedata.GetSpacing() | 731 | spacing_x, spacing_y, spacing_z = self.imagedata.GetSpacing() |
732 | + | ||
740 | x = x/spacing_x | 733 | x = x/spacing_x |
741 | y = y/spacing_y | 734 | y = y/spacing_y |
742 | z = z/spacing_z | 735 | z = z/spacing_z |
743 | 736 | ||
737 | + proj = project.Project() | ||
738 | + orig_orien = proj.original_orientation | ||
744 | # Based on the current orientation, we define 3D position | 739 | # Based on the current orientation, we define 3D position |
745 | - coordinates = {"SAGITAL": [self.slice_number, y, z], | ||
746 | - "CORONAL": [x, self.slice_number, z], | ||
747 | - "AXIAL": [x, y, self.slice_number]} | ||
748 | - coord = [int(coord) for coord in coordinates[self.orientation]] | 740 | + # Sagita, coronal, axial |
741 | + coordinates = {const.AXIAL: [x, y, z], | ||
742 | + const.SAGITAL: [z, x, y], | ||
743 | + const.CORONAL: [x, z, y]} | ||
744 | + | ||
745 | + coord = [int(i) for i in coordinates[orig_orien]] | ||
749 | 746 | ||
750 | # According to vtkImageData extent, we limit min and max value | 747 | # According to vtkImageData extent, we limit min and max value |
751 | # If this is not done, a VTK Error occurs when mouse is pressed outside | 748 | # If this is not done, a VTK Error occurs when mouse is pressed outside |
@@ -763,6 +760,13 @@ class Viewer(wx.Panel): | @@ -763,6 +760,13 @@ class Viewer(wx.Panel): | ||
763 | def get_coordinate_cursor(self): | 760 | def get_coordinate_cursor(self): |
764 | # Find position | 761 | # Find position |
765 | x, y, z = self.pick.GetPickPosition() | 762 | x, y, z = self.pick.GetPickPosition() |
763 | + bounds = self.actor.GetBounds() | ||
764 | + if bounds[0] == bounds[1]: | ||
765 | + x = bounds[0] | ||
766 | + elif bounds[2] == bounds[3]: | ||
767 | + y = bounds[2] | ||
768 | + elif bounds[4] == bounds[5]: | ||
769 | + z = bounds[4] | ||
766 | return x, y, z | 770 | return x, y, z |
767 | 771 | ||
768 | def get_coordinate_cursor_edition(self, slice_data): | 772 | def get_coordinate_cursor_edition(self, slice_data): |
@@ -1128,8 +1132,8 @@ class Viewer(wx.Panel): | @@ -1128,8 +1132,8 @@ class Viewer(wx.Panel): | ||
1128 | #xz = [x, y - abs(y * 0.001), z] | 1132 | #xz = [x, y - abs(y * 0.001), z] |
1129 | #xy = [x, y, z + abs(z * 0.001)] | 1133 | #xy = [x, y, z + abs(z * 0.001)] |
1130 | 1134 | ||
1131 | - #proj = project.Project() | ||
1132 | - #orig_orien = proj.original_orientation | 1135 | + proj = project.Project() |
1136 | + orig_orien = proj.original_orientation | ||
1133 | #pos = [x, y, z] | 1137 | #pos = [x, y, z] |
1134 | 1138 | ||
1135 | #if (orig_orien == const.SAGITAL): | 1139 | #if (orig_orien == const.SAGITAL): |