Commit 7e582d992adda167caecbf0a236b536909b7319e
1 parent
267cdf77
Exists in
master
and in
6 other branches
ENH: Events of slice viewer work
Showing
1 changed file
with
113 additions
and
99 deletions
Show diff stats
invesalius/data/viewer_slice.py
... | ... | @@ -103,6 +103,7 @@ class Viewer(wx.Panel): |
103 | 103 | |
104 | 104 | |
105 | 105 | def OnContextMenu(self, evt): |
106 | + self.right_pressed = 0 | |
106 | 107 | self.PopupMenu(self.menu) |
107 | 108 | |
108 | 109 | def SetPopupMenu(self, menu): |
... | ... | @@ -151,13 +152,11 @@ class Viewer(wx.Panel): |
151 | 152 | { |
152 | 153 | "MouseMoveEvent": self.OnCrossMove, |
153 | 154 | "LeftButtonPressEvent": self.OnCrossMouseClick, |
154 | - "LeftButtonReleaseEvent": self.OnCrossMouseRelease | |
155 | 155 | }, |
156 | 156 | const.SLICE_STATE_EDITOR: |
157 | 157 | { |
158 | 158 | "MouseMoveEvent": self.OnBrushMove, |
159 | 159 | "LeftButtonPressEvent": self.OnBrushClick, |
160 | - "LeftButtonReleaseEvent": self.OnMouseRelease, | |
161 | 160 | "EnterEvent": self.OnEnterInteractor, |
162 | 161 | "LeaveEvent": self.OnLeaveInteractor |
163 | 162 | }, |
... | ... | @@ -165,43 +164,42 @@ class Viewer(wx.Panel): |
165 | 164 | { |
166 | 165 | "MouseMoveEvent": self.OnPanMove, |
167 | 166 | "LeftButtonPressEvent": self.OnPanClick, |
168 | - "LeftButtonReleaseEvent": self.OnReleaseLeftButton | |
167 | + "LeftButtonReleaseEvent": self.OnVtkRightRelease | |
169 | 168 | }, |
170 | 169 | const.STATE_SPIN: |
171 | 170 | { |
172 | 171 | "MouseMoveEvent": self.OnSpinMove, |
173 | 172 | "LeftButtonPressEvent": self.OnSpinClick, |
174 | - "LeftButtonReleaseEvent": self.OnReleaseLeftButton | |
173 | + "LeftButtonReleaseEvent": self.OnVtkRightRelease | |
175 | 174 | }, |
176 | 175 | const.STATE_ZOOM: |
177 | 176 | { |
178 | - "MouseMoveEvent": self.OnZoomMove, | |
177 | + "MouseMoveEvent": self.OnZoomMoveLeft, | |
179 | 178 | "LeftButtonPressEvent": self.OnZoomLeftClick, |
180 | - "LeftButtonReleaseEvent": self.OnReleaseLeftButton, | |
179 | + "LeftButtonReleaseEvent": self.OnVtkRightRelease | |
181 | 180 | }, |
182 | 181 | const.SLICE_STATE_SCROLL: |
183 | 182 | { |
184 | 183 | "MouseMoveEvent": self.OnChangeSliceMove, |
185 | 184 | "LeftButtonPressEvent": self.OnChangeSliceClick, |
186 | - "LeftButtonReleaseEvent": self.OnReleaseLeftButton | |
187 | 185 | }, |
188 | 186 | const.STATE_WL: |
189 | 187 | { |
190 | 188 | "MouseMoveEvent": self.OnWindowLevelMove, |
191 | 189 | "LeftButtonPressEvent": self.OnWindowLevelClick, |
192 | - "LeftButtonReleaseEvent": self.OnReleaseLeftButton, | |
193 | 190 | }, |
194 | 191 | const.STATE_DEFAULT: |
195 | 192 | { |
196 | - "MouseMoveEvent": self.OnZoomMove, | |
197 | - "RightButtonPressEvent": self.OnZoomLeftClick, | |
198 | - "RightButtonReleaseEvent": self.OnReleaseRightButton, | |
199 | 193 | } |
200 | 194 | } |
201 | 195 | |
202 | 196 | # Bind method according to current mode |
203 | 197 | if(state == const.STATE_ZOOM_SL): |
204 | 198 | style = vtk.vtkInteractorStyleRubberBandZoom() |
199 | + | |
200 | + style.AddObserver("RightButtonPressEvent", self.QuitRubberBandZoom) | |
201 | + #style.AddObserver("RightButtonPressEvent", self.EnterRubberBandZoom) | |
202 | + | |
205 | 203 | else: |
206 | 204 | style = vtk.vtkInteractorStyleImage() |
207 | 205 | |
... | ... | @@ -210,9 +208,18 @@ class Viewer(wx.Panel): |
210 | 208 | # Bind event |
211 | 209 | style.AddObserver(event, |
212 | 210 | action[state][event]) |
213 | - | |
214 | - style.AddObserver("RightButtonPressEvent",self.OnRightClick) | |
215 | - style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton) | |
211 | + | |
212 | + # Common to all styles | |
213 | + # Mouse Buttons' presses / releases | |
214 | + style.AddObserver("LeftButtonPressEvent", self.OnLeftClick) | |
215 | + style.AddObserver("LeftButtonReleaseEvent", self.OnReleaseLeftButton) | |
216 | + style.AddObserver("RightButtonPressEvent", self.OnRightClick) | |
217 | + style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton) | |
218 | + | |
219 | + # Zoom using right button | |
220 | + style.AddObserver("RightButtonPressEvent",self.OnZoomRightClick) | |
221 | + style.AddObserver("MouseMoveEvent", self.OnZoomMoveRight) | |
222 | + style.AddObserver("RightButtonReleaseEvent", self.OnVtkRightRelease) | |
216 | 223 | |
217 | 224 | if ((state == const.STATE_ZOOM) or (state == const.STATE_ZOOM_SL)): |
218 | 225 | self.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnUnZoom) |
... | ... | @@ -222,15 +229,51 @@ class Viewer(wx.Panel): |
222 | 229 | self.style = style |
223 | 230 | self.interactor.SetInteractorStyle(style) |
224 | 231 | |
225 | - #def OnMouseMove(self, evt, obj): | |
226 | - # if(self.left_pressed): | |
227 | - | |
228 | - # if(self.state == const.SLICE_STATE_CROSS): | |
229 | - | |
230 | - | |
232 | + | |
233 | + def QuitRubberBandZoom(self, evt, obj): | |
234 | + style = vtk.vtkInteractorStyleImage() | |
235 | + self.interactor.SetInteractorStyle(style) | |
236 | + self.style = style | |
237 | + | |
238 | + style.AddObserver("LeftButtonPressEvent", self.EnterRubberBandZoom) | |
239 | + | |
240 | + # Zoom using right button | |
241 | + style.AddObserver("RightButtonPressEvent", self.OnRightClick) | |
242 | + style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton) | |
243 | + style.AddObserver("RightButtonPressEvent",self.OnZoomRightClick) | |
244 | + style.AddObserver("MouseMoveEvent", self.OnZoomMoveRight) | |
245 | + style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton) | |
246 | + | |
247 | + def EnterRubberBandZoom(self, evt, obj): | |
248 | + style = vtk.vtkInteractorStyleRubberBandZoom() | |
249 | + self.interactor.SetInteractorStyle(style) | |
250 | + self.style = style | |
251 | + | |
252 | + style.AddObserver("RightButtonPressEvent", self.QuitRubberBandZoom) | |
253 | + | |
231 | 254 | def OnRightClick(self, evt, obj): |
255 | + print "OnRightClick" | |
232 | 256 | self.right_pressed = 1 |
233 | - | |
257 | + | |
258 | + def OnReleaseRightButton(self, evt, obj): | |
259 | + print "OnReleaseRightButton" | |
260 | + self.right_pressed = 0 | |
261 | + ps.Publisher().sendMessage('Update slice viewer') | |
262 | + | |
263 | + def OnLeftClick(self, evt, obj): | |
264 | + print "OnLeftClick" | |
265 | + self.left_pressed = 1 | |
266 | + | |
267 | + def OnZoomLeftClick(self, evt, obj): | |
268 | + print "OnZoomLeftClick" | |
269 | + evt.StartDolly() | |
270 | + | |
271 | + def OnReleaseLeftButton(self, evt, obj): | |
272 | + self.left_pressed = 0 | |
273 | + ps.Publisher().sendMessage('Update slice viewer') | |
274 | + | |
275 | + | |
276 | + | |
234 | 277 | |
235 | 278 | def OnWindowLevelMove(self, evt, obj): |
236 | 279 | if (self.left_pressed): |
... | ... | @@ -255,15 +298,11 @@ class Viewer(wx.Panel): |
255 | 298 | #Necessary update the slice plane in the volume case exists |
256 | 299 | ps.Publisher().sendMessage('Render volume viewer') |
257 | 300 | |
258 | - elif(self.right_pressed): | |
259 | - self.OnZoomMove(evt, obj) | |
260 | - | |
261 | 301 | self.interactor.Render() |
262 | 302 | |
263 | 303 | |
264 | 304 | def OnWindowLevelClick(self, evt, obj): |
265 | 305 | self.last_x, self.last_y = self.interactor.GetLastEventPosition() |
266 | - self.left_pressed = 1 | |
267 | 306 | |
268 | 307 | def UpdateWindowLevelValue(self, pubsub_evt): |
269 | 308 | window, level = pubsub_evt.data |
... | ... | @@ -290,11 +329,8 @@ class Viewer(wx.Panel): |
290 | 329 | self.scroll.SetThumbPosition(self.acum_achange_slice) |
291 | 330 | self.OnScrollBar() |
292 | 331 | |
293 | - elif(self.right_pressed): | |
294 | - self.OnZoomMove(evt, obj) | |
295 | 332 | |
296 | 333 | def OnChangeSliceClick(self, evt, obj): |
297 | - self.left_pressed = 1 | |
298 | 334 | position = list(self.interactor.GetLastEventPosition()) |
299 | 335 | self.acum_achange_slice = self.scroll.GetThumbPosition() |
300 | 336 | self.last_position = position[1] |
... | ... | @@ -303,22 +339,21 @@ class Viewer(wx.Panel): |
303 | 339 | if (self.left_pressed): |
304 | 340 | evt.Pan() |
305 | 341 | evt.OnRightButtonDown() |
306 | - elif(self.right_pressed): | |
307 | - self.OnZoomMove(evt, obj) | |
308 | - | |
342 | + | |
309 | 343 | def OnPanClick(self, evt, obj): |
310 | - self.left_pressed = 1 | |
311 | 344 | evt.StartPan() |
312 | 345 | |
313 | - def OnZoomMove(self, evt, obj): | |
314 | - if (self.left_pressed or self.right_pressed): | |
346 | + def OnZoomMoveLeft(self, evt, obj): | |
347 | + if self.left_pressed: | |
348 | + print "OnZoomMoveLeft:" | |
315 | 349 | evt.Dolly() |
316 | 350 | evt.OnRightButtonDown() |
317 | 351 | |
318 | - def OnZoomLeftClick(self, evt, obj): | |
319 | - self.left_pressed = 1 | |
320 | - evt.StartDolly() | |
321 | - | |
352 | + def OnVtkRightRelease(self, evt, obj): | |
353 | + print "On VTK" | |
354 | + evt.OnRightButtonUp() | |
355 | + | |
356 | + | |
322 | 357 | def OnUnZoom(self, evt, obj = None): |
323 | 358 | mouse_x, mouse_y = self.interactor.GetLastEventPosition() |
324 | 359 | ren = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
... | ... | @@ -332,24 +367,10 @@ class Viewer(wx.Panel): |
332 | 367 | if (self.left_pressed): |
333 | 368 | evt.Spin() |
334 | 369 | evt.OnRightButtonDown() |
335 | - elif(self.right_pressed): | |
336 | - self.OnZoomMove(evt, obj) | |
337 | - | |
338 | 370 | |
339 | 371 | def OnSpinClick(self, evt, obj): |
340 | - self.left_pressed = 1 | |
341 | 372 | evt.StartSpin() |
342 | 373 | |
343 | - def OnReleaseLeftButton(self, evt, obj): | |
344 | - self.left_pressed = 0 | |
345 | - ps.Publisher().sendMessage('Update slice viewer') | |
346 | - | |
347 | - def OnReleaseRightButton(self, evt, obj): | |
348 | - self.right_pressed = 0 | |
349 | - ps.Publisher().sendMessage('Update slice viewer') | |
350 | - | |
351 | - | |
352 | - | |
353 | 374 | def OnEnterInteractor(self, evt, obj): |
354 | 375 | #self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK)) |
355 | 376 | pass |
... | ... | @@ -537,14 +558,8 @@ class Viewer(wx.Panel): |
537 | 558 | self.interactor.Render() |
538 | 559 | #self.cursor = cursor |
539 | 560 | |
540 | - def OnMouseClick(self, evt, obj): | |
541 | - self.left_pressed = 1 | |
542 | - | |
543 | - def OnMouseRelease(self, evt, obj): | |
544 | - self.left_pressed = 0 | |
545 | 561 | |
546 | 562 | def OnBrushClick(self, evt, obj): |
547 | - self.left_pressed = 1 | |
548 | 563 | |
549 | 564 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
550 | 565 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
... | ... | @@ -574,38 +589,34 @@ class Viewer(wx.Panel): |
574 | 589 | |
575 | 590 | def OnBrushMove(self, evt, obj): |
576 | 591 | |
577 | - if(self.right_pressed): | |
578 | - self.OnZoomLeftClick(evt, obj) | |
579 | - self.OnZoomMove(evt, obj) | |
580 | - else: | |
581 | - mouse_x, mouse_y = self.interactor.GetEventPosition() | |
582 | - render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | |
583 | - slice_data = self.get_slice_data(render) | |
584 | - | |
585 | - # TODO: Improve! | |
586 | - for i in self.slice_data_list: | |
587 | - i.cursor.Show(0) | |
588 | - slice_data.cursor.Show() | |
589 | - | |
590 | - self.pick.Pick(mouse_x, mouse_y, 0, render) | |
591 | - coord = self.get_coordinate_cursor() | |
592 | - slice_data.cursor.SetPosition(coord) | |
593 | - slice_data.cursor.SetEditionPosition( | |
594 | - self.get_coordinate_cursor_edition(slice_data)) | |
595 | - self.__update_cursor_position(slice_data, coord) | |
596 | - | |
597 | - if self._brush_cursor_op == const.BRUSH_ERASE: | |
598 | - evt_msg = 'Erase mask pixel' | |
599 | - elif self._brush_cursor_op == const.BRUSH_DRAW: | |
600 | - evt_msg = 'Add mask pixel' | |
601 | - elif self._brush_cursor_op == const.BRUSH_THRESH: | |
602 | - evt_msg = 'Edit mask pixel' | |
603 | - | |
604 | - if (self.left_pressed): | |
605 | - pixels = itertools.ifilter(self.test_operation_position, | |
606 | - slice_data.cursor.GetPixels()) | |
607 | - ps.Publisher().sendMessage(evt_msg, pixels) | |
608 | - ps.Publisher().sendMessage('Update slice viewer') | |
592 | + mouse_x, mouse_y = self.interactor.GetEventPosition() | |
593 | + render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | |
594 | + slice_data = self.get_slice_data(render) | |
595 | + | |
596 | + # TODO: Improve! | |
597 | + for i in self.slice_data_list: | |
598 | + i.cursor.Show(0) | |
599 | + slice_data.cursor.Show() | |
600 | + | |
601 | + self.pick.Pick(mouse_x, mouse_y, 0, render) | |
602 | + coord = self.get_coordinate_cursor() | |
603 | + slice_data.cursor.SetPosition(coord) | |
604 | + slice_data.cursor.SetEditionPosition( | |
605 | + self.get_coordinate_cursor_edition(slice_data)) | |
606 | + self.__update_cursor_position(slice_data, coord) | |
607 | + | |
608 | + if self._brush_cursor_op == const.BRUSH_ERASE: | |
609 | + evt_msg = 'Erase mask pixel' | |
610 | + elif self._brush_cursor_op == const.BRUSH_DRAW: | |
611 | + evt_msg = 'Add mask pixel' | |
612 | + elif self._brush_cursor_op == const.BRUSH_THRESH: | |
613 | + evt_msg = 'Edit mask pixel' | |
614 | + | |
615 | + if (self.left_pressed): | |
616 | + pixels = itertools.ifilter(self.test_operation_position, | |
617 | + slice_data.cursor.GetPixels()) | |
618 | + ps.Publisher().sendMessage(evt_msg, pixels) | |
619 | + ps.Publisher().sendMessage('Update slice viewer') | |
609 | 620 | |
610 | 621 | self.interactor.Render() |
611 | 622 | |
... | ... | @@ -627,9 +638,17 @@ class Viewer(wx.Panel): |
627 | 638 | coord[1]) |
628 | 639 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), |
629 | 640 | coord[2]) |
630 | - elif(self.right_pressed): | |
631 | - self.OnZoomLeftClick(evt, obj) | |
632 | - self.OnZoomMove(evt, obj) | |
641 | + | |
642 | + def OnZoomMoveRight(self, evt, obj): | |
643 | + if (self.right_pressed): | |
644 | + print "OnZoomMoveRight" | |
645 | + evt.Dolly() | |
646 | + evt.OnRightButtonDown() | |
647 | + | |
648 | + def OnZoomRightClick(self, evt, obj): | |
649 | + print "OnZoomRightClick" | |
650 | + evt.StartDolly() | |
651 | + | |
633 | 652 | |
634 | 653 | def OnCrossMouseClick(self, evt, obj): |
635 | 654 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
... | ... | @@ -645,10 +664,7 @@ class Viewer(wx.Panel): |
645 | 664 | coord[1]) |
646 | 665 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), |
647 | 666 | coord[2]) |
648 | - self.left_pressed = 1 | |
649 | 667 | |
650 | - def OnCrossMouseRelease(self, evt, obj): | |
651 | - self.left_pressed = 0 | |
652 | 668 | |
653 | 669 | def get_slice_data(self, render): |
654 | 670 | for slice_data in self.slice_data_list: |
... | ... | @@ -776,7 +792,6 @@ class Viewer(wx.Panel): |
776 | 792 | del slice_data |
777 | 793 | |
778 | 794 | self.modes = []#['DEFAULT'] |
779 | - self.mouse_pressed = 0 | |
780 | 795 | self.slice_data_list = [] |
781 | 796 | self.layout = (1, 1) |
782 | 797 | self.orientation_texts = [] |
... | ... | @@ -788,7 +803,6 @@ class Viewer(wx.Panel): |
788 | 803 | |
789 | 804 | def OnSetMode(self, pubsub_evt): |
790 | 805 | state = pubsub_evt.data |
791 | - self.left_pressed = 0 | |
792 | 806 | self.SetState(state) |
793 | 807 | |
794 | 808 | |
... | ... | @@ -801,7 +815,7 @@ class Viewer(wx.Panel): |
801 | 815 | self.scroll.Bind(wx.EVT_SCROLL_THUMBTRACK, self.OnScrollBarRelease) |
802 | 816 | #self.scroll.Bind(wx.EVT_SCROLL_ENDSCROLL, self.OnScrollBarRelease) |
803 | 817 | self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
804 | - self.interactor.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) | |
818 | + self.interactor.Bind(wx.EVT_RIGHT_UP, self.OnContextMenu) | |
805 | 819 | self.Bind(wx.EVT_SIZE, self.OnSize) |
806 | 820 | |
807 | 821 | def LoadImagedata(self, pubsub_evt): | ... | ... |