news 2026/7/7 6:40:37

Lorenz 标量填充vtkStructuredPoints生成的三位体素数据

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Lorenz 标量填充vtkStructuredPoints生成的三位体素数据

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①三维体素数据的填充


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkMinimalStandardRandomSequence, vtkShortArray from vtkmodules.vtkCommonDataModel import vtkStructuredPoints from vtkmodules.vtkFiltersCore import vtkContourFilter from vtkmodules.vtkRenderingCore import ( vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() Pr = 10.0 # The Lorenz parameters b = 2.667 r = 28.0 h = 0.01 # integration step size resolution = 200 # slice resolution iterations = 10000000 # number of iterations xmin = -30.0 # x, y, z range for voxels xmax = 30.0 ymin = -30.0 ymax = 30.0 zmin = -10.0 zmax = 60.0 # Take a stab at an integration step size. xIncr = resolution / (xmax - xmin) yIncr = resolution / (ymax - ymin) zIncr = resolution / (zmax - zmin) randomSequence = vtkMinimalStandardRandomSequence() randomSequence.SetSeed(8775070) x = randomSequence.GetRangeValue(xmin, xmax) randomSequence.Next() y = randomSequence.GetRangeValue(ymin, ymax) randomSequence.Next() z = randomSequence.GetRangeValue(zmin, zmax) randomSequence.Next() # allocate memory for the slices sliceSize = resolution * resolution numPts = sliceSize * resolution scalars = vtkShortArray() for i in range(0, numPts): scalars.InsertTuple1(i, 0) for j in range(0, iterations): # Integrate to the next time step. xx = x + h * Pr * (y - x) yy = y + h * (x * (r - z) - y) zz = z + h * (x * y - (b * z)) x = xx y = yy z = zz # Calculate the voxel index. if xmax > x > xmin and ymax > y > ymin and zmax > z > zmin: xxx = int(float(xx - xmin) * xIncr) yyy = int(float(yy - ymin) * yIncr) zzz = int(float(zz - zmin) * zIncr) index = xxx + yyy * resolution + zzz * sliceSize scalars.SetTuple1(index, scalars.GetTuple1(index) + 1) """ 使用**vtkStructuredPoints类来创建一个三维体数据(volume data)对象, 并用之前模拟洛伦兹吸引子轨迹得到的标量数据**填充它 """ volume = vtkStructuredPoints() volume.GetPointData().SetScalars(scalars) volume.SetDimensions(resolution, resolution, resolution) volume.SetOrigin(xmin, ymin, zmin) volume.SetSpacing((xmax - xmin) / resolution, (ymax - ymin) / resolution, (zmax - zmin) / resolution) # Create iso-surface contour = vtkContourFilter() contour.SetInputData(volume) contour.SetValue(0, 50) # Create mapper. mapper = vtkPolyDataMapper() mapper.SetInputConnection(contour.GetOutputPort()) mapper.ScalarVisibilityOff() # Create actor. actor = vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(colors.GetColor3d('DodgerBlue')) renderer = vtkRenderer() renWin = vtkRenderWindow() renWin.AddRenderer(renderer) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d('PaleGoldenrod')) renWin.SetSize(640, 480) # interact with data renWin.Render() renWin.SetWindowName('Lorenz') camera = renderer.GetActiveCamera() camera.SetPosition(-67.645167, -25.714343, 63.483516) camera.SetFocalPoint(3.224902, -4.398594, 29.552112) camera.SetViewUp(-0.232264, 0.965078, 0.121151) camera.SetDistance(81.414176) camera.SetClippingRange(18.428905, 160.896031) iren.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/7 9:52:40

华为2025营销回顾,产品广告依旧遥遥领先

华为开屏广告 前几日,三联生活周刊公布了《2023年度十大热梗》,“遥遥领先”位列其中。伴随着Mate60系列的爆火,华为强势回归,再次激发手机市场的新活力。 市场调研机构CounterpointResearch表示,2023年正好是智能手机…

作者头像 李华
网站建设 2026/7/6 21:44:34

Chrome DevTools Protocol实战指南:解决浏览器自动化的5大痛点

Chrome DevTools Protocol实战指南:解决浏览器自动化的5大痛点 【免费下载链接】devtools-protocol Chrome DevTools Protocol 项目地址: https://gitcode.com/gh_mirrors/de/devtools-protocol 当你面对复杂的浏览器自动化需求时,是否曾为传统工…

作者头像 李华
网站建设 2026/7/7 16:59:21

p5.js网页编辑器终极指南:零基础快速上手创意编程

p5.js网页编辑器终极指南:零基础快速上手创意编程 【免费下载链接】p5.js-editor Deprecated desktop editor for p5.js 项目地址: https://gitcode.com/gh_mirrors/p5/p5.js-editor p5.js网页编辑器是一款专为创意编程设计的可视化开发工具,让编…

作者头像 李华
网站建设 2026/7/7 16:52:03

Vue.Draggable版本管理深度解析:从语义化版本到风险控制

在Vue.js生态系统中,Vue.Draggable作为最受欢迎的拖拽组件,其版本管理策略直接影响着数千个项目的稳定性。当前版本2.24.3采用语义化版本控制规范,为开发者提供了清晰的升级路径和兼容性保证。本文将深入剖析Vue.Draggable的版本演进图谱&…

作者头像 李华
网站建设 2026/7/7 17:45:33

数字化转型实践:SRM系统,如何提升采购团队的整体执行力?

在现代供应链体系中,采购执行环节的高效与否,已成为影响企业运营成本和市场响应速度的关键因素。然而,如今许多企业仍深陷效率陷阱:跨部门数据不一致、供应商沟通耗时长、人工核对易出错、以及合规性难以追溯。传统的线下管理方式…

作者头像 李华
网站建设 2026/7/7 17:50:37

[Script] 添加网格属性脚本

[Script] 添加网格属性脚本 引言 正文 调用方法 添加 np density 并导入数据 Author: JiJi \textrm{Author: JiJi} Author: JiJi Created Time: 2025.12.12 \textrm{Created Time: 2025.12.12} Created Time: 2025.12.12

作者头像 李华