Hi, David<br><br>Thank you very much for your reply. It is really helpful and fits my problem perfectly.<br><br>At the same time, I find another way, that is <br><br><b> polys->InitTraversal();<br> for(int i = 0; i < polys->GetNumberOfCells(); i++)<br>
{<br> polys->GetNextCell(idList);<br> int a = idList->GetId(0);<br> int b = idList->GetId(1);<br> int c = idList->GetId(2);<br> }</b><br><br>However, I find this way doesn't work in the following code clip<br>
<b><br> polys->InitTraversal();<br> for(int i = 0; i < polys->GetNumberOfCells(); i++)<br> {<br> polys->GetCell(i, idList); // This method returns wrong ids<br> int a = idList->GetId(0);<br>
int b = idList->GetId(1);<br> int c = idList->GetId(2);<br> }</b><br><br>May I know why? And how to deal with it?<br><br>Thank you very much.<br><br>Best wishes<br>Wenlong<br><br><div class="gmail_quote">
2013/1/4 David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Wenlong,<br>
<br>
My favorite way of getting polygons out of a vtkCellArray is with<br>
a loop like this:<br>
<br>
vtkIdType numCells = cellArray->GetNumberOfCells();<br>
vtkIdType cellLocation = 0; // the index into the cell array<br>
<br>
for (vtkIdType i = 0; i < numCells; i++)<br>
{<br>
vtkIdType numIds; // to hold the size of the cell<br>
vtkIdType *pointIds; // to hold the ids in the cell<br>
<br>
cellArray->GetCell(cellLocation, numIds, pointIds);<br>
cellLocation += 1 + numIds;<br>
<br>
...<br>
}<br>
<span class="HOEnZb"><font color="#888888"><br>
- David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Fri, Jan 4, 2013 at 2:44 PM, Wenlong Wang <<a href="mailto:scc.wwl@gmail.com">scc.wwl@gmail.com</a>> wrote:<br>
> Hi, all<br>
><br>
> I am looking into a 3D shape model. It has 5,000+ points, and 9,000+ cells.<br>
> Thus in the .vtk file, I have the polygon data in the format such as follows<br>
><br>
> POLYGONS 9637 38548<br>
> 3 0 1 2<br>
> 3 1 3 4<br>
> 3 2 1 4<br>
> 3 3 5 6<br>
> 3 4 3 6<br>
> 3 5 7 8<br>
> .......<br>
><br>
> The first number of each line indicates how many points are included in the<br>
> cell, and the next 3 numbers indicate the point ids. In my case, the polygon<br>
> is combined by triangles.<br>
><br>
> I use vtkGenericDataObjectReader to open the .vtk file, and then use<br>
> vtkPolyData::GetPolys to get the polygons of the shape model, whose type is<br>
> vtkCellArray pointer.<br>
><br>
> Here is my code clip:<br>
> vtkSmartPointer<vtkGenericDataObjectReader> reader =<br>
> vtkSmartPointer<vtkGenericDataObjectReader>::New();<br>
> reader->SetFileName("C:\\meanshape.vtk");<br>
> reader->OpenVTKFile();<br>
> reader->Update();<br>
><br>
> vtkSmartPointer<vtkPolyData> shape =<br>
> vtkSmartPointer<vtkPolyData>::New();<br>
> shape = reader->GetPolyDataOutput();<br>
><br>
> vtkSmartPointer<vtkCellArray> polys =<br>
> vtkSmartPointer<vtkCellArray>::New();<br>
> polys = shape->GetPolys();<br>
><br>
> My problem is: After I have polygon data in a vtkCellArray instance, how can<br>
> I get access to the point ids in each triangle cell? For example, I want to<br>
> read "0 1 2" in the first line, "1 3 4" in the second line, etc.<br>
><br>
> Can you help me out of this? Many thanks in advance for your kind help.<br>
><br>
> All bests<br>
> Wenlong<br>
</div></div></blockquote></div><br>