Commit 12e311c6c0e1598bb612e521c08267f3294d29b9

Authored by Paulo Henrique Junqueira Amorim
1 parent a460a443

ADD: Zoom initial size of the screen.

Showing 1 changed file with 77 additions and 5 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -65,6 +65,7 @@ class Viewer(wx.Panel):
65 65  
66 66 self.__bind_events()
67 67 self.__bind_events_wx()
  68 +
68 69  
69 70 def __init_gui(self):
70 71  
... ... @@ -155,7 +156,76 @@ class Viewer(wx.Panel):
155 156 action[mode][event])
156 157 self.style = style
157 158 self.interactor.SetInteractorStyle(style)
158   -
  159 +
  160 +
  161 + def Reposition(self):
  162 + """
  163 + Based on code of method Zoom in the
  164 + vtkInteractorStyleRubberBandZoom, the of
  165 + vtk 5.4.3
  166 + """
  167 + size = self.ren.GetSize()
  168 +
  169 + if (size[0] <= size[1] + 100):
  170 +
  171 + bound = self.actor.GetBounds()
  172 +
  173 + width = abs((bound[3] - bound[2]) * -1)
  174 + height = abs((bound[1] - bound[0]) * -1)
  175 +
  176 + origin = self.ren.GetOrigin()
  177 + cam = self.ren.GetActiveCamera()
  178 +
  179 + min = []
  180 + min.append(bound[0])
  181 + min.append(bound[2])
  182 +
  183 + rbcenter = []
  184 + rbcenter.append(min[0] + 0.5 * width)
  185 + rbcenter.append(min[1] + 0.5 * height)
  186 + rbcenter.append(0)
  187 +
  188 + self.ren.SetDisplayPoint(rbcenter)
  189 + self.ren.DisplayToView()
  190 + self.ren.ViewToWorld()
  191 +
  192 + worldRBCenter = self.ren.GetWorldPoint()
  193 + worldRBCenter = list(worldRBCenter)
  194 +
  195 + invw = 1.0/worldRBCenter[3]
  196 +
  197 + worldRBCenter[0] *= invw
  198 + worldRBCenter[1] *= invw
  199 + worldRBCenter[2] *= invw
  200 +
  201 + winCenter = []
  202 + winCenter.append(origin[0] + 0.5 * size[0])
  203 + winCenter.append(origin[1] + 0.5 * size[1])
  204 + winCenter.append(0)
  205 +
  206 + self.ren.SetDisplayPoint(winCenter)
  207 + self.ren.DisplayToView()
  208 + self.ren.ViewToWorld()
  209 +
  210 + worldWinCenter = list(self.ren.GetWorldPoint())
  211 + invw = 1.0/worldWinCenter[3]
  212 + worldWinCenter[0] *= invw
  213 + worldWinCenter[1] *= invw
  214 + worldWinCenter[2] *= invw
  215 +
  216 + translation = []
  217 + translation.append(worldRBCenter[0] - worldWinCenter[0])
  218 + translation.append(worldRBCenter[1] - worldWinCenter[1])
  219 + translation.append(worldRBCenter[2] - worldWinCenter[2])
  220 +
  221 + if (width > height):
  222 + cam.Zoom(size[0] / width)
  223 + else:
  224 + cam.Zoom(size[1] / height)
  225 +
  226 + self.interactor.Render()
  227 +
  228 +
159 229 def ChangeEditorMode(self, pubsub_evt):
160 230 self.append_mode('EDITOR')
161 231 self.mouse_pressed = 0
... ... @@ -165,7 +235,7 @@ class Viewer(wx.Panel):
165 235 self.append_mode('SPIN')
166 236 self.mouse_pressed = 0
167 237 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
168   -
  238 +
169 239 def ChangeZoomMode(self, pubsub_evt):
170 240 self.append_mode('ZOOM')
171 241 self.mouse_pressed = 0
... ... @@ -203,7 +273,7 @@ class Viewer(wx.Panel):
203 273 def OnUnZoom(self, evt, obj):
204 274 self.ren.ResetCamera()
205 275 self.ren.ResetCameraClippingRange()
206   - self.interactor.Render()
  276 + self.Reposition()
207 277  
208 278 def OnSpinMove(self, evt, obj):
209 279 if (self.mouse_pressed):
... ... @@ -496,6 +566,7 @@ class Viewer(wx.Panel):
496 566 cursor.SetColour(self._brush_cursor_colour)
497 567 cursor.SetSpacing(self.imagedata.GetSpacing())
498 568 cursor.Show(0)
  569 + self.cursor_ = cursor
499 570 return cursor
500 571  
501 572 def SetInput(self, imagedata):
... ... @@ -550,10 +621,10 @@ class Viewer(wx.Panel):
550 621 actor_bound = actor.GetBounds()
551 622  
552 623 # Insert cursor
553   -
554   -
555 624 self.append_mode('EDITOR')
556 625  
  626 + self.Reposition()
  627 +
557 628 def __update_cursor_position(self, slice_data, position):
558 629 x, y, z = position
559 630 if (slice_data.cursor):
... ... @@ -640,6 +711,7 @@ class Viewer(wx.Panel):
640 711 def OnScrollBar(self, evt=None):
641 712 pos = self.scroll.GetThumbPosition()
642 713 self.set_slice_number(pos)
  714 + self.cursor_.Show(1)
643 715 self.interactor.Render()
644 716 if evt:
645 717 evt.Skip()
... ...