Commit 7f8d5bc7b184335accd755464fc8a174c9956f92
1 parent
705d3adf
Exists in
master
and in
68 other branches
ENH: Created a new class to store each render, actor, slice_number
Showing
3 changed files
with
63 additions
and
49 deletions
Show diff stats
.gitattributes
| ... | ... | @@ -87,6 +87,7 @@ invesalius/data/mask.py -text |
| 87 | 87 | invesalius/data/orientation.py -text |
| 88 | 88 | invesalius/data/polydata_utils.py -text |
| 89 | 89 | invesalius/data/slice_.py -text |
| 90 | +invesalius/data/slice_data.py -text | |
| 90 | 91 | invesalius/data/styles.py -text |
| 91 | 92 | invesalius/data/surface.py -text |
| 92 | 93 | invesalius/data/viewer.py -text | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -29,6 +29,8 @@ import constants as const |
| 29 | 29 | import project |
| 30 | 30 | import cursor_actors as ca |
| 31 | 31 | |
| 32 | +from slice_data import SliceData | |
| 33 | + | |
| 32 | 34 | class Viewer(wx.Panel): |
| 33 | 35 | |
| 34 | 36 | def __init__(self, prnt, orientation='AXIAL'): |
| ... | ... | @@ -42,10 +44,10 @@ class Viewer(wx.Panel): |
| 42 | 44 | self.mouse_pressed = 0 |
| 43 | 45 | |
| 44 | 46 | # All renderers and image actors in this viewer |
| 45 | - self.image_windows = [] | |
| 46 | - # The layout from image_window, the first is number of cols, the second | |
| 47 | + self.slice_data_list = [] | |
| 48 | + # The layout from slice_data, the first is number of cols, the second | |
| 47 | 49 | # is the number of rows |
| 48 | - self.layout = (1, 1) | |
| 50 | + self.layout = (2, 2) | |
| 49 | 51 | |
| 50 | 52 | self.__init_gui() |
| 51 | 53 | |
| ... | ... | @@ -96,7 +98,6 @@ class Viewer(wx.Panel): |
| 96 | 98 | self.cam = ren.GetActiveCamera() |
| 97 | 99 | self.ren = ren |
| 98 | 100 | |
| 99 | - | |
| 100 | 101 | def append_mode(self, mode): |
| 101 | 102 | |
| 102 | 103 | # Retrieve currently set modes |
| ... | ... | @@ -161,7 +162,7 @@ class Viewer(wx.Panel): |
| 161 | 162 | cursor = ca.CursorCircle() |
| 162 | 163 | self.cursor = cursor |
| 163 | 164 | |
| 164 | - cursor.set_orientation(self.orientation) | |
| 165 | + cursor.SetOrientation(self.orientation) | |
| 165 | 166 | coordinates = {"SAGITAL": [self.slice_number, 0, 0], |
| 166 | 167 | "CORONAL": [0, self.slice_number, 0], |
| 167 | 168 | "AXIAL": [0, 0, self.slice_number]} |
| ... | ... | @@ -174,7 +175,6 @@ class Viewer(wx.Panel): |
| 174 | 175 | self.interactor.Render() |
| 175 | 176 | self.cursor = cursor |
| 176 | 177 | |
| 177 | - | |
| 178 | 178 | def OnMouseClick(self, obj, evt_vtk): |
| 179 | 179 | self.mouse_pressed = 1 |
| 180 | 180 | |
| ... | ... | @@ -186,13 +186,13 @@ class Viewer(wx.Panel): |
| 186 | 186 | |
| 187 | 187 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
| 188 | 188 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
| 189 | - image_window = self.get_image_window(render) | |
| 189 | + slice_data = self.get_slice_data(render) | |
| 190 | 190 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
| 191 | 191 | |
| 192 | 192 | coord = self.get_coordinate_cursor() |
| 193 | 193 | self.cursor.SetPosition(coord) |
| 194 | 194 | self.cursor.SetEditionPosition( |
| 195 | - self.get_coordinate_cursor_edition(image_window)) | |
| 195 | + self.get_coordinate_cursor_edition(slice_data)) | |
| 196 | 196 | self.__update_cursor_position(coord) |
| 197 | 197 | #render.Render() |
| 198 | 198 | |
| ... | ... | @@ -213,12 +213,12 @@ class Viewer(wx.Panel): |
| 213 | 213 | def OnBrushMove(self, obj, evt_vtk): |
| 214 | 214 | mouse_x, mouse_y = self.interactor.GetEventPosition() |
| 215 | 215 | render = self.interactor.FindPokedRenderer(mouse_x, mouse_y) |
| 216 | - image_window = self.get_image_window(render) | |
| 216 | + slice_data = self.get_slice_data(render) | |
| 217 | 217 | self.pick.Pick(mouse_x, mouse_y, 0, render) |
| 218 | 218 | coord = self.get_coordinate_cursor() |
| 219 | 219 | self.cursor.SetPosition(coord) |
| 220 | 220 | self.cursor.SetEditionPosition( |
| 221 | - self.get_coordinate_cursor_edition(image_window)) | |
| 221 | + self.get_coordinate_cursor_edition(slice_data)) | |
| 222 | 222 | self.__update_cursor_position(coord) |
| 223 | 223 | |
| 224 | 224 | if self._brush_cursor_op == const.BRUSH_ERASE: |
| ... | ... | @@ -249,10 +249,10 @@ class Viewer(wx.Panel): |
| 249 | 249 | ps.Publisher().sendMessage(('Set scroll position', 'AXIAL'), |
| 250 | 250 | coord[2]) |
| 251 | 251 | |
| 252 | - def get_image_window(self, render): | |
| 253 | - for i in self.image_windows: | |
| 254 | - if i[0] is render: | |
| 255 | - return i | |
| 252 | + def get_slice_data(self, render): | |
| 253 | + for slice_data in self.slice_data_list: | |
| 254 | + if slice_data.renderer is render: | |
| 255 | + return slice_data | |
| 256 | 256 | |
| 257 | 257 | def get_coordinate(self): |
| 258 | 258 | # Find position |
| ... | ... | @@ -297,9 +297,10 @@ class Viewer(wx.Panel): |
| 297 | 297 | x, y, z = self.pick.GetPickPosition() |
| 298 | 298 | return x, y, z |
| 299 | 299 | |
| 300 | - def get_coordinate_cursor_edition(self, image_window): | |
| 300 | + def get_coordinate_cursor_edition(self, slice_data): | |
| 301 | 301 | # Find position |
| 302 | - actor, slice_number = image_window[1::] | |
| 302 | + actor = slice_data.actor | |
| 303 | + slice_number = slice_data.number | |
| 303 | 304 | x, y, z = self.pick.GetPickPosition() |
| 304 | 305 | |
| 305 | 306 | # First we fix the position origin, based on vtkActor bounds |
| ... | ... | @@ -369,10 +370,9 @@ class Viewer(wx.Panel): |
| 369 | 370 | for j in xrange(self.layout[1]): |
| 370 | 371 | position = ((i*proportion_x, j * proportion_y, |
| 371 | 372 | (i+1)*proportion_x, (j+1)*proportion_y)) |
| 372 | - ren, actor = self.create_slice_window(image) | |
| 373 | - ren.SetViewport(position) | |
| 374 | - self.image_windows.append([ren, actor, 0]) | |
| 375 | - | |
| 373 | + slice_data = self.create_slice_window(image) | |
| 374 | + slice_data.renderer.SetViewport(position) | |
| 375 | + self.slice_data_list.append(slice_data) | |
| 376 | 376 | |
| 377 | 377 | def SetInput(self, imagedata): |
| 378 | 378 | self.imagedata = imagedata |
| ... | ... | @@ -385,11 +385,11 @@ class Viewer(wx.Panel): |
| 385 | 385 | if slice_.imagedata is None: |
| 386 | 386 | slice_.SetInput(imagedata) |
| 387 | 387 | |
| 388 | - | |
| 389 | 388 | #actor = vtk.vtkImageActor() |
| 390 | 389 | #actor.SetInput(slice_.GetOutput()) |
| 391 | 390 | self.load_renderers(slice_.GetOutput()) |
| 392 | - ren, actor = self.image_windows[0][:2] | |
| 391 | + ren = self.slice_data_list[0].renderer | |
| 392 | + actor = self.slice_data_list[0].actor | |
| 393 | 393 | actor_bound = actor.GetBounds() |
| 394 | 394 | self.actor = actor |
| 395 | 395 | self.ren = ren |
| ... | ... | @@ -411,11 +411,14 @@ class Viewer(wx.Panel): |
| 411 | 411 | |
| 412 | 412 | #ren.AddActor(actor) |
| 413 | 413 | #ren.AddActor(text_actor) |
| 414 | - for ren, actor, n in self.image_windows: | |
| 415 | - self.__update_camera(ren, actor, n) | |
| 414 | + for slice_data in self.slice_data_list: | |
| 415 | + self.__update_camera(slice_data) | |
| 416 | 416 | |
| 417 | + number_of_slices = self.layout[0] * self.layout[1] | |
| 417 | 418 | max_slice_number = actor.GetSliceNumberMax() / \ |
| 418 | - (self.layout[0] * self.layout[1]) | |
| 419 | + number_of_slices | |
| 420 | + if actor.GetSliceNumberMax() % number_of_slices: | |
| 421 | + max_slice_number += 1 | |
| 419 | 422 | self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, |
| 420 | 423 | max_slice_number) |
| 421 | 424 | self.set_scroll_position(0) |
| ... | ... | @@ -459,23 +462,26 @@ class Viewer(wx.Panel): |
| 459 | 462 | |
| 460 | 463 | def set_orientation(self, orientation): |
| 461 | 464 | self.orientation = orientation |
| 462 | - for ren, actor, n in self.image_windows: | |
| 463 | - self.__update_camera(ren, actor, n) | |
| 465 | + for slice_data in self.slice_data_list: | |
| 466 | + self.__update_camera(slice_data) | |
| 464 | 467 | |
| 465 | - def create_slice_window(self, image): | |
| 466 | - render = vtk.vtkRenderer() | |
| 467 | - self.interactor.GetRenderWindow().AddRenderer(render) | |
| 468 | + def create_slice_window(self, imagedata): | |
| 469 | + renderer = vtk.vtkRenderer() | |
| 470 | + self.interactor.GetRenderWindow().AddRenderer(renderer) | |
| 468 | 471 | actor = vtk.vtkImageActor() |
| 469 | - actor.SetInput(image) | |
| 470 | - render.AddActor(actor) | |
| 471 | - return render, actor | |
| 472 | - | |
| 473 | - def __update_camera(self, ren, actor, pos): | |
| 472 | + actor.SetInput(imagedata) | |
| 473 | + renderer.AddActor(actor) | |
| 474 | + slice_data = SliceData() | |
| 475 | + slice_data.renderer = renderer | |
| 476 | + slice_data.actor = actor | |
| 477 | + return slice_data | |
| 478 | + | |
| 479 | + def __update_camera(self, slice_data): | |
| 474 | 480 | orientation = self.orientation |
| 475 | 481 | proj = project.Project() |
| 476 | 482 | orig_orien = proj.original_orientation |
| 477 | 483 | |
| 478 | - cam = ren.GetActiveCamera() | |
| 484 | + cam = slice_data.renderer.GetActiveCamera() | |
| 479 | 485 | cam.SetFocalPoint(0, 0, 0) |
| 480 | 486 | cam.SetViewUp(const.SLICE_POSITION[orig_orien][0][self.orientation]) |
| 481 | 487 | cam.SetPosition(const.SLICE_POSITION[orig_orien][1][self.orientation]) |
| ... | ... | @@ -483,14 +489,16 @@ class Viewer(wx.Panel): |
| 483 | 489 | cam.OrthogonalizeViewUp() |
| 484 | 490 | cam.ParallelProjectionOn() |
| 485 | 491 | |
| 486 | - self.__update_display_extent(actor, ren, pos) | |
| 492 | + self.__update_display_extent(slice_data) | |
| 487 | 493 | |
| 488 | - ren.ResetCamera() | |
| 489 | - ren.Render() | |
| 494 | + slice_data.renderer.ResetCamera() | |
| 495 | + slice_data.renderer.Render() | |
| 490 | 496 | |
| 491 | - def __update_display_extent(self, actor, render, pos): | |
| 497 | + def __update_display_extent(self, slice_data): | |
| 492 | 498 | e = self.imagedata.GetWholeExtent() |
| 493 | 499 | proj = project.Project() |
| 500 | + | |
| 501 | + pos = slice_data.number | |
| 494 | 502 | |
| 495 | 503 | x = (pos, pos, e[2], e[3], e[4], e[5]) |
| 496 | 504 | y = (e[0], e[1], pos, pos, e[4], e[5]) |
| ... | ... | @@ -503,9 +511,8 @@ class Viewer(wx.Panel): |
| 503 | 511 | elif(proj.original_orientation == const.CORONAL): |
| 504 | 512 | new_extent = {"SAGITAL": x,"CORONAL": z,"AXIAL": y} |
| 505 | 513 | |
| 506 | - actor.SetDisplayExtent(new_extent[self.orientation]) | |
| 507 | - render.ResetCameraClippingRange() | |
| 508 | - #render.Render() | |
| 514 | + slice_data.actor.SetDisplayExtent(new_extent[self.orientation]) | |
| 515 | + slice_data.renderer.ResetCameraClippingRange() | |
| 509 | 516 | |
| 510 | 517 | def UpdateRender(self, evt): |
| 511 | 518 | self.interactor.Render() |
| ... | ... | @@ -542,13 +549,14 @@ class Viewer(wx.Panel): |
| 542 | 549 | def set_slice_number(self, index): |
| 543 | 550 | self.text_actor.SetInput(str(index)) |
| 544 | 551 | self.slice_number = index |
| 545 | - for n, window in enumerate(self.image_windows): | |
| 546 | - ren, actor = window[:2] | |
| 552 | + for n, slice_data in enumerate(self.slice_data_list): | |
| 553 | + ren = slice_data.renderer | |
| 554 | + actor = slice_data.actor | |
| 547 | 555 | pos = self.layout[0] * self.layout[1] * index + n |
| 548 | - print pos | |
| 549 | - self.__update_display_extent(actor, ren, pos) | |
| 550 | - self.image_windows[n][2] = pos | |
| 551 | ||
| 556 | + max = actor.GetSliceNumberMax() | |
| 557 | + if pos < max: | |
| 558 | + slice_data.number = pos | |
| 559 | + self.__update_display_extent(slice_data) | |
| 552 | 560 | |
| 553 | 561 | position = {"SAGITAL": {0: self.slice_number}, |
| 554 | 562 | "CORONAL": {1: self.slice_number}, | ... | ... |