news 2026/6/12 21:17:14

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/6/7 6:14:42

GreenLuma 2024 Manager:重新定义Steam游戏管理体验

GreenLuma 2024 Manager:重新定义Steam游戏管理体验 【免费下载链接】GreenLuma-2024-Manager An app made in python to manage GreenLuma 2024 AppList 项目地址: https://gitcode.com/gh_mirrors/gr/GreenLuma-2024-Manager 想要获得前所未有的Steam游戏管…

作者头像 李华
网站建设 2026/6/7 7:09:33

Screenbox:Windows平台终极媒体播放解决方案

还在为电脑上的媒体播放器不够用而烦恼吗?想要一款真正能打的全能播放工具?Screenbox就是你的答案!这款基于LibVLC技术的UWP应用,重新定义了Windows平台的影音体验。 【免费下载链接】Screenbox LibVLC-based media player for th…

作者头像 李华
网站建设 2026/6/7 6:36:23

别再盲目调参了!:Open-AutoGLM沉思模式的3种高级用法,让你事半功倍

第一章:Open-AutoGLM沉思模式的核心价值Open-AutoGLM 的沉思模式是一种创新的推理机制,旨在提升大语言模型在复杂任务中的逻辑连贯性与决策深度。该模式通过模拟人类“深思熟虑”的认知过程,在生成响应前进行多轮内部推演,从而显著…

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

为什么这6大压缩算法能让你的文件处理效率翻倍?

为什么这6大压缩算法能让你的文件处理效率翻倍? 【免费下载链接】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 在当今数据密集型工作环境中&#xff0c…

作者头像 李华
网站建设 2026/6/9 22:23:20

基于STM32的校园室内体育馆环境监测与控制系统(有完整资料)

资料查找方式:特纳斯电子(电子校园网):搜索下面编号即可编号:T0202402M设计简介:本设计是基于STM32的校园室内体育馆环境监测与控制系统,主要实现以下功能:通过温湿度传感器检测环境…

作者头像 李华
网站建设 2026/6/10 1:48:58

5分钟掌握AI对话聚合:多模型对比的终极利器

5分钟掌握AI对话聚合:多模型对比的终极利器 【免费下载链接】ChatALL Concurrently chat with ChatGPT, Bing Chat, Bard, Alpaca, Vicuna, Claude, ChatGLM, MOSS, 讯飞星火, 文心一言 and more, discover the best answers 项目地址: https://gitcode.com/gh_m…

作者头像 李华