Commit 46f4452a1b5c39e826de86c383345df72eeeb9b1

Authored by Thiago Franco de Moraes
1 parent 4a7add3a
Exists in interactor_style

Cleaning code related to vtk events from viewer_slice

Showing 1 changed file with 2 additions and 244 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -178,6 +178,8 @@ class Viewer(wx.Panel):
178 178 self.__set_cross_visibility(0)
179 179 self.on_wl = False
180 180 self.wl_text.Hide()
  181 + self.state = state
  182 +
181 183 if state == const.STATE_DEFAULT:
182 184 style = styles.DefaultInteractorStyle(self)
183 185 self.style = style
... ... @@ -257,156 +259,12 @@ class Viewer(wx.Panel):
257 259 self.interactor.SetInteractorStyle(style)
258 260 self.interactor.Render()
259 261  
260   - else:
261   - self.state = state
262   - action = {
263   - const.SLICE_STATE_EDITOR:
264   - {
265   - "MouseMoveEvent": self.OnBrushMove,
266   - "LeftButtonPressEvent": self.OnBrushClick,
267   - "LeftButtonReleaseEvent": self.OnBrushRelease,
268   - "EnterEvent": self.OnEnterInteractor,
269   - "LeaveEvent": self.OnLeaveInteractor
270   - },
271   - const.STATE_DEFAULT:
272   - {
273   - },
274   - }
275   -
276   -
277   - if state == const.SLICE_STATE_CROSS:
278   - self.__set_cross_visibility(1)
279   - Publisher.sendMessage('Activate ball reference')
280   - else:
281   - self.__set_cross_visibility(0)
282   - Publisher.sendMessage('Deactivate ball reference')
283   -
284   - if state == const.STATE_WL:
285   - self.on_wl = True
286   - self.wl_text.Show()
287   - else:
288   - self.on_wl = False
289   - self.wl_text.Hide()
290   -
291   - self._set_editor_cursor_visibility(0)
292   -
293   - # Bind method according to current mode
294   - if(state == const.STATE_ZOOM_SL):
295   - style = vtk.vtkInteractorStyleRubberBandZoom()
296   -
297   - style.AddObserver("RightButtonPressEvent", self.QuitRubberBandZoom)
298   - #style.AddObserver("RightButtonPressEvent", self.EnterRubberBandZoom)
299   -
300   - else:
301   - style = vtk.vtkInteractorStyleImage()
302   -
303   - # Check each event available for each state
304   - for event in action[state]:
305   - # Bind event
306   - style.AddObserver(event,
307   - action[state][event])
308   -
309   - # Common to all styles
310   - # Mouse Buttons' presses / releases
311   - style.AddObserver("LeftButtonPressEvent", self.OnLeftClick)
312   - style.AddObserver("LeftButtonReleaseEvent", self.OnReleaseLeftButton)
313   - style.AddObserver("RightButtonPressEvent", self.OnRightClick)
314   - style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton)
315   -
316   - # Zoom using right button
317   - style.AddObserver("RightButtonPressEvent",self.OnZoomRightClick)
318   - style.AddObserver("MouseMoveEvent", self.OnZoomMoveRight)
319   - style.AddObserver("RightButtonReleaseEvent", self.OnVtkRightRelease)
320   -
321   - #Scroll change slice
322   - style.AddObserver("MouseWheelForwardEvent",self.OnScrollForward)
323   - style.AddObserver("MouseWheelBackwardEvent", self.OnScrollBackward)
324   -
325   -
326   - # Measures are using vtkPropPicker because they need to get which actor
327   - # was picked.
328   - if state in (const.STATE_MEASURE_DISTANCE, const.STATE_MEASURE_ANGLE):
329   - self.pick = vtk.vtkPropPicker()
330   - self.interactor.SetPicker(self.pick)
331   - else:
332   - self.pick = vtk.vtkWorldPointPicker()
333   - self.interactor.SetPicker(self.pick)
334   -
335   - self.style = style
336   - self.interactor.SetInteractorStyle(style)
337   - self.interactor.Render()
338   -
339   - def QuitRubberBandZoom(self, evt, obj):
340   - style = vtk.vtkInteractorStyleImage()
341   - self.interactor.SetInteractorStyle(style)
342   - self.style = style
343   -
344   - style.AddObserver("LeftButtonPressEvent", self.EnterRubberBandZoom)
345   -
346   - # Zoom using right button
347   - style.AddObserver("RightButtonPressEvent", self.OnRightClick)
348   - style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton)
349   - style.AddObserver("RightButtonPressEvent",self.OnZoomRightClick)
350   - style.AddObserver("MouseMoveEvent", self.OnZoomMoveRight)
351   - style.AddObserver("RightButtonReleaseEvent", self.OnReleaseRightButton)
352   -
353   - def EnterRubberBandZoom(self, evt, obj):
354   - style = vtk.vtkInteractorStyleRubberBandZoom()
355   - self.interactor.SetInteractorStyle(style)
356   - self.style = style
357   -
358   - style.AddObserver("RightButtonPressEvent", self.QuitRubberBandZoom)
359   -
360   - def OnRightClick(self, evt, obj):
361   - self.last_position_mouse_move = \
362   - self.interactor.GetLastEventPosition()
363   -
364   - self.right_pressed = 1
365   -
366   - def OnReleaseRightButton(self, evt, obj):
367   - self.right_pressed = 0
368   - Publisher.sendMessage('Update slice viewer')
369   -
370   - def OnLeftClick(self, evt, obj):
371   - self.left_pressed = 1
372   -
373   - def OnReleaseLeftButton(self, evt, obj):
374   - self.left_pressed = 0
375   - Publisher.sendMessage('Update slice viewer')
376   -
377 262 def UpdateWindowLevelValue(self, pubsub_evt):
378 263 window, level = pubsub_evt.data
379 264 self.acum_achange_window, self.acum_achange_level = (window, level)
380 265 self.SetWLText(window, level)
381 266 Publisher.sendMessage('Update all slice')
382 267  
383   - def OnPanMove(self, evt, obj):
384   - mouse_x, mouse_y = self.interactor.GetLastEventPosition()
385   - ren = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
386   - cam = ren.GetActiveCamera()
387   -
388   - if (self.left_pressed):
389   - evt.Pan()
390   - evt.OnRightButtonDown()
391   - self.paned_image = True
392   -
393   - def OnPanClick(self, evt, obj):
394   - evt.StartPan()
395   -
396   - def OnVtkRightRelease(self, evt, obj):
397   - evt.OnRightButtonUp()
398   -
399   - def OnEnterInteractor(self, evt, obj):
400   - if (self.slice_.buffer_slices[self.orientation].mask is None):
401   - return
402   - self.slice_data.cursor.Show()
403   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
404   -
405   - def OnLeaveInteractor(self, evt, obj):
406   - self.slice_data.cursor.Show(0)
407   - self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
408   - self.interactor.Render()
409   -
410 268 def SetWLText(self, window_width, window_level):
411 269 value = STR_WL%(window_level, window_width)
412 270 if (self.wl_text):
... ... @@ -660,98 +518,6 @@ class Viewer(wx.Panel):
660 518 slice_data.SetCursor(cursor)
661 519 self.interactor.Render()
662 520  
663   - def OnBrushClick(self, evt, obj):
664   - if (self.slice_.buffer_slices[self.orientation].mask is None):
665   - return
666   -
667   - self._set_editor_cursor_visibility(1)
668   -
669   - mouse_x, mouse_y = self.interactor.GetEventPosition()
670   - render = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
671   - slice_data = self.get_slice_data(render)
672   -
673   - # TODO: Improve!
674   - #for i in self.slice_data_list:
675   - #i.cursor.Show(0)
676   - self.slice_data.cursor.Show()
677   -
678   - self.pick.Pick(mouse_x, mouse_y, 0, render)
679   -
680   - coord = self.get_coordinate_cursor()
681   - position = self.slice_data.actor.GetInput().FindPoint(coord)
682   -
683   - if position != -1:
684   - coord = self.slice_data.actor.GetInput().GetPoint(position)
685   -
686   - slice_data.cursor.SetPosition(coord)
687   - cursor = self.slice_data.cursor
688   - radius = cursor.radius
689   -
690   - if position < 0:
691   - position = self.calculate_matrix_position(coord)
692   -
693   - self.slice_.edit_mask_pixel(self._brush_cursor_op, cursor.GetPixels(),
694   - position, radius, self.orientation)
695   - self._flush_buffer = True
696   -
697   - # TODO: To create a new function to reload images to viewer.
698   - self.OnScrollBar()
699   -
700   - def OnBrushMove(self, evt, obj):
701   - if (self.slice_.buffer_slices[self.orientation].mask is None):
702   - return
703   -
704   - self._set_editor_cursor_visibility(1)
705   -
706   - mouse_x, mouse_y = self.interactor.GetEventPosition()
707   - render = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
708   - slice_data = self.get_slice_data(render)
709   -
710   - # TODO: Improve!
711   - #for i in self.slice_data_list:
712   - #i.cursor.Show(0)
713   -
714   - self.pick.Pick(mouse_x, mouse_y, 0, render)
715   -
716   - #if (self.pick.GetViewProp()):
717   - #self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
718   - #else:
719   - #self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
720   -
721   - coord = self.get_coordinate_cursor()
722   - position = self.slice_data.actor.GetInput().FindPoint(coord)
723   -
724   - # when position == -1 the cursos is not over the image, so is not
725   - # necessary to set the cursor position to world coordinate center of
726   - # pixel from slice image.
727   - if position != -1:
728   - coord = self.slice_data.actor.GetInput().GetPoint(position)
729   - slice_data.cursor.SetPosition(coord)
730   - #self.__update_cursor_position(slice_data, coord)
731   -
732   - if (self.left_pressed):
733   - cursor = self.slice_data.cursor
734   - position = self.slice_data.actor.GetInput().FindPoint(coord)
735   - radius = cursor.radius
736   -
737   - if position < 0:
738   - position = self.calculate_matrix_position(coord)
739   -
740   - self.slice_.edit_mask_pixel(self._brush_cursor_op, cursor.GetPixels(),
741   - position, radius, self.orientation)
742   - # TODO: To create a new function to reload images to viewer.
743   - self.OnScrollBar(update3D=False)
744   -
745   - else:
746   - self.interactor.Render()
747   -
748   - def OnBrushRelease(self, evt, obj):
749   - if (self.slice_.buffer_slices[self.orientation].mask is None):
750   - return
751   -
752   - self.slice_.apply_slice_buffer_to_mask(self.orientation)
753   - self._flush_buffer = False
754   -
755 521 def Navigation(self, pubsub_evt):
756 522 # Get point from base change
757 523 x, y, z = pubsub_evt.data
... ... @@ -781,14 +547,6 @@ class Viewer(wx.Panel):
781 547 Publisher.sendMessage(('Set scroll position', 'SAGITAL'),
782 548 coord[0])
783 549  
784   - def OnZoomMoveRight(self, evt, obj):
785   - if (self.right_pressed):
786   - evt.Dolly()
787   - evt.OnRightButtonDown()
788   -
789   - def OnZoomRightClick(self, evt, obj):
790   - evt.StartDolly()
791   -
792 550 def get_slice_data(self, render):
793 551 #for slice_data in self.slice_data_list:
794 552 #if slice_data.renderer is render:
... ...