Commit 1a050b55e99b9a30652e5ee07b68c69f72ebd265
1 parent
ced29bd1
Exists in
master
and in
68 other branches
ENH: Reading 8 bit preset raycasting
Showing
1 changed file
with
31 additions
and
15 deletions
Show diff stats
invesalius/data/volume.py
| @@ -122,12 +122,21 @@ class Volume(): | @@ -122,12 +122,21 @@ class Volume(): | ||
| 122 | 122 | ||
| 123 | def SetRaycastPreset(self, pubsub_evt): | 123 | def SetRaycastPreset(self, pubsub_evt): |
| 124 | self.LoadConfig(pubsub_evt.data) | 124 | self.LoadConfig(pubsub_evt.data) |
| 125 | + self.__config_preset() | ||
| 125 | self.Create16bColorTable(self.scale) | 126 | self.Create16bColorTable(self.scale) |
| 126 | self.CreateOpacityTable(self.scale) | 127 | self.CreateOpacityTable(self.scale) |
| 127 | self.SetShading() | 128 | self.SetShading() |
| 128 | colour = self.CreateBackgroundColor() | 129 | colour = self.CreateBackgroundColor() |
| 129 | ps.Publisher.sendMessage('Set colour interactor', colour) | 130 | ps.Publisher.sendMessage('Set colour interactor', colour) |
| 130 | 131 | ||
| 132 | + def __config_preset(self): | ||
| 133 | + if self.config['advancedCLUT']: | ||
| 134 | + self.Create16bColorTable(self.scale) | ||
| 135 | + self.CreateOpacityTable(self.scale) | ||
| 136 | + else: | ||
| 137 | + self.Create8bColorTable() | ||
| 138 | + self.Create8bOpacityTable() | ||
| 139 | + | ||
| 131 | def SetWWWL(self, pubsub_evt): | 140 | def SetWWWL(self, pubsub_evt): |
| 132 | ww, wl, n = pubsub_evt.data | 141 | ww, wl, n = pubsub_evt.data |
| 133 | print "Setting ww, wl", ww, wl | 142 | print "Setting ww, wl", ww, wl |
| @@ -188,13 +197,18 @@ class Volume(): | @@ -188,13 +197,18 @@ class Volume(): | ||
| 188 | def Create8bColorTable(self): | 197 | def Create8bColorTable(self): |
| 189 | color_transfer = vtk.vtkColorTransferFunction() | 198 | color_transfer = vtk.vtkColorTransferFunction() |
| 190 | color_preset = self.config['CLUT'] | 199 | color_preset = self.config['CLUT'] |
| 191 | - p = plistlib.readPlist( os.path.join('ColorList', color_preset + '.plist')) | ||
| 192 | - r = p['Red'] | ||
| 193 | - g = p['Green'] | ||
| 194 | - b = p['Blue'] | ||
| 195 | - colors = zip(r,g,b) | ||
| 196 | - for i,rgb in enumerate(colors): | ||
| 197 | - color_transfer.AddRGBPoint(i, *rgb) | 200 | + if color_preset != "No CLUT": |
| 201 | + p = plistlib.readPlist( os.path.join('ColorList', color_preset + '.plist')) | ||
| 202 | + r = p['Red'] | ||
| 203 | + g = p['Green'] | ||
| 204 | + b = p['Blue'] | ||
| 205 | + colors = zip(r,g,b) | ||
| 206 | + ww = self.config['ww'] | ||
| 207 | + wl = self.TranslateScale(scale, self.config['wl']) | ||
| 208 | + inc = ww / 254.0 | ||
| 209 | + for i,rgb in enumerate(colors): | ||
| 210 | + print i,inc, ww, wl - ww/2 + i * inc, rgb | ||
| 211 | + color_transfer.AddRGBPoint((wl - ww/2) + (i * inc), *[i/255.0 for i in rgb]) | ||
| 198 | return color_transfer | 212 | return color_transfer |
| 199 | 213 | ||
| 200 | def CreateOpacityTable(self, scale): | 214 | def CreateOpacityTable(self, scale): |
| @@ -236,22 +250,23 @@ class Volume(): | @@ -236,22 +250,23 @@ class Volume(): | ||
| 236 | opacities = [] | 250 | opacities = [] |
| 237 | 251 | ||
| 238 | ww = self.config['ww'] | 252 | ww = self.config['ww'] |
| 239 | - wl = self.config['wl'] | 253 | + wl = self.TranslateScale(scale, self.config['wl']) |
| 240 | 254 | ||
| 241 | print ww, wl | 255 | print ww, wl |
| 242 | 256 | ||
| 243 | l1 = wl - ww/2.0 | 257 | l1 = wl - ww/2.0 |
| 244 | l2 = wl + ww/2.0 | 258 | l2 = wl + ww/2.0 |
| 245 | 259 | ||
| 260 | + opacity_transfer_func.RemoveAllPoints() | ||
| 261 | + opacity_transfer_func.AddSegment(0, 0, 2**16-1, 0) | ||
| 262 | + | ||
| 263 | + print "l1, l2", l1, l2 | ||
| 264 | + | ||
| 246 | k1 = 0.0 | 265 | k1 = 0.0 |
| 247 | k2 = 1.0 | 266 | k2 = 1.0 |
| 248 | 267 | ||
| 249 | - opacity_transfer_func.AddPoint(0, 0) | ||
| 250 | - opacity_transfer_func.AddPoint(l1-1, 0) | ||
| 251 | - opacity_transfer_func.AddPoint(l1, 1) | 268 | + opacity_transfer_func.AddPoint(l1, 0) |
| 252 | opacity_transfer_func.AddPoint(l2, 1) | 269 | opacity_transfer_func.AddPoint(l2, 1) |
| 253 | - opacity_transfer_func.AddPoint(l2+1, 0) | ||
| 254 | - opacity_transfer_func.AddPoint(255, 0) | ||
| 255 | 270 | ||
| 256 | return opacity_transfer_func | 271 | return opacity_transfer_func |
| 257 | 272 | ||
| @@ -317,6 +332,7 @@ class Volume(): | @@ -317,6 +332,7 @@ class Volume(): | ||
| 317 | 332 | ||
| 318 | cast = vtk.vtkImageShiftScale() | 333 | cast = vtk.vtkImageShiftScale() |
| 319 | cast.SetInput(image) | 334 | cast.SetInput(image) |
| 335 | + print "> ", self.config['advancedCLUT'] | ||
| 320 | if self.config['advancedCLUT']: | 336 | if self.config['advancedCLUT']: |
| 321 | cast.SetShift(abs(scale[0])) | 337 | cast.SetShift(abs(scale[0])) |
| 322 | #cast.SetScale(2**16-1) | 338 | #cast.SetScale(2**16-1) |
| @@ -328,8 +344,8 @@ class Volume(): | @@ -328,8 +344,8 @@ class Volume(): | ||
| 328 | image2 = cast | 344 | image2 = cast |
| 329 | else: | 345 | else: |
| 330 | cast.SetShift(abs(scale[0])) | 346 | cast.SetShift(abs(scale[0])) |
| 331 | - cast.SetScale(255.0/(scale[1] - scale[0])) | ||
| 332 | - cast.SetOutputScalarTypeToUnsignedChar() | 347 | + #cast.SetScale(255.0/(scale[1] - scale[0])) |
| 348 | + cast.SetOutputScalarTypeToUnsignedShort() | ||
| 333 | color_transfer = self.Create8bColorTable() | 349 | color_transfer = self.Create8bColorTable() |
| 334 | opacity_transfer_func = self.Create8bOpacityTable() | 350 | opacity_transfer_func = self.Create8bOpacityTable() |
| 335 | cast.Update() | 351 | cast.Update() |