python - 如何在 PyCharm 中正确使用 VTK
问题描述
这是我的 Hello-World 示例。渲染窗口在运行时只有黑色背景;我试图改变背景颜色,但没有奏效。现在,我没有别的办法了,希望你能帮我找到问题。谢谢你。
这是我的代码:
import vtk
def main():
colors = vtk.vtkNamedColors()
# Set the background color.
bkg = map(lambda x: x / 255.0, [26, 51, 102, 255])
colors.SetColor("BkgColor", *bkg)
# This creates a polygonal cylinder model with eight circumferential
# facets.
cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)
# The mapper is responsible for pushing the geometry into the graphics
# library. It may also do color mapping, if scalars or other
# attributes are defined.
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())
# The actor is a grouping mechanism: besides the geometry (mapper), it
# also has a property, transformation matrix, and/or texture map.
# Here we set its color and rotate it -22.5 degrees.
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))
cylinderActor.RotateX(30.0)
cylinderActor.RotateY(-45.0)
# Create the graphics structure. The renderer renders into the render
# window. The render window interactor captures mouse events and will
# perform appropriate camera or actor manipulation depending on the
# nature of the events.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
ren.AddActor(cylinderActor)
ren.SetBackground(colors.GetColor3d("BkgColor"))
renWin.SetSize(300, 300)
renWin.SetWindowName('CylinderExample')
# This allows the interactor to initalize itself. It has to be
# called before an event loop.
iren.Initialize()
# We'll zoom in a little by accessing the camera and invoking a "Zoom"
# method on it.
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
renWin.Render()
# Start the event loop.
iren.Start()
if __name__ == '__main__':
main()
解决方案
推荐阅读
- android - Ubuntu:生成apk android studio 3.3
- primefaces - 将图标(例如材料设计或 Prime 图标)添加到 ap:inputText
- html - 具有可滚动内容和固定导航栏的 div
- android - 如何解耦房间实体
- javascript - 我在向画布添加对象时遇到了很多麻烦,但它比这复杂得多
- windows - 为什么我在 Windows 的不同终端中激活 anaconda 环境时会得到不同的结果?
- python - Django:避免数据类型限制
- json - 如何使用 shell 脚本管道 json 卷曲以发送松弛消息
- angular - 如何在 home.page.scss 内的 angular + ionic 应用程序中设置背景图像?
- hangouts-chat - Hangout 聊天 api (chat.spaces().messages().create) 抛出权限错误 (403)