Skip to content

Commit

Permalink
Merge pull request #63 from sankhesh/perf_updates
Browse files Browse the repository at this point in the history
Minor improvements to the head and neck example
  • Loading branch information
psavery authored Oct 30, 2023
2 parents 9c12ff4 + ee49877 commit f77b1d1
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions Examples/Python/cinematic_rendering/head_and_neck_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import signal

import numpy as np
import logging

import vtk

Expand All @@ -10,6 +11,8 @@
# Kill the program when ctrl-c is used
signal.signal(signal.SIGINT, signal.SIG_DFL)

logging.basicConfig(level=logging.INFO)

data_url = "https://data.kitware.com/api/v1/file/62daaa69bddec9d0c4bfd42a/download"
data_file = "head_and_neck_ct.vtk"

Expand Down Expand Up @@ -37,9 +40,6 @@

renWin = vtkRenderingLookingGlass.vtkLookingGlassInterface.CreateLookingGlassRenderWindow()

if renWin.GetDeviceType() == "standard":
# This looks better on large settings
renWin.SetDeviceType("large")

renWin.AddRenderer(ren)

Expand All @@ -59,6 +59,11 @@
volume_prop.SetScalarOpacityUnitDistance(1.5)
volume_prop.SetInterpolationType(vtk.VTK_LINEAR_INTERPOLATION)

volume_prop_l = vtk.vtkVolumeProperty()
volume_prop_l.ShadeOn()
volume_prop_l.SetScalarOpacityUnitDistance(1.5)
volume_prop_l.SetInterpolationType(vtk.VTK_LINEAR_INTERPOLATION)

# volume_prop.SetDiffuse(1.0)
# volume_prop.SetAmbient(0.3)
# volume_prop.SetSpecular(0.1)
Expand Down Expand Up @@ -92,9 +97,37 @@
opacity.AddPoint(3231.0, 0.875)
volume_prop.SetScalarOpacity(opacity)

opacity_l = vtk.vtkPiecewiseFunction()
opacity_l.AddPoint(-1000, 0)
opacity_l.AddPoint(-600, 0)
opacity_l.AddPoint(-599, 0.15)
opacity_l.AddPoint(-400, 0.15)
opacity_l.AddPoint(-399, 0)
opacity_l.AddPoint(2952, 0)
volume_prop_l.SetScalarOpacity(opacity_l)

color_l = vtk.vtkColorTransferFunction()
color_l.AddRGBPoint(-1000, 0.3, 0.3, 1)
color_l.AddRGBPoint(-600, 0, 0, 1)
color_l.AddRGBPoint(-530, 0.134704, 0.781726, 0.0724558)
color_l.AddRGBPoint(-460, 0.929244, 1, 0.109473)
color_l.AddRGBPoint(-400, 0.888889, 0.254949, 0.0240258)
color_l.AddRGBPoint(2952, 1, 0.3, 0.3)
volume_prop_l.SetColor(color_l)

volume = vtk.vtkVolume()
volume.SetProperty(volume_prop)

def on_key_press(style, event):
if style.GetInteractor().GetKeySym() == 'l':
logging.info('Switching to lung TF')
volume.SetProperty(volume_prop_l)
renWin.Render()
elif style.GetInteractor().GetKeySym() == 'b':
logging.info('Switching to bone TF')
volume.SetProperty(volume_prop)
renWin.Render()

mapper = vtk.vtkGPUVolumeRayCastMapper()
mapper.SetInputData(image)
mapper.SetBlendModeToComposite()
Expand Down Expand Up @@ -139,11 +172,18 @@
# Set up the interactor style
iren_style = vtk.vtkInteractorStyleTrackballCamera()
iren.SetInteractorStyle(iren_style)
iren_style.AddObserver("KeyPressEvent", on_key_press)

def adjust_resolution(mapper, event):
interactive = volume.GetAllocatedRenderTime() < 1
mapper.SetUseJittering(not interactive)
volume_prop.SetShade(not interactive)
mapper.SetAutoAdjustSampleDistances(not interactive)
mapper.SetVolumetricScatteringBlending(0.0 if interactive else volumetric_scattering_blending)
mapper.SetAutoAdjustSampleDistances(not interactive)
mapper.SetSampleDistance(5.0 if interactive else 1.0)
light1.SetSwitch(not interactive)
light2.SetSwitch(not interactive)
light3.SetSwitch(not interactive)
light4.SetSwitch(not interactive)

mapper.AddObserver("VolumeMapperRenderStartEvent", adjust_resolution)

Expand Down

0 comments on commit f77b1d1

Please sign in to comment.