news 2026/9/1 17:18:00

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/9/1 14:08:31

使用STM32单片机进行串口通信的过程描述

STM32F103 串口通信实现全指南本文以 STM32F103C8T6(最小系统板)为例,详细讲解串口通信的硬件连接、软件配置、代码实现及调试问题解决方案,分别覆盖标准外设库(STM32F10x_StdPeriph_Driver) 和HAL 库两种主…

作者头像 李华
网站建设 2026/9/1 7:13:32

JetBrains Maple Mono字体深度体验与配置指南

JetBrains Maple Mono字体深度体验与配置指南 【免费下载链接】Fusion-JetBrainsMapleMono JetBrains Maple Mono: The free and open-source font fused with JetBrains Mono & Maple Mono 项目地址: https://gitcode.com/gh_mirrors/fu/Fusion-JetBrainsMapleMono …

作者头像 李华
网站建设 2026/8/31 15:37:30

【Java毕设源码分享】基于springboot+vue的个人博客系统的设计与实现(程序+文档+代码讲解+一条龙定制)

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围:&am…

作者头像 李华
网站建设 2026/9/1 0:22:14

PaddleSpeech模型版本管理终极指南:从混乱到秩序

PaddleSpeech模型版本管理终极指南:从混乱到秩序 【免费下载链接】PaddleSpeech Easy-to-use Speech Toolkit including Self-Supervised Learning model, SOTA/Streaming ASR with punctuation, Streaming TTS with text frontend, Speaker Verification System, E…

作者头像 李华
网站建设 2026/9/1 5:52:56

闪电AI文档转换Lite:离线免费的全能文档处理神器

闪电AI文档转换Lite:离线免费的全能文档处理神器 【免费下载链接】convert-lite flashai-convert-lite,离线免费文档转换工具,支持pdf to markdown,word to markdown,excel to markdown,ppt to markdown, html to markdown,image to markdown…

作者头像 李华
网站建设 2026/8/31 16:27:30

Windows系统pgvector一键部署攻略:告别编译烦恼,轻松开启向量搜索

还在为pgvector在Windows上的安装而头疼吗?🤔 别担心,今天我带你绕开所有坑点,用最简单的方式在Windows系统上成功部署这个强大的PostgreSQL向量搜索扩展!无论你是AI开发者还是数据库爱好者,都能在10分钟内…

作者头像 李华