news 2026/4/8 7:44:15

MotionBlur 演示简单运动模糊

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
MotionBlur 演示简单运动模糊

一:主要的知识点

1、说明

本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程——逐行解析官网所有Python示例-CSDN博客

2、知识点纪要

本段代码主要涉及的有①vtkRenderStepsPass的使用


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkInteractionStyle from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkRenderingCore import vtkRenderer, vtkRenderWindow, vtkRenderWindowInteractor, vtkPolyDataMapper, vtkActor from vtkmodules.vtkIOPLY import vtkPLYReader from vtkmodules.vtkRenderingOpenGL2 import vtkRenderStepsPass, vtkSimpleMotionBlurPass def main(): fileName = "Data/Armadillo.ply" colors = vtkNamedColors() colors.SetColor('A1Diff', [255, 204, 77, 255]) colors.SetColor('A2Amb', [51, 51, 255, 255]) colors.SetColor('A2Diff', [51, 255, 204, 255]) colors.SetColor('A3Amb', [128, 166, 255, 255]) colors.SetColor('Bkg', [77, 102, 153, 255]) renderer = vtkRenderer() renderer.SetBackground(colors.GetColor3d("Bkg")) renderWindow = vtkRenderWindow() renderWindow.SetSize(500, 500) renderWindow.SetWindowName('MotionBlur') renderWindow.AddRenderer(renderer) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renderWindow) reader = vtkPLYReader() reader.SetFileName(fileName) reader.Update() mapper = vtkPolyDataMapper() mapper.SetInputConnection(reader.GetOutputPort()) # 创建3个模型 actor = vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetAmbientColor(colors.GetColor3d('Red')) actor.GetProperty().SetDiffuseColor(colors.GetColor3d('A1Diff')) actor.GetProperty().SetSpecular(0.0) actor.GetProperty().SetDiffuse(0.5) actor.GetProperty().SetAmbient(0.3) actor.SetPosition(-0.1, 0.0, -0.1) renderer.AddActor(actor) actor = vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetAmbientColor(colors.GetColor3d('A2Amb')) actor.GetProperty().SetDiffuseColor(colors.GetColor3d('A2Diff')) actor.GetProperty().SetSpecularColor(colors.GetColor3d('Black')) actor.GetProperty().SetSpecular(0.2) actor.GetProperty().SetDiffuse(0.9) actor.GetProperty().SetAmbient(0.1) actor.GetProperty().SetSpecularPower(10.0) renderer.AddActor(actor) actor = vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetDiffuseColor(colors.GetColor3d('A3Amb')) actor.GetProperty().SetSpecularColor(colors.GetColor3d('White')) actor.GetProperty().SetSpecular(0.7) actor.GetProperty().SetDiffuse(0.4) actor.GetProperty().SetSpecularPower(60.0) actor.SetPosition(0.1, 0.0, 0.1) renderer.AddActor(actor) """ SetMultiSamples(0) 禁用多重采样抗锯齿 SetMultiSamples 设置为大于1的值时(例如 4 或 8), 图形卡会为每个像素在多个位置采样颜色和深度信息,然后将这些样本混合起来, 从而产生平滑的边缘。 """ renderWindow.SetMultiSamples(0) """ vtkRenderStepsPass 属于VTK的渲染管线的高级部分,它是一个渲染步骤通道(Render Pass)类,用于调试和分阶段执行渲染过程 在现代VTK中(尤其是8.X以后的版本),渲染过程被模块化为一系列 渲染步骤,比如 绘制几何体(geometry pass) 绘制阴影(shadow pass) 绘制透明度(translucent pass) 绘制体数据(volume pass) 绘制后期处理(post-processing pass) 这些步骤可以由一个"Pass管线"按顺序执行 其主要作用是:封装并依次执行 VTK 的标准渲染步骤,用于调试或自定义渲染流程 vtkRenderStepPass 内部通常会依次执行以下pass 顺序 渲染阶段(Pass) 说明 1 vtkSequencePass 渲染步骤序列管理器(内部容器) 2 vtkLightsPass 设置光照 3 vtkCameraPass 应用相机变换 4 vtkOpaquePass 绘制不透明物体 5 vtkTranslucentPass 绘制透明物体 6 vtkVolumetricPass 绘制体渲染对象(volume) 7 vtkOverlayPass 绘制叠加层(文本、UI) """ basicPasses = vtkRenderStepsPass() """ vtkSimpleMotionBlurPass 是一个 图像后期处理(post-processing)渲染 pass,用于在渲染结果中实现运动模糊(Motion Blur)效果 它在渲染完成后,对场景的多帧进行时间平均,从而模拟 相机快门导致的运动模糊效果 工作原理:“渲染多帧场景 → 累积图像 → 平均 → 产生模糊感” 渲染结构的关系: vtkSimpleMotionBlurPass并不自己绘制几何体,它是一个"包裹"pass,必须包裹一个基础渲染pass。 例如: vtkCameraPass └── vtkSimpleMotionBlurPass └── vtkRenderStepsPass 整个链条会按层次执行: vtkRenderStepsPass → 绘制正常场景 vtkSimpleMotionBlurPass → 对渲染结果做累积与平均 vtkCameraPass → 管理相机和最终合成 """ motion = vtkSimpleMotionBlurPass() """ SetDelegatePass 指定内部真正负责绘制场景的渲染pass vtkSimpleMotionBlurPass的其余方法: SetNumberOfFrames(number):设置渲染并累积的帧数(数值越大,模糊越平滑,但性能越低) GetNumberOfFrames():获取帧数 Render():执行渲染与混合操作 ReleaseGraphicsResources():释放显存和缓冲区资源 """ motion.SetDelegatePass(basicPasses) """ SetPass: vtk中,渲染器(vtkRenderer)有两种工作模式: 1、默认渲染模式, 使用VTK内部默认流程,绘制几何体、光照、透明、叠加层等 2、自定义Render Pass模式 通过 renderer.SetPass() 手动设置一条自定义渲染管线,由你控制渲染的每个步骤 当调用 renderer.SetPass(some_pass) 时, 就告诉 VTK:“别用你默认的渲染方式,用我指定的渲染 pass 管线来绘制场景。” """ renderer.SetPass(motion) numRenders = 30 renderer.GetActiveCamera().SetPosition(0, 0, -1) renderer.GetActiveCamera().SetFocalPoint(0, 0, 0) renderer.GetActiveCamera().SetViewUp(0, 1, 0) renderer.ResetCamera() renderer.GetActiveCamera().Azimuth(15.0) renderer.GetActiveCamera().Zoom(1.2) renderWindow.Render() for i in range(0, numRenders): renderer.GetActiveCamera().Azimuth(10.0 / numRenders) renderer.GetActiveCamera().Elevation(10.0 / numRenders) renderWindow.Render() iren.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/1 20:00:19

