如何在 vtkStructuredGrid 上设置数据值 [英] How to set data values on a vtkStructuredGrid

查看:48
本文介绍了如何在 vtkStructuredGrid 上设置数据值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用分析字段填充结构化网格,但尽管阅读了 vtk 文档,我还没有找到如何在网格点实际设置标量值或设置间距/原点信息网格.从下面的代码开始,我如何

I'm trying to fill in a structured grid with an analytical field, but despite reading the vtk docs, I haven't found out how to actually set scalar values at the grid points or the set the spacing/origin info of the grid. Starting from the code below, how do I

  1. 将空间信息与网格相关联(即单元格 0,0,0 在坐标 0,0,0 处,每个方向的间距为 dx)
  2. 将标量值与每个网格点相关联.首先,我只需要一个,但最终我想在每个点存储 3 个数据(不是向量,3 个不同的标量).

grid = vtk.vtkStructuredGrid()
numPoints = int((maxGrid - minGrid)/dx)
grid.SetDimensions(numPoints, numPoints, numPoints)

推荐答案

在 VTK 中有 3 种类型的结构化"网格,vtkImageData(vtkUniformGrid 派生自此)、vtkRectilinearGrid 和 vtkStructuredGrid.从拓扑设置的意义上来说,它们都是结构化的.vtkImageData 点之间的间距恒定并且轴对齐,vtkRectilinearGrid 轴对齐但可以改变每个轴方向的间距,vtkStructuredGrid 具有任意定位的点(尽管单元格可能无效).

In VTK there are 3 types of "structured" grids, vtkImageData (vtkUniformGrid derives from this), vtkRectilinearGrid, and vtkStructuredGrid. They are all structured in the sense that the topology is set. vtkImageData has constant spacing between points and is axis aligned, vtkRectilinearGrid is axis aligned but can vary the spacing in each axis direction, and vtkStructuredGrid has arbitrarily located points (cells may not be valid though).

对于你想做的事,你应该这样做:

For what you want to do you should do:

from vtk import *
dx = 2.0
grid = vtkImageData()
grid.SetOrigin(0, 0, 0) # default values
grid.SetSpacing(dx, dx, dx)
grid.SetDimensions(5, 8, 10) # number of points in each direction
# print grid.GetNumberOfPoints()
# print grid.GetNumberOfCells()
array = vtkDoubleArray()
array.SetNumberOfComponents(1) # this is 3 for a vector
array.SetNumberOfTuples(grid.GetNumberOfPoints())
for i in range(grid.GetNumberOfPoints()):
    array.SetValue(i, 1)

grid.GetPointData().AddArray(array)
# print grid.GetPointData().GetNumberOfArrays()
array.SetName("unit array")

这篇关于如何在 vtkStructuredGrid 上设置数据值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