wordpress页面连接数据库连接,下沙网站优化,商标设计图片,手机设计装修软件一#xff1a;主要的知识点
1、说明
本文只是教程内容的一小段#xff0c;因博客字数限制#xff0c;故进行拆分。主教程链接#xff1a;vtk教程——逐行解析官网所有Python示例-CSDN博客
2、知识点纪要
本段代码主要涉及的有①vtkExplicitStructuredGridToUnstructure…一主要的知识点1、说明本文只是教程内容的一小段因博客字数限制故进行拆分。主教程链接vtk教程——逐行解析官网所有Python示例-CSDN博客2、知识点纪要本段代码主要涉及的有①vtkExplicitStructuredGridToUnstructuredGrid结构化网格转换为非结构化网格二代码及注释import vtkmodules.vtkRenderingOpenGL2 import vtkmodules.vtkInteractionStyle from vtkmodules.vtkCommonCore import vtkPoints from vtkmodules.vtkCommonDataModel import vtkCellArray, vtkExplicitStructuredGrid import numpy as np from vtkmodules.vtkFiltersCore import ( vtkExplicitStructuredGridToUnstructuredGrid, vtkUnstructuredGridToExplicitStructuredGrid ) from vtkmodules.vtkRenderingCore import ( vtkActor, vtkDataSetMapper, vtkRenderWindow, vtkRenderWindowInteractor, vtkRenderer ) from vtkmodules.vtkCommonColor import vtkNamedColors def convert_to_unstructured_grid(grid): vtkExplicitStructuredGridToUnstructuredGrid 将一个显式结构化网格vtkExplicitStructuredGrid转换为一个标准的非结构化网格vtkUnstructuredGrid 这种转换是因为兼容性可以利用VTK最为广泛的现有过滤器库也可以进行数据简化 converter vtkExplicitStructuredGridToUnstructuredGrid() converter.SetInputData(grid) converter.Update() return converter.GetOutput() def convert_to_explicit_structured_grid(grid): vtkUnstructuredGridToExplicitStructuredGrid 将一个非结构化网格vtkUnstructuredGrid, USGrid转换回一个显式结构化网格vtkExplicitStructuredGrid, ESGrid converter vtkUnstructuredGridToExplicitStructuredGrid() converter.SetInputData(grid) 该过滤器依赖于输入 USGrid 的**单元数据Cell Data**中存在三个特殊的数组。这些数组定义了 USGrid 中每个单元在目标 ESGrid 中的 I,J,K 索引 converter.SetInputArrayToProcess(0, 0, 0, 1, BLOCK_I) converter.SetInputArrayToProcess(1, 0, 0, 1, BLOCK_J) converter.SetInputArrayToProcess(2, 0, 0, 1, BLOCK_K) converter.Update() return converter.GetOutput() def main(): # 创建一个结构模型 dimensions (5, 6, 7) spacing (20, 10, 1) ni, nj, nk dimensions si, sj, sk spacing points vtkPoints() for z in range(0, nk * sk, sk): for y in range(0, nj * sj, sj): for x in range(0, ni * si, si): points.InsertNextPoint((x, y, z)) cells vtkCellArray() for k in range(0, nk - 1): for j in range(0, nj - 1): for i in range(0, ni - 1): multi_index ([i, i 1, i 1, i, i, i 1, i 1, i], [j, j, j 1, j 1, j, j, j 1, j 1], [k, k, k, k, k 1, k 1, k 1, k 1]) pts np.ravel_multi_index(multi_index, dimensions, orderF) cells.InsertNextCell(8, pts) vtkExplicitStructuredGrid 是 VTK 中一种用于表示 **3D 结构化数据集Structured Data Set**的高级数据结构 它在传统的结构化网格如 vtkStructuredGrid和非结构化网格vtkUnstructuredGrid之间提供了一个非常灵活的桥梁 1. 传统的结构化网格如 vtkStructuredGrid 隐式拓扑Implicit Topology你只需要定义网格的点坐标和维度I×J×K。 连接关系单元Cell的连接关系是自动且固定的。例如点 (i,j,k) 总是连接到 (i1,j,k) 和 (i,j1,k) 等等。 限制由于连接是隐式的这种网格必须是拓扑上的矩形体不能包含内部空腔或断裂。 2. 显式结构化网格 (vtkExplicitStructuredGrid) 显式拓扑Explicit Topology它保留了 I×J×K 的维度信息结构化特性。 连接关系它显式地存储了每个单元Cell由哪些点组成就像非结构化网格一样。 简单来说ESGrid 仍然具有 I,J,K 索引的便利性结构化但它通过显式定义连接关系打破了传统结构化网格必须是拓扑矩形的限制 grid vtkExplicitStructuredGrid() 构建ESGrid的要素必须提供三个核心组件 维度 必须定义网格的I*J*K的尺寸 点坐标 单元连接一个 vtkCellArray它显式地列出构成每个单元通常是六面体的 8 个点的全局索引 grid.SetDimensions(ni, nj, nk) grid.SetPoints(points) grid.SetCells(cells) # 转换为非结构化网格 grid convert_to_unstructured_grid(grid) # 由非结构化网格转化为显示结构化网格 grid convert_to_explicit_structured_grid(grid) mapper vtkDataSetMapper() mapper.SetInputData(grid) colors vtkNamedColors() actor vtkActor() actor.SetMapper(mapper) actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().LightingOff() actor.GetProperty().SetColor(colors.GetColor3d(Seashell)) renderer vtkRenderer() renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d(DarkSlateGray)) window vtkRenderWindow() window.AddRenderer(renderer) window.SetWindowName(CreateESGrid) window.SetSize(1024, 768) window.Render() camera renderer.GetActiveCamera() camera.SetPosition(8.383354, -72.468670, 94.262605) camera.SetFocalPoint(42.295234, 21.111537, -0.863606) camera.SetViewUp(0.152863, 0.676710, 0.720206) camera.SetDistance(137.681759) camera.SetClippingRange(78.173985, 211.583658) interactor vtkRenderWindowInteractor() interactor.SetRenderWindow(window) interactor.SetInteractorStyle(vtkInteractorStyleRubberBandPick()) window.Render() interactor.Start() if __name__ __main__: main()