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 | 77 | """ |
78 | 78 | Interactor style responsible for the Cross. |
79 | 79 | """ |
80 | - def __init__(self, orientation, slice_data): | |
80 | + def __init__(self, viewer): | |
81 | 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 | 87 | self.picker = vtk.vtkWorldPointPicker() |
88 | 88 | |
... | ... | @@ -183,14 +183,16 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): |
183 | 183 | """ |
184 | 184 | Interactor style responsible for Window Level & Width functionality. |
185 | 185 | """ |
186 | - def __init__(self, ww, wl): | |
186 | + def __init__(self, viewer): | |
187 | 187 | RightZoomInteractorStyle.__init__(self) |
188 | 188 | |
189 | + self.viewer = viewer | |
190 | + | |
189 | 191 | self.last_x = 0 |
190 | 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 | 197 | self.AddObserver("MouseMoveEvent", self.OnWindowLevelMove) |
196 | 198 | self.AddObserver("LeftButtonPressEvent", self.OnWindowLevelClick) |
... | ... | @@ -222,16 +224,20 @@ class WWWLInteractorStyle(RightZoomInteractorStyle): |
222 | 224 | iren = obj.GetInteractor() |
223 | 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 | 231 | class LinearMeasureInteractorStyle(RightZoomInteractorStyle): |
227 | 232 | """ |
228 | 233 | Interactor style responsible for insert linear measurements. |
229 | 234 | """ |
230 | - def __init__(self, orientation, slice_data): | |
235 | + def __init__(self, viewer): | |
231 | 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 | 242 | self.picker = vtk.vtkCellPicker() |
237 | 243 | |
... | ... | @@ -249,18 +255,19 @@ class LinearMeasureInteractorStyle(RightZoomInteractorStyle): |
249 | 255 | ((x, y,z), const.LINEAR, |
250 | 256 | ORIENTATIONS[self.orientation], |
251 | 257 | slice_number)) |
252 | - Publisher.sendMessage('Update slice viewer') | |
258 | + self.viewer.interactor.Render() | |
253 | 259 | |
254 | 260 | |
255 | 261 | class AngularMeasureInteractorStyle(RightZoomInteractorStyle): |
256 | 262 | """ |
257 | 263 | Interactor style responsible for insert angular measurements. |
258 | 264 | """ |
259 | - def __init__(self, orientation, slice_data): | |
265 | + def __init__(self, viewer): | |
260 | 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 | 272 | self.picker = vtk.vtkCellPicker() |
266 | 273 | |
... | ... | @@ -278,7 +285,7 @@ class AngularMeasureInteractorStyle(RightZoomInteractorStyle): |
278 | 285 | ((x, y,z), const.ANGULAR, |
279 | 286 | ORIENTATIONS[self.orientation], |
280 | 287 | slice_number)) |
281 | - Publisher.sendMessage('Update slice viewer') | |
288 | + self.viewer.interactor.Render() | |
282 | 289 | |
283 | 290 | |
284 | 291 | class PanMoveInteractorStyle(RightZoomInteractorStyle): | ... | ... |
invesalius/data/viewer_slice.py
... | ... | @@ -176,8 +176,7 @@ class Viewer(wx.Panel): |
176 | 176 | |
177 | 177 | def SetInteractorStyle(self, state): |
178 | 178 | if state == const.SLICE_STATE_CROSS: |
179 | - style = styles.CrossInteractorStyle(self.orientation, | |
180 | - self.slice_data) | |
179 | + style = styles.CrossInteractorStyle(self) | |
181 | 180 | self.style = style |
182 | 181 | self.interactor.SetInteractorStyle(style) |
183 | 182 | self.interactor.Render() |
... | ... | @@ -197,22 +196,19 @@ class Viewer(wx.Panel): |
197 | 196 | self.on_wl = True |
198 | 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 | 200 | self.style = style |
205 | 201 | self.interactor.SetInteractorStyle(style) |
206 | 202 | self.interactor.Render() |
207 | 203 | |
208 | 204 | elif state == const.STATE_MEASURE_DISTANCE: |
209 | - style = styles.LinearMeasureInteractorStyle(self.orientation, self.slice_data) | |
205 | + style = styles.LinearMeasureInteractorStyle(self) | |
210 | 206 | self.style = style |
211 | 207 | self.interactor.SetInteractorStyle(style) |
212 | 208 | self.interactor.Render() |
213 | 209 | |
214 | 210 | elif state == const.STATE_MEASURE_ANGLE: |
215 | - style = styles.AngularMeasureInteractorStyle(self.orientation, self.slice_data) | |
211 | + style = styles.AngularMeasureInteractorStyle(self) | |
216 | 212 | self.style = style |
217 | 213 | self.interactor.SetInteractorStyle(style) |
218 | 214 | self.interactor.Render() |
... | ... | @@ -263,11 +259,6 @@ class Viewer(wx.Panel): |
263 | 259 | "EnterEvent": self.OnEnterInteractor, |
264 | 260 | "LeaveEvent": self.OnLeaveInteractor |
265 | 261 | }, |
266 | - const.SLICE_STATE_SCROLL: | |
267 | - { | |
268 | - "MouseMoveEvent": self.OnChangeSliceMove, | |
269 | - "LeftButtonPressEvent": self.OnChangeSliceClick, | |
270 | - }, | |
271 | 262 | const.STATE_DEFAULT: |
272 | 263 | { |
273 | 264 | }, |
... | ... | @@ -380,32 +371,6 @@ class Viewer(wx.Panel): |
380 | 371 | self.SetWLText(window, level) |
381 | 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 | 374 | def OnPanMove(self, evt, obj): |
410 | 375 | mouse_x, mouse_y = self.interactor.GetLastEventPosition() |
411 | 376 | ren = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | ... | ... |