[vtkusers] python-vtk and reading vtk files

Xavier Barthelemy xabart at gmail.com
Tue Jun 1 22:53:25 EDT 2010


Greetings everyone,

I am a new subscriber to this list, and i need some help.

I want to make a post process calculation from the exits of a code, in python.

my code, which is a Bem formulation, gives an output in .vtk files.
Theses files have all the information I need, obviously at the
boundary.
Others output of the code is in a regular grid inside the domain, and
has no evident relation between the boundary mesh.

What i want to do is read the different infos on the boundaries, and
then doing some calculations with the inner grid, and probably write a
vtk file.

All of that at each time step.

that brings me to my questions:
i know this is an unstructured grid,

my python code is:

import vtk
reader = vtk.vtkDataSetReader()
reader.SetFileName("testvtk1.vtk")
reader.Update()


datas=reader.GetOutput()

npoints=datas.GetNumberOfPoints()
ncells = datas.GetNumberOfCells()
nscalars=reader.GetNumberOfScalarsInFile()
nvectors=reader.GetNumberOfVectorsInFile()
ntensors=reader.GetNumberOfTensorsInFile()
print "Number of tensorss: " ,  ntensors
for i in xrange(nscalars):
  Scalarnames=reader.GetScalarsNameInFile(i)
  print "Scalarnames",i,Scalarnames
for i in xrange(nvectors):
  Vectornames=reader.GetVectorsNameInFile(i)
  print "vectornames",i,Vectornames


until there everything is okey
but when i want to access to the datas: points coordinates,cell and
connectivity, mesh, and values of the scalars and vectors at the
points, let's say everything. I don't understand how it is working

for example
points=reader.ReadPointData()

tells me it needs a vtkDataset, but vtkDataSet is a superclass, and i
don't really understand how to create it

i have been looking over the differents mailing list, test, examples,
wikis, and even the headers of the C++ code, but still I don't
understand.

Is someone know how to read these files?
I thanks you in advance,
Xavier



More information about the vtkusers mailing list