ios底部按钮被挡住

大家开发小程序时,需要在底部固定一个按钮时,却发现有时候被ios的小横条 (Home Indicator) 遮挡内容,有时候触发不了事件。我们这边是用uniapp开发小程序可以设置一个全局样式类.ios_bottom {padding-bottom: 0;padding-bottom: constant(saf…

作者头像 李华
网站建设 2026/4/3 4:33:44

终极Bootstrap 3.4.1完整指南:如何快速构建响应式网站

终极Bootstrap 3.4.1完整指南:如何快速构建响应式网站 【免费下载链接】Bootstrap3.4.1资源下载 本资源库提供Bootstrap 3.4.1版本的压缩文件下载,包含前端框架的核心组件、CSS样式及JavaScript插件。Bootstrap以其强大的响应式布局能力著称,…

作者头像 李华
网站建设 2026/4/7 4:18:04

Julia数据可视化终极指南:10个快速掌握Plots.jl的实用技巧

Julia数据可视化终极指南:10个快速掌握Plots.jl的实用技巧 【免费下载链接】Plots.jl Powerful convenience for Julia visualizations and data analysis 项目地址: https://gitcode.com/gh_mirrors/pl/Plots.jl Plots.jl是Julia编程语言中最强大的数据可视…

作者头像 李华
网站建设 2026/4/4 5:41:24

LaTeX公式OCR识别新突破:基于Qwen3-VL模型的Lora微调实战指南

LaTeX公式OCR识别新突破:基于Qwen3-VL模型的Lora微调实战指南 【免费下载链接】self-llm 项目地址: https://gitcode.com/GitHub_Trending/se/self-llm 想要让AI模型准确识别复杂的数学公式吗?🤔 在科研和学术工作中,数学…

作者头像 李华