news 2026/4/23 8:13:49

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/4/21 17:04:13

基于单片机的智能暖风机系统设计(有完整资料)

资料查找方式:特纳斯电子(电子校园网):搜索下面编号即可编号:T0222402M设计简介:本设计是基于单片机的智能暖风机系统设计,主要实现以下功能:通过温度传感器监测温度,当温…

作者头像 李华
网站建设 2026/4/21 6:47:39

Obsidian Full Calendar 终极指南:打造高效日程管理系统

Obsidian Full Calendar 终极指南:打造高效日程管理系统 【免费下载链接】obsidian-full-calendar Keep events and manage your calendar alongside all your other notes in your Obsidian Vault. 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-full-c…

作者头像 李华
网站建设 2026/4/10 18:22:32

Screenbox:Windows平台终极免费视频播放器完整指南

还在为Windows视频播放的各种问题烦恼吗?格式不兼容、卡顿死机、操作复杂...这些困扰终于有了完美解决方案!Screenbox媒体播放器基于LibVLC技术,为你带来前所未有的流畅播放体验。 【免费下载链接】Screenbox LibVLC-based media player for …

作者头像 李华
网站建设 2026/4/18 19:30:17

Simple Live跨平台直播聚合技术解析:全设备适配与快速部署方法

Simple Live跨平台直播聚合技术解析:全设备适配与快速部署方法 【免费下载链接】dart_simple_live 简简单单的看直播 项目地址: https://gitcode.com/GitHub_Trending/da/dart_simple_live 应用场景与技术实现 在当前的直播观看生态中,用户往往面…

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

7-Zip ZS:六大压缩算法的技术革命与实战应用

7-Zip ZS:六大压缩算法的技术革命与实战应用 【免费下载链接】7-Zip-zstd 7-Zip with support for Brotli, Fast-LZMA2, Lizard, LZ4, LZ5 and Zstandard 项目地址: https://gitcode.com/gh_mirrors/7z/7-Zip-zstd 在数据存储与传输需求日益增长的今天&#…

作者头像 李华