Issue
I cannot display a vtk file using python. Spyder Code Analysis prompts me that vtkDataSetMapper is an undefined name.
I know the vtk file is in order because I have already displayed it using Paraview.
My vtk file looks like this:
# 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)
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:
AttributeError: 'vtkRenderingCorePython.vtkDataSetMapper' object has no attribute 'SetInput'
I'm expecting a 3D visualisation of my data.
Can you please help me to get it?
Solution
I guess you are missing the vtk. in
mapper = vtk.vtkDataSetMapper()
and you probably need to use
mapper.SetInputData(data)
Answered By - mmusy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.