Commit 6bdbe8bf338ad87333cce304ac91fa5ea7357f6d
1 parent
8bdc2a60
Exists in
master
and in
56 other branches
Added mida contour to invesalius (only to test yet)
Showing
2 changed files
with
57 additions
and
9 deletions
Show diff stats
invesalius/data/slice_.py
| ... | ... | @@ -33,6 +33,7 @@ import utils |
| 33 | 33 | |
| 34 | 34 | from mask import Mask |
| 35 | 35 | from project import Project |
| 36 | +from data import mips | |
| 36 | 37 | |
| 37 | 38 | OTHER=0 |
| 38 | 39 | PLIST=1 |
| ... | ... | @@ -83,6 +84,9 @@ class Slice(object): |
| 83 | 84 | self.blend_filter = None |
| 84 | 85 | self.histogram = None |
| 85 | 86 | self._matrix = None |
| 87 | + | |
| 88 | + self._type_projection = 'MIDA CONTOUR' | |
| 89 | + | |
| 86 | 90 | self.spacing = (1.0, 1.0, 1.0) |
| 87 | 91 | |
| 88 | 92 | self.number_of_colours = 256 |
| ... | ... | @@ -421,12 +425,14 @@ class Slice(object): |
| 421 | 425 | self.buffer_slices[orientation].discard_vtk_mask() |
| 422 | 426 | |
| 423 | 427 | |
| 424 | - def GetSlices(self, orientation, slice_number): | |
| 425 | - if self.buffer_slices[orientation].index == slice_number: | |
| 428 | + def GetSlices(self, orientation, slice_number, number_slices): | |
| 429 | + if self.buffer_slices[orientation].index == slice_number and \ | |
| 430 | + self._type_projection == 'NORMAL': | |
| 426 | 431 | if self.buffer_slices[orientation].vtk_image: |
| 427 | 432 | image = self.buffer_slices[orientation].vtk_image |
| 428 | 433 | else: |
| 429 | - n_image = self.get_image_slice(orientation, slice_number) | |
| 434 | + n_image = self.get_image_slice(orientation, slice_number, | |
| 435 | + number_slices) | |
| 430 | 436 | image = converters.to_vtk(n_image, self.spacing, slice_number, orientation) |
| 431 | 437 | ww_wl_image = self.do_ww_wl(image) |
| 432 | 438 | image = self.do_colour_image(ww_wl_image) |
| ... | ... | @@ -446,7 +452,8 @@ class Slice(object): |
| 446 | 452 | final_image = image |
| 447 | 453 | self.buffer_slices[orientation].vtk_image = image |
| 448 | 454 | else: |
| 449 | - n_image = self.get_image_slice(orientation, slice_number) | |
| 455 | + n_image = self.get_image_slice(orientation, slice_number, | |
| 456 | + number_slices) | |
| 450 | 457 | image = converters.to_vtk(n_image, self.spacing, slice_number, orientation) |
| 451 | 458 | ww_wl_image = self.do_ww_wl(image) |
| 452 | 459 | image = self.do_colour_image(ww_wl_image) |
| ... | ... | @@ -469,17 +476,44 @@ class Slice(object): |
| 469 | 476 | |
| 470 | 477 | return final_image |
| 471 | 478 | |
| 472 | - def get_image_slice(self, orientation, slice_number): | |
| 479 | + def get_image_slice(self, orientation, slice_number, number_slices=1): | |
| 473 | 480 | if self.buffer_slices[orientation].index == slice_number \ |
| 474 | 481 | and self.buffer_slices[orientation].image is not None: |
| 475 | 482 | n_image = self.buffer_slices[orientation].image |
| 476 | 483 | else: |
| 477 | 484 | if orientation == 'AXIAL': |
| 478 | - n_image = numpy.array(self.matrix[slice_number]) | |
| 485 | + if self._type_projection == 'MIDA CONTOUR': | |
| 486 | + tmp_array = numpy.array(self.matrix[slice_number: | |
| 487 | + slice_number + number_slices]) | |
| 488 | + n_image = numpy.empty(shape=(tmp_array.shape[1], | |
| 489 | + tmp_array.shape[2]), | |
| 490 | + dtype=tmp_array.dtype) | |
| 491 | + mips.fast_countour_mip(tmp_array, 0.2, 0, self.window_level, | |
| 492 | + self.window_level, 2, n_image) | |
| 493 | + else: | |
| 494 | + n_image = numpy.array(self.matrix[slice_number]) | |
| 479 | 495 | elif orientation == 'CORONAL': |
| 480 | - n_image = numpy.array(self.matrix[..., slice_number, ...]) | |
| 496 | + if self._type_projection == 'MIDA CONTOUR': | |
| 497 | + tmp_array = numpy.array(self.matrix[..., slice_number: | |
| 498 | + slice_number + number_slices, ...]) | |
| 499 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 500 | + tmp_array.shape[2]), | |
| 501 | + dtype=tmp_array.dtype) | |
| 502 | + mips.fast_countour_mip(tmp_array, 0.2, 1, self.window_level, | |
| 503 | + self.window_level, 2, n_image) | |
| 504 | + else: | |
| 505 | + n_image = numpy.array(self.matrix[..., slice_number, ...]) | |
| 481 | 506 | elif orientation == 'SAGITAL': |
| 482 | - n_image = numpy.array(self.matrix[..., ..., slice_number]) | |
| 507 | + if self._type_projection == 'MIDA CONTOUR': | |
| 508 | + tmp_array = numpy.array(self.matrix[..., ..., | |
| 509 | + slice_number: slice_number + number_slices]) | |
| 510 | + n_image = numpy.empty(shape=(tmp_array.shape[0], | |
| 511 | + tmp_array.shape[1]), | |
| 512 | + dtype=tmp_array.dtype) | |
| 513 | + mips.fast_countour_mip(tmp_array, 0.2, 2, self.window_level, | |
| 514 | + self.window_level, 2, n_image) | |
| 515 | + else: | |
| 516 | + n_image = numpy.array(self.matrix[..., ..., slice_number]) | |
| 483 | 517 | return n_image |
| 484 | 518 | |
| 485 | 519 | def get_mask_slice(self, orientation, slice_number): | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -63,6 +63,8 @@ class Viewer(wx.Panel): |
| 63 | 63 | #self.modes = []#['DEFAULT'] |
| 64 | 64 | self.left_pressed = 0 |
| 65 | 65 | self.right_pressed = 0 |
| 66 | + | |
| 67 | + self.number_slices = 10 | |
| 66 | 68 | |
| 67 | 69 | self.spined_image = False #Use to control to spin |
| 68 | 70 | self.paned_image = False |
| ... | ... | @@ -1030,6 +1032,17 @@ class Viewer(wx.Panel): |
| 1030 | 1032 | elif (evt.GetKeyCode() == wx.WXK_DOWN and pos < max): |
| 1031 | 1033 | self.OnScrollBackward() |
| 1032 | 1034 | self.OnScrollBar() |
| 1035 | + | |
| 1036 | + elif (evt.GetKeyCode() == wx.WXK_NUMPAD_ADD): | |
| 1037 | + self.number_slices += 1 | |
| 1038 | + print "ADDing", self.number_slices | |
| 1039 | + self.OnScrollBar() | |
| 1040 | + | |
| 1041 | + elif (evt.GetKeyCode() == wx.WXK_NUMPAD_SUBTRACT): | |
| 1042 | + if self.number_slices > 1: | |
| 1043 | + self.number_slices -= 1 | |
| 1044 | + print "Subtracting", self.number_slices | |
| 1045 | + self.OnScrollBar() | |
| 1033 | 1046 | |
| 1034 | 1047 | self.UpdateSlice3D(pos) |
| 1035 | 1048 | self.interactor.Render() |
| ... | ... | @@ -1068,7 +1081,8 @@ class Viewer(wx.Panel): |
| 1068 | 1081 | evt.Skip() |
| 1069 | 1082 | |
| 1070 | 1083 | def set_slice_number(self, index): |
| 1071 | - image = self.slice_.GetSlices(self.orientation, index) | |
| 1084 | + image = self.slice_.GetSlices(self.orientation, index, | |
| 1085 | + self.number_slices) | |
| 1072 | 1086 | self.slice_data.actor.SetInput(image) |
| 1073 | 1087 | for actor in self.actors_by_slice_number.get(self.slice_data.number, []): |
| 1074 | 1088 | self.slice_data.renderer.RemoveActor(actor) | ... | ... |