[vtkusers] python-vtk and reading vtk files

Rodrigo Valiña Gutiérrez rodrigo.valina at usc.es
Wed Jun 2 03:26:15 EDT 2010


Hi Xavier,

maybe calling:

reader.ReadAllScalarsOn(), reader.ReadAllVectorsOn() (...) before
reader.Update(),

and

d = datas.GetCellData()
d = datas.GetPointData()
array = d.GetArray(name)
size = array.GetNumberOfTuples()
comp = array.GetNumberOfComponents()
for i in range(size):
    print array.GetValue(i)

--

Rodrigo

On Wed, Jun 2, 2010 at 4:53 AM, Xavier Barthelemy <xabart at gmail.com> wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list