Commit 7eecf2b454cc1973e158c96d566c0af084573c22
1 parent
8ff12506
Exists in
master
and in
68 other branches
ADD: Reading shading config from raycasting preset
Showing
1 changed file
with
51 additions
and
10 deletions
Show diff stats
invesalius/data/volume.py
@@ -33,6 +33,35 @@ Kernels = { | @@ -33,6 +33,35 @@ Kernels = { | ||
33 | 1.0, 1.0, 1.0, 1.0, 1.0] | 33 | 1.0, 1.0, 1.0, 1.0, 1.0] |
34 | } | 34 | } |
35 | 35 | ||
36 | +SHADING = { | ||
37 | + "Default": { | ||
38 | + "ambient" :0.15, | ||
39 | + "diffuse" :0.9, | ||
40 | + "specular" :0.3, | ||
41 | + "specularPower" :15, | ||
42 | + }, | ||
43 | + | ||
44 | + "Glossy Vascular":{ | ||
45 | + "ambient" :0.15, | ||
46 | + "diffuse" :0.28, | ||
47 | + "specular" :1.42, | ||
48 | + "specularPower" :50, | ||
49 | + }, | ||
50 | + | ||
51 | + "Glossy Bone": { | ||
52 | + "ambient" :0.15, | ||
53 | + "diffuse" :0.24, | ||
54 | + "specular" :1.17, | ||
55 | + "specularPower" :6.98, | ||
56 | + }, | ||
57 | + | ||
58 | + "Endoscopy": { | ||
59 | + "ambient" :0.12, | ||
60 | + "diffuse" :0.64, | ||
61 | + "specular" :0.73, | ||
62 | + "specularPower" :50, | ||
63 | + } | ||
64 | +} | ||
36 | 65 | ||
37 | PRESETS = ["Airways", "Airways II", "Bone + Skin", "Bone + Skin II", "Dark Bone", | 66 | PRESETS = ["Airways", "Airways II", "Bone + Skin", "Bone + Skin II", "Dark Bone", |
38 | "Gold Bone", "Skin On Blue", "Skin On Blue II", "Soft + Skin", "Soft + Skin II", | 67 | "Gold Bone", "Skin On Blue", "Skin On Blue II", "Soft + Skin", "Soft + Skin II", |
@@ -58,20 +87,24 @@ class Volume(): | @@ -58,20 +87,24 @@ class Volume(): | ||
58 | 'Set raycasting preset') | 87 | 'Set raycasting preset') |
59 | ps.Publisher().subscribe(self.SetWWWL, | 88 | ps.Publisher().subscribe(self.SetWWWL, |
60 | 'Set raycasting wwwl') | 89 | 'Set raycasting wwwl') |
90 | + ps.Publisher().subscribe(self.Refresh, | ||
91 | + 'Set raycasting refresh') | ||
61 | 92 | ||
62 | def OnLoadVolume(self, pubsub_evt): | 93 | def OnLoadVolume(self, pubsub_evt): |
63 | label = pubsub_evt.data | 94 | label = pubsub_evt.data |
64 | - self.LoadConfig(label) | 95 | + #self.LoadConfig(label) |
65 | self.LoadVolume() | 96 | self.LoadVolume() |
66 | 97 | ||
67 | def LoadConfig(self, label): | 98 | def LoadConfig(self, label): |
99 | + print label | ||
68 | if not label: | 100 | if not label: |
69 | label = "Skin On Blue" | 101 | label = "Skin On Blue" |
70 | 102 | ||
71 | - path = os.path.join("..", "presets", "raycasting", | ||
72 | - label+".plist") | ||
73 | - self.config = plistlib.readPlist(path) | ||
74 | - print path | 103 | + path = os.path.join("..", "presets", "raycasting", |
104 | + label+".plist") | ||
105 | + label = plistlib.readPlist(path) | ||
106 | + self.config = label | ||
107 | + #print path | ||
75 | 108 | ||
76 | def OnHideVolume(self, pubsub_evt): | 109 | def OnHideVolume(self, pubsub_evt): |
77 | self.volume.SetVisibility(0) | 110 | self.volume.SetVisibility(0) |
@@ -90,6 +123,7 @@ class Volume(): | @@ -90,6 +123,7 @@ class Volume(): | ||
90 | self.LoadConfig(pubsub_evt.data) | 123 | self.LoadConfig(pubsub_evt.data) |
91 | self.Create16bColorTable(self.scale) | 124 | self.Create16bColorTable(self.scale) |
92 | self.CreateOpacityTable(self.scale) | 125 | self.CreateOpacityTable(self.scale) |
126 | + self.SetShading() | ||
93 | colour = self.CreateBackgroundColor() | 127 | colour = self.CreateBackgroundColor() |
94 | ps.Publisher.sendMessage('Set colour interactor', colour) | 128 | ps.Publisher.sendMessage('Set colour interactor', colour) |
95 | 129 | ||
@@ -122,6 +156,9 @@ class Volume(): | @@ -122,6 +156,9 @@ class Volume(): | ||
122 | print curve | 156 | print curve |
123 | ps.Publisher().sendMessage('Render volume viewer', None) | 157 | ps.Publisher().sendMessage('Render volume viewer', None) |
124 | 158 | ||
159 | + def Refresh(self, pubsub_evt): | ||
160 | + self.Create16bColorTable(self.scale) | ||
161 | + self.CreateOpacityTable(self.scale) | ||
125 | 162 | ||
126 | #*************** | 163 | #*************** |
127 | def Create16bColorTable(self, scale): | 164 | def Create16bColorTable(self, scale): |
@@ -130,6 +167,7 @@ class Volume(): | @@ -130,6 +167,7 @@ class Volume(): | ||
130 | else: | 167 | else: |
131 | color_transfer = vtk.vtkColorTransferFunction() | 168 | color_transfer = vtk.vtkColorTransferFunction() |
132 | color_transfer.RemoveAllPoints() | 169 | color_transfer.RemoveAllPoints() |
170 | + print self.config | ||
133 | curve_table = self.config['16bitClutCurves'] | 171 | curve_table = self.config['16bitClutCurves'] |
134 | color_table = self.config['16bitClutColors'] | 172 | color_table = self.config['16bitClutColors'] |
135 | colors = [] | 173 | colors = [] |
@@ -247,7 +285,13 @@ class Volume(): | @@ -247,7 +285,13 @@ class Volume(): | ||
247 | 285 | ||
248 | return colors, opacities, color_background, p['useShading'] | 286 | return colors, opacities, color_background, p['useShading'] |
249 | 287 | ||
250 | - | 288 | + def SetShading(self): |
289 | + print "Shading" | ||
290 | + shading = SHADING[self.config['shading']] | ||
291 | + self.volume_properties.SetAmbient(shading['ambient']) | ||
292 | + self.volume_properties.SetDiffuse(shading['diffuse']) | ||
293 | + self.volume_properties.SetSpecular(shading['specular']) | ||
294 | + self.volume_properties.SetSpecularPower(shading['specularPower']) | ||
251 | 295 | ||
252 | def LoadVolume(self): | 296 | def LoadVolume(self): |
253 | proj = Project() | 297 | proj = Project() |
@@ -318,13 +362,10 @@ class Volume(): | @@ -318,13 +362,10 @@ class Volume(): | ||
318 | volume_properties.ShadeOn() | 362 | volume_properties.ShadeOn() |
319 | else: | 363 | else: |
320 | volume_properties.ShadeOff() | 364 | volume_properties.ShadeOff() |
321 | - volume_properties.SetAmbient(0.1) | ||
322 | - volume_properties.SetDiffuse(0.6) | ||
323 | - volume_properties.SetSpecular(0.5) | ||
324 | - volume_properties.SetSpecularPower(44.0) | ||
325 | 365 | ||
326 | volume_properties.SetInterpolationTypeToLinear() | 366 | volume_properties.SetInterpolationTypeToLinear() |
327 | volume_properties.SetColor(self.color_transfer) | 367 | volume_properties.SetColor(self.color_transfer) |
368 | + self.volume_properties = volume_properties | ||
328 | 369 | ||
329 | try: | 370 | try: |
330 | volume_properties.SetScalarOpacity(self.opacity_transfer_func) | 371 | volume_properties.SetScalarOpacity(self.opacity_transfer_func) |