[vtkusers] Help in writing a python script

Jérôme jerome.velut at gmail.com
Fri Dec 4 06:09:11 EST 2009


Hi Luca,

In ParaView, you can open directly a CSV file and then do some calculation
on your data. I am sure you will find -recent- threads and wikis about that.

Outside ParaView (for VTK only script), you could to embed your vtkPoints
into a vtkPolyData and then plug the PolyData into a PolyDataWriter:

polydata = vtk.vtkPolyData( )
polydata.SetPoints( newPoints )

writer = vtk.vtkPolyDataWriter( )
writer.SetInput( polydata )
writer.SetFileName( "your_name" )
writer.Write( )

[I wrote it without any warranty and verifications... good luck!]

BTW, isn't there a vtkCSVReader in VTK???

Jerome

2009/12/4 Luca Penasa <luca.penasa at email.it>

>  hi everybody, im new to the list (and to vtk programming), so please be
> patient with my questions :-)
>
> I am trying to write down a script for converting a csv-like file into a
> vtk readable file.
>
> *Some example rows of the original file:*
>
> 9.045410 9.358978 2772.13 15 0x01
> 9.051514 9.358978 2771.82 21 0x01
> 9.061432 9.361267 2771.79 16 0x01
> 9.069061 9.358215 2771.79 16 0x01
>
> *This is part of the script i wrote for reading this type of csv-like
> file:*
>
> reader =  csv.reader(infile, delimiter=' ')
> newPoints = vtk.vtkPoints()
> newline = []
> ID = 0
>
> for line in reader:
>
> newline.append(cos(float(line[1])*2*pi/180)*sin(float(line[0])*2*pi/180)*float(line[2]))
> #X
>
> newline.append(cos(float(line[1])*2*pi/180)*cos(float(line[0])*2*pi/180)*float(line[2]))
> #Y
>     newline.append(sin(float(line[1])*2*pi/180)*float(line[2]))  #Z
>     newline.append(float(line[3])) #Intensity
>     newPoints.InsertPoint(ID, newline[0], newline[1], newline[2])
>     ID = ID+1
> infile.close()
>
> After reading the file with csv.reader, i do some arithmetics on the
> coordinates and then i put my points in a vtkPoints object..
>
> Now i dont know how to set up a vtk writer for writing out that object in a
> vtk-compatible file format (after that i would like to open that file in
> Paraview)..
> Anybody can help me??
>
> I would like to preserve the 4th column attributes for every point, couse
> is the data i am interested in...
>
>
> Thousand Thanks!!
>
>
>
>
>   --
> ---------------------------
> Luca Penasa
> Student at Geosciences Dpt.
> University of Padua (IT)luca.penasa at email.it
> ---------------------------
>
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091204/af76a548/attachment.htm>


More information about the vtkusers mailing list