class reference
https://vtk.org/doc/nightly/html/classvtkXMLUnstructuredGridReader.html
If you don't have the functionality you want, you may also want to investigate the parent class vtkXMLUnstructuredDataReader
.
By using vtkXMLUnstructuredGridReader
, you can read vtm format
files with vtk library.
This time we will create a vtu file using the result of OpenFOAM
terminal
$ git clone https://github.com/matsubaraDaisuke/vtk-data-set.git
$ cd openfoam_case
$ foamTovkt -ascii
VTK
is created directly under ʻopenfoam_case, and a folder is created every output time of ʻOpenFOAM
. The vtm file
is in that folder.
import vtk
# reader
reader = vtk.vtkXMLUnstructuredGridReader ()
reader.SetFileName("VTK/src_283/internal.vtu"); #vtu file path
reader.Update()
# filter
filter = vtk.vtkGeometryFilter()
filter.SetInputConnection(reader.GetOutputPort())
filter.Update()
# mapper
mapper = vtk.vtkCompositePolyDataMapper2()
mapper.SetInputConnection(filter.GetOutputPort()) #Set filter in mapper
# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper) #Set mapper for actor
actor.GetProperty().EdgeVisibilityOn()
# renderer
renderer = vtk.vtkRenderer()
renderer.AddActor(actor) #Set actor in renderer
##Background color setting
renderer.GradientBackgroundOn() #Set gradient background
renderer.SetBackground2(0.2,0.4,0.6) #Top color
renderer.SetBackground(1,1,1) #Bottom color
#Window
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer) #Set renderer in Window
iren = vtk.vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
renWin.SetSize(850, 850)
renWin.Render()
iren.Start();
You can see the information with print
print(reader)
>>
vtkXMLUnstructuredGridReader (0x7ff031cf9b50)
Debug: Off
Modified Time: 9623
Reference Count: 2
Registered Events: (none)
Executive: 0x7ff031cf3c90
ErrorCode: Undefined error: 0
Information: 0x7ff031ce3700
AbortExecute: Off
Progress: 1
Progress Text: (None)
FileName: VTK/src_283/internal.vtu
CellDataArraySelection: 0x7ff031ce3b20
PointDataArraySelection: 0x7ff031cef0e0
ColumnArraySelection: 0x7ff031cef0e0
Stream: (none)
TimeStep:0
NumberOfTimeSteps:0
TimeStepRange:(0,0)
It is actually implemented in vtkXMLUnstructuredDataReader
.
GetNumberOfPoints Number of parts? Get
reader.GetNumberOfPoints()
>> 1
GetNumberOfCells Get the number of cells
reader.GetNumberOfCells ()
>> 12225
GetNumberOfPoints Get the number of nodes
GetNumberOfPoints
>> 25012
Recommended Posts