我想改变其中一个演员的颜色。好像是这样的方法 SetColor(colors.GetColor3d("Silver"))
是不行的。
我也试过用 b.GetMapper().ScalarVisibilityOff()
但不工作。
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()
EDIT:
呼叫之后 Render
就像Nico建议的那样,我得到了这个警告。
2020-06-01 12:45:40.413 ( 5.598s) [ ] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined.2020-06-01 12:45:40.467 ( 5.652s) [ ] vtkOpenGLState.cxx:1380 WARN| Hardware does not support the number of textures defined.2020-06-01 12:45:40.484 ( 5.669s) [ ] vtkShaderProgram.cxx:437 ERR| vtkShaderProgram (000002380CB1D770): 1: #version 150
2: #ifndef GL_ES
3: #define highp
4: #define mediump
5: #define lowp
6: #endif // GL_ES
7: #define attribute in
8: #define varying out
9:
10:
11: /*=========================================================================
12:
13: Program: Visualization Toolkit
14: Module: vtkPolyDataVS.glsl
15:
16: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
17: All rights reserved.
18: See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
19:
20: This software is distributed WITHOUT ANY WARRANTY; without even
21: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22: PURPOSE. See the above copyright notice for more information.
23:
24: =========================================================================*/
25:
26: in vec4 vertexMC;
27:
28:
29:
30: // frag position in VC
31: out vec4 vertexVCVSOutput;
32:
33: // optional normal declaration
34: //VTK::Normal::Dec
35:
36: // extra lighting parameters
37: //VTK::Light::Dec
38:
39: // Texture coordinates
40: //VTK::TCoord::Dec
41:
42: // material property values
43: //VTK::Color::Dec
44:
45: // clipping plane vars
46: //VTK::Clip::Dec
47:
48: // camera and actor matrix values
49: uniform mat4 MCDCMatrix;
50: uniform mat4 MCVCMatrix;
51:
52: // Apple Bug
53: //VTK::PrimID::Dec
54:
55: // Value raster
56: //VTK::ValuePass::Dec
57:
58: // picking support
59: //VTK::Picking::Dec
60:
61: void main()
62: {
63: //VTK::Color::Impl
64:
65: //VTK::Normal::Impl
66:
67: //VTK::TCoord::Impl
68:
69: //VTK::Clip::Impl
70:
71: //VTK::PrimID::Impl
72:
73: vertexVCVSOutput = MCVCMatrix * vertexMC;
74: gl_Position = MCDCMatrix * vertexMC;
75:
76:
77: //VTK::ValuePass::Impl
78:
79: //VTK::Light::Impl
80:
81: //VTK::Picking::Impl
82: }
2020-06-01 12:45:41.157 ( 6.341s) [ ] vtkShaderProgram.cxx:438 ERR| vtkShaderProgram (000002380CB1D770): Could not create shader object.
VTK是在懒惰评估模式下工作的,以保持性能。如果你想看到修改后的效果,你应该手动要求渲染。
所以添加一个 renderWindow.Render()
之后 SetColor(colors.GetColor3d("Silver"))
行