使用 Python 绘制 vtk 文件
Plot vtk file using Python
我无法使用 python 显示 vtk 文件。 Spyder 代码分析提示我 vtkDataSetMapper 是一个未定义的名称。
我知道 vtk 文件是有序的,因为我已经使用 Paraview 显示了它。
我的 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
...
...
...
在显示的最后一行之后,vtk 文件包含其余信息,这些信息仅仅是数字(~ 300000 个值)
我的代码如下所示:
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)
尝试编译代码时,python提示我这个错误:
AttributeError: 'vtkRenderingCorePython.vtkDataSetMapper' object has no attribute 'SetInput'
我期待数据的 3D 可视化。
你能帮我拿一下吗?
我猜你错过了 vtk。在
mapper = vtk.vtkDataSetMapper()
你可能需要使用
mapper.SetInputData(data)
我无法使用 python 显示 vtk 文件。 Spyder 代码分析提示我 vtkDataSetMapper 是一个未定义的名称。
我知道 vtk 文件是有序的,因为我已经使用 Paraview 显示了它。
我的 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
...
...
...
在显示的最后一行之后,vtk 文件包含其余信息,这些信息仅仅是数字(~ 300000 个值)
我的代码如下所示:
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)
尝试编译代码时,python提示我这个错误:
AttributeError: 'vtkRenderingCorePython.vtkDataSetMapper' object has no attribute 'SetInput'
我期待数据的 3D 可视化。
你能帮我拿一下吗?
我猜你错过了 vtk。在
mapper = vtk.vtkDataSetMapper()
你可能需要使用
mapper.SetInputData(data)