VTK: 三维图像处理和可视化利器
VTK在Java, Tcl, Python中都有接口,本文介绍VTK在Python中的接口
。
VTK (The Visualization Toolkit ) 是一款用于计算机3D成像、构建模型、图像处理、容积渲染、科学数据可视化
等方面的免费软件系统,支持Linux, Windows, Mac, Web, mobile devices等平台;
快速上手
pip install vtk
例子
import vtkmodules.vtkInteractionStyle import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkFiltersSources import vtkCylinderSource from vtkmodules.vtkRenderingCore import (vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer) # 数据准备 colors = vtkNamedColors() bkg = map(lambda x: x / 255.0, [26, 51, 102, 255]) colors.SetColor("BkgColor", *bkg) cylinder = vtkCylinderSource() cylinder.SetResolution(8) # 映射 cylinderMapper = vtkPolyDataMapper() cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) # 添加绘制对象 cylinderActor = vtkActor() #绘制对象添加映射器 cylinderActor.SetMapper(cylinderMapper) cylinderActor.GetProperty().SetColor(colors.GetColor3d("Tomato")) cylinderActor.RotateX(30.0) cylinderActor.RotateY(-45.0) # 添加绘制器 ren = vtkRenderer() # 添加绘制窗口 renWin = vtkRenderWindow() renWin.AddRenderer(ren) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # 绘制器添加对象 ren.AddActor(cylinderActor) ren.SetBackground(colors.GetColor3d("BkgColor")) renWin.SetSize(300, 300) renWin.SetWindowName('CylinderExample') # 交互器初始化 iren.Initialize() ren.ResetCamera() ren.GetActiveCamera().Zoom(1.5) renWin.Render() # 交互器启动 iren.Start()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!