Strange Visualization Results With Transparency on Polydata
| Newsgroups | gmane.comp.lib.vtk.user |
|---|---|
| Message-ID | <[email protected]> |
Dear All, I am experiencing some strange visualization results in VTK 8.1.0 on polydata using a LUT with some transparency for some entries and opacity for others. I am attaching a Python example to reproduce the problem. The code creates two polydata spheres which are spatially separated. An array with a uniform values of 1 is associated to cell data for the first sphere, and an array with values of 2 to the second sphere. The two spheres are appended together for convenience with a polydata append filter. A LUT is created with two entries, solid red RGBA = (1,0,0,1) and transparent green RGBA = (0,1,0,0.2), the scalar range is set to (1,2) mapping the cells of the first sphere to the first LUT entry and the cells of the second sphere to the second LUT entry. As shown by the attached rendering the red sphere also appears as semi-transparent, and in a wired way, if rotated some portions of the sphere seem more transparent, and others less. Setting the second LUT entry to solid green RGBA = (0,1,0,1) makes both spheres opaque - this is expected, but why does modifying the alpha channel of the second LUT entry affects also the appearance of the first sphere? I am experiencing this on two different Windows 10 computers equipped with modern NVIDIA GPUs, and on a 2017 iMac 27 running Mojave, all these computers have VTK 8.1.0. Any comment / advice is welcome, Thanks, Best Regards, Andrea _______________________________________________ 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
Spheres.PNG
(image/png, 452.3 KB) - not displayed
two_spheres.py
(text/plain, 2.3 KB)
import vtk
from vtk.util import numpy_support
import numpy as np
# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create source 1
source1 = vtk.vtkSphereSource()
source1.SetCenter(0,0,0)
source1.SetRadius(5.0)
source1.Update()
# get poly data of the sphere
sphere1 = source1.GetOutput()
# create a scalar array of all 1s and associate it with cell data
scalar_array_1 = np.ones(sphere1.GetNumberOfCells()) * 1
scalar_array_1_vtk = numpy_support.numpy_to_vtk(num_array=scalar_array_1, deep=True)
scalar_array_1_vtk.SetName("array_1")
sphere1.GetCellData().AddArray(scalar_array_1_vtk)
sphere1.GetCellData().SetActiveScalars("array_1")
# create source 2
source2 = vtk.vtkSphereSource()
source2.SetCenter(10,0,0)
source2.SetRadius(5.0)
source2.Update()
# get poly data of the sphere
sphere2 = source2.GetOutput()
# create a scalar array of all 2s and associate it with cell data
scalar_array_2 = np.ones(sphere1.GetNumberOfCells()) * 2
scalar_array_2_vtk = numpy_support.numpy_to_vtk(num_array=scalar_array_2, deep=True)
scalar_array_2_vtk.SetName("array_2")
sphere2.GetCellData().AddArray(scalar_array_2_vtk)
sphere2.GetCellData().SetActiveScalars("array_2")
# append the two spheres together
appendF = vtk.vtkAppendPolyData()
appendF.AddInputData(sphere1)
appendF.AddInputData(sphere2)
appendF.Update()
two_spheres = appendF.GetOutput()
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(two_spheres)
# build lookup table
lut_table = vtk.vtkLookupTable()
lut_table.SetNumberOfTableValues(2)
lut_table.Build()
lut_table.SetTableValue(0, (1, 0, 0, 1)) # 1 solid red (but becomes transparent if a transparency is applied to the second entry in the LUT)
lut_table.SetTableValue(1, (0, 1, 0, 0.2)) # 2 green, opacity 0.2 - causes also the red to become transparent and in a wired way
# apply lookup table to mapper
mapper.SetScalarRange(1,2)
mapper.SetLookupTable(lut_table)
mapper.ScalarVisibilityOn()
mapper.SetColorModeToMapScalars()
mapper.SetScalarModeToUseCellData()
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
# assign actor to the renderer
ren.AddActor(actor)
# start the interactor
iren.Initialize()
renWin.Render()
iren.Start()