[vtkusers] How to get access to polygons?
David Gobbi
david.gobbi at gmail.com
Fri Jan 4 17:09:50 EST 2013
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
More information about the vtkusers
mailing list