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 | 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 | 66 | PRESETS = ["Airways", "Airways II", "Bone + Skin", "Bone + Skin II", "Dark Bone", |
38 | 67 | "Gold Bone", "Skin On Blue", "Skin On Blue II", "Soft + Skin", "Soft + Skin II", |
... | ... | @@ -58,20 +87,24 @@ class Volume(): |
58 | 87 | 'Set raycasting preset') |
59 | 88 | ps.Publisher().subscribe(self.SetWWWL, |
60 | 89 | 'Set raycasting wwwl') |
90 | + ps.Publisher().subscribe(self.Refresh, | |
91 | + 'Set raycasting refresh') | |
61 | 92 | |
62 | 93 | def OnLoadVolume(self, pubsub_evt): |
63 | 94 | label = pubsub_evt.data |
64 | - self.LoadConfig(label) | |
95 | + #self.LoadConfig(label) | |
65 | 96 | self.LoadVolume() |
66 | 97 | |
67 | 98 | def LoadConfig(self, label): |
99 | + print label | |
68 | 100 | if not label: |
69 | 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 | 109 | def OnHideVolume(self, pubsub_evt): |
77 | 110 | self.volume.SetVisibility(0) |
... | ... | @@ -90,6 +123,7 @@ class Volume(): |
90 | 123 | self.LoadConfig(pubsub_evt.data) |
91 | 124 | self.Create16bColorTable(self.scale) |
92 | 125 | self.CreateOpacityTable(self.scale) |
126 | + self.SetShading() | |
93 | 127 | colour = self.CreateBackgroundColor() |
94 | 128 | ps.Publisher.sendMessage('Set colour interactor', colour) |
95 | 129 | |
... | ... | @@ -122,6 +156,9 @@ class Volume(): |
122 | 156 | print curve |
123 | 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 | 164 | def Create16bColorTable(self, scale): |
... | ... | @@ -130,6 +167,7 @@ class Volume(): |
130 | 167 | else: |
131 | 168 | color_transfer = vtk.vtkColorTransferFunction() |
132 | 169 | color_transfer.RemoveAllPoints() |
170 | + print self.config | |
133 | 171 | curve_table = self.config['16bitClutCurves'] |
134 | 172 | color_table = self.config['16bitClutColors'] |
135 | 173 | colors = [] |
... | ... | @@ -247,7 +285,13 @@ class Volume(): |
247 | 285 | |
248 | 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 | 296 | def LoadVolume(self): |
253 | 297 | proj = Project() |
... | ... | @@ -318,13 +362,10 @@ class Volume(): |
318 | 362 | volume_properties.ShadeOn() |
319 | 363 | else: |
320 | 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 | 366 | volume_properties.SetInterpolationTypeToLinear() |
327 | 367 | volume_properties.SetColor(self.color_transfer) |
368 | + self.volume_properties = volume_properties | |
328 | 369 | |
329 | 370 | try: |
330 | 371 | volume_properties.SetScalarOpacity(self.opacity_transfer_func) | ... | ... |