Commit 13b7b7ff758a45cf9e89b9ddbcdd190b2de8a8b9
1 parent
89d8c617
Exists in
interactor_style
Passing the viewer to all interactor styles
Showing
2 changed files
with
26 additions
and
54 deletions
Show diff stats
invesalius/data/styles.py
@@ -77,12 +77,12 @@ class CrossInteractorStyle(RightZoomInteractorStyle): | @@ -77,12 +77,12 @@ class CrossInteractorStyle(RightZoomInteractorStyle): | ||
77 | """ | 77 | """ |
78 | Interactor style responsible for the Cross. | 78 | Interactor style responsible for the Cross. |
79 | """ | 79 | """ |
80 | - def __init__(self, orientation, slice_data): | 80 | + def __init__(self, viewer): |
81 | RightZoomInteractorStyle.__init__(self) | 81 | RightZoomInteractorStyle.__init__(self) |
82 | 82 | ||
83 | - self.orientation = orientation | ||
84 | - self.slice_actor = slice_data.actor | ||
85 | - self.slice_data = slice_data | 83 | + self.orientation = viewer.orientation |
84 | + self.slice_actor = viewer.slice_data.actor | ||
85 | + self.slice_data = viewer.slice_data | ||
86 | 86 | ||
87 | self.picker = vtk.vtkWorldPointPicker() | 87 | self.picker = vtk.vtkWorldPointPicker() |
88 | 88 | ||
@@ -183,14 +183,16 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): | @@ -183,14 +183,16 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): | ||
183 | """ | 183 | """ |
184 | Interactor style responsible for Window Level & Width functionality. | 184 | Interactor style responsible for Window Level & Width functionality. |
185 | """ | 185 | """ |
186 | - def __init__(self, ww, wl): | 186 | + def __init__(self, viewer): |
187 | RightZoomInteractorStyle.__init__(self) | 187 | RightZoomInteractorStyle.__init__(self) |
188 | 188 | ||
189 | + self.viewer = viewer | ||
190 | + | ||
189 | self.last_x = 0 | 191 | self.last_x = 0 |
190 | self.last_y = 0 | 192 | self.last_y = 0 |
191 | 193 | ||
192 | - self.acum_achange_window = ww | ||
193 | - self.acum_achange_level = wl | 194 | + self.acum_achange_window = viewer.slice_.window_width |
195 | + self.acum_achange_level = viewer.slice_.window_level | ||
194 | 196 | ||
195 | self.AddObserver("MouseMoveEvent", self.OnWindowLevelMove) | 197 | self.AddObserver("MouseMoveEvent", self.OnWindowLevelMove) |
196 | self.AddObserver("LeftButtonPressEvent", self.OnWindowLevelClick) | 198 | self.AddObserver("LeftButtonPressEvent", self.OnWindowLevelClick) |
@@ -222,16 +224,20 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): | @@ -222,16 +224,20 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): | ||
222 | iren = obj.GetInteractor() | 224 | iren = obj.GetInteractor() |
223 | self.last_x, self.last_y = iren.GetLastEventPosition() | 225 | self.last_x, self.last_y = iren.GetLastEventPosition() |
224 | 226 | ||
227 | + self.acum_achange_window = viewer.slice_.window_width | ||
228 | + self.acum_achange_level = viewer.slice_.window_level | ||
229 | + | ||
225 | 230 | ||
226 | class LinearMeasureInteractorStyle(RightZoomInteractorStyle): | 231 | class LinearMeasureInteractorStyle(RightZoomInteractorStyle): |
227 | """ | 232 | """ |
228 | Interactor style responsible for insert linear measurements. | 233 | Interactor style responsible for insert linear measurements. |
229 | """ | 234 | """ |
230 | - def __init__(self, orientation, slice_data): | 235 | + def __init__(self, viewer): |
231 | RightZoomInteractorStyle.__init__(self) | 236 | RightZoomInteractorStyle.__init__(self) |
232 | 237 | ||
233 | - self.orientation = orientation | ||
234 | - self.slice_data = slice_data | 238 | + self.viewer = viewer |
239 | + self.orientation = viewer.orientation | ||
240 | + self.slice_data = viewer.slice_data | ||
235 | 241 | ||
236 | self.picker = vtk.vtkCellPicker() | 242 | self.picker = vtk.vtkCellPicker() |
237 | 243 | ||
@@ -249,18 +255,19 @@ class LinearMeasureInteractorStyle(RightZoomInteractorStyle): | @@ -249,18 +255,19 @@ class LinearMeasureInteractorStyle(RightZoomInteractorStyle): | ||
249 | ((x, y,z), const.LINEAR, | 255 | ((x, y,z), const.LINEAR, |
250 | ORIENTATIONS[self.orientation], | 256 | ORIENTATIONS[self.orientation], |
251 | slice_number)) | 257 | slice_number)) |
252 | - Publisher.sendMessage('Update slice viewer') | 258 | + self.viewer.interactor.Render() |
253 | 259 | ||
254 | 260 | ||
255 | class AngularMeasureInteractorStyle(RightZoomInteractorStyle): | 261 | class AngularMeasureInteractorStyle(RightZoomInteractorStyle): |
256 | """ | 262 | """ |
257 | Interactor style responsible for insert angular measurements. | 263 | Interactor style responsible for insert angular measurements. |
258 | """ | 264 | """ |
259 | - def __init__(self, orientation, slice_data): | 265 | + def __init__(self, viewer): |
260 | RightZoomInteractorStyle.__init__(self) | 266 | RightZoomInteractorStyle.__init__(self) |
261 | 267 | ||
262 | - self.orientation = orientation | ||
263 | - self.slice_data = slice_data | 268 | + self.viewer = viewer |
269 | + self.orientation = viewer.orientation | ||
270 | + self.slice_data = viewer.slice_data | ||
264 | 271 | ||
265 | self.picker = vtk.vtkCellPicker() | 272 | self.picker = vtk.vtkCellPicker() |
266 | 273 | ||
@@ -278,7 +285,7 @@ class AngularMeasureInteractorStyle(RightZoomInteractorStyle): | @@ -278,7 +285,7 @@ class AngularMeasureInteractorStyle(RightZoomInteractorStyle): | ||
278 | ((x, y,z), const.ANGULAR, | 285 | ((x, y,z), const.ANGULAR, |
279 | ORIENTATIONS[self.orientation], | 286 | ORIENTATIONS[self.orientation], |
280 | slice_number)) | 287 | slice_number)) |
281 | - Publisher.sendMessage('Update slice viewer') | 288 | + self.viewer.interactor.Render() |
282 | 289 | ||
283 | 290 | ||
284 | class PanMoveInteractorStyle(RightZoomInteractorStyle): | 291 | class PanMoveInteractorStyle(RightZoomInteractorStyle): |
invesalius/data/viewer_slice.py
@@ -176,8 +176,7 @@ class Viewer(wx.Panel): | @@ -176,8 +176,7 @@ class Viewer(wx.Panel): | ||
176 | 176 | ||
177 | def SetInteractorStyle(self, state): | 177 | def SetInteractorStyle(self, state): |
178 | if state == const.SLICE_STATE_CROSS: | 178 | if state == const.SLICE_STATE_CROSS: |
179 | - style = styles.CrossInteractorStyle(self.orientation, | ||
180 | - self.slice_data) | 179 | + style = styles.CrossInteractorStyle(self) |
181 | self.style = style | 180 | self.style = style |
182 | self.interactor.SetInteractorStyle(style) | 181 | self.interactor.SetInteractorStyle(style) |
183 | self.interactor.Render() | 182 | self.interactor.Render() |
@@ -197,22 +196,19 @@ class Viewer(wx.Panel): | @@ -197,22 +196,19 @@ class Viewer(wx.Panel): | ||
197 | self.on_wl = True | 196 | self.on_wl = True |
198 | self.wl_text.Show() | 197 | self.wl_text.Show() |
199 | 198 | ||
200 | - ww = sl.Slice().window_width | ||
201 | - wl = sl.Slice().window_level | ||
202 | - | ||
203 | - style = styles.WWWLInteractorStyle(ww, wl) | 199 | + style = styles.WWWLInteractorStyle(self) |
204 | self.style = style | 200 | self.style = style |
205 | self.interactor.SetInteractorStyle(style) | 201 | self.interactor.SetInteractorStyle(style) |
206 | self.interactor.Render() | 202 | self.interactor.Render() |
207 | 203 | ||
208 | elif state == const.STATE_MEASURE_DISTANCE: | 204 | elif state == const.STATE_MEASURE_DISTANCE: |
209 | - style = styles.LinearMeasureInteractorStyle(self.orientation, self.slice_data) | 205 | + style = styles.LinearMeasureInteractorStyle(self) |
210 | self.style = style | 206 | self.style = style |
211 | self.interactor.SetInteractorStyle(style) | 207 | self.interactor.SetInteractorStyle(style) |
212 | self.interactor.Render() | 208 | self.interactor.Render() |
213 | 209 | ||
214 | elif state == const.STATE_MEASURE_ANGLE: | 210 | elif state == const.STATE_MEASURE_ANGLE: |
215 | - style = styles.AngularMeasureInteractorStyle(self.orientation, self.slice_data) | 211 | + style = styles.AngularMeasureInteractorStyle(self) |
216 | self.style = style | 212 | self.style = style |
217 | self.interactor.SetInteractorStyle(style) | 213 | self.interactor.SetInteractorStyle(style) |
218 | self.interactor.Render() | 214 | self.interactor.Render() |
@@ -263,11 +259,6 @@ class Viewer(wx.Panel): | @@ -263,11 +259,6 @@ class Viewer(wx.Panel): | ||
263 | "EnterEvent": self.OnEnterInteractor, | 259 | "EnterEvent": self.OnEnterInteractor, |
264 | "LeaveEvent": self.OnLeaveInteractor | 260 | "LeaveEvent": self.OnLeaveInteractor |
265 | }, | 261 | }, |
266 | - const.SLICE_STATE_SCROLL: | ||
267 | - { | ||
268 | - "MouseMoveEvent": self.OnChangeSliceMove, | ||
269 | - "LeftButtonPressEvent": self.OnChangeSliceClick, | ||
270 | - }, | ||
271 | const.STATE_DEFAULT: | 262 | const.STATE_DEFAULT: |
272 | { | 263 | { |
273 | }, | 264 | }, |
@@ -380,32 +371,6 @@ class Viewer(wx.Panel): | @@ -380,32 +371,6 @@ class Viewer(wx.Panel): | ||
380 | self.SetWLText(window, level) | 371 | self.SetWLText(window, level) |
381 | Publisher.sendMessage('Update all slice') | 372 | Publisher.sendMessage('Update all slice') |
382 | 373 | ||
383 | - | ||
384 | - def OnChangeSliceMove(self, evt, obj): | ||
385 | - if (self.left_pressed): | ||
386 | - min = 0 | ||
387 | - max = self.slice_.GetMaxSliceNumber(self.orientation) | ||
388 | - | ||
389 | - if (self.left_pressed): | ||
390 | - position = self.interactor.GetLastEventPosition() | ||
391 | - scroll_position = self.scroll.GetThumbPosition() | ||
392 | - | ||
393 | - if (position[1] > self.last_position) and\ | ||
394 | - (self.acum_achange_slice > min): | ||
395 | - self.acum_achange_slice -= 1 | ||
396 | - elif(position[1] < self.last_position) and\ | ||
397 | - (self.acum_achange_slice < max): | ||
398 | - self.acum_achange_slice += 1 | ||
399 | - self.last_position = position[1] | ||
400 | - | ||
401 | - self.scroll.SetThumbPosition(self.acum_achange_slice) | ||
402 | - self.OnScrollBar() | ||
403 | - | ||
404 | - def OnChangeSliceClick(self, evt, obj): | ||
405 | - position = list(self.interactor.GetLastEventPosition()) | ||
406 | - self.acum_achange_slice = self.scroll.GetThumbPosition() | ||
407 | - self.last_position = position[1] | ||
408 | - | ||
409 | def OnPanMove(self, evt, obj): | 374 | def OnPanMove(self, evt, obj): |
410 | mouse_x, mouse_y = self.interactor.GetLastEventPosition() | 375 | mouse_x, mouse_y = self.interactor.GetLastEventPosition() |
411 | ren = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | 376 | ren = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |