Commit 2f2deade4a1ff3916d6b1cdac57aea049eb5268f
1 parent
21bf3bc6
Exists in
master
and in
67 other branches
ENH: Adding new masks to notebook list, not showing in slices.
Showing
3 changed files
with
43 additions
and
32 deletions
Show diff stats
invesalius/data/mask.py
| @@ -20,7 +20,9 @@ | @@ -20,7 +20,9 @@ | ||
| 20 | import os | 20 | import os |
| 21 | import plistlib | 21 | import plistlib |
| 22 | import random | 22 | import random |
| 23 | +import tempfile | ||
| 23 | 24 | ||
| 25 | +import numpy | ||
| 24 | import vtk | 26 | import vtk |
| 25 | 27 | ||
| 26 | import constants as const | 28 | import constants as const |
| @@ -81,3 +83,7 @@ class Mask(): | @@ -81,3 +83,7 @@ class Mask(): | ||
| 81 | 83 | ||
| 82 | def _set_class_index(self, index): | 84 | def _set_class_index(self, index): |
| 83 | Mask.general_index = index | 85 | Mask.general_index = index |
| 86 | + | ||
| 87 | + def create_mask(self, shape): | ||
| 88 | + self.temp_file = tempfile.mktemp() | ||
| 89 | + self.matrix = numpy.memmap(self.temp_file, mode='w+', dtype='uint8', shape=shape) |
invesalius/data/slice_.py
| @@ -261,9 +261,9 @@ class Slice(object): | @@ -261,9 +261,9 @@ class Slice(object): | ||
| 261 | proj.mask_dict[index].colour = colour | 261 | proj.mask_dict[index].colour = colour |
| 262 | 262 | ||
| 263 | (r,g,b) = colour | 263 | (r,g,b) = colour |
| 264 | - scalar_range = int(self.imagedata.GetScalarRange()[1]) | ||
| 265 | - self.lut_mask.SetTableValue(0, 0, 0, 0, 0.0) | ||
| 266 | - self.lut_mask.SetTableValue(scalar_range - 1, r, g, b, 1.0) | 264 | + #scalar_range = int(self.imagedata.GetScalarRange()[1]) |
| 265 | + #self.lut_mask.SetTableValue(0, 0, 0, 0, 0.0) | ||
| 266 | + #self.lut_mask.SetTableValue(scalar_range - 1, r, g, b, 1.0) | ||
| 267 | 267 | ||
| 268 | colour_wx = [r*255, g*255, b*255] | 268 | colour_wx = [r*255, g*255, b*255] |
| 269 | ps.Publisher().sendMessage('Change mask colour in notebook', | 269 | ps.Publisher().sendMessage('Change mask colour in notebook', |
| @@ -536,6 +536,11 @@ class Slice(object): | @@ -536,6 +536,11 @@ class Slice(object): | ||
| 536 | opacity=None, threshold_range=None, | 536 | opacity=None, threshold_range=None, |
| 537 | edition_threshold_range = None, | 537 | edition_threshold_range = None, |
| 538 | edited_points=None): | 538 | edited_points=None): |
| 539 | + | ||
| 540 | + # TODO: mask system to new system. | ||
| 541 | + future_mask = Mask() | ||
| 542 | + future_mask.create_mask(self.matrix.shape) | ||
| 543 | + | ||
| 539 | 544 | ||
| 540 | future_mask = Mask() | 545 | future_mask = Mask() |
| 541 | if colour: | 546 | if colour: |
| @@ -547,40 +552,40 @@ class Slice(object): | @@ -547,40 +552,40 @@ class Slice(object): | ||
| 547 | if edited_points: | 552 | if edited_points: |
| 548 | future_mask.edited_points = edited_points | 553 | future_mask.edited_points = edited_points |
| 549 | 554 | ||
| 550 | - # this is not the first mask, so we will import data from old imagedata | ||
| 551 | - if imagedata is None: | ||
| 552 | - old_mask = self.current_mask | ||
| 553 | - imagedata = old_mask.imagedata | ||
| 554 | - future_mask.threshold_range = old_mask.threshold_range | ||
| 555 | - | ||
| 556 | - if threshold_range: | ||
| 557 | - future_mask.threshold_range = threshold_range | ||
| 558 | - future_mask.imagedata = self.__create_mask_threshold(self.imagedata, | ||
| 559 | - threshold_range) | ||
| 560 | - else: | ||
| 561 | - future_mask.imagedata = vtk.vtkImageData() | ||
| 562 | - future_mask.imagedata.DeepCopy(imagedata) | ||
| 563 | - future_mask.imagedata.Update() | ||
| 564 | - | ||
| 565 | - | ||
| 566 | - # when this is not the first instance, user will have defined a name | ||
| 567 | - if name is not None: | ||
| 568 | - future_mask.name = name | ||
| 569 | - if future_mask.is_shown: | ||
| 570 | - self.blend_filter.SetOpacity(1, future_mask.opacity) | ||
| 571 | - else: | ||
| 572 | - self.blend_filter.SetOpacity(1, 0) | ||
| 573 | - self.blend_filter.Update() | 555 | + ## this is not the first mask, so we will import data from old imagedata |
| 556 | + #if imagedata is None: | ||
| 557 | + #old_mask = self.current_mask | ||
| 558 | + #imagedata = old_mask.imagedata | ||
| 559 | + #future_mask.threshold_range = old_mask.threshold_range | ||
| 560 | + | ||
| 561 | + #if threshold_range: | ||
| 562 | + #future_mask.threshold_range = threshold_range | ||
| 563 | + #future_mask.imagedata = self.__create_mask_threshold(self.imagedata, | ||
| 564 | + #threshold_range) | ||
| 565 | + #else: | ||
| 566 | + #future_mask.imagedata = vtk.vtkImageData() | ||
| 567 | + #future_mask.imagedata.DeepCopy(imagedata) | ||
| 568 | + #future_mask.imagedata.Update() | ||
| 569 | + | ||
| 570 | + | ||
| 571 | + ## when this is not the first instance, user will have defined a name | ||
| 572 | + #if name is not None: | ||
| 573 | + #future_mask.name = name | ||
| 574 | + #if future_mask.is_shown: | ||
| 575 | + #self.blend_filter.SetOpacity(1, future_mask.opacity) | ||
| 576 | + #else: | ||
| 577 | + #self.blend_filter.SetOpacity(1, 0) | ||
| 578 | + #self.blend_filter.Update() | ||
| 574 | 579 | ||
| 575 | # insert new mask into project and retrieve its index | 580 | # insert new mask into project and retrieve its index |
| 576 | proj = Project() | 581 | proj = Project() |
| 577 | index = proj.AddMask(future_mask) | 582 | index = proj.AddMask(future_mask) |
| 578 | future_mask.index = index | 583 | future_mask.index = index |
| 579 | - if threshold_range: | ||
| 580 | - self.SetMaskThreshold(index, threshold_range) | ||
| 581 | - future_mask.edited_points = {} | 584 | + #if threshold_range: |
| 585 | + #self.SetMaskThreshold(index, threshold_range) | ||
| 586 | + #future_mask.edited_points = {} | ||
| 582 | 587 | ||
| 583 | - # update gui related to mask | 588 | + ## update gui related to mask |
| 584 | ps.Publisher().sendMessage('Add mask', | 589 | ps.Publisher().sendMessage('Add mask', |
| 585 | (future_mask.index, | 590 | (future_mask.index, |
| 586 | future_mask.name, | 591 | future_mask.name, |
invesalius/gui/data_notebook.py
| @@ -839,7 +839,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | @@ -839,7 +839,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin): | ||
| 839 | index = pubsub_evt.data[0] | 839 | index = pubsub_evt.data[0] |
| 840 | name = pubsub_evt.data[1] | 840 | name = pubsub_evt.data[1] |
| 841 | colour = pubsub_evt.data[2] | 841 | colour = pubsub_evt.data[2] |
| 842 | - volume = "%d"%(int(pubsub_evt.data[3])) | 842 | + volume = "%.3f"%pubsub_evt.data[3] |
| 843 | transparency = "%d%%"%(int(100*pubsub_evt.data[4])) | 843 | transparency = "%d%%"%(int(100*pubsub_evt.data[4])) |
| 844 | 844 | ||
| 845 | if index not in self.surface_list_index: | 845 | if index not in self.surface_list_index: |