Hi everybody, I am starting with VTK and I encounter this issue. I searched for this problem but I didn’t find anything. I hope somebody can help me.
I’m trying to change the color of one of the actors. Seems like the method SetColor(colors.GetColor3d("Silver"))
is not working.
I’m also tried with b.GetMapper().ScalarVisibilityOff()
but doesn´t work.
import vtk
colors = vtk.vtkNamedColors()
def crear_superficie(*puntos):
points = vtk.vtkPoints()
polygon = vtk.vtkPolygon()
polygon.GetPointIds().SetNumberOfIds(len(puntos))
for i, p in enumerate(puntos):
points.InsertNextPoint(*p)
polygon.GetPointIds().SetId(i, i)
polygons = vtk.vtkCellArray()
polygons.InsertNextCell(polygon)
# Create a PolyData
polygonPolyData = vtk.vtkPolyData()
polygonPolyData.SetPoints(points)
polygonPolyData.SetPolys(polygons)
# Create a mapper and actor
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polygonPolyData)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().EdgeVisibilityOn()
actor.GetProperty().SetLineWidth(2)
actor.GetProperty().SetColor(colors.GetColor3d("Banana"))
return actor
def main():
a = crear_superficie((0, 0, 0), (0, 6, 0), (15, 10, 0), (30, 6, 0), (30, 0, 0))
b = crear_superficie((0, 6, 0), (15, 10, 0), (15, 10, 60), (0, 6, 60))
# Add the polygon to a list of polygons
# Visualize
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.SetWindowName("Polygon")
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(a)
renderer.AddActor(b)
renderer.SetBackground(colors.GetColor3d("Silver"))
renderWindow.Render()
renderWindowInteractor.Start()
b.GetProperty().SetColor(colors.GetColor3d("Silver"))
if __name__ == '__main__':
main()