Commit 1a050b55e99b9a30652e5ee07b68c69f72ebd265

Authored by tfmoraes
1 parent ced29bd1

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 122  
123 123 def SetRaycastPreset(self, pubsub_evt):
124 124 self.LoadConfig(pubsub_evt.data)
  125 + self.__config_preset()
125 126 self.Create16bColorTable(self.scale)
126 127 self.CreateOpacityTable(self.scale)
127 128 self.SetShading()
128 129 colour = self.CreateBackgroundColor()
129 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 140 def SetWWWL(self, pubsub_evt):
132 141 ww, wl, n = pubsub_evt.data
133 142 print "Setting ww, wl", ww, wl
... ... @@ -188,13 +197,18 @@ class Volume():
188 197 def Create8bColorTable(self):
189 198 color_transfer = vtk.vtkColorTransferFunction()
190 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 212 return color_transfer
199 213  
200 214 def CreateOpacityTable(self, scale):
... ... @@ -236,22 +250,23 @@ class Volume():
236 250 opacities = []
237 251  
238 252 ww = self.config['ww']
239   - wl = self.config['wl']
  253 + wl = self.TranslateScale(scale, self.config['wl'])
240 254  
241 255 print ww, wl
242 256  
243 257 l1 = wl - ww/2.0
244 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 265 k1 = 0.0
247 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 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 271 return opacity_transfer_func
257 272  
... ... @@ -317,6 +332,7 @@ class Volume():
317 332  
318 333 cast = vtk.vtkImageShiftScale()
319 334 cast.SetInput(image)
  335 + print "> ", self.config['advancedCLUT']
320 336 if self.config['advancedCLUT']:
321 337 cast.SetShift(abs(scale[0]))
322 338 #cast.SetScale(2**16-1)
... ... @@ -328,8 +344,8 @@ class Volume():
328 344 image2 = cast
329 345 else:
330 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 349 color_transfer = self.Create8bColorTable()
334 350 opacity_transfer_func = self.Create8bOpacityTable()
335 351 cast.Update()
... ...