How to find all cells connected to a list of points?


How can I find the set of cells in a vtkPolyData or vtkUnstructuredGrid that are connected to a set of points?

I have a vtkPolyData with a PointData field. I want to find all cells that connect to points where the PointData meets some criteria.

I see methods to get cells from ondividual points but I don’t see a bulk method (I’m working in Python and don’t want to iterate)

Any advice will be gratefully received.


You might want to consider the GetPointCells() function of vtkPolyData and vtkUnstructuredGrid.

Unfortunatley that method only takes a single point as input. As I’m working in Python I don’t really want to iterate over the set of piints

vtkPolyDataConnectivityFilter (or vtkConnectivityFilter) might work depending on your data - there is an option for point seeded regions. However if I remember correctly, these extract connected “regions” not necessarily just the cells connected to specific points. So you might have to combine this with the ScalarConnectivity option, and set the ScalarRange of the seed points in an appropriate range.

Thanks Will. I think these filters require you to add one seed ata time too and since I’m working in Python and have a lot of seeds I’m keen to avoid this approach.

I think I’m going to try getting the CellLinks from the poly and see if I can wrangle these into numpy or pandas.

It does seem like it would be a useful method to add though. Maybe I’ll give it a go - although I’m struggling to find the time :frowning:

You can add multiple seeds prior to filter execution. But using scalars to control extraction of cells is admittedly a bit obscure. It would be useful to create an extraction filter that outputs cells connected to specified points, I’m actually quite surprised that one doesn’t already exist, but I sure can’t find it :slight_smile:

Yes - you can add multiple seeds but you have to add them one at a time instead of a list/array . No ‘AddSeeds()’ method.

Despite the fact I’m using Python, I am very performance sensitive :slight_smile:

Yes - I was surprised that there wasn’t already a filter. As it turns out, I no longer need this capability - at least for the moment. Figured out better overall solution to my proble.


Got it, these connectivity classes should be extended to support seed arrays. I’ll add it to my list (unless you want to take a crack at it).

Will - Turns out you can do this using the selection classes. The hidden gem is the last line of this block.
I can’t actually find this documented anywhere, BUT, there is an example which I just converted to Python and sucesfully tested

    selectionNode.GetProperties().Set(vtkSelectionNode.CONTAINING_CELLS(), 1)

I take back what I said about this being undocumented - it is referenced on the vtkSelectionNode class docs

Most excellent, old dog, new trick, thanks!

1 Like

Doug, check this out and provide feedback. Connectivity filters were modified etc.

Thanks Will - I’ll test and provide feedback, although it may take a few days…