我无法使用python显示vtk文件。Spyder Code Analysis提示我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可视化。
你能帮我拿一下吗?
发布于 2019-09-20 22:13:09
我猜你错过vtk了。在mapper = vtk.vtkDataSetMapper()中
而且您可能需要使用mapper.SetInputData(data)
https://stackoverflow.com/questions/58001639
复制相似问题