Commit b6b1506bed151f054fc20b54bb85121814549987
1 parent
9a6b5311
Exists in
master
and in
6 other branches
ENH: Progress values fixed in the raycast
Showing
1 changed file
with
20 additions
and
17 deletions
Show diff stats
invesalius/data/volume.py
@@ -385,16 +385,17 @@ class Volume(): | @@ -385,16 +385,17 @@ class Volume(): | ||
385 | self.volume_properties.SetSpecular(shading['specular']) | 385 | self.volume_properties.SetSpecular(shading['specular']) |
386 | self.volume_properties.SetSpecularPower(shading['specularPower']) | 386 | self.volume_properties.SetSpecularPower(shading['specularPower']) |
387 | 387 | ||
388 | - def ApplyConvolution(self, imagedata): | 388 | + def ApplyConvolution(self, imagedata, update_progress = None): |
389 | number_filters = len(self.config['convolutionFilters']) | 389 | number_filters = len(self.config['convolutionFilters']) |
390 | if number_filters: | 390 | if number_filters: |
391 | - update_progress= vtk_utils.ShowProgress(number_filters) | 391 | + if not(update_progress): |
392 | + update_progress = vtk_utils.ShowProgress(number_filters) | ||
392 | for filter in self.config['convolutionFilters']: | 393 | for filter in self.config['convolutionFilters']: |
393 | convolve = vtk.vtkImageConvolve() | 394 | convolve = vtk.vtkImageConvolve() |
394 | convolve.SetInput(imagedata) | 395 | convolve.SetInput(imagedata) |
395 | convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) | 396 | convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) |
396 | convolve.AddObserver("ProgressEvent", lambda obj,evt: | 397 | convolve.AddObserver("ProgressEvent", lambda obj,evt: |
397 | - update_progress(convolve, "%s ..." % filter)) | 398 | + update_progress(convolve, "Rendering...")) |
398 | imagedata = convolve.GetOutput() | 399 | imagedata = convolve.GetOutput() |
399 | #convolve.GetOutput().ReleaseDataFlagOn() | 400 | #convolve.GetOutput().ReleaseDataFlagOn() |
400 | return imagedata | 401 | return imagedata |
@@ -402,8 +403,9 @@ class Volume(): | @@ -402,8 +403,9 @@ class Volume(): | ||
402 | def LoadVolume(self): | 403 | def LoadVolume(self): |
403 | proj = prj.Project() | 404 | proj = prj.Project() |
404 | image = proj.imagedata | 405 | image = proj.imagedata |
405 | - | ||
406 | - update_progress= vtk_utils.ShowProgress(4) | 406 | + |
407 | + number_filters = len(self.config['convolutionFilters']) | ||
408 | + update_progress= vtk_utils.ShowProgress(2 + number_filters) | ||
407 | 409 | ||
408 | # Flip original vtkImageData | 410 | # Flip original vtkImageData |
409 | flip = vtk.vtkImageFlip() | 411 | flip = vtk.vtkImageFlip() |
@@ -411,7 +413,7 @@ class Volume(): | @@ -411,7 +413,7 @@ class Volume(): | ||
411 | flip.SetFilteredAxis(1) | 413 | flip.SetFilteredAxis(1) |
412 | flip.FlipAboutOriginOn() | 414 | flip.FlipAboutOriginOn() |
413 | flip.AddObserver("ProgressEvent", lambda obj,evt: | 415 | flip.AddObserver("ProgressEvent", lambda obj,evt: |
414 | - update_progress(flip, "Fliping ...")) | 416 | + update_progress(flip, "Rendering...")) |
415 | flip.Update() | 417 | flip.Update() |
416 | 418 | ||
417 | image = flip.GetOutput() | 419 | image = flip.GetOutput() |
@@ -424,7 +426,7 @@ class Volume(): | @@ -424,7 +426,7 @@ class Volume(): | ||
424 | cast.SetShift(abs(scale[0])) | 426 | cast.SetShift(abs(scale[0])) |
425 | cast.SetOutputScalarTypeToUnsignedShort() | 427 | cast.SetOutputScalarTypeToUnsignedShort() |
426 | cast.AddObserver("ProgressEvent", lambda obj,evt: | 428 | cast.AddObserver("ProgressEvent", lambda obj,evt: |
427 | - update_progress(cast, "Casting ...")) | 429 | + update_progress(cast, "Rendering...")) |
428 | cast.Update() | 430 | cast.Update() |
429 | image2 = cast | 431 | image2 = cast |
430 | self.imagedata = image2 | 432 | self.imagedata = image2 |
@@ -434,7 +436,9 @@ class Volume(): | @@ -434,7 +436,9 @@ class Volume(): | ||
434 | else: | 436 | else: |
435 | self.Create8bColorTable(scale) | 437 | self.Create8bColorTable(scale) |
436 | self.Create8bOpacityTable(scale) | 438 | self.Create8bOpacityTable(scale) |
437 | - image2 = self.ApplyConvolution(image2.GetOutput()) | 439 | + |
440 | + | ||
441 | + image2 = self.ApplyConvolution(image2.GetOutput(), update_progress) | ||
438 | self.final_imagedata = image2 | 442 | self.final_imagedata = image2 |
439 | 443 | ||
440 | composite_function = vtk.vtkVolumeRayCastCompositeFunction() | 444 | composite_function = vtk.vtkVolumeRayCastCompositeFunction() |
@@ -449,21 +453,21 @@ class Volume(): | @@ -449,21 +453,21 @@ class Volume(): | ||
449 | if const.TYPE_RAYCASTING_MAPPER: | 453 | if const.TYPE_RAYCASTING_MAPPER: |
450 | volume_mapper = vtk.vtkVolumeRayCastMapper() | 454 | volume_mapper = vtk.vtkVolumeRayCastMapper() |
451 | #volume_mapper.AutoAdjustSampleDistancesOff() | 455 | #volume_mapper.AutoAdjustSampleDistancesOff() |
452 | - volume_mapper.SetInput(image2) | 456 | + #volume_mapper.SetInput(image2) |
453 | volume_mapper.SetVolumeRayCastFunction(composite_function) | 457 | volume_mapper.SetVolumeRayCastFunction(composite_function) |
454 | #volume_mapper.SetGradientEstimator(gradientEstimator) | 458 | #volume_mapper.SetGradientEstimator(gradientEstimator) |
455 | volume_mapper.IntermixIntersectingGeometryOn() | 459 | volume_mapper.IntermixIntersectingGeometryOn() |
456 | else: | 460 | else: |
457 | volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper() | 461 | volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper() |
458 | #volume_mapper.AutoAdjustSampleDistancesOff() | 462 | #volume_mapper.AutoAdjustSampleDistancesOff() |
459 | - volume_mapper.SetInput(image2) | 463 | + |
460 | volume_mapper.IntermixIntersectingGeometryOn() | 464 | volume_mapper.IntermixIntersectingGeometryOn() |
461 | #volume_mapper.SetBlendModeToMaximumIntensity() | 465 | #volume_mapper.SetBlendModeToMaximumIntensity() |
462 | - | ||
463 | - volume_mapper.AddObserver("ProgressEvent", lambda obj,evt: | ||
464 | - update_progress(volume_mapper, "Mapper ...")) | 466 | + volume_mapper.SetInput(image2) |
465 | self.volume_mapper = volume_mapper | 467 | self.volume_mapper = volume_mapper |
466 | - | 468 | + |
469 | + | ||
470 | + | ||
467 | # TODO: Look to this | 471 | # TODO: Look to this |
468 | #volume_mapper_hw = vtk.vtkVolumeTextureMapper3D() | 472 | #volume_mapper_hw = vtk.vtkVolumeTextureMapper3D() |
469 | #volume_mapper_hw.SetInput(image2) | 473 | #volume_mapper_hw.SetInput(image2) |
@@ -496,14 +500,12 @@ class Volume(): | @@ -496,14 +500,12 @@ class Volume(): | ||
496 | volume_mapper.SetImageSampleDistance(0.25) | 500 | volume_mapper.SetImageSampleDistance(0.25) |
497 | volume_mapper.SetSampleDistance(pix_diag / 5.0) | 501 | volume_mapper.SetSampleDistance(pix_diag / 5.0) |
498 | volume_properties.SetScalarOpacityUnitDistance(pix_diag) | 502 | volume_properties.SetScalarOpacityUnitDistance(pix_diag) |
499 | - | 503 | + |
500 | self.volume_properties = volume_properties | 504 | self.volume_properties = volume_properties |
501 | 505 | ||
502 | volume = vtk.vtkVolume() | 506 | volume = vtk.vtkVolume() |
503 | volume.SetMapper(volume_mapper) | 507 | volume.SetMapper(volume_mapper) |
504 | volume.SetProperty(volume_properties) | 508 | volume.SetProperty(volume_properties) |
505 | - volume.AddObserver("ProgressEvent", lambda obj,evt: | ||
506 | - update_progress(volume, "Volume ...")) | ||
507 | self.volume = volume | 509 | self.volume = volume |
508 | 510 | ||
509 | colour = self.GetBackgroundColour() | 511 | colour = self.GetBackgroundColour() |
@@ -511,6 +513,7 @@ class Volume(): | @@ -511,6 +513,7 @@ class Volume(): | ||
511 | ps.Publisher().sendMessage('Load volume into viewer', | 513 | ps.Publisher().sendMessage('Load volume into viewer', |
512 | (volume, colour, (self.ww, self.wl))) | 514 | (volume, colour, (self.ww, self.wl))) |
513 | 515 | ||
516 | + | ||
514 | def OnEnableTool(self, pubsub_evt): | 517 | def OnEnableTool(self, pubsub_evt): |
515 | print "OnEnableTool" | 518 | print "OnEnableTool" |
516 | tool_name, enable = pubsub_evt.data | 519 | tool_name, enable = pubsub_evt.data |