[PYTHON] vtkXMLUnstructuredGridReader Summary (updated from time to time)

About vtkXMLUnstructuredGridReader

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.

Basic code

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();

image.png

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)

Method

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

vtkXMLUnstructuredGridReader Summary (updated from time to time)
vtkOpenFOAMReader Summary (Updated from time to time)
vtkClipPolyData / DataSet Summary (Updated from time to time)
Summary of vtkThreshold (updated from time to time)
Summary of gcc options (updated from time to time)
Engineer vocabulary (updated from time to time)
Machine learning python code summary (updated from time to time)
Tensorflow memo [updated from time to time]
[Updated from time to time] Summary of design patterns in Java
Private Python handbook (updated from time to time)
[Updated from time to time] PostmarketOS related notes
[Updated from time to time] LetCode algorithm and library
Notes on machine learning (updated from time to time)
OpenFOAM post-processing cheat sheet (updated from time to time)
progate Python learning memo (updated from time to time)
Useful help sites, etc. (updated from time to time)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Apache settings, log confirmation, etc. (* Updated from time to time)
[Updated from time to time] Review of Let Code NumPy
I read the Chainer reference (updated from time to time)
Python (from first time to execution)
[Notes / Updated from time to time] This and that of Azure Functions
[Note] AI / machine learning / python related websites [updated from time to time]
Easy conversion from UTC to local time
Summary of folders where Ruby, Python, PostgreSQL, etc. are installed on macOS (updated from time to time)
Updated to Python 2.7.9
Sum from 1 to 10
(Updated from time to time) Summary of machine learning APIs that allow you to quickly build apps by Team AI
Understand design patterns by comparing implementations in JavaScript and Java [Updated from time to time]
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Transition from WSL1 to WSL2
[Updated from time to time] Python memos often used for data analysis [N division, etc.]
A memorandum of commands, packages, terms, etc. used in linux (updated from time to time)
From editing to execution
Updated Hospital_dashboard to ver.2.0
(Updated from time to time) Storage location of various VS Code configuration files Memorandum memo
List of my articles that may be useful in competition pros (updated from time to time)
Summary from building Python 3.4. * From source to building a scientific computing environment
[Introduction to matplotlib] Read the end time from COVID-19 data ♬
Post from Python to Slack
Cheating from PHP to Python
Porting from argparse to hydra
Migrating from Chainer v1 to Chainer v2
Migrated from Flask-RESTPlus to Flask-RESTX
Updated home watching camera: Summary
Update python-social-auth from 0.1.x to 0.2.x
Migrate from requirements.txt to pipenv
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
git / python> git log analysis (v0.1, v0.2)> Implementation to estimate work time from git log
Summary of advantages (disadvantages) when switching from CUnit to Google Test