Commit 03258f78c496a44699c4f5a4b7186ff100171961
1 parent
fb4bd5e7
Exists in
master
and in
68 other branches
ENH: Show more then a slice by window
Showing
1 changed file
with
48 additions
and
20 deletions
Show diff stats
invesalius/data/viewer_slice.py
... | ... | @@ -41,6 +41,10 @@ class Viewer(wx.Panel): |
41 | 41 | self.modes = []#['DEFAULT'] |
42 | 42 | self.mouse_pressed = 0 |
43 | 43 | |
44 | + # All renderers and image actors in this viewer | |
45 | + self.image_windows = [] | |
46 | + self.slice_dispostion = (2, 2) | |
47 | + | |
44 | 48 | self.__init_gui() |
45 | 49 | |
46 | 50 | self.orientation = orientation |
... | ... | @@ -179,11 +183,13 @@ class Viewer(wx.Panel): |
179 | 183 | self.mouse_pressed = 1 |
180 | 184 | |
181 | 185 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
182 | - self.pick.Pick(mouse_x, mouse_y, 0, self.ren) | |
186 | + render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | |
187 | + actor = self.get_image_window(render) | |
188 | + self.pick.Pick(mouse_x, mouse_y, 0, render) | |
183 | 189 | |
184 | 190 | coord = self.GetCoordinateCursor() |
185 | 191 | self.cursor.SetPosition(coord) |
186 | - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition()) | |
192 | + self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(actor)) | |
187 | 193 | self.__update_cursor_position(coord) |
188 | 194 | self.ren.Render() |
189 | 195 | |
... | ... | @@ -203,10 +209,12 @@ class Viewer(wx.Panel): |
203 | 209 | |
204 | 210 | def OnBrushMove(self, obj, evt_vtk): |
205 | 211 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
206 | - self.pick.Pick(mouse_x, mouse_y, 0, self.ren) | |
212 | + render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) | |
213 | + actor = self.get_image_window(render) | |
214 | + self.pick.Pick(mouse_x, mouse_y, 0, render) | |
207 | 215 | coord = self.GetCoordinateCursor() |
208 | 216 | self.cursor.SetPosition(coord) |
209 | - self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition()) | |
217 | + self.cursor.SetEditionPosition(self.GetCoordinateCursorEdition(actor)) | |
210 | 218 | self.__update_cursor_position(coord) |
211 | 219 | |
212 | 220 | if self._brush_cursor_op == const.BRUSH_ERASE: |
... | ... | @@ -237,6 +245,11 @@ class Viewer(wx.Panel): |
237 | 245 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), |
238 | 246 | coord[2]) |
239 | 247 | |
248 | + def get_image_window(self, render): | |
249 | + for r, a in self.image_windows: | |
250 | + if r is render: | |
251 | + return a | |
252 | + | |
240 | 253 | def GetCoordinate(self): |
241 | 254 | # Find position |
242 | 255 | x, y, z = self.pick.GetPickPosition() |
... | ... | @@ -280,12 +293,12 @@ class Viewer(wx.Panel): |
280 | 293 | x, y, z = self.pick.GetPickPosition() |
281 | 294 | return x, y, z |
282 | 295 | |
283 | - def GetCoordinateCursorEdition(self): | |
296 | + def GetCoordinateCursorEdition(self, actor): | |
284 | 297 | # Find position |
285 | 298 | x, y, z = self.pick.GetPickPosition() |
286 | 299 | |
287 | 300 | # First we fix the position origin, based on vtkActor bounds |
288 | - bounds = self.actor.GetBounds() | |
301 | + bounds = actor.GetBounds() | |
289 | 302 | bound_xi, bound_xf, bound_yi, bound_yf, bound_zi, bound_zf = bounds |
290 | 303 | x = float(x - bound_xi) |
291 | 304 | y = float(y - bound_yi) |
... | ... | @@ -338,6 +351,18 @@ class Viewer(wx.Panel): |
338 | 351 | imagedata = pubsub_evt.data |
339 | 352 | self.SetInput(imagedata) |
340 | 353 | |
354 | + 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]): | |
359 | + position = ((i*proportion_x, j * proportion_y, | |
360 | + (i+1)*proportion_x, (j+1)*proportion_y)) | |
361 | + ren, actor = self.create_slice_window(image) | |
362 | + ren.SetViewport(position) | |
363 | + self.image_windows.append((ren, actor)) | |
364 | + | |
365 | + | |
341 | 366 | def SetInput(self, imagedata): |
342 | 367 | self.imagedata = imagedata |
343 | 368 | |
... | ... | @@ -352,7 +377,8 @@ class Viewer(wx.Panel): |
352 | 377 | |
353 | 378 | #actor = vtk.vtkImageActor() |
354 | 379 | #actor.SetInput(slice_.GetOutput()) |
355 | - ren, actor = self.add_actor(slice_.GetOutput()) | |
380 | + self.load_renderers(slice_.GetOutput()) | |
381 | + ren, actor = self.image_windows[0] | |
356 | 382 | actor_bound = actor.GetBounds() |
357 | 383 | self.actor = actor |
358 | 384 | self.ren = ren |
... | ... | @@ -374,7 +400,8 @@ class Viewer(wx.Panel): |
374 | 400 | |
375 | 401 | #ren.AddActor(actor) |
376 | 402 | #ren.AddActor(text_actor) |
377 | - self.__update_camera() | |
403 | + for ren, actor in self.image_windows: | |
404 | + self.__update_camera(ren, actor) | |
378 | 405 | |
379 | 406 | max_slice_number = actor.GetSliceNumberMax() |
380 | 407 | self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, |
... | ... | @@ -408,9 +435,10 @@ class Viewer(wx.Panel): |
408 | 435 | |
409 | 436 | def SetOrientation(self, orientation): |
410 | 437 | self.orientation = orientation |
411 | - self.__update_camera() | |
438 | + for ren, actor in self.image_windows: | |
439 | + self.__update_camera(ren, actor) | |
412 | 440 | |
413 | - def add_actor(self, image): | |
441 | + def create_slice_window(self, image): | |
414 | 442 | render = vtk.vtkRenderer() |
415 | 443 | self.interactor.GetRenderWindow().AddRenderer(render) |
416 | 444 | actor = vtk.vtkImageActor() |
... | ... | @@ -418,10 +446,10 @@ class Viewer(wx.Panel): |
418 | 446 | render.AddActor(actor) |
419 | 447 | return render, actor |
420 | 448 | |
421 | - def __update_camera(self): | |
449 | + def __update_camera(self, ren, actor): | |
422 | 450 | orientation = self.orientation |
423 | 451 | |
424 | - cam = self.cam | |
452 | + cam = ren.GetActiveCamera() | |
425 | 453 | cam.SetFocalPoint(0, 0, 0) |
426 | 454 | cam.SetPosition(const.CAM_POSITION[self.orientation]) |
427 | 455 | cam.SetViewUp(const.CAM_VIEW_UP[self.orientation]) |
... | ... | @@ -429,12 +457,12 @@ class Viewer(wx.Panel): |
429 | 457 | cam.OrthogonalizeViewUp() |
430 | 458 | cam.ParallelProjectionOn() |
431 | 459 | |
432 | - self.__update_display_extent() | |
460 | + self.__update_display_extent(actor, ren) | |
433 | 461 | |
434 | - self.ren.ResetCamera() | |
435 | - self.ren.Render() | |
462 | + ren.ResetCamera() | |
463 | + ren.Render() | |
436 | 464 | |
437 | - def __update_display_extent(self): | |
465 | + def __update_display_extent(self, actor, render): | |
438 | 466 | pos = self.slice_number |
439 | 467 | e = self.imagedata.GetWholeExtent() |
440 | 468 | |
... | ... | @@ -442,9 +470,9 @@ class Viewer(wx.Panel): |
442 | 470 | "CORONAL": (e[0], e[1], pos, pos, e[4], e[5]), |
443 | 471 | "AXIAL": (e[0], e[1], e[2], e[3], pos, pos)} |
444 | 472 | |
445 | - self.actor.SetDisplayExtent(new_extent[self.orientation]) | |
446 | - self.ren.ResetCameraClippingRange() | |
447 | - self.ren.Render() | |
473 | + actor.SetDisplayExtent(new_extent[self.orientation]) | |
474 | + render.ResetCameraClippingRange() | |
475 | + render.Render() | |
448 | 476 | |
449 | 477 | def UpdateRender(self, evt): |
450 | 478 | self.interactor.Render() |
... | ... | @@ -481,7 +509,7 @@ class Viewer(wx.Panel): |
481 | 509 | def SetSliceNumber(self, index): |
482 | 510 | self.text_actor.SetInput(str(index)) |
483 | 511 | self.slice_number = index |
484 | - self.__update_display_extent() | |
512 | + self.__update_display_extent(self.actor, self.ren) | |
485 | 513 | |
486 | 514 | position = {"SAGITAL": {0: self.slice_number}, |
487 | 515 | "CORONAL": {1: self.slice_number}, | ... | ... |