[vtkusers] Polydata cell connectivity list

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Sun Feb 6 16:15:33 EST 2005





Hi Wesley,
  here are some fragments from C++ code that traverses cells connected to a
point of given id (pid):

  int pid, nCells, cellNum, cid;
  vtkIdList *cells = vtkIdList::New();
  vtkCell *cell;

  // get cells the point belongs to
  this->input->GetPointCells( pid, cells );

  // for each cell
  nCells = cells->GetNumberOfIds();
  for( cellNum=0; cellNum<nCells; cellNum++ )
    {
    cid = cells->GetId( cellNum );          // get cell id from the list
    cell = this->input->GetCell( cid );    // get the actual cell

    // now do something with the cell...
    // for example get its points....
    vtkPoints *pts = cell->GetPoints();  // now get points for this cell
...
    }

See a couple of comments below, hope that helps,
   Dave P

vtkusers-bounces at vtk.org wrote on 05/02/2005 01:59:08:

> Dear Users,
>
> I'm presently trying to find out what other cells a cell is linked to
> by one of its vertexes. And it's driving me slightly mad!
>
>         for supid in self.nobad:
>
>             supcell = self.polydata.GetCell(supid)
>             supid1 = supcell.GetPointId(0)
>             supid2 = supcell.GetPointId(1)
>             checklist = [supid1, supid2]
  the above assumes cells have just 2 points, I guess that is correct?
>
>             for id in checklist:
  checklist is a list of (two) point ids
>                 cells = vtk.vtkIdList()
>                 self.polydata.GetCellPoints(id, cells)
  GetCellPoints expects a cell id, you are passing a point id !
>
>                 numofid = cells.GetNumberOfIds()
>
>                 for cell in range(numofid):
>                     idcell = cells.GetId(cell)
>
>                     if idcell != supid:
>                         if idcell in self.lowbad:
>                             if id not in self.supportlist:
>                                 print "S5"
>                                 self.supportlist.append(id)
>
> Here's the section that is giving me the problem. In my program when
> run there are 1900 cells in the list self.nobad which it has to check.
> If the cell is connected to another cell in the lowbad list the shared
> vertexes id is stored in the list self.supportlist only if it is not
> already contained within this list.
>
> Run as above it runs until cell 656 out of 1900 and closes python with
> an error window without giving any error messages in the Python Shell
> just "pythonw.exe has encountered a problem and needs to close. We are
> sorry for the incovenience."
>
> I've tried adding combinations of  self.polydata.Update(),
> self.polydata.BuildCells(), and self.polydata.BuildLinks() to no
> success. The last, BuildLinks() would only run if there were a 0 value
> inside the brackets, this tip was found from a previous post. I've
> also discovered through various print statements (since removed as
> after two days of bug hunting the language can get 'colourful'!) that
> the loop is crashing on the self.polydata.GetCellPoints(id, cells)
> statement on the 656th pass and does not seem to be finding any cells
> with more or less than 2 cells sharing a vertex when I expect most
> vertexes to be shared by up to ten cells.
>
> Any alternative, perhaps quicker approaches or feed back on the above
> code would also be greatly appreciated; I'm a beginner to programming
> and having to deal with datasets which have included up to 310000
> cells.
>
> Many thanks for your time.
>
> Yours Faithfully,
>
> Wesley Brooks
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.
> org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list