[vtkusers] Volume rendering - cannot make the image semi-transparecy

caseywang777 caseywang777 at gmail.com
Tue Nov 20 14:30:01 EST 2018


Hi,

I am using VTK to do volume rendering for IEEE SciVis 2018 contest.
This is the time step I am using, 
http://oceans11.lanl.gov/deepwaterimpact/yA31/300x300x300-FourScalars_resolution/pv_insitu_300x300x300_30068.vti

I found that I cannot make the data (semi)transparent  even if I have
already set the opacity to very low (lower than 0.001).
My question is how can I make it transparent? Or do I do anything wrong?

The following is the code (Python-vtk)


import vtk
import numpy as np
import vtk.util.numpy_support as VN

fileName = '/home/caseywang777/Downloads/pv_insitu_300x300x300_30068.vti' 
#download from 
http://oceans11.lanl.gov/deepwaterimpact/yA31/300x300x300-FourScalars_resolution/pv_insitu_300x300x300_30068.vti

colors = vtk.vtkNamedColors()
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Create the reader for the data.
# reader = vtk.vtkStructuredPointsReader()
# reader.SetFileName(fileName)
# Create the reader for the data
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(fileName)
reader.Update()

# specify the data array in the file to process
reader.GetOutput().GetPointData().SetActiveAttribute('v02',0)

# convert the data array to numpy array and get the min and maximum valule
dary = VN.vtk_to_numpy(reader.GetOutput().GetPointData().GetScalars('v02'))
dMax = np.amax(dary) #data min value
dMin = np.amin(dary) #data max value
dRange = dMax - dMin

# Create transfer mapping scalar value to opacity.
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(dMin, 0.0)
#opacityTransferFunction.AddPoint(dMin + dRange/2, 0.005)
opacityTransferFunction.AddPoint(dMax, 0.001) ###### very small, still
opaque

# Create transfer mapping scalar value to color.
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(dMin, 0.2, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(dMin + (dRange/4)*1, 1.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(dMin + (dRange/4)*2, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(dMin + (dRange/4)*3, 0.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(dMin + (dRange/4)*4, 0.0, 0.2, 0.0)

# The property describes how the data will look.
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOn()
volumeProperty.SetInterpolationTypeToLinear()

# The mapper / ray cast function know how to render the data.
# volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper()  # too slow? does
not work?
volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
volumeMapper.SetInputConnection(reader.GetOutputPort())

# The volume holds the mapper and the property and
# can be used to position/orient the volume.
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)

ren1.AddVolume(volume)
ren1.SetBackground(colors.GetColor3d("Wheat"))
ren1.GetActiveCamera().Azimuth(45)
ren1.GetActiveCamera().Elevation(30)
ren1.ResetCameraClippingRange()
ren1.ResetCamera()

renWin.SetSize(600, 600)
renWin.Render()

iren.Start()



Thanks foro you help!!




--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list