news 2026/9/2 5:30:20

BlankPoint 结构化网格点或单元的“隐藏”或“空白化”

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
BlankPoint 结构化网格点或单元的“隐藏”或“空白化”

一:主要的知识点

1、说明

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

2、知识点纪要

本段代码主要涉及的有①将抽象的 3D 体积或拓扑数据 (vtkStructuredGrid) 转换为可被渲染器直接绘制的 2D 几何体 (vtkPolyData)


二:代码及注释

import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkInteractionStyle from vtkmodules.vtkCommonColor import vtkNamedColors from vtkmodules.vtkCommonCore import vtkPoints from vtkmodules.vtkCommonDataModel import vtkStructuredGrid from vtkmodules.vtkFiltersGeometry import vtkStructuredGridGeometryFilter from vtkmodules.vtkRenderingCore import ( vtkActor, vtkDataSetMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) def main(): colors = vtkNamedColors() points = vtkPoints() grid_size = 8 counter = 0 pt_idx = 0 # Create a 5x5 grid of points for j in range(0, grid_size): for i in range(0, grid_size): if i == 3 and j == 3: # Make one point higher than the rest. points.InsertNextPoint(i, j, 2) print(f'The different point is number {counter}.') pt_idx = counter else: # Make most of the points the same height. points.InsertNextPoint(i, j, 0) counter += 1 """ vtkStructuredGrid 结构化网格中,每个单元默认连接相邻的点,例如: 一个 2D 网格(nx×ny×1)中的单元是四边形, 一个 3D 网格(nx×ny×nz)中的单元是六面体(hexahedron) 比如: Cell (i,j,k) 由 8 个点组成:这个Cell所在位置索引为(i, j, k) (i,j,k) (i+1,j,k) (i,j+1,k) (i+1,j+1,k) (i,j,k+1) (i+1,j,k+1) (i,j+1,k+1) (i+1,j+1,k+1) VTK 在内部自动根据维度推导出这些连接关系 """ structured_grid = vtkStructuredGrid() # Specify the dimensions of the grid, set the points and blank one point. structured_grid.SetDimensions(grid_size, grid_size, 1) structured_grid.SetPoints(points) # 把第 pt_idx 个点(也就是那个高起来的点)标记为无效(blanked) # 这个点或单元在可视化或计算中应当被忽略,不参与渲染或插值 structured_grid.BlankPoint(pt_idx) # 忽略掉某个cell # structured_grid.BlankCell() def is_visible(pt_num): # 判定某个点是否可见 if structured_grid.IsPointVisible(pt_num): return f'Point {pt_num:2d} is visible.' else: return f'Point {pt_num:2d} is not visible.' # Should not be visible. print(is_visible(pt_idx)) # Should be visible. print(is_visible(7)) # 将structured_grid转化为polyData """ 将抽象的 3D 体积或拓扑数据 (vtkStructuredGrid) 转换为可被渲染器直接绘制的 2D 几何体 (vtkPolyData) 这里完成两个任务 1:提取集合表面,因为结构化网格代表的是 3D 空间中的点和体素。渲染器无法直接绘制这些体素 2:执行空白化操作,当你调用 structured_grid.BlankPoint(pt_idx) 时,你只是在数据结构内部标记了一个点是不可见的 vtkStructuredGridGeometryFilter 在生成多边形时,会检查每个单元的 8 个角点。 如果一个单元(Cell)的任何一个角点被标记为“空白”(Blanked),那么这个过滤器会完全跳过这个单元,不会为它生成任何几何表面 """ geometry_filter = vtkStructuredGridGeometryFilter() geometry_filter.SetInputData(structured_grid) # Create a mapper and actor. grid_mapper = vtkDataSetMapper() grid_mapper.SetInputConnection(geometry_filter.GetOutputPort()) grid_actor = vtkActor() grid_actor.SetMapper(grid_mapper) grid_actor.GetProperty().EdgeVisibilityOn() grid_actor.GetProperty().SetEdgeColor(colors.GetColor3d('Blue')) # Visualize renderer = vtkRenderer() ren_win = vtkRenderWindow() ren_win.AddRenderer(renderer) iren = vtkRenderWindowInteractor() iren.SetRenderWindow(ren_win) renderer.AddActor(grid_actor) renderer.SetBackground(colors.GetColor3d('ForestGreen')) # ren_win.SetSize(640, 480) ren_win.SetWindowName('BlankPoint') ren_win.Render() iren.Start() if __name__ == '__main__': main()
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/9/2 22:55:24

REINVENT4:终极AI分子设计平台完整指南

REINVENT4:终极AI分子设计平台完整指南 【免费下载链接】REINVENT4 AI molecular design tool for de novo design, scaffold hopping, R-group replacement, linker design and molecule optimization. 项目地址: https://gitcode.com/gh_mirrors/re/REINVENT4 …

作者头像 李华
网站建设 2026/9/3 0:45:27

Screenbox媒体播放器:5个让你爱上Windows视频播放的理由

Screenbox媒体播放器:5个让你爱上Windows视频播放的理由 【免费下载链接】Screenbox LibVLC-based media player for the Universal Windows Platform 项目地址: https://gitcode.com/gh_mirrors/sc/Screenbox 还在为Windows系统上找不到好用的媒体播放器而烦…

作者头像 李华
网站建设 2026/9/2 21:14:45

Open-AutoGLM模型部署难题全解析,专家亲授7大避坑指南

第一章:Open-AutoGLM模型部署难题全解析在将Open-AutoGLM这类大型语言模型投入生产环境时,开发者常面临性能、兼容性与资源调度等多重挑战。由于该模型依赖复杂的推理图结构和高精度参数计算,标准部署流程往往难以满足低延迟与高并发的业务需…

作者头像 李华
网站建设 2026/9/2 2:58:56

APatch完整指南:Android设备极速Root与内核修补技术

APatch完整指南:Android设备极速Root与内核修补技术 【免费下载链接】APatch Patching, hooking, and rooting the Android using only a stripped kernel image. 项目地址: https://gitcode.com/gh_mirrors/ap/APatch APatch是一款革命性的Android内核修补工…

作者头像 李华
网站建设 2026/9/3 3:10:45

Screenbox:Windows平台终极免费多媒体播放器完全指南

Screenbox:Windows平台终极免费多媒体播放器完全指南 【免费下载链接】Screenbox LibVLC-based media player for the Universal Windows Platform 项目地址: https://gitcode.com/gh_mirrors/sc/Screenbox Screenbox是一款基于LibVLC技术的现代化媒体播放器…

作者头像 李华