[vtkusers] access polygons in Python

Alex Southern mrapsouthern at gmail.com
Sat Jun 30 06:23:46 EDT 2012


What are the chances? with in 1 minute of me thinking about asking this, 
you actually ask it.

I dont have the solution myself yet, but I was just looking at (in C++)

vtkCellArray *polys;
vtkSmartPointer<vtkPolyDataReader> pd = 
vtkSmartPointer<vtkPolyDataReader>::New();

pd->SetFileName( "test.vtk" );
polys = pd->GetOutput()->GetPolys();

so I guess for python it is..

Data = Reader.GetOutput().GetPolys()   ???? I dont know Python so well.

If it works, or you find the solution please followup.

Thanks
A.

On 6/30/2012 1:18 AM, Forrest Sheng Bao wrote:
> Hi,
>
> I am struggling to access polygon faces in my VTK files using Python. 
> Suppose I have the following segment in my
> file:
>
> POLYGONS 275558 1102232
> 3 0 1 2
> 3 3 2 1
> 3 0 45 46
> 3 0 46 1
> 3 0 2 50
>
> I used the piece of code below to prepare:
>
>     import vtk
>     Reader = vtk.vtkDataSetReader()
>     Reader.SetFileName('my_test_file.vtk')
>     Reader.ReadAllScalarsOn()  # Activate the reading of all scalars
>     Reader.Update()
>     Data = Reader.GetOutput()
>     CellData = Data.GetCell(0)
>
> I assume CellData.GetPointId(x) is what I should use. But I got wrong 
> point ID after x =3.
>
> Can someone help me on this?
>
> Cheers,
> Forrest
>
>
> _______________________________________________
> 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/20120630/0071a25a/attachment.htm>


More information about the vtkusers mailing list