Commit 2e98f651c06f083be47f24030df49897e4b0c9d1
1 parent
e2ad208d
Exists in
master
and in
6 other branches
ENC: Changed GUI related to raycasting set/not set and type
Showing
4 changed files
with
77 additions
and
55 deletions
Show diff stats
invesalius/constants.py
@@ -157,6 +157,7 @@ folder=RAYCASTING_PRESETS_DIRECTORY= os.path.join("..", "presets", "raycasting") | @@ -157,6 +157,7 @@ folder=RAYCASTING_PRESETS_DIRECTORY= os.path.join("..", "presets", "raycasting") | ||
157 | RAYCASTING_TYPES = [filename.split(".")[0] for filename in | 157 | RAYCASTING_TYPES = [filename.split(".")[0] for filename in |
158 | os.listdir(folder) if | 158 | os.listdir(folder) if |
159 | os.path.isfile(os.path.join(folder,filename))] | 159 | os.path.isfile(os.path.join(folder,filename))] |
160 | +RAYCASTING_TYPES.append(' Off') | ||
160 | RAYCASTING_TYPES.sort() | 161 | RAYCASTING_TYPES.sort() |
161 | -RAYCASTING_LABEL = "Skin On Blue" | 162 | +RAYCASTING_OFF_LABEL = ' Off' |
162 | 163 |
invesalius/control.py
@@ -107,10 +107,13 @@ class Controller(): | @@ -107,10 +107,13 @@ class Controller(): | ||
107 | 107 | ||
108 | def LoadRaycastingPreset(self, pubsub_evt): | 108 | def LoadRaycastingPreset(self, pubsub_evt): |
109 | label = pubsub_evt.data | 109 | label = pubsub_evt.data |
110 | - if not label: | ||
111 | - label = const.RAYCASTING_LABEL | ||
112 | - | ||
113 | - path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, | ||
114 | - label+".plist") | ||
115 | - preset = plistlib.readPlist(path) | ||
116 | - prj.Project().raycasting_preset = preset | 110 | + if label != const.RAYCASTING_OFF_LABEL: |
111 | + path = os.path.join(const.RAYCASTING_PRESETS_DIRECTORY, | ||
112 | + label+".plist") | ||
113 | + preset = plistlib.readPlist(path) | ||
114 | + prj.Project().raycasting_preset = preset | ||
115 | + # Notify volume | ||
116 | + # TODO: Chamar grafico tb! | ||
117 | + ps.Publisher().sendMessage('Update raycasting preset') | ||
118 | + else: | ||
119 | + ps.Publisher().sendMessage("Hide raycasting volume") |
invesalius/data/volume.py
@@ -24,7 +24,7 @@ import wx | @@ -24,7 +24,7 @@ import wx | ||
24 | import wx.lib.pubsub as ps | 24 | import wx.lib.pubsub as ps |
25 | 25 | ||
26 | import constants as const | 26 | import constants as const |
27 | -from project import Project | 27 | +import project as prj |
28 | 28 | ||
29 | Kernels = { | 29 | Kernels = { |
30 | "Basic Smooth 5x5" : [1.0, 1.0, 1.0, 1.0, 1.0, | 30 | "Basic Smooth 5x5" : [1.0, 1.0, 1.0, 1.0, 1.0, |
@@ -80,12 +80,12 @@ class Volume(): | @@ -80,12 +80,12 @@ class Volume(): | ||
80 | 80 | ||
81 | def __bind_events(self): | 81 | def __bind_events(self): |
82 | #ps.Publisher().subscribe(self.OnLoadVolume, 'Create volume raycasting') | 82 | #ps.Publisher().subscribe(self.OnLoadVolume, 'Create volume raycasting') |
83 | - ps.Publisher().subscribe(self.OnShowVolume, | ||
84 | - 'Show raycasting volume') | 83 | + #ps.Publisher().subscribe(self.OnShowVolume, |
84 | + # 'Show raycasting volume') | ||
85 | ps.Publisher().subscribe(self.OnHideVolume, | 85 | ps.Publisher().subscribe(self.OnHideVolume, |
86 | 'Hide raycasting volume') | 86 | 'Hide raycasting volume') |
87 | - ps.Publisher().subscribe(self.SetRaycastPreset, | ||
88 | - 'Set raycasting preset') | 87 | + ps.Publisher().subscribe(self.OnUpdatePreset, |
88 | + 'Update raycasting preset') | ||
89 | ps.Publisher().subscribe(self.OnSetWindowLevel, | 89 | ps.Publisher().subscribe(self.OnSetWindowLevel, |
90 | 'Set raycasting wwwl') | 90 | 'Set raycasting wwwl') |
91 | ps.Publisher().subscribe(self.Refresh, | 91 | ps.Publisher().subscribe(self.Refresh, |
@@ -98,9 +98,6 @@ class Volume(): | @@ -98,9 +98,6 @@ class Volume(): | ||
98 | #self.LoadConfig(label) | 98 | #self.LoadConfig(label) |
99 | self.LoadVolume() | 99 | self.LoadVolume() |
100 | 100 | ||
101 | - def LoadConfig(self): | ||
102 | - self.config = Project().raycasting_preset | ||
103 | - | ||
104 | def OnHideVolume(self, pubsub_evt): | 101 | def OnHideVolume(self, pubsub_evt): |
105 | self.volume.SetVisibility(0) | 102 | self.volume.SetVisibility(0) |
106 | ps.Publisher().sendMessage('Render volume viewer') | 103 | ps.Publisher().sendMessage('Render volume viewer') |
@@ -115,22 +112,41 @@ class Volume(): | @@ -115,22 +112,41 @@ class Volume(): | ||
115 | self.LoadVolume() | 112 | self.LoadVolume() |
116 | self.exist = 1 | 113 | self.exist = 1 |
117 | 114 | ||
118 | - def SetRaycastPreset(self, pubsub_evt): | ||
119 | - self.LoadConfig() | ||
120 | - self.__config_preset() | ||
121 | - self.SetShading() | ||
122 | - colour = self.CreateBackgroundColor() | ||
123 | - ps.Publisher.sendMessage('Change volume viewer background colour', colour) | 115 | + def OnUpdatePreset(self, pubsub_evt): |
116 | + self.__load_preset_config() | ||
117 | + if self.exist: | ||
118 | + self.__load_preset() | ||
119 | + self.volume.SetVisibility(1) | ||
120 | + ps.Publisher().sendMessage('Render volume viewer') | ||
121 | + else: | ||
122 | + self.LoadVolume() | ||
123 | + self.exist = 1 | ||
124 | 124 | ||
125 | - def __config_preset(self): | 125 | + def __load_preset_config(self): |
126 | + self.config = prj.Project().raycasting_preset | ||
127 | + | ||
128 | + def __update_colour_table(self): | ||
126 | if self.config['advancedCLUT']: | 129 | if self.config['advancedCLUT']: |
127 | self.Create16bColorTable(self.scale) | 130 | self.Create16bColorTable(self.scale) |
128 | self.CreateOpacityTable(self.scale) | 131 | self.CreateOpacityTable(self.scale) |
129 | else: | 132 | else: |
130 | self.Create8bColorTable(self.scale) | 133 | self.Create8bColorTable(self.scale) |
131 | self.Create8bOpacityTable(self.scale) | 134 | self.Create8bOpacityTable(self.scale) |
132 | - image = self.DoConvolutionFilters(self.imagedata.GetOutput()) | ||
133 | - self.volume_mapper.SetInput(image) | 135 | + |
136 | + def __load_preset(self): | ||
137 | + # Update colour table | ||
138 | + self.__update_colour_table() | ||
139 | + | ||
140 | + # Update convolution filter | ||
141 | + original_imagedata = self.imagedata.GetOutput() | ||
142 | + imagedata = self.ApplyConvolution(original_imagedata) | ||
143 | + self.volume_mapper.SetInput(imagedata) | ||
144 | + | ||
145 | + # Update other information | ||
146 | + self.SetShading() | ||
147 | + colour = self.GetBackgroundColour() | ||
148 | + ps.Publisher.sendMessage('Change volume viewer background colour', colour) | ||
149 | + | ||
134 | 150 | ||
135 | def OnSetRelativeWindowLevel(self, pubsub_evt): | 151 | def OnSetRelativeWindowLevel(self, pubsub_evt): |
136 | diff_ww, diff_wl = pubsub_evt.data | 152 | diff_ww, diff_wl = pubsub_evt.data |
@@ -144,7 +160,8 @@ class Volume(): | @@ -144,7 +160,8 @@ class Volume(): | ||
144 | 160 | ||
145 | def OnSetWindowLevel(self, pubsub_evt): | 161 | def OnSetWindowLevel(self, pubsub_evt): |
146 | ww, wl, n = pubsub_evt.data | 162 | ww, wl, n = pubsub_evt.data |
147 | - self.SetWWWL(ww,wl,n) | 163 | + self.n = n |
164 | + self.SetWWWL(ww,wl) | ||
148 | 165 | ||
149 | def SetWWWL(self, ww, wl): | 166 | def SetWWWL(self, ww, wl): |
150 | 167 | ||
@@ -173,11 +190,11 @@ class Volume(): | @@ -173,11 +190,11 @@ class Volume(): | ||
173 | self.config['wl'] = wl | 190 | self.config['wl'] = wl |
174 | self.config['ww'] = ww | 191 | self.config['ww'] = ww |
175 | 192 | ||
176 | - self.__config_preset() | ||
177 | - #ps.Publisher().sendMessage('Render volume viewer', None) | 193 | + self.__update_colour_table() |
194 | + ps.Publisher().sendMessage('Render volume viewer') | ||
178 | 195 | ||
179 | def Refresh(self, pubsub_evt): | 196 | def Refresh(self, pubsub_evt): |
180 | - self.__config_preset() | 197 | + self.__set_preset() |
181 | 198 | ||
182 | #*************** | 199 | #*************** |
183 | def Create16bColorTable(self, scale): | 200 | def Create16bColorTable(self, scale): |
@@ -287,11 +304,11 @@ class Volume(): | @@ -287,11 +304,11 @@ class Volume(): | ||
287 | self.opacity_transfer_func = opacity_transfer_func | 304 | self.opacity_transfer_func = opacity_transfer_func |
288 | return opacity_transfer_func | 305 | return opacity_transfer_func |
289 | 306 | ||
290 | - def CreateBackgroundColor(self): | ||
291 | - color_background = (self.config['backgroundColorRedComponent'], | 307 | + def GetBackgroundColour(self): |
308 | + colour = (self.config['backgroundColorRedComponent'], | ||
292 | self.config['backgroundColorGreenComponent'], | 309 | self.config['backgroundColorGreenComponent'], |
293 | self.config['backgroundColorBlueComponent']) | 310 | self.config['backgroundColorBlueComponent']) |
294 | - return color_background | 311 | + return colour |
295 | 312 | ||
296 | def BuildTable(): | 313 | def BuildTable(): |
297 | curve_table = p['16bitClutCurves'] | 314 | curve_table = p['16bitClutCurves'] |
@@ -329,7 +346,7 @@ class Volume(): | @@ -329,7 +346,7 @@ class Volume(): | ||
329 | self.volume_properties.SetSpecular(shading['specular']) | 346 | self.volume_properties.SetSpecular(shading['specular']) |
330 | self.volume_properties.SetSpecularPower(shading['specularPower']) | 347 | self.volume_properties.SetSpecularPower(shading['specularPower']) |
331 | 348 | ||
332 | - def DoConvolutionFilters(self, imagedata): | 349 | + def ApplyConvolution(self, imagedata): |
333 | for filter in self.config['convolutionFilters']: | 350 | for filter in self.config['convolutionFilters']: |
334 | convolve = vtk.vtkImageConvolve() | 351 | convolve = vtk.vtkImageConvolve() |
335 | convolve.SetInput(imagedata) | 352 | convolve.SetInput(imagedata) |
@@ -339,7 +356,7 @@ class Volume(): | @@ -339,7 +356,7 @@ class Volume(): | ||
339 | return imagedata | 356 | return imagedata |
340 | 357 | ||
341 | def LoadVolume(self): | 358 | def LoadVolume(self): |
342 | - proj = Project() | 359 | + proj = prj.Project() |
343 | image = proj.imagedata | 360 | image = proj.imagedata |
344 | 361 | ||
345 | # Flip original vtkImageData | 362 | # Flip original vtkImageData |
@@ -368,7 +385,7 @@ class Volume(): | @@ -368,7 +385,7 @@ class Volume(): | ||
368 | self.Create8bColorTable(scale) | 385 | self.Create8bColorTable(scale) |
369 | self.Create8bOpacityTable(scale) | 386 | self.Create8bOpacityTable(scale) |
370 | 387 | ||
371 | - image2 = self.DoConvolutionFilters(image2.GetOutput()) | 388 | + image2 = self.ApplyConvolution(image2.GetOutput()) |
372 | 389 | ||
373 | composite_function = vtk.vtkVolumeRayCastCompositeFunction() | 390 | composite_function = vtk.vtkVolumeRayCastCompositeFunction() |
374 | composite_function.SetCompositeMethodToInterpolateFirst() | 391 | composite_function.SetCompositeMethodToInterpolateFirst() |
@@ -399,7 +416,7 @@ class Volume(): | @@ -399,7 +416,7 @@ class Volume(): | ||
399 | #volume_mapper.SetInput(image2.GetOutput()) | 416 | #volume_mapper.SetInput(image2.GetOutput()) |
400 | 417 | ||
401 | #Cut Plane | 418 | #Cut Plane |
402 | - CutPlane(image2, volume_mapper) | 419 | + #CutPlane(image2, volume_mapper) |
403 | 420 | ||
404 | #self.color_transfer = color_transfer | 421 | #self.color_transfer = color_transfer |
405 | 422 | ||
@@ -434,7 +451,7 @@ class Volume(): | @@ -434,7 +451,7 @@ class Volume(): | ||
434 | volume.SetProperty(volume_properties) | 451 | volume.SetProperty(volume_properties) |
435 | self.volume = volume | 452 | self.volume = volume |
436 | 453 | ||
437 | - colour = self.CreateBackgroundColor() | 454 | + colour = self.GetBackgroundColour() |
438 | ps.Publisher().sendMessage('Load volume into viewer', (volume, colour)) | 455 | ps.Publisher().sendMessage('Load volume into viewer', (volume, colour)) |
439 | 456 | ||
440 | def TranslateScale(self, scale, value): | 457 | def TranslateScale(self, scale, value): |
invesalius/gui/default_viewers.py
@@ -212,18 +212,18 @@ class VolumeToolPanel(wx.Panel): | @@ -212,18 +212,18 @@ class VolumeToolPanel(wx.Panel): | ||
212 | id = wx.NewId() | 212 | id = wx.NewId() |
213 | item = wx.MenuItem(menu, id, name, kind=wx.ITEM_RADIO) | 213 | item = wx.MenuItem(menu, id, name, kind=wx.ITEM_RADIO) |
214 | menu.AppendItem(item) | 214 | menu.AppendItem(item) |
215 | - if name == const.RAYCASTING_LABEL: | 215 | + if name == const.RAYCASTING_OFF_LABEL: |
216 | item.Check(1) | 216 | item.Check(1) |
217 | ID_TO_NAME[id] = name | 217 | ID_TO_NAME[id] = name |
218 | self.menu_raycasting = menu | 218 | self.menu_raycasting = menu |
219 | menu.Bind(wx.EVT_MENU, self.OnMenuRaycasting) | 219 | menu.Bind(wx.EVT_MENU, self.OnMenuRaycasting) |
220 | 220 | ||
221 | #button_raycasting=btn.GenBitmapToggleButton(self, 1, BMP_RAYCASTING, size=(24,24)) | 221 | #button_raycasting=btn.GenBitmapToggleButton(self, 1, BMP_RAYCASTING, size=(24,24)) |
222 | - self.button_raycasting_toggle = 0 | 222 | + #self.button_raycasting_toggle = 0 |
223 | button_raycasting = pbtn.PlateButton(self, BUTTON_RAYCASTING,"", | 223 | button_raycasting = pbtn.PlateButton(self, BUTTON_RAYCASTING,"", |
224 | BMP_RAYCASTING, style=pbtn.PB_STYLE_SQUARE, | 224 | BMP_RAYCASTING, style=pbtn.PB_STYLE_SQUARE, |
225 | size=(24,24)) | 225 | size=(24,24)) |
226 | - self.Bind(wx.EVT_BUTTON, self.OnToggleRaycasting) | 226 | + #self.Bind(wx.EVT_BUTTON, self.OnToggleRaycasting) |
227 | button_raycasting.SetMenu(menu) | 227 | button_raycasting.SetMenu(menu) |
228 | 228 | ||
229 | self.button_raycasting = button_raycasting | 229 | self.button_raycasting = button_raycasting |
@@ -261,11 +261,12 @@ class VolumeToolPanel(wx.Panel): | @@ -261,11 +261,12 @@ class VolumeToolPanel(wx.Panel): | ||
261 | sizer.Fit(self) | 261 | sizer.Fit(self) |
262 | 262 | ||
263 | def OnMenuRaycasting(self, evt): | 263 | def OnMenuRaycasting(self, evt): |
264 | - """Events from button menus.""" | 264 | + """Events from raycasting menu.""" |
265 | ps.Publisher().sendMessage('Load 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) | ||
268 | - ps.Publisher().sendMessage('Render volume viewer') | 267 | + # ps.Publisher().sendMessage('Set raycasting preset', None) |
268 | + # ps.Publisher().sendMessage('Render volume viewer') | ||
269 | + | ||
269 | 270 | ||
270 | def OnMenuView(self, evt): | 271 | def OnMenuView(self, evt): |
271 | """Events from button menus.""" | 272 | """Events from button menus.""" |
@@ -279,15 +280,15 @@ class VolumeToolPanel(wx.Panel): | @@ -279,15 +280,15 @@ class VolumeToolPanel(wx.Panel): | ||
279 | colour = c = [i/255.0 for i in evt.GetValue()] | 280 | colour = c = [i/255.0 for i in evt.GetValue()] |
280 | ps.Publisher().sendMessage('Change volume viewer background colour', colour) | 281 | ps.Publisher().sendMessage('Change volume viewer background colour', colour) |
281 | 282 | ||
282 | - def OnToggleRaycasting(self, evt): | ||
283 | - print "oi" | ||
284 | - if self.button_raycasting_toggle: | ||
285 | - ps.Publisher().sendMessage('Hide raycasting volume') | ||
286 | - self.button_raycasting.SetBackgroundColour(self.GetParent().GetBackgroundColour()) | ||
287 | - #self.button_raycasting.SetBitmapSelected(ID_TO_BMP2[0]) | ||
288 | - self.button_raycasting_toggle = 0 | ||
289 | - else: | ||
290 | - ps.Publisher().sendMessage('Show raycasting volume') | ||
291 | - self.button_raycasting_toggle = 1 | ||
292 | - #self.button_raycasting.SetBitmapSelected(ID_TO_BMP2[1]) | ||
293 | - self.button_raycasting.SetBackgroundColour((255,255,255)) | 283 | + #def OnToggleRaycasting(self, evt): |
284 | + # print "oi" | ||
285 | + # if self.button_raycasting_toggle: | ||
286 | + # ps.Publisher().sendMessage('Hide raycasting volume') | ||
287 | + # self.button_raycasting.SetBackgroundColour(self.GetParent().GetBackgroundColour()) | ||
288 | + # #self.button_raycasting.SetBitmapSelected(ID_TO_BMP2[0]) | ||
289 | + # self.button_raycasting_toggle = 0 | ||
290 | + # else: | ||
291 | + # ps.Publisher().sendMessage('Show raycasting volume') | ||
292 | + # self.button_raycasting_toggle = 1 | ||
293 | + # #self.button_raycasting.SetBitmapSelected(ID_TO_BMP2[1]) | ||
294 | + # self.button_raycasting.SetBackgroundColour((255,255,255)) |