From 56c24d9b5e1ce64fbda4eb943f493cd90357d7c2 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Fri, 14 Aug 2009 17:41:50 +0000 Subject: [PATCH] ENH: Passing to volume raycasting the plist object instead of filename --- invesalius/control.py | 16 +++++++++++++--- invesalius/data/volume.py | 39 ++++++++++++--------------------------- invesalius/gui/default_viewers.py | 3 ++- invesalius/gui/widgets/clut_raycasting.py | 14 +++++++++----- invesalius/project.py | 16 ++++++++++++---- 5 files changed, 48 insertions(+), 40 deletions(-) diff --git a/invesalius/control.py b/invesalius/control.py index 9fa66ea..0c5a9ca 100755 --- a/invesalius/control.py +++ b/invesalius/control.py @@ -1,3 +1,6 @@ +import os +import plistlib + import wx.lib.pubsub as ps import constants as const @@ -18,10 +21,11 @@ class Controller(): self.volume = volume.Volume() self.__bind_events() - def __bind_events(self): ps.Publisher().subscribe(self.ImportDirectory, 'Import directory') ps.Publisher().subscribe(self.StartImportPanel, "Load data to import panel") + ps.Publisher().subscribe(self.LoadRaycastingPreset, + 'Load raycasting preset') def StartImportPanel(self, pubsub_evt): path = pubsub_evt.data @@ -101,6 +105,12 @@ class Controller(): key= thresh_modes[const.THRESHOLD_PRESETS_INDEX] (min_thresh, max_thresh) = proj.threshold_modes.get_value(key) + def LoadRaycastingPreset(self, pubsub_evt): + label = pubsub_evt.data + if not label: + label = const.RAYCASTING_LABEL - - + path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, + label+".plist") + preset = plistlib.readPlist(path) + prj.Project().raycasting_preset = preset diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index a8a982b..83443b4 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -93,15 +93,8 @@ class Volume(): #self.LoadConfig(label) self.LoadVolume() - def LoadConfig(self, label): - print label - if not label: - label = const.RAYCASTING_LABEL - - path = os.path.join("..", "presets", "raycasting", - label+".plist") - label = plistlib.readPlist(path) - self.config = label + def LoadConfig(self): + self.config = Project().raycasting_preset #print path def OnHideVolume(self, pubsub_evt): @@ -113,12 +106,13 @@ class Volume(): self.volume.SetVisibility(1) ps.Publisher().sendMessage('Render volume viewer') else: - self.LoadConfig(None) + ps.Publisher.sendMessage('Load raycasting preset', const.RAYCASTING_LABEL) + self.LoadConfig() self.LoadVolume() self.exist = 1 def SetRaycastPreset(self, pubsub_evt): - self.LoadConfig(pubsub_evt.data) + self.LoadConfig() self.__config_preset() self.SetShading() colour = self.CreateBackgroundColor() @@ -341,25 +335,16 @@ class Volume(): cast = vtk.vtkImageShiftScale() cast.SetInput(image) - print "> ", self.config['advancedCLUT'] + cast.SetShift(abs(scale[0])) + cast.SetOutputScalarTypeToUnsignedShort() + cast.Update() + image2 = cast if self.config['advancedCLUT']: - cast.SetShift(abs(scale[0])) - #cast.SetScale(2**16-1) - cast.SetOutputScalarTypeToUnsignedShort() - #scale = image.GetScalarRange() self.Create16bColorTable(scale) self.CreateOpacityTable(scale) - cast.Update() - image2 = cast else: - cast.SetShift(abs(scale[0])) - #cast.SetScale(255.0/(scale[1] - scale[0])) - cast.SetOutputScalarTypeToUnsignedShort() - color_transfer = self.Create8bColorTable(scale) - opacity_transfer_func = self.Create8bOpacityTable(scale) - cast.Update() - image2 = cast - #cast.ClampOverflowOff() + self.Create8bColorTable(scale) + self.Create8bOpacityTable(scale) convolve = vtk.vtkImageConvolve() convolve.SetInput(image2.GetOutput()) @@ -367,7 +352,7 @@ class Volume(): convolve.Update() image2 = convolve - + composite_function = vtk.vtkVolumeRayCastCompositeFunction() composite_function.SetCompositeMethodToInterpolateFirst() diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index b014e6e..aef9289 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -262,8 +262,9 @@ class VolumeToolPanel(wx.Panel): def OnMenuRaycasting(self, evt): """Events from button menus.""" - ps.Publisher().sendMessage('Set raycasting preset', + ps.Publisher().sendMessage('Load raycasting preset', ID_TO_NAME[evt.GetId()]) + ps.Publisher().sendMessage('Set raycasting preset', None) ps.Publisher().sendMessage('Render volume viewer') def OnMenuView(self, evt): diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index a5974f0..1880a2c 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -9,6 +9,8 @@ import wx import wx.lib.pubsub as ps import wx.lib.wxcairo +import project + FONT_COLOUR = (1, 1, 1) LINE_COLOUR = (0.5, 0.5, 0.5) LINE_WIDTH = 2 @@ -301,10 +303,11 @@ class CLUTRaycastingWidget(wx.Panel): ctx.set_line_width(HISTOGRAM_LINE_WIDTH) for x,y in self.histogram_pixel_points: ctx.line_to(x,y) + ctx.line_to(x, height) ctx.line_to(0, height) x,y = self.histogram_pixel_points[0] - ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR) ctx.line_to(x, y) + ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR) ctx.fill_preserve() ctx.set_source_rgb(*HISTOGRAM_LINE_COLOUR) ctx.stroke() @@ -351,7 +354,6 @@ class CLUTRaycastingWidget(wx.Panel): y = math.log(self.histogram_array[i]) else: y = 0 - print y x = self.init+ i x = (x + abs(self.init)) * proportion_x y = height - y * proportion_y @@ -392,10 +394,12 @@ class CLUTRaycastingWidget(wx.Panel): print x,y def SetRaycastPreset(self, preset): - if preset.data['advancedCLUT']: + preset = project.Project().raycasting_preset + print preset + if preset['advancedCLUT']: self.to_draw_points = 1 - self.points = preset.data['16bitClutCurves'] - self.colours = preset.data['16bitClutColors'] + self.points = preset['16bitClutCurves'] + self.colours = preset['16bitClutColors'] self.CreatePixelArray() else: self.to_draw_points = 0 diff --git a/invesalius/project.py b/invesalius/project.py index dc3df6c..7949444 100755 --- a/invesalius/project.py +++ b/invesalius/project.py @@ -17,7 +17,10 @@ # detalhes. #-------------------------------------------------------------------------- +import os +import plistlib import wx +import wx.lib.pubsub as ps from utils import Singleton from presets import Presets @@ -78,10 +81,13 @@ class Project(object): # InVesalius configuration file # self.render_mode = {} + # The raycasting preset setted in this project + self.raycasting_preset = None + self.debug = 0 - + ####### MASK OPERATIONS - + def AddMask(self, index, mask): """ Insert new mask (Mask) into project data. @@ -106,5 +112,7 @@ class Project(object): else: print "Different Acquisition Modality!!!" - - \ No newline at end of file + def SetRaycastPreset(self, label): + path = os.path.join(RAYCASTING_PRESETS_DIRECTORY, label + '.plist') + preset = plistlib.readPlist(path) + ps.Publisher.sendMessage('Set raycasting preset', preset) -- libgit2 0.21.2