Commit 56c24d9b5e1ce64fbda4eb943f493cd90357d7c2

Authored by tfmoraes
1 parent 448f330e

ENH: Passing to volume raycasting the plist object instead of filename

invesalius/control.py
  1 +import os
  2 +import plistlib
  3 +
1 4 import wx.lib.pubsub as ps
2 5  
3 6 import constants as const
... ... @@ -18,10 +21,11 @@ class Controller():
18 21 self.volume = volume.Volume()
19 22 self.__bind_events()
20 23  
21   -
22 24 def __bind_events(self):
23 25 ps.Publisher().subscribe(self.ImportDirectory, 'Import directory')
24 26 ps.Publisher().subscribe(self.StartImportPanel, "Load data to import panel")
  27 + ps.Publisher().subscribe(self.LoadRaycastingPreset,
  28 + 'Load raycasting preset')
25 29  
26 30 def StartImportPanel(self, pubsub_evt):
27 31 path = pubsub_evt.data
... ... @@ -101,6 +105,12 @@ class Controller():
101 105 key= thresh_modes[const.THRESHOLD_PRESETS_INDEX]
102 106 (min_thresh, max_thresh) = proj.threshold_modes.get_value(key)
103 107  
  108 + def LoadRaycastingPreset(self, pubsub_evt):
  109 + label = pubsub_evt.data
  110 + if not label:
  111 + label = const.RAYCASTING_LABEL
104 112  
105   -
106   -
  113 + path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY,
  114 + label+".plist")
  115 + preset = plistlib.readPlist(path)
  116 + prj.Project().raycasting_preset = preset
... ...
invesalius/data/volume.py
... ... @@ -93,15 +93,8 @@ class Volume():
93 93 #self.LoadConfig(label)
94 94 self.LoadVolume()
95 95  
96   - def LoadConfig(self, label):
97   - print label
98   - if not label:
99   - label = const.RAYCASTING_LABEL
100   -
101   - path = os.path.join("..", "presets", "raycasting",
102   - label+".plist")
103   - label = plistlib.readPlist(path)
104   - self.config = label
  96 + def LoadConfig(self):
  97 + self.config = Project().raycasting_preset
105 98 #print path
106 99  
107 100 def OnHideVolume(self, pubsub_evt):
... ... @@ -113,12 +106,13 @@ class Volume():
113 106 self.volume.SetVisibility(1)
114 107 ps.Publisher().sendMessage('Render volume viewer')
115 108 else:
116   - self.LoadConfig(None)
  109 + ps.Publisher.sendMessage('Load raycasting preset', const.RAYCASTING_LABEL)
  110 + self.LoadConfig()
117 111 self.LoadVolume()
118 112 self.exist = 1
119 113  
120 114 def SetRaycastPreset(self, pubsub_evt):
121   - self.LoadConfig(pubsub_evt.data)
  115 + self.LoadConfig()
122 116 self.__config_preset()
123 117 self.SetShading()
124 118 colour = self.CreateBackgroundColor()
... ... @@ -341,25 +335,16 @@ class Volume():
341 335  
342 336 cast = vtk.vtkImageShiftScale()
343 337 cast.SetInput(image)
344   - print "> ", self.config['advancedCLUT']
  338 + cast.SetShift(abs(scale[0]))
  339 + cast.SetOutputScalarTypeToUnsignedShort()
  340 + cast.Update()
  341 + image2 = cast
345 342 if self.config['advancedCLUT']:
346   - cast.SetShift(abs(scale[0]))
347   - #cast.SetScale(2**16-1)
348   - cast.SetOutputScalarTypeToUnsignedShort()
349   - #scale = image.GetScalarRange()
350 343 self.Create16bColorTable(scale)
351 344 self.CreateOpacityTable(scale)
352   - cast.Update()
353   - image2 = cast
354 345 else:
355   - cast.SetShift(abs(scale[0]))
356   - #cast.SetScale(255.0/(scale[1] - scale[0]))
357   - cast.SetOutputScalarTypeToUnsignedShort()
358   - color_transfer = self.Create8bColorTable(scale)
359   - opacity_transfer_func = self.Create8bOpacityTable(scale)
360   - cast.Update()
361   - image2 = cast
362   - #cast.ClampOverflowOff()
  346 + self.Create8bColorTable(scale)
  347 + self.Create8bOpacityTable(scale)
363 348  
364 349 convolve = vtk.vtkImageConvolve()
365 350 convolve.SetInput(image2.GetOutput())
... ... @@ -367,7 +352,7 @@ class Volume():
367 352 convolve.Update()
368 353  
369 354 image2 = convolve
370   -
  355 +
371 356 composite_function = vtk.vtkVolumeRayCastCompositeFunction()
372 357 composite_function.SetCompositeMethodToInterpolateFirst()
373 358  
... ...
invesalius/gui/default_viewers.py
... ... @@ -262,8 +262,9 @@ class VolumeToolPanel(wx.Panel):
262 262  
263 263 def OnMenuRaycasting(self, evt):
264 264 """Events from button menus."""
265   - ps.Publisher().sendMessage('Set raycasting preset',
  265 + ps.Publisher().sendMessage('Load raycasting preset',
266 266 ID_TO_NAME[evt.GetId()])
  267 + ps.Publisher().sendMessage('Set raycasting preset', None)
267 268 ps.Publisher().sendMessage('Render volume viewer')
268 269  
269 270 def OnMenuView(self, evt):
... ...
invesalius/gui/widgets/clut_raycasting.py
... ... @@ -9,6 +9,8 @@ import wx
9 9 import wx.lib.pubsub as ps
10 10 import wx.lib.wxcairo
11 11  
  12 +import project
  13 +
12 14 FONT_COLOUR = (1, 1, 1)
13 15 LINE_COLOUR = (0.5, 0.5, 0.5)
14 16 LINE_WIDTH = 2
... ... @@ -301,10 +303,11 @@ class CLUTRaycastingWidget(wx.Panel):
301 303 ctx.set_line_width(HISTOGRAM_LINE_WIDTH)
302 304 for x,y in self.histogram_pixel_points:
303 305 ctx.line_to(x,y)
  306 + ctx.line_to(x, height)
304 307 ctx.line_to(0, height)
305 308 x,y = self.histogram_pixel_points[0]
306   - ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR)
307 309 ctx.line_to(x, y)
  310 + ctx.set_source_rgb(*HISTOGRAM_FILL_COLOUR)
308 311 ctx.fill_preserve()
309 312 ctx.set_source_rgb(*HISTOGRAM_LINE_COLOUR)
310 313 ctx.stroke()
... ... @@ -351,7 +354,6 @@ class CLUTRaycastingWidget(wx.Panel):
351 354 y = math.log(self.histogram_array[i])
352 355 else:
353 356 y = 0
354   - print y
355 357 x = self.init+ i
356 358 x = (x + abs(self.init)) * proportion_x
357 359 y = height - y * proportion_y
... ... @@ -392,10 +394,12 @@ class CLUTRaycastingWidget(wx.Panel):
392 394 print x,y
393 395  
394 396 def SetRaycastPreset(self, preset):
395   - if preset.data['advancedCLUT']:
  397 + preset = project.Project().raycasting_preset
  398 + print preset
  399 + if preset['advancedCLUT']:
396 400 self.to_draw_points = 1
397   - self.points = preset.data['16bitClutCurves']
398   - self.colours = preset.data['16bitClutColors']
  401 + self.points = preset['16bitClutCurves']
  402 + self.colours = preset['16bitClutColors']
399 403 self.CreatePixelArray()
400 404 else:
401 405 self.to_draw_points = 0
... ...
invesalius/project.py
... ... @@ -17,7 +17,10 @@
17 17 # detalhes.
18 18 #--------------------------------------------------------------------------
19 19  
  20 +import os
  21 +import plistlib
20 22 import wx
  23 +import wx.lib.pubsub as ps
21 24  
22 25 from utils import Singleton
23 26 from presets import Presets
... ... @@ -78,10 +81,13 @@ class Project(object):
78 81 # InVesalius configuration file
79 82 # self.render_mode = {}
80 83  
  84 + # The raycasting preset setted in this project
  85 + self.raycasting_preset = None
  86 +
81 87 self.debug = 0
82   -
  88 +
83 89 ####### MASK OPERATIONS
84   -
  90 +
85 91 def AddMask(self, index, mask):
86 92 """
87 93 Insert new mask (Mask) into project data.
... ... @@ -106,5 +112,7 @@ class Project(object):
106 112 else:
107 113 print "Different Acquisition Modality!!!"
108 114  
109   -
110   -
111 115 \ No newline at end of file
  116 + def SetRaycastPreset(self, label):
  117 + path = os.path.join(RAYCASTING_PRESETS_DIRECTORY, label + '.plist')
  118 + preset = plistlib.readPlist(path)
  119 + ps.Publisher.sendMessage('Set raycasting preset', preset)
... ...