diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 65e3f6d..f476e57 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -34,6 +34,11 @@ import utils from mask import Mask from project import Project +OTHER=0 +PLIST=1 +WIDGET=2 + + class SliceBuffer(object): """ This class is used as buffer that mantains the vtkImageData and numpy array @@ -66,9 +71,6 @@ class SliceBuffer(object): self.vtk_mask = None - - - class Slice(object): __metaclass__= utils.Singleton # Only one slice will be initialized per time (despite several viewers @@ -94,8 +96,7 @@ class Slice(object): self.num_gradient = 0 self.interaction_style = st.StyleStateManager() - self.from_plist = False - + self.from_ = OTHER self.__bind_events() def __bind_events(self): @@ -130,6 +131,9 @@ class Slice(object): Publisher.subscribe(self.UpdateColourTableBackgroundPlist,\ 'Change colour table from background image from plist') + Publisher.subscribe(self.UpdateColourTableBackgroundWidget,\ + 'Change colour table from background image from widget') + Publisher.subscribe(self.InputImageWidget, 'Input Image in the widget') Publisher.subscribe(self.OnExportMask,'Export mask to file') @@ -707,7 +711,7 @@ class Slice(object): def UpdateColourTableBackground(self, pubsub_evt): values = pubsub_evt.data - self.from_plist = False + self.from_= OTHER self.number_of_colours= values[0] self.saturation_range = values[1] self.hue_range = values[2] @@ -718,7 +722,14 @@ class Slice(object): def UpdateColourTableBackgroundPlist(self, pubsub_evt): self.values = pubsub_evt.data - self.from_plist = True + self.from_= PLIST + for buffer_ in self.buffer_slices.values(): + buffer_.discard_vtk_image() + Publisher.sendMessage('Reload actual slice') + + def UpdateColourTableBackgroundWidget(self, pubsub_evt): + self.values = pubsub_evt.data + self.from_= WIDGET for buffer_ in self.buffer_slices.values(): buffer_.discard_vtk_image() Publisher.sendMessage('Reload actual slice') @@ -829,7 +840,7 @@ class Slice(object): Publisher.sendMessage('Update slice viewer') def do_ww_wl(self, image): - if self.from_plist: + if self.from_ == PLIST: lut = vtk.vtkWindowLevelLookupTable() lut.SetWindow(self.window_width) lut.SetLevel(self.window_level) @@ -847,6 +858,20 @@ class Slice(object): colorer.SetLookupTable(lut) colorer.SetOutputFormatToRGB() colorer.Update() + elif self.from_ == WIDGET: + lut = vtk.vtkColorTransferFunction() + + for n in self.values: + r, g, b = n.colour + lut.AddRGBPoint(n.value, r/255.0, g/255.0, b/255.0) + + lut.Build() + + colorer = vtk.vtkImageMapToColors() + colorer.SetLookupTable(lut) + colorer.SetInput(image) + colorer.SetOutputFormatToRGB() + colorer.Update() else: colorer = vtk.vtkImageMapToWindowLevelColors() colorer.SetInput(image) @@ -869,7 +894,7 @@ class Slice(object): return m.astype('uint8') def do_colour_image(self, imagedata): - if self.from_plist: + if self.from_ in (PLIST, WIDGET): return imagedata else: # map scalar values into colors diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 24c5ea5..c970dea 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -34,6 +34,9 @@ import project as proj import session as ses import utils +from gui.widgets import clut_imagedata + +import numpy as np class MaskEvent(wx.PyCommandEvent): def __init__(self , evtType, id, mask_index): @@ -1274,9 +1277,32 @@ class SurfaceMethodPanel(wx.Panel): self.method_sizer.Layout() +class ClutImagedataDialog(wx.Dialog): + def __init__(self): + pre = wx.PreDialog() + pre.Create(None, -1, style=wx.DEFAULT_DIALOG_STYLE) + self.PostCreate(pre) + self._init_gui() + self._bind_events_wx() - + def _init_gui(self): + self.clut_widget = clut_imagedata.CLUTImageDataWidget(self, -1, + np.random.randint(0, + 1000, + (1000,)), + -1000, 1000, + 230, 255) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.clut_widget, 1, wx.EXPAND) + + self.SetSizer(sizer) + self.Fit() + def _bind_events_wx(self): + self.clut_widget.Bind(clut_imagedata.EVT_CLUT_POINT_MOVE, self.OnClutChange) + def OnClutChange(self, evt): + Publisher.sendMessage('Change colour table from background image from widget', + evt.GetNodes()) diff --git a/invesalius/gui/widgets/slice_menu.py b/invesalius/gui/widgets/slice_menu.py index 7658b21..9b25d5d 100644 --- a/invesalius/gui/widgets/slice_menu.py +++ b/invesalius/gui/widgets/slice_menu.py @@ -26,6 +26,8 @@ from wx.lib.pubsub import pub as Publisher import constants as const import presets +from gui.dialogs import ClutImagedataDialog + class SliceMenu(wx.Menu): def __init__(self): wx.Menu.__init__(self) @@ -93,6 +95,11 @@ class SliceMenu(wx.Menu): color_item = wx.MenuItem(submenu_wl, new_id, name, kind=wx.ITEM_RADIO) submenu_pseudo_colours.AppendItem(color_item) self.ID_TO_TOOL_ITEM[new_id] = color_item + + new_id = wx.NewId() + color_item = wx.MenuItem(submenu_wl, new_id, _('Custom'), kind=wx.ITEM_RADIO) + submenu_pseudo_colours.AppendItem(color_item) + self.ID_TO_TOOL_ITEM[new_id] = color_item flag_tiling = False #------------ Sub menu of the image tiling --------------- @@ -180,5 +187,10 @@ class SliceMenu(wx.Menu): Publisher.sendMessage('Set slice viewer layout', values) Publisher.sendMessage('Update slice viewer') + elif key == _('Custom'): + cdialog = ClutImagedataDialog() + cdialog.Show() + + evt.Skip() -- libgit2 0.21.2