Commit 3b7ebb7afb0f726dd9ef240e5396de70b6c40512

Authored by Thiago Franco de Moraes
1 parent 894282fe
Exists in measure

Showing the histogram at the clut widget

invesalius/data/slice_.py
... ... @@ -81,7 +81,8 @@ class Slice(object):
81 81 self.imagedata = None
82 82 self.current_mask = None
83 83 self.blend_filter = None
84   - self.matrix = None
  84 + self.histogram = None
  85 + self._matrix = None
85 86 self.spacing = (1.0, 1.0, 1.0)
86 87  
87 88 self.number_of_colours = 256
... ... @@ -99,6 +100,17 @@ class Slice(object):
99 100 self.from_ = OTHER
100 101 self.__bind_events()
101 102  
  103 + @property
  104 + def matrix(self):
  105 + return self._matrix
  106 +
  107 + @matrix.setter
  108 + def matrix(self, value):
  109 + self._matrix = value
  110 + i, e = value.min(), value.max()
  111 + r = e - i
  112 + self.histogram = numpy.histogram(self._matrix, r, (i, e))[0]
  113 +
102 114 def __bind_events(self):
103 115 # General slice control
104 116 Publisher.subscribe(self.CreateSurfaceFromIndex,
... ...
invesalius/gui/dialogs.py
... ... @@ -1278,21 +1278,26 @@ class SurfaceMethodPanel(wx.Panel):
1278 1278  
1279 1279  
1280 1280 class ClutImagedataDialog(wx.Dialog):
1281   - def __init__(self):
  1281 + def __init__(self, histogram, init, end, wl, ww):
1282 1282 pre = wx.PreDialog()
1283 1283 pre.Create(None, -1, style=wx.DEFAULT_DIALOG_STYLE)
1284 1284 self.PostCreate(pre)
1285 1285  
  1286 + self.histogram = histogram
  1287 + self.init = init
  1288 + self.end = end
  1289 + self.wl = wl
  1290 + self.ww = ww
  1291 +
1286 1292 self._init_gui()
1287 1293 self._bind_events_wx()
1288 1294  
1289 1295 def _init_gui(self):
1290 1296 self.clut_widget = clut_imagedata.CLUTImageDataWidget(self, -1,
1291   - np.random.randint(0,
1292   - 1000,
1293   - (1000,)),
1294   - -1000, 1000,
1295   - 230, 255)
  1297 + self.histogram,
  1298 + self.init,
  1299 + self.end,
  1300 + self.wl, self.ww)
1296 1301 sizer = wx.BoxSizer(wx.VERTICAL)
1297 1302 sizer.Add(self.clut_widget, 1, wx.EXPAND)
1298 1303  
... ...
invesalius/gui/widgets/slice_menu.py
... ... @@ -23,7 +23,9 @@ import sys
23 23  
24 24 import wx
25 25 from wx.lib.pubsub import pub as Publisher
  26 +
26 27 import constants as const
  28 +import data.slice_ as sl
27 29 import presets
28 30  
29 31 from gui.dialogs import ClutImagedataDialog
... ... @@ -188,7 +190,14 @@ class SliceMenu(wx.Menu):
188 190 Publisher.sendMessage('Update slice viewer')
189 191  
190 192 elif key == _('Custom'):
191   - cdialog = ClutImagedataDialog()
  193 + slc = sl.Slice()
  194 + histogram = slc.histogram
  195 + init = slc.matrix.min()
  196 + end = slc.matrix.max()
  197 + wl = slc.window_level
  198 + ww = slc.window_width
  199 +
  200 + cdialog = ClutImagedataDialog(histogram, init, end, wl, ww)
192 201 cdialog.Show()
193 202  
194 203  
... ...