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