Commit 159f813aab3f1ef69e07347b4608c549198a19e5

Authored by tatiana
1 parent 0c6c3676

ENH: Inserted multiple modes option inside slice viewer, for user style selection

invesalius/data/viewer_slice.py
@@ -28,26 +28,25 @@ import constants as const @@ -28,26 +28,25 @@ import constants as const
28 import project 28 import project
29 29
30 class Viewer(wx.Panel): 30 class Viewer(wx.Panel):
31 - 31 +
32 def __init__(self, prnt, orientation='AXIAL'): 32 def __init__(self, prnt, orientation='AXIAL'):
33 wx.Panel.__init__(self, prnt, size=wx.Size(320, 300)) 33 wx.Panel.__init__(self, prnt, size=wx.Size(320, 300))
34 34
35 colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]] 35 colour = [255*c for c in const.ORIENTATION_COLOUR[orientation]]
36 self.SetBackgroundColour(colour) 36 self.SetBackgroundColour(colour)
37 37
  38 + # Interactor aditional style
  39 + self.modes = []
  40 + self.mouse_pressed = 0
  41 +
38 self.__init_gui() 42 self.__init_gui()
39 43
40 self.orientation = orientation 44 self.orientation = orientation
41 self.slice_number = 0 45 self.slice_number = 0
42 -  
43 - # Interactor aditional style  
44 - self.mode = 'DEFAULT'  
45 - self.mouse_pressed = 0  
46 46
47 # VTK pipeline and actors 47 # VTK pipeline and actors
48 self.__config_interactor() 48 self.__config_interactor()
49 self.pick = vtk.vtkCellPicker() 49 self.pick = vtk.vtkCellPicker()
50 - #self.cursor =  
51 50
52 self.__bind_events() 51 self.__bind_events()
53 self.__bind_events_wx() 52 self.__bind_events_wx()
@@ -75,23 +74,22 @@ class Viewer(wx.Panel): @@ -75,23 +74,22 @@ class Viewer(wx.Panel):
75 self.interactor = interactor 74 self.interactor = interactor
76 75
77 def __config_interactor(self): 76 def __config_interactor(self):
78 -  
79 - style = vtk.vtkInteractorStyleImage()  
80 - self.style = style  
81 - 77 +
82 ren = vtk.vtkRenderer() 78 ren = vtk.vtkRenderer()
83 79
84 interactor = self.interactor 80 interactor = self.interactor
85 - interactor.SetInteractorStyle(style)  
86 interactor.GetRenderWindow().AddRenderer(ren) 81 interactor.GetRenderWindow().AddRenderer(ren)
87 82
88 self.cam = ren.GetActiveCamera() 83 self.cam = ren.GetActiveCamera()
89 self.ren = ren 84 self.ren = ren
90 85
91 - self.SetMode(self.mode) 86 + self.AppendMode('DEFAULT')
  87 +
  88 + def AppendMode(self, mode):
  89 +
  90 + # Retrieve currently set modes
  91 + self.modes.append(mode)
92 92
93 - def SetMode(self, mode):  
94 - self.mode = mode  
95 # All modes and bindings 93 # All modes and bindings
96 action = {'DEFAULT': { 94 action = {'DEFAULT': {
97 "MouseMoveEvent": self.OnCrossMove, 95 "MouseMoveEvent": self.OnCrossMove,
@@ -106,11 +104,17 @@ class Viewer(wx.Panel): @@ -106,11 +104,17 @@ class Viewer(wx.Panel):
106 } 104 }
107 105
108 # Bind method according to current mode 106 # Bind method according to current mode
109 - style = self.style 107 + style = vtk.vtkInteractorStyleImage()
  108 + self.style = style
  109 + self.interactor.SetInteractorStyle(style)
110 110
111 - for event in action[mode]:  
112 - style.AddObserver(event,  
113 - action[mode][event]) 111 + # Check all modes set by user
  112 + for mode in self.modes:
  113 + # Check each event available for each mode
  114 + for event in action[mode]:
  115 + # Bind event
  116 + style.AddObserver(event,
  117 + action[mode][event])
114 118
115 119
116 def OnMouseClick(self, obj, evt_vtk): 120 def OnMouseClick(self, obj, evt_vtk):
@@ -133,10 +137,14 @@ class Viewer(wx.Panel): @@ -133,10 +137,14 @@ class Viewer(wx.Panel):
133 coord = self.GetCoordinate() 137 coord = self.GetCoordinate()
134 # Update position in other slices 138 # Update position in other slices
135 if self.mouse_pressed: 139 if self.mouse_pressed:
136 - ps.Publisher().sendMessage('Update cursor position in slice', coord)  
137 - ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'), coord[0])  
138 - ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'), coord[1])  
139 - ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), coord[2]) 140 + ps.Publisher().sendMessage('Update cursor position in slice',
  141 + coord)
  142 + ps.Publisher().sendMessage(('Set scroll position', 'SAGITAL'),
  143 + coord[0])
  144 + ps.Publisher().sendMessage(('Set scroll position', 'CORONAL'),
  145 + coord[1])
  146 + ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'),
  147 + coord[2])
140 148
141 149
142 def GetCoordinate(self): 150 def GetCoordinate(self):
invesalius/data/viewer_volume.py
@@ -78,7 +78,6 @@ class Viewer(wx.Panel): @@ -78,7 +78,6 @@ class Viewer(wx.Panel):
78 self.UpdateRender() 78 self.UpdateRender()
79 self.Refresh() 79 self.Refresh()
80 print dir(self.iren) 80 print dir(self.iren)
81 - self.UpdateRender()  
82 self.iren.UpdateWindowUI() 81 self.iren.UpdateWindowUI()
83 self.iren.Update() 82 self.iren.Update()
84 evt.Skip() 83 evt.Skip()