DataSet.find_containing_cell#
- DataSet.find_containing_cell( ) int | NumpyArray[int][source]#
Find index of a cell that contains the given point.
Warning
This filter internally builds and caches a vtkStaticCellLocator. If the mesh’s geometry is modified, the cache will no longer be valid.
- Parameters:
- point
VectorLike[float] |MatrixLike[float], Coordinates of point to query (length 3) or a
numpy.ndarrayofnpoints with shape(n, 3).
- point
- Returns:
- output
int|numpy.ndarray Index or indices of the cell in this mesh that contains the given point.
Changed in version 0.35.0: Inputs of shape
(1, 3)now return anumpy.ndarrayof shape(1,).
- output
Examples#
Download Python source code | Download Jupyter notebook
A unit square with 16 equal sized cells is created and a cell
containing the point [0.3, 0.3, 0.0] is found.
>>> import pyvista as pv
>>> mesh = pv.ImageData(dimensions=[5, 5, 1], spacing=[1 / 4, 1 / 4, 0])
>>> mesh
ImageData...
>>> mesh.find_containing_cell([0.3, 0.3, 0.0])
5
A point outside the mesh domain will return -1.
>>> mesh.find_containing_cell([0.3, 0.3, 1.0])
-1
Find the cells that contain 1000 random points inside the mesh.
>>> import numpy as np
>>> points = np.random.default_rng().random((1000, 3))
>>> indices = mesh.find_containing_cell(points)
>>> indices.shape
(1000,)