python - 渲染窗口后更改演员颜色
问题描述
我正在尝试改变其中一位演员的颜色。好像方法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()
编辑:
在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"))
推荐阅读
- node.js - 在 Nodejs 中解析 POST 参数
- ruby-on-rails - 使用带有最新帖子的 Rails 应用程序
- java - 如何获得正确的消息显示?
- python - 如何通过更改 URL 中的一个数字来循环完整的 API 集合
- node.js - EC2 describeImages 然后 AWS.request 不会返回任何东西
- vue.js - 如何在 Vue.JS 应用程序中使用模拟
- python - 如何在来自joblib的并行for循环期间附加列表
- kubernetes - K8S:将“kubeadm init”命令行参数转换为“--config”YAML
- stock - 我如何将 pinescript 用于 STOCKTRADE?
- google-sheets - UPS Tracking On Google Sheet 返回导入的内容为空