[vtkusers] How to get access to polygons?

Wenlong Wang scc.wwl at gmail.com
Fri Jan 4 16:44:39 EST 2013


Hi, all

I am looking into a 3D shape model. It has 5,000+ points, and 9,000+ cells.
Thus in the .vtk file, I have the polygon data in the format such as follows

POLYGONS 9637 38548
3 0 1 2
3 1 3 4
3 2 1 4
3 3 5 6
3 4 3 6
3 5 7 8
.......

The first number of each line indicates how many points are included in the
cell, and the next 3 numbers indicate the point ids. In my case, the
polygon is combined by triangles.

I use *vtkGenericDataObjectReader* to open the .vtk file, and then use *
vtkPolyData::GetPolys* to get the polygons of the shape model, whose type
is *vtkCellArray* pointer.

Here is my code clip:
    vtkSmartPointer<vtkGenericDataObjectReader> reader =
vtkSmartPointer<vtkGenericDataObjectReader>::New();
    reader->SetFileName("C:\\meanshape.vtk");
    reader->OpenVTKFile();
    reader->Update();

    vtkSmartPointer<vtkPolyData> shape =
vtkSmartPointer<vtkPolyData>::New();
    shape = reader->GetPolyDataOutput();

    vtkSmartPointer<vtkCellArray> polys =
vtkSmartPointer<vtkCellArray>::New();
    polys = shape->GetPolys();
*
My problem is:* After I have polygon data in a vtkCellArray instance, how
can I get access to the point ids in each triangle cell? For example, I
want to read "0 1 2" in the first line, "1 3 4" in the second line, etc.

Can you help me out of this? Many thanks in advance for your kind help.

All bests
Wenlong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130104/21c5d415/attachment.htm>


More information about the vtkusers mailing list