Commit d1963727a3a955e36bd1b3c24022fed694a481ca

Authored by tfmoraes
1 parent af75e942

ENH: Changing all the image_window slice when scrolling

Showing 1 changed file with 37 additions and 30 deletions   Show diff stats
invesalius/data/viewer_slice.py
... ... @@ -43,7 +43,7 @@ class Viewer(wx.Panel):
43 43  
44 44 # All renderers and image actors in this viewer
45 45 self.image_windows = []
46   - self.slice_dispostion = (2, 2)
  46 + self.layout = (2, 2)
47 47  
48 48 self.__init_gui()
49 49  
... ... @@ -184,14 +184,14 @@ class Viewer(wx.Panel):
184 184  
185 185 mouse_x, mouse_y = self.interactor.GetEventPosition()
186 186 render = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
187   - actor = self.get_image_window(render)
  187 + image_window = self.get_image_window(render)
188 188 self.pick.Pick(mouse_x, mouse_y, 0, render)
189 189  
190 190 coord = self.GetCoordinateCursor()
191 191 self.cursor.SetPosition(coord)
192   - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(actor))
  192 + self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(image_window))
193 193 self.__update_cursor_position(coord)
194   - self.ren.Render()
  194 + #render.Render()
195 195  
196 196 evt_msg = {const.BRUSH_ERASE: 'Erase mask pixel',
197 197 const.BRUSH_DRAW: 'Add mask pixel',
... ... @@ -210,11 +210,11 @@ class Viewer(wx.Panel):
210 210 def OnBrushMove(self, obj, evt_vtk):
211 211 mouse_x, mouse_y = self.interactor.GetEventPosition()
212 212 render = self.interactor.FindPokedRenderer(mouse_x, mouse_y)
213   - actor = self.get_image_window(render)
  213 + image_window = self.get_image_window(render)
214 214 self.pick.Pick(mouse_x, mouse_y, 0, render)
215 215 coord = self.GetCoordinateCursor()
216 216 self.cursor.SetPosition(coord)
217   - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(actor))
  217 + self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(image_window))
218 218 self.__update_cursor_position(coord)
219 219  
220 220 if self._brush_cursor_op == const.BRUSH_ERASE:
... ... @@ -246,9 +246,9 @@ class Viewer(wx.Panel):
246 246 coord[2])
247 247  
248 248 def get_image_window(self, render):
249   - for r, a in self.image_windows:
250   - if r is render:
251   - return a
  249 + for i in self.image_windows:
  250 + if i[0] is render:
  251 + return i
252 252  
253 253 def GetCoordinate(self):
254 254 # Find position
... ... @@ -293,8 +293,9 @@ class Viewer(wx.Panel):
293 293 x, y, z = self.pick.GetPickPosition()
294 294 return x, y, z
295 295  
296   - def GetCoordinateCursorEdition(self, actor):
  296 + def GetCoordinateCursorEdition(self, image_window):
297 297 # Find position
  298 + actor, slice_number = image_window[1::]
298 299 x, y, z = self.pick.GetPickPosition()
299 300  
300 301 # First we fix the position origin, based on vtkActor bounds
... ... @@ -313,15 +314,15 @@ class Viewer(wx.Panel):
313 314 try:
314 315 x = (x * dimensions[0]) / dx
315 316 except ZeroDivisionError:
316   - x = self.slice_number
  317 + x = slice_number
317 318 try:
318 319 y = (y * dimensions[1]) / dy
319 320 except ZeroDivisionError:
320   - y = self.slice_number
  321 + y = slice_number
321 322 try:
322 323 z = (z * dimensions[2]) / dz
323 324 except ZeroDivisionError:
324   - z = self.slice_number
  325 + z = slice_number
325 326  
326 327 return x,y,z
327 328  
... ... @@ -352,15 +353,15 @@ class Viewer(wx.Panel):
352 353 self.SetInput(imagedata)
353 354  
354 355 def load_renderers(self, image):
355   - proportion_x = 1.0 / self.slice_dispostion[0]
356   - proportion_y = 1.0 / self.slice_dispostion[1]
357   - for i in xrange(self.slice_dispostion[0]):
358   - for j in xrange(self.slice_dispostion[1]):
  356 + proportion_x = 1.0 / self.layout[0]
  357 + proportion_y = 1.0 / self.layout[1]
  358 + for i in xrange(self.layout[0]):
  359 + for j in xrange(self.layout[1]):
359 360 position = ((i*proportion_x, j * proportion_y,
360 361 (i+1)*proportion_x, (j+1)*proportion_y))
361 362 ren, actor = self.create_slice_window(image)
362 363 ren.SetViewport(position)
363   - self.image_windows.append((ren, actor))
  364 + self.image_windows.append([ren, actor, 0])
364 365  
365 366  
366 367 def SetInput(self, imagedata):
... ... @@ -378,7 +379,7 @@ class Viewer(wx.Panel):
378 379 #actor = vtk.vtkImageActor()
379 380 #actor.SetInput(slice_.GetOutput())
380 381 self.load_renderers(slice_.GetOutput())
381   - ren, actor = self.image_windows[0]
  382 + ren, actor = self.image_windows[0][:2]
382 383 actor_bound = actor.GetBounds()
383 384 self.actor = actor
384 385 self.ren = ren
... ... @@ -400,10 +401,11 @@ class Viewer(wx.Panel):
400 401  
401 402 #ren.AddActor(actor)
402 403 #ren.AddActor(text_actor)
403   - for ren, actor in self.image_windows:
404   - self.__update_camera(ren, actor)
  404 + for ren, actor, n in self.image_windows:
  405 + self.__update_camera(ren, actor, n)
405 406  
406   - max_slice_number = actor.GetSliceNumberMax()
  407 + max_slice_number = actor.GetSliceNumberMax() / \
  408 + (self.layout[0] * self.layout[1])
407 409 self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number,
408 410 max_slice_number)
409 411 self.SetScrollPosition(0)
... ... @@ -435,8 +437,8 @@ class Viewer(wx.Panel):
435 437  
436 438 def SetOrientation(self, orientation):
437 439 self.orientation = orientation
438   - for ren, actor in self.image_windows:
439   - self.__update_camera(ren, actor)
  440 + for ren, actor, n in self.image_windows:
  441 + self.__update_camera(ren, actor, n)
440 442  
441 443 def create_slice_window(self, image):
442 444 render = vtk.vtkRenderer()
... ... @@ -446,7 +448,7 @@ class Viewer(wx.Panel):
446 448 render.AddActor(actor)
447 449 return render, actor
448 450  
449   - def __update_camera(self, ren, actor):
  451 + def __update_camera(self, ren, actor, pos):
450 452 orientation = self.orientation
451 453  
452 454 cam = ren.GetActiveCamera()
... ... @@ -457,13 +459,12 @@ class Viewer(wx.Panel):
457 459 cam.OrthogonalizeViewUp()
458 460 cam.ParallelProjectionOn()
459 461  
460   - self.__update_display_extent(actor, ren)
  462 + self.__update_display_extent(actor, ren, pos)
461 463  
462 464 ren.ResetCamera()
463 465 ren.Render()
464 466  
465   - def __update_display_extent(self, actor, render):
466   - pos = self.slice_number
  467 + def __update_display_extent(self, actor, render, pos):
467 468 e = self.imagedata.GetWholeExtent()
468 469  
469 470 new_extent = {"SAGITAL": (pos, pos, e[2], e[3], e[4], e[5]),
... ... @@ -472,7 +473,7 @@ class Viewer(wx.Panel):
472 473  
473 474 actor.SetDisplayExtent(new_extent[self.orientation])
474 475 render.ResetCameraClippingRange()
475   - render.Render()
  476 + #render.Render()
476 477  
477 478 def UpdateRender(self, evt):
478 479 self.interactor.Render()
... ... @@ -509,7 +510,13 @@ class Viewer(wx.Panel):
509 510 def SetSliceNumber(self, index):
510 511 self.text_actor.SetInput(str(index))
511 512 self.slice_number = index
512   - self.__update_display_extent(self.actor, self.ren)
  513 + for n, window in enumerate(self.image_windows):
  514 + ren, actor = window[:2]
  515 + pos = self.layout[0] * self.layout[1] * index + n
  516 + print pos
  517 + self.__update_display_extent(actor, ren, pos)
  518 + self.image_windows[n][2] = pos
  519 + print
513 520  
514 521 position = {"SAGITAL": {0: self.slice_number},
515 522 "CORONAL": {1: self.slice_number},
... ...