Commit c68dfbfb620a66c880c011d702f871c954d2ef9a
1 parent
b3f71dbc
Exists in
master
and in
68 other branches
ADD: Poup-up Menu with Window and Level
Showing
2 changed files
with
74 additions
and
16 deletions
Show diff stats
invesalius/data/slice_.py
| @@ -341,6 +341,7 @@ class Slice(object): | @@ -341,6 +341,7 @@ class Slice(object): | ||
| 341 | self.cross = cross | 341 | self.cross = cross |
| 342 | 342 | ||
| 343 | self.window_level = vtk.vtkImageMapToWindowLevelColors() | 343 | self.window_level = vtk.vtkImageMapToWindowLevelColors() |
| 344 | + self.window_level.SetInput(self.imagedata) | ||
| 344 | #cast = vtk.vtkImageCast() | 345 | #cast = vtk.vtkImageCast() |
| 345 | #cast.SetInput(cross.GetOutput()) | 346 | #cast.SetInput(cross.GetOutput()) |
| 346 | #cast.GetOutput().SetUpdateExtentToWholeExtent() | 347 | #cast.GetOutput().SetUpdateExtentToWholeExtent() |
| @@ -396,15 +397,19 @@ class Slice(object): | @@ -396,15 +397,19 @@ class Slice(object): | ||
| 396 | def UpdateWindowLevelBackground(self, pubsub_evt): | 397 | def UpdateWindowLevelBackground(self, pubsub_evt): |
| 397 | window, level = pubsub_evt.data | 398 | window, level = pubsub_evt.data |
| 398 | window_level = self.window_level | 399 | window_level = self.window_level |
| 399 | - window_level.SetInput(self.imagedata) | ||
| 400 | - window_level.SetWindow(window) | ||
| 401 | - window_level.SetLevel(level) | ||
| 402 | - window_level.SetOutputFormatToLuminance() | ||
| 403 | - window_level.Update() | ||
| 404 | - | ||
| 405 | - thresh_min, thresh_max = window_level.GetOutput().GetScalarRange() | ||
| 406 | - self.lut_bg.SetTableRange(thresh_min, thresh_max) | ||
| 407 | - self.img_colours_bg.SetInput(window_level.GetOutput()) | 400 | + |
| 401 | + if not((window == window_level.GetWindow()) and\ | ||
| 402 | + (level == window_level.GetLevel())): | ||
| 403 | + | ||
| 404 | + window_level.SetWindow(window) | ||
| 405 | + window_level.SetLevel(level) | ||
| 406 | + window_level.SetOutputFormatToLuminance() | ||
| 407 | + window_level.Update() | ||
| 408 | + | ||
| 409 | + thresh_min, thresh_max = window_level.GetOutput().GetScalarRange() | ||
| 410 | + self.lut_bg.SetTableRange(thresh_min, thresh_max) | ||
| 411 | + self.img_colours_bg.SetInput(window_level.GetOutput()) | ||
| 412 | + | ||
| 408 | 413 | ||
| 409 | def CreateMask(self, imagedata=None, name=None): | 414 | def CreateMask(self, imagedata=None, name=None): |
| 410 | 415 |
invesalius/data/viewer_slice.py
| @@ -33,6 +33,8 @@ import data.vtk_utils as vtku | @@ -33,6 +33,8 @@ import data.vtk_utils as vtku | ||
| 33 | import project | 33 | import project |
| 34 | from slice_data import SliceData | 34 | from slice_data import SliceData |
| 35 | 35 | ||
| 36 | +ID_TO_TOOL_ITEM = {} | ||
| 37 | + | ||
| 36 | class Viewer(wx.Panel): | 38 | class Viewer(wx.Panel): |
| 37 | 39 | ||
| 38 | def __init__(self, prnt, orientation='AXIAL'): | 40 | def __init__(self, prnt, orientation='AXIAL'): |
| @@ -68,6 +70,7 @@ class Viewer(wx.Panel): | @@ -68,6 +70,7 @@ class Viewer(wx.Panel): | ||
| 68 | 70 | ||
| 69 | self.__bind_events() | 71 | self.__bind_events() |
| 70 | self.__bind_events_wx() | 72 | self.__bind_events_wx() |
| 73 | + self.__init_menus() | ||
| 71 | 74 | ||
| 72 | 75 | ||
| 73 | def __init_gui(self): | 76 | def __init_gui(self): |
| @@ -85,13 +88,47 @@ class Viewer(wx.Panel): | @@ -85,13 +88,47 @@ class Viewer(wx.Panel): | ||
| 85 | background_sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) | 88 | background_sizer.Add(scroll, 0, wx.EXPAND|wx.GROW) |
| 86 | self.SetSizer(background_sizer) | 89 | self.SetSizer(background_sizer) |
| 87 | background_sizer.Fit(self) | 90 | background_sizer.Fit(self) |
| 88 | - | 91 | + |
| 92 | + | ||
| 89 | self.Layout() | 93 | self.Layout() |
| 90 | self.Update() | 94 | self.Update() |
| 91 | self.SetAutoLayout(1) | 95 | self.SetAutoLayout(1) |
| 92 | 96 | ||
| 93 | self.interactor = interactor | 97 | self.interactor = interactor |
| 94 | - | 98 | + |
| 99 | + | ||
| 100 | + | ||
| 101 | + def __init_menus(self): | ||
| 102 | + | ||
| 103 | + menu = self.menu = wx.Menu() | ||
| 104 | + submenu_wl = wx.Menu() | ||
| 105 | + | ||
| 106 | + for name in sorted(const.WINDOW_LEVEL): | ||
| 107 | + new_id = wx.NewId() | ||
| 108 | + wl_item = wx.MenuItem(submenu_wl, new_id, name, kind=wx.ITEM_RADIO) | ||
| 109 | + submenu_wl.AppendItem(wl_item) | ||
| 110 | + ID_TO_TOOL_ITEM[new_id] = wl_item | ||
| 111 | + | ||
| 112 | + menu.AppendMenu(1, "Window Width & Level", submenu_wl) | ||
| 113 | + self.Bind(wx.EVT_MENU, self.OnPopupWindowLevel) | ||
| 114 | + self.Fit() | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + | ||
| 118 | + def OnPopupWindowLevel(self, evt): | ||
| 119 | + item = ID_TO_TOOL_ITEM[evt.GetId()] | ||
| 120 | + key = item.GetLabel() | ||
| 121 | + window, level = const.WINDOW_LEVEL[key] | ||
| 122 | + | ||
| 123 | + ps.Publisher().sendMessage('Bright and contrast adjustment image', | ||
| 124 | + (window, level)) | ||
| 125 | + ps.Publisher().sendMessage('Update slice viewer') | ||
| 126 | + evt.Skip() | ||
| 127 | + | ||
| 128 | + def OnContextMenu(self, evt): | ||
| 129 | + self.PopupMenu(self.menu) | ||
| 130 | + #evt.Skip() | ||
| 131 | + | ||
| 95 | def __config_interactor(self): | 132 | def __config_interactor(self): |
| 96 | 133 | ||
| 97 | ren = vtk.vtkRenderer() | 134 | ren = vtk.vtkRenderer() |
| @@ -101,6 +138,9 @@ class Viewer(wx.Panel): | @@ -101,6 +138,9 @@ class Viewer(wx.Panel): | ||
| 101 | 138 | ||
| 102 | self.cam = ren.GetActiveCamera() | 139 | self.cam = ren.GetActiveCamera() |
| 103 | self.ren = ren | 140 | self.ren = ren |
| 141 | + | ||
| 142 | + | ||
| 143 | + | ||
| 104 | 144 | ||
| 105 | def append_mode(self, mode): | 145 | def append_mode(self, mode): |
| 106 | 146 | ||
| @@ -225,9 +265,8 @@ class Viewer(wx.Panel): | @@ -225,9 +265,8 @@ class Viewer(wx.Panel): | ||
| 225 | 265 | ||
| 226 | ps.Publisher().sendMessage('Update window and level text',\ | 266 | ps.Publisher().sendMessage('Update window and level text',\ |
| 227 | "WL: %d WW: %d"%(proj.level, proj.window)) | 267 | "WL: %d WW: %d"%(proj.level, proj.window)) |
| 228 | - self.interactor.Render() | ||
| 229 | - #ps.Publisher().sendMessage("Update slice viewer") | ||
| 230 | - | 268 | + self.interactor.Render() |
| 269 | + | ||
| 231 | 270 | ||
| 232 | def OnWindowLevelClick(self, evt, obj): | 271 | def OnWindowLevelClick(self, evt, obj): |
| 233 | proj = project.Project() | 272 | proj = project.Project() |
| @@ -652,9 +691,23 @@ class Viewer(wx.Panel): | @@ -652,9 +691,23 @@ class Viewer(wx.Panel): | ||
| 652 | print pubsub_evt.data | 691 | print pubsub_evt.data |
| 653 | self._brush_cursor_op = pubsub_evt.data | 692 | self._brush_cursor_op = pubsub_evt.data |
| 654 | 693 | ||
| 694 | + | ||
| 695 | + def popupID1(self, evt): | ||
| 696 | + print "A" | ||
| 697 | + print "...b..." | ||
| 698 | + | ||
| 699 | + evt.Skip() | ||
| 700 | + | ||
| 701 | + def popupID8(self, evt): | ||
| 702 | + print "B" | ||
| 703 | + evt.Skip() | ||
| 704 | + | ||
| 655 | def __bind_events_wx(self): | 705 | def __bind_events_wx(self): |
| 656 | self.scroll.Bind(wx.EVT_SCROLL, self.OnScrollBar) | 706 | self.scroll.Bind(wx.EVT_SCROLL, self.OnScrollBar) |
| 657 | - self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) | 707 | + self.interactor.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) |
| 708 | + self.interactor.Bind(wx.EVT_RIGHT_DOWN, self.OnContextMenu) | ||
| 709 | + | ||
| 710 | + | ||
| 658 | 711 | ||
| 659 | def LoadImagedata(self, pubsub_evt): | 712 | def LoadImagedata(self, pubsub_evt): |
| 660 | imagedata = pubsub_evt.data | 713 | imagedata = pubsub_evt.data |
| @@ -903,7 +956,7 @@ class Viewer(wx.Panel): | @@ -903,7 +956,7 @@ class Viewer(wx.Panel): | ||
| 903 | 956 | ||
| 904 | def UpdateRender(self, evt): | 957 | def UpdateRender(self, evt): |
| 905 | self.interactor.Render() | 958 | self.interactor.Render() |
| 906 | - | 959 | + |
| 907 | def set_scroll_position(self, position): | 960 | def set_scroll_position(self, position): |
| 908 | self.scroll.SetThumbPosition(position) | 961 | self.scroll.SetThumbPosition(position) |
| 909 | self.OnScrollBar() | 962 | self.OnScrollBar() |