[vtkusers] Volume rendering - cannot make the image semi-transparecy
Elvis Stansvik
elvis.stansvik at orexplore.com
Tue Nov 20 14:54:48 EST 2018
I haven't finished downloading all of your example data file yet, but
I can already see that it has a very large Spacing:
[estan at newton Hämtningar]$ head pv_insitu_300x300x300_30068.vti.part
<VTKFile type="ImageData" version="2.1" byte_order="LittleEndian"
header_type="UInt64" compressor="vtkZLibDataCompressor">
<ImageData WholeExtent="0 299 0 299 0 299" Origin="-2300000 -500000
-1200000" Spacing="15384.615385 9364.548495 8026.7558528">
<FieldData>
<DataArray type="Float32" Name="xrage_version" NumberOfTuples="1"
format="ascii">
1604.21
</DataArray>
<DataArray type="Int32" Name="cycle_index" NumberOfTuples="1"
format="ascii" RangeMin="0" RangeMax="0">
30068
</DataArray>
<DataArray type="Float32" Name="simulated_time" NumberOfTuples="1"
format="ascii" RangeMin="0" RangeMax="0">
[estan at newton Hämtningar]$
Try adjusting the ScalarOpacityUnitDistance of your vtkVolumeProperty
to account for this. E.g. set it to something like 10000.
See the docs for that property for more info:
https://www.vtk.org/doc/nightly/html/classvtkVolumeProperty.html#a7dfb2d52c36821254ed078ce00cdab2a
"Set/Get the unit distance on which the scalar opacity transfer
function is defined. By default this is 1.0, meaning that over a
distance of 1.0 units, a given opacity (from the transfer function) is
accumulated. This is adjusted for the actual sampling distance during
rendering."
Elvis
Den tis 20 nov. 2018 kl 20:30 skrev caseywang777 <caseywang777 at gmail.com>:
>
>
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list