[英]Plot vtk file using Python
I cannot display a vtk file using python.我无法使用 python 显示 vtk 文件。 Spyder Code Analysis prompts me that vtkDataSetMapper is an undefined name.
Spyder 代码分析提示我 vtkDataSetMapper 是一个未定义的名称。
I know the vtk file is in order because I have already displayed it using Paraview.我知道 vtk 文件是有序的,因为我已经使用 Paraview 显示了它。
My vtk file looks like this:我的 vtk 文件如下所示:
# vtk DataFile Version 2.0
velocity field
ASCII
DATASET STRUCTURED_POINTS
DIMENSIONS 108 103 31
ORIGIN 0.0000000000000000 0.0000000000000000 -297.50000000000000
SPACING 15.465818554775332 12.565027060488859 10.000000000000000
POINT_DATA 344844
SCALARS scalars float
LOOKUP_TABLE default
8.4405251
8.4405251
...
...
...
After the last shown line, the vtk file contains the rest of information, which are merely numbers (~ 300000 values)在最后显示的行之后,vtk 文件包含 rest 的信息,它们只是数字(~ 300000 个值)
My code looks like this:我的代码如下所示:
import vtk
# Read vtk file data
reader = vtk.vtkDataSetReader()
reader.SetFileName("seaust.vtk")
reader.ReadAllScalarsOn() # Activate the reading of all scalars
reader.ReadAllVectorsOn() # Activate the reading of all vectors
reader.ReadAllTensorsOn() # Activate the reading of all tensors
reader.Update()
data = reader.GetOutput()
scalar_range = data.GetScalarRange()
# Create the mapper that corresponds the objects of the vtk file
# into graphics elements
mapper = vtkDataSetMapper()
mapper.SetInput(data)
When trying to compile the code, python prompts me this error:尝试编译代码时,python 提示我这个错误:
AttributeError: 'vtkRenderingCorePython.vtkDataSetMapper' object has no attribute 'SetInput'
I'm expecting a 3D visualisation of my data.我期待我的数据的 3D 可视化。
Can you please help me to get it?你能帮我得到它吗?
I guess you are missing the vtk.我猜你错过了vtk。 in
mapper = vtk.vtkDataSetMapper()
在
mapper = vtk.vtkDataSetMapper()
and you probably need to use mapper.SetInputData(data)
你可能需要使用
mapper.SetInputData(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.