From 0bc27bcb98f3788d2742e4a38f8317d76ffcb276 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Wed, 9 Dec 2009 13:06:17 +0000 Subject: [PATCH] FIX: Better MIP Support, added a MIP preset --- .gitattributes | 1 + invesalius/constants.py | 4 ++-- invesalius/data/volume.py | 55 +++++++++++++++++++++++++++---------------------------- presets/raycasting/MIP.plist | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 30 deletions(-) create mode 100644 presets/raycasting/MIP.plist diff --git a/.gitattributes b/.gitattributes index 3888c6e..94f1e59 100644 --- a/.gitattributes +++ b/.gitattributes @@ -157,6 +157,7 @@ presets/raycasting/Glossy.plist -text presets/raycasting/Gold[!!-~]Bone.plist -text presets/raycasting/High[!!-~]Contrast.plist -text presets/raycasting/Low[!!-~]Contrast.plist -text +presets/raycasting/MIP.plist -text presets/raycasting/Mid[!!-~]Contrast.plist -text presets/raycasting/No[!!-~]Shading.plist -text presets/raycasting/Pencil.plist -text diff --git a/invesalius/constants.py b/invesalius/constants.py index b8eb90f..ed21f83 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -225,7 +225,7 @@ WINDOW_LEVEL = {"Abdomen":(350,50), "Vasculature - Hard":(240,80), "Vasculature - Soft":(650,160)} -REDUCE_IMAGEDATA_QUALITY = 1 +REDUCE_IMAGEDATA_QUALITY = 0 ICON_DIR = os.path.abspath(os.path.join('..', 'icons')) @@ -239,7 +239,7 @@ ID_TO_BMP = {VOL_FRONT: ["Front", os.path.join(ICON_DIR, "view_front.png")], } # if 1, use vtkVolumeRaycastMapper, if 0, use vtkFixedPointVolumeRayCastMapper -TYPE_RAYCASTING_MAPPER = 1 +TYPE_RAYCASTING_MAPPER = 0 folder=RAYCASTING_PRESETS_DIRECTORY= os.path.abspath(os.path.join("..", "presets", diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 8a99bc0..7d023b3 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -70,7 +70,7 @@ SHADING = { class Volume(): - + def __init__(self): self.config = None self.exist = None @@ -81,9 +81,9 @@ class Volume(): self.curve = 0 self.plane = None self.plane_on = False - + self.__bind_events() - + def __bind_events(self): ps.Publisher().subscribe(self.OnHideVolume, 'Hide raycasting volume') @@ -387,12 +387,22 @@ class Volume(): self.volume_properties.SetSpecularPower(shading['specularPower']) def SetTypeRaycasting(self): - if self.config['name'].upper().startswith('MIP'): - print "MIP" - self.volume_mapper.SetBlendModeToMaximumIntensity() + if self.volume_mapper.IsA("vtkFixedPointVolumeRayCastMapper"): + if self.config.get('MIP', False): + print "MIP" + self.volume_mapper.SetBlendModeToMaximumIntensity() + else: + print "Composite" + self.volume_mapper.SetBlendModeToComposite() else: - print "Composite" - self.volume_mapper.SetBlendModeToComposite() + if self.config.get('MIP', False): + print "MIP" + raycasting_function = vtk.vtkVolumeRayCastMIPFunction() + else: + print "Composite" + raycasting_function = vtk.vtkVolumeRayCastCompositeFunction() + raycasting_function.SetCompositeMethodToInterpolateFirst() + self.volume_mapper.SetVolumeRayCastFunction(raycasting_function) def ApplyConvolution(self, imagedata, update_progress = None): number_filters = len(self.config['convolutionFilters']) @@ -412,7 +422,7 @@ class Volume(): def LoadVolume(self): proj = prj.Project() image = proj.imagedata - + number_filters = len(self.config['convolutionFilters']) update_progress= vtk_utils.ShowProgress(2 + number_filters) @@ -424,7 +434,7 @@ class Volume(): flip.AddObserver("ProgressEvent", lambda obj,evt: update_progress(flip, "Rendering...")) flip.Update() - + image = flip.GetOutput() scale = image.GetScalarRange() @@ -445,17 +455,10 @@ class Volume(): else: self.Create8bColorTable(scale) self.Create8bOpacityTable(scale) - - + image2 = self.ApplyConvolution(image2.GetOutput(), update_progress) self.final_imagedata = image2 - composite_function = vtk.vtkVolumeRayCastCompositeFunction() - composite_function.SetCompositeMethodToInterpolateFirst() - - gradientEstimator = vtk.vtkFiniteDifferenceGradientEstimator() - gradientEstimator.SetGradientMagnitudeScale(1) - # Changed the vtkVolumeRayCast to vtkFixedPointVolumeRayCastMapper # because it's faster and the image is better # TODO: To test if it's true. @@ -463,7 +466,7 @@ class Volume(): volume_mapper = vtk.vtkVolumeRayCastMapper() #volume_mapper.AutoAdjustSampleDistancesOff() #volume_mapper.SetInput(image2) - volume_mapper.SetVolumeRayCastFunction(composite_function) + #volume_mapper.SetVolumeRayCastFunction(composite_function) #volume_mapper.SetGradientEstimator(gradientEstimator) volume_mapper.IntermixIntersectingGeometryOn() self.volume_mapper = volume_mapper @@ -471,9 +474,9 @@ class Volume(): volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper() #volume_mapper.AutoAdjustSampleDistancesOff() self.volume_mapper = volume_mapper - self.SetTypeRaycasting() volume_mapper.IntermixIntersectingGeometryOn() + self.SetTypeRaycasting() volume_mapper.SetInput(image2) # TODO: Look to this @@ -487,11 +490,6 @@ class Volume(): volume_properties = vtk.vtkVolumeProperty() #volume_properties.IndependentComponentsOn() - if self.config['useShading']: - volume_properties.ShadeOn() - else: - volume_properties.ShadeOff() - volume_properties.SetInterpolationTypeToLinear() volume_properties.SetColor(self.color_transfer) @@ -508,20 +506,21 @@ class Volume(): volume_mapper.SetImageSampleDistance(0.25) volume_mapper.SetSampleDistance(pix_diag / 5.0) volume_properties.SetScalarOpacityUnitDistance(pix_diag) - + self.volume_properties = volume_properties + self.SetShading() + volume = vtk.vtkVolume() volume.SetMapper(volume_mapper) volume.SetProperty(volume_properties) self.volume = volume - + colour = self.GetBackgroundColour() ps.Publisher().sendMessage('Load volume into viewer', (volume, colour, (self.ww, self.wl))) - def OnEnableTool(self, pubsub_evt): print "OnEnableTool" tool_name, enable = pubsub_evt.data diff --git a/presets/raycasting/MIP.plist b/presets/raycasting/MIP.plist new file mode 100644 index 0000000..b1fa818 --- /dev/null +++ b/presets/raycasting/MIP.plist @@ -0,0 +1,104 @@ + + + + + 16bitClutColors + + + + blue + 0.0 + green + 0.0 + red + 0.0 + + + blue + 1.0 + green + 1.0 + red + 1.0 + + + blue + 1.0 + green + 1.0 + red + 1.0 + + + blue + 1.0 + green + 1.0 + red + 1.0 + + + + 16bitClutCurves + + + + x + -1024.0 + y + 0.0 + + + x + 596.66286215978903 + y + 0.25342465753424659 + + + x + 2541.4582967515362 + y + 1.0 + + + x + 3032.9999999999995 + y + 1.0 + + + + CLUT + 16-bit CLUT + advancedCLUT + + backgroundColorBlueComponent + 0.0 + backgroundColorGreenComponent + 0.0 + backgroundColorRedComponent + 0.0 + convolutionFilters + + Basic Smooth 5x5 + + groupName + Soft Tissue CT + name + MIP + opacity + Logarithmic Inverse Table + projection + 1 + shading + Endoscopy + useShading + + MIP + + wl + -439.46817016601562 + ww + 408.62579345703125 + + -- libgit2 0.21.2