我需要用python编写一个xml vtk文件。 特别在StructuredGrid中。 我有坐标x,y,z轴和空间中每个点的x,y,z分量的值。 我如何写这个文件?python vtk作家
0
A
回答
1
(编辑),你可以做到这一点通过这个功能(在python)
def writeVtkStructuredGrid(StructuredGrid, file_name):
"""
StructuredGrid : StructuredGrid input object
file_name : output xml path file (example: 'out.vtp')
"""
sg = vtkXMLStructuredGridWriter()
sg.SetFileName(file_name)
sg.SetInput(StructuredGrid)
sg.Write()
约vtkXMLPolyDataWriter对象的文档是: vtkXMLPolyDataWriter class reference
-1
请检查该#1链路调整注释的代码即可完成你的工作。 StackOverflow Link。具体的例子from tvtk
一个示例代码
from numpy import mgrid, empty, sin, pi
from tvtk.api import tvtk, write_data
# Generate some points.
x, y, z = mgrid[1:6:11j, 0:4:13j, 0:3:6j]
base = x[..., 0] + y[..., 0]
# Some interesting z values.
for i in range(z.shape[2]):
z[..., i] = base * 0.25 * i
# The actual points.
pts = empty(z.shape + (3,), dtype=float)
pts[..., 0] = x
pts[..., 1] = y
pts[..., 2] = z
# Simple scalars.
scalars = x * x + y * y + z * z
# Some vectors
vectors = empty(z.shape + (3,), dtype=float)
vectors[..., 0] = (4 - y * 2)
vectors[..., 1] = (x * 3 - 12)
vectors[..., 2] = sin(z * pi)
# We reorder the points, scalars and vectors so this is as per VTK's
# requirement of x first, y next and z last.
pts = pts.transpose(2, 1, 0, 3).copy()
pts.shape = pts.size/3, 3
scalars = scalars.T.copy()
vectors = vectors.transpose(2, 1, 0, 3).copy()
vectors.shape = vectors.size/3, 3
# Create the dataset.
sg = tvtk.StructuredGrid(dimensions=x.shape, points=pts)
sg.point_data.scalars = scalars.ravel()
sg.point_data.scalars.name = 'temperature'
sg.point_data.vectors = vectors
sg.point_data.vectors.name = 'velocity'
write_data(sg, 'test') # creates test.vtu xml file
#write_data(sg, 'test.vtk') # creates test.vtk
相关问题
- 1. VTK/Python/compile
- 2. VTK 7.1.0 + Python 3.5.2出错
- 3. Python中的vtk用户类
- 4. 无法检测到vtk python
- 5. 编译vtk与python包装
- 6. VTK与Python 3.6,蟒蛇4.4
- 7. Python VTK polydata没有更新
- 8. Python的CSV作家空行
- 9. 列表CSV作家Python
- 10. Python中的XML作家
- 11. VTK:
- 12. 在Python中导入VTK解释器
- 13. Python VTK,如何录制视频?
- 14. Python-VTK:将计算卸载到GPU
- 15. 使用Python读取.vtk文件
- 16. 在Python中导入.vtk错误
- 17. Python VTK:直接与PolyData坐标
- 18. 问题与VTK的Python绑定
- 19. VTK与Qt一起工作的问题
- 20. VTK中的StreamLines
- 21. VTK:从pointcoud
- 22. 的Python 2 CSV作家在Windows
- 23. Python csv作家截断数字格式
- 24. Python的CSV作家和列表理解
- 25. 使用anaconda安装VTK 3.6
- 26. CMake错误 - cmTryCompileExec已停止工作(VTK)
- 27. VTK示例不起作用 - QVTKOpenGLWidget?
- 28. PyUnicodeUCS2_ *导入VTK时出错
- 29. 将ITK/VTK导入到Matlab或Matlab到VTK/ITK环境中?
- 30. 作曲家:RuntimeException
他指的是vtkStructuredGrid文件,而不是一个vtkPolyData文件。我不认为他有一个vtkStructuredGrid内置,并需要从他目前的数据做到这一点。 – andybauer