Commit 2f2deade4a1ff3916d6b1cdac57aea049eb5268f

Authored by tfmoraes
1 parent 21bf3bc6

ENH: Adding new masks to notebook list, not showing in slices.

invesalius/data/mask.py
... ... @@ -20,7 +20,9 @@
20 20 import os
21 21 import plistlib
22 22 import random
  23 +import tempfile
23 24  
  25 +import numpy
24 26 import vtk
25 27  
26 28 import constants as const
... ... @@ -81,3 +83,7 @@ class Mask():
81 83  
82 84 def _set_class_index(self, index):
83 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 261 proj.mask_dict[index].colour = colour
262 262  
263 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 268 colour_wx = [r*255, g*255, b*255]
269 269 ps.Publisher().sendMessage('Change mask colour in notebook',
... ... @@ -536,6 +536,11 @@ class Slice(object):
536 536 opacity=None, threshold_range=None,
537 537 edition_threshold_range = None,
538 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 545 future_mask = Mask()
541 546 if colour:
... ... @@ -547,40 +552,40 @@ class Slice(object):
547 552 if edited_points:
548 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 580 # insert new mask into project and retrieve its index
576 581 proj = Project()
577 582 index = proj.AddMask(future_mask)
578 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 589 ps.Publisher().sendMessage('Add mask',
585 590 (future_mask.index,
586 591 future_mask.name,
... ...
invesalius/gui/data_notebook.py
... ... @@ -839,7 +839,7 @@ class SurfacesListCtrlPanel(wx.ListCtrl, listmix.TextEditMixin):
839 839 index = pubsub_evt.data[0]
840 840 name = pubsub_evt.data[1]
841 841 colour = pubsub_evt.data[2]
842   - volume = "%d"%(int(pubsub_evt.data[3]))
  842 + volume = "%.3f"%pubsub_evt.data[3]
843 843 transparency = "%d%%"%(int(100*pubsub_evt.data[4]))
844 844  
845 845 if index not in self.surface_list_index:
... ...