[vtkusers] Enable depth peeling after initialization
Ignacio Fernández Galván
jellby at yahoo.com
Tue Jan 9 11:57:08 EST 2018
Hi all,
I'm trying to enable depth peeling with VTK. Currently my goal is using
it with Mayavi and python. My problem, and a sample code, is in
https://stackoverflow.com/questions/47738246/depth-peeling-in-mayavi.
I think the reason is that depth peeling must be enabled before
initializing the window, but Mayavi initializes the window as soon as it
is declared, so changing the settings after does nothing. Consider the
following simple, pure VTK, code:
#=============================================================
import vtk
init_before = True
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
ren.SetBackground([.2, .2, .2])
if init_before:
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
# enable depth peeling
ren.SetUseDepthPeeling(1)
ren.SetOcclusionRatio(0.1)
ren.SetMaximumNumberOfPeels(100)
renWin.SetMultiSamples(0)
renWin.SetAlphaBitPlanes(1)
if not init_before:
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
# create source
source = vtk.vtkCylinderSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
source.SetHeight(7.0)
source.SetResolution(100)
source.Update()
# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(source.GetOutput())
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
# assign actor to the renderer
ren.AddActor(actor)
ren.ResetCamera()
# enable user interface interactor
renWin.Render()
print ren.GetLastRenderingUsedDepthPeeling()
iren.Start()
#=============================================================
With init_before=False I get that depth peeling was used, but not with
init_before=True.
Is there anything I can do to force and update of the render window to
pick up the new settings? I tried iren.Reinitialize() to no avail. The
only way I could find was removing renWin and iren and creating new
ones, but that doesn't help with Mayavi.
Thanks,
Ignacio
More information about the vtkusers
mailing list