Commit 53e99da85d4acc68b2ccd220356b9fe11eb91f0b

Authored by tfmoraes
1 parent bc5cd630

ENH: Applying the convolution filter when a new raycasting preset is setted

Showing 1 changed file with 18 additions and 10 deletions   Show diff stats
invesalius/data/volume.py
@@ -129,6 +129,8 @@ class Volume(): @@ -129,6 +129,8 @@ class Volume():
129 else: 129 else:
130 self.Create8bColorTable(self.scale) 130 self.Create8bColorTable(self.scale)
131 self.Create8bOpacityTable(self.scale) 131 self.Create8bOpacityTable(self.scale)
  132 + image = self.DoConvolutionFilters(self.imagedata.GetOutput())
  133 + self.volume_mapper.SetInput(image)
132 134
133 def OnSetRelativeWindowLevel(self, pubsub_evt): 135 def OnSetRelativeWindowLevel(self, pubsub_evt):
134 diff_ww, diff_wl = pubsub_evt.data 136 diff_ww, diff_wl = pubsub_evt.data
@@ -327,6 +329,15 @@ class Volume(): @@ -327,6 +329,15 @@ class Volume():
327 self.volume_properties.SetSpecular(shading['specular']) 329 self.volume_properties.SetSpecular(shading['specular'])
328 self.volume_properties.SetSpecularPower(shading['specularPower']) 330 self.volume_properties.SetSpecularPower(shading['specularPower'])
329 331
  332 + def DoConvolutionFilters(self, imagedata):
  333 + for filter in self.config['convolutionFilters']:
  334 + convolve = vtk.vtkImageConvolve()
  335 + convolve.SetInput(imagedata)
  336 + convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]])
  337 + convolve.Update()
  338 + imagedata = convolve.GetOutput()
  339 + return imagedata
  340 +
330 def LoadVolume(self): 341 def LoadVolume(self):
331 proj = Project() 342 proj = Project()
332 image = proj.imagedata 343 image = proj.imagedata
@@ -340,7 +351,6 @@ class Volume(): @@ -340,7 +351,6 @@ class Volume():
340 351
341 image = flip.GetOutput() 352 image = flip.GetOutput()
342 353
343 -  
344 scale = image.GetScalarRange() 354 scale = image.GetScalarRange()
345 self.scale = scale 355 self.scale = scale
346 356
@@ -350,6 +360,7 @@ class Volume(): @@ -350,6 +360,7 @@ class Volume():
350 cast.SetOutputScalarTypeToUnsignedShort() 360 cast.SetOutputScalarTypeToUnsignedShort()
351 cast.Update() 361 cast.Update()
352 image2 = cast 362 image2 = cast
  363 + self.imagedata = image2
353 if self.config['advancedCLUT']: 364 if self.config['advancedCLUT']:
354 self.Create16bColorTable(scale) 365 self.Create16bColorTable(scale)
355 self.CreateOpacityTable(scale) 366 self.CreateOpacityTable(scale)
@@ -357,12 +368,7 @@ class Volume(): @@ -357,12 +368,7 @@ class Volume():
357 self.Create8bColorTable(scale) 368 self.Create8bColorTable(scale)
358 self.Create8bOpacityTable(scale) 369 self.Create8bOpacityTable(scale)
359 370
360 - convolve = vtk.vtkImageConvolve()  
361 - convolve.SetInput(image2.GetOutput())  
362 - convolve.SetKernel5x5([i/60.0 for i in Kernels[self.config['convolutionFilters'][0]]])  
363 - convolve.Update()  
364 -  
365 - image2 = convolve 371 + image2 = self.DoConvolutionFilters(image2.GetOutput())
366 372
367 composite_function = vtk.vtkVolumeRayCastCompositeFunction() 373 composite_function = vtk.vtkVolumeRayCastCompositeFunction()
368 composite_function.SetCompositeMethodToInterpolateFirst() 374 composite_function.SetCompositeMethodToInterpolateFirst()
@@ -376,22 +382,24 @@ class Volume(): @@ -376,22 +382,24 @@ class Volume():
376 if const.TYPE_RAYCASTING_MAPPER: 382 if const.TYPE_RAYCASTING_MAPPER:
377 volume_mapper = vtk.vtkVolumeRayCastMapper() 383 volume_mapper = vtk.vtkVolumeRayCastMapper()
378 #volume_mapper.AutoAdjustSampleDistancesOff() 384 #volume_mapper.AutoAdjustSampleDistancesOff()
379 - volume_mapper.SetInput(image2.GetOutput()) 385 + volume_mapper.SetInput(image2)
380 volume_mapper.SetVolumeRayCastFunction(composite_function) 386 volume_mapper.SetVolumeRayCastFunction(composite_function)
381 #volume_mapper.SetGradientEstimator(gradientEstimator) 387 #volume_mapper.SetGradientEstimator(gradientEstimator)
382 volume_mapper.IntermixIntersectingGeometryOn() 388 volume_mapper.IntermixIntersectingGeometryOn()
383 else: 389 else:
384 volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper() 390 volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper()
385 #volume_mapper.AutoAdjustSampleDistancesOff() 391 #volume_mapper.AutoAdjustSampleDistancesOff()
386 - volume_mapper.SetInput(image2.GetOutput()) 392 + volume_mapper.SetInput(image2)
387 volume_mapper.IntermixIntersectingGeometryOn() 393 volume_mapper.IntermixIntersectingGeometryOn()
388 394
  395 + self.volume_mapper = volume_mapper
  396 +
389 # TODO: Look to this 397 # TODO: Look to this
390 #volume_mapper = vtk.vtkVolumeTextureMapper2D() 398 #volume_mapper = vtk.vtkVolumeTextureMapper2D()
391 #volume_mapper.SetInput(image2.GetOutput()) 399 #volume_mapper.SetInput(image2.GetOutput())
392 400
393 #Cut Plane 401 #Cut Plane
394 - CutPlane(image2.GetOutput(), volume_mapper) 402 + CutPlane(image2, volume_mapper)
395 403
396 #self.color_transfer = color_transfer 404 #self.color_transfer = color_transfer
397 405