news 2026/5/25 20:32:51

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/5/25 23:27:23

节点NotReady后容器驱逐时间调整

一、简介 早期k8s版本中,Kubernetes Controller Manager 有一些相关参数,用于控制节点监控和 Pod 驱逐的行为。 --node-monitor-grace-period40s(节点失联后等待多久才标记为不健康) --node-monitor-period30s(Contr…

作者头像 李华
网站建设 2026/5/26 4:22:54

深入浅出窗口看门狗(WWDG):从原理到实战,守护MCU系统稳定运行

在嵌入式系统开发中,“稳定性”是贯穿始终的核心诉求。无论是工业控制中的PLC、汽车电子中的ECU,还是智能家居中的传感器节点,一旦程序出现“跑飞”“死循环”等异常,都可能引发设备故障、数据丢失甚至安全事故。为应对这类问题&a…

作者头像 李华
网站建设 2026/5/26 4:22:52

Qwen2-VL微调终极指南:3步快速上手视觉语言模型训练

Qwen2-VL微调终极指南:3步快速上手视觉语言模型训练 【免费下载链接】Qwen2-VL-Finetune An open-source implementaion for fine-tuning Qwen2-VL and Qwen2.5-VL series by Alibaba Cloud. 项目地址: https://gitcode.com/gh_mirrors/qw/Qwen2-VL-Finetune …

作者头像 李华
网站建设 2026/5/26 4:22:50

XAPK转换实战指南:轻松解决安卓应用安装困扰

XAPK转换实战指南:轻松解决安卓应用安装困扰 【免费下载链接】xapk-to-apk A simple standalone python script that converts .xapk file into a normal universal .apk file 项目地址: https://gitcode.com/gh_mirrors/xa/xapk-to-apk 你是否遇到过下载的安…

作者头像 李华
网站建设 2026/5/25 19:19:18

终极阿尔比恩OL数据分析工具完整指南:快速掌握游戏数据奥秘

终极阿尔比恩OL数据分析工具完整指南:快速掌握游戏数据奥秘 【免费下载链接】AlbionOnline-StatisticsAnalysis A tool with many features for the game Albion Online 项目地址: https://gitcode.com/gh_mirrors/al/AlbionOnline-StatisticsAnalysis 在《阿…

作者头像 李华
网站建设 2026/5/25 8:55:18

用友网页版打不开,界面一直转圈

有时候使用用友T 时经常会遇到页面一直转圈,加载不出来的情况解决方案:点击电脑上的开始程序,找到畅捷通T服务管理器,点击切换到iis如果切换到iis失败,可在【控制面板】位置找到【程序】-【程序和功能】,点…

作者头像 李华