I want to display two polygon in one renderer. And the result is:
The green and red color indicates two polygons.
However, when I rotate it, some part of green color disappear:
My environment is:
win 10
python 3.7.13
vtk: 9.2.4
I can 100% reproduce this phenomenon, and the code to reproduce my problem is:
import vtkmodules.all as vtk
def buildPolygon(points):
polydata = vtk.vtkPolyData()
vps = vtk.vtkPoints()
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(len(points))
for i in range(len(points)):
vps.InsertNextPoint(points[i][0], points[i][1], points[i][2])
polygon.GetPointIds().SetId(i, i)
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
polydata.SetPoints(vps)
polydata.SetPolys(polygons)
return polydata
polydata1 = buildPolygon([
[0, 0, 0],
[10, 0, 0],
[10, 10, 0],
[0, 10, 0]
])
map1 = vtk.vtkPolyDataMapper()
map1.SetInputData(polydata1)
actor1 = vtk.vtkActor()
actor1.SetMapper(map1)
actor1.GetProperty().SetColor(1, 0, 0)
polydata2 = buildPolygon([
[0, 0, 0],
[5, 0, 0],
[5, 5, 0],
[0, 5, 0]
])
map2 = vtk.vtkPolyDataMapper()
map2.SetInputData(polydata2)
actor2 = vtk.vtkActor()
actor2.SetMapper(map2)
actor2.GetProperty().SetColor(0, 1, 0)
render = vtk.vtkRenderer()
render.AddActor(actor1)
render.AddActor(actor2)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(render)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()