From 4ed57aabd87a640a2ad7741b67b576aec7263e6f Mon Sep 17 00:00:00 2001 From: tatiana Date: Mon, 17 Aug 2009 15:19:55 +0000 Subject: [PATCH] ENH: In the process of adjusting raycasting plane --- invesalius/constants.py | 2 +- invesalius/data/volume.py | 8 ++++++++ invesalius/gui/default_viewers.py | 34 +++++++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index dcde109..764be5f 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -160,5 +160,5 @@ RAYCASTING_TYPES = [filename.split(".")[0] for filename in RAYCASTING_TYPES.append(' Off') RAYCASTING_TYPES.sort() RAYCASTING_OFF_LABEL = ' Off' -RAYCASTING_TOOLS = ["Plane cutter"] +RAYCASTING_TOOLS = ["Cut plane"] diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index a138b85..bbda6fe 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -92,6 +92,8 @@ class Volume(): 'Set raycasting refresh') ps.Publisher().subscribe(self.OnSetRelativeWindowLevel, 'Set raycasting relative window and level') + ps.Publisher().subscribe(self.OnEnableTool, + 'Enable raycasting tool') def OnLoadVolume(self, pubsub_evt): label = pubsub_evt.data @@ -386,6 +388,7 @@ class Volume(): self.Create8bOpacityTable(scale) image2 = self.ApplyConvolution(image2.GetOutput()) + self.final_imagedata = image2 composite_function = vtk.vtkVolumeRayCastCompositeFunction() composite_function.SetCompositeMethodToInterpolateFirst() @@ -454,6 +457,11 @@ class Volume(): colour = self.GetBackgroundColour() ps.Publisher().sendMessage('Load volume into viewer', (volume, colour)) + def OnEnableTool(self, pubsub_evt): + tool_name = pubsub_evt.data + if tool_name == "Cut plane": + plane = CutPlane(self.final_imagedata, self.volume_mapper) + def TranslateScale(self, scale, value): #if value < 0: # valor = 2**16 - abs(value) diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 102473e..5ca3563 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -176,7 +176,7 @@ import wx.lib.colourselect as csel import constants as const [BUTTON_RAYCASTING, BUTTON_VIEW] = [wx.NewId() for num in xrange(2)] - +RAYCASTING_TOOLS = wx.NewId() ID_TO_BMP = {const.VOL_FRONT: ["Front", "../icons/view_front.png"], const.VOL_BACK: ["Back", "../icons/view_back.png"], @@ -189,6 +189,7 @@ ID_TO_BMP = {const.VOL_FRONT: ["Front", "../icons/view_front.png"], ID_TO_NAME = {} ID_TO_TOOL = {} +ID_TO_TOOL_ITEM = {} class VolumeViewerCover(wx.Panel): def __init__(self, parent): @@ -208,6 +209,7 @@ class VolumeToolPanel(wx.Panel): BMP_RAYCASTING = wx.Bitmap("../icons/volume_raycasting.png", wx.BITMAP_TYPE_PNG) + # MENU RELATED TO RAYCASTING TYPES menu = wx.Menu() for name in const.RAYCASTING_TYPES: id = wx.NewId() @@ -218,22 +220,25 @@ class VolumeToolPanel(wx.Panel): ID_TO_NAME[id] = name menu.AppendSeparator() + # MENU RELATED TO RAYCASTING TOOLS submenu = wx.Menu() - for tool in const.RAYCASTING_TOOLS: + for name in const.RAYCASTING_TOOLS: id = wx.NewId() item = wx.MenuItem(submenu, id, name, kind=wx.ITEM_CHECK) submenu.AppendItem(item) ID_TO_TOOL[id] = name + ID_TO_TOOL_ITEM[id] = item + #submenu.Enable(0) + self.submenu_raycasting_tools = submenu + menu.AppendMenu(RAYCASTING_TOOLS, "Tools", submenu) + menu.Enable(RAYCASTING_TOOLS, 0) self.menu_raycasting = menu menu.Bind(wx.EVT_MENU, self.OnMenuRaycasting) - #button_raycasting=btn.GenBitmapToggleButton(self, 1, BMP_RAYCASTING, size=(24,24)) - #self.button_raycasting_toggle = 0 button_raycasting = pbtn.PlateButton(self, BUTTON_RAYCASTING,"", BMP_RAYCASTING, style=pbtn.PB_STYLE_SQUARE, size=(24,24)) - #self.Bind(wx.EVT_BUTTON, self.OnToggleRaycasting) button_raycasting.SetMenu(menu) self.button_raycasting = button_raycasting @@ -274,11 +279,26 @@ class VolumeToolPanel(wx.Panel): """Events from raycasting menu.""" id = evt.GetId() if id in ID_TO_NAME.keys(): + name = ID_TO_NAME[evt.GetId()] ps.Publisher().sendMessage('Load raycasting preset', ID_TO_NAME[evt.GetId()]) + if name != const.RAYCASTING_OFF_LABEL: + self.menu_raycasting.Enable(RAYCASTING_TOOLS, 1) + else: + self.menu_raycasting.Enable(RAYCASTING_TOOLS, 0) else: - ps.Publisher().sendMessage('Enable raycasting tool', - ID_TO_TOOL(evt.GetId()) + item = ID_TO_TOOL_ITEM[evt.GetId()] + if not item.IsChecked(): + for i in ID_TO_TOOL_ITEM.values(): + if i is not item: + i.Check(0) + + ps.Publisher().sendMessage('Enable raycasting tool', + [ID_TO_TOOL[evt.GetId()],1]) + else: + ps.Publisher().sendMessage('Enable raycasting tool', + [ID_TO_TOOL[evt.GetId()],0]) + def OnMenuView(self, evt): """Events from button menus.""" -- libgit2 0.21.2