[vtkusers] How to get access to polygons?

Wenlong Wang scc.wwl at gmail.com
Fri Jan 4 17:53:08 EST 2013


Hi, David

Thank you very much for your reply. It is really helpful and fits my
problem perfectly.

At the same time, I find another way, that is

*    polys->InitTraversal();
    for(int i = 0; i < polys->GetNumberOfCells(); i++)
    {
        polys->GetNextCell(idList);
        int a = idList->GetId(0);
        int b = idList->GetId(1);
        int c = idList->GetId(2);
    }*

However, I find this way doesn't work in the following code clip
*
    polys->InitTraversal();
    for(int i = 0; i < polys->GetNumberOfCells(); i++)
    {
        polys->GetCell(i, idList);    // This method returns wrong ids
        int a = idList->GetId(0);
        int b = idList->GetId(1);
        int c = idList->GetId(2);
    }*

May I know why? And how to deal with it?

Thank you very much.

Best wishes
Wenlong

2013/1/4 David Gobbi <david.gobbi at gmail.com>

> Hi Wenlong,
>
> My favorite way of getting polygons out of a vtkCellArray is with
> a loop like this:
>
>   vtkIdType numCells = cellArray->GetNumberOfCells();
>   vtkIdType cellLocation = 0; // the index into the cell array
>
>   for (vtkIdType i = 0; i < numCells; i++)
>     {
>     vtkIdType numIds; // to hold the size of the cell
>     vtkIdType *pointIds; // to hold the ids in the cell
>
>     cellArray->GetCell(cellLocation, numIds, pointIds);
>     cellLocation += 1 + numIds;
>
>     ...
>   }
>
>  - David
>
>
> On Fri, Jan 4, 2013 at 2:44 PM, Wenlong Wang <scc.wwl at gmail.com> wrote:
> > 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/1e745c08/attachment.htm>


More information about the vtkusers mailing list