LoopStructural.datatypes.BoundingBox#
- class LoopStructural.datatypes.BoundingBox(origin: ndarray | None = None, maximum: ndarray | None = None, global_origin: ndarray | None = None, nsteps: ndarray | None = None, step_vector: ndarray | None = None, dimensions: int | None = 3)#
Bases:
object
A bounding box for a model, defined by the origin, maximum and number of steps in each direction
- Parameters:
dimensions (int, optional) – _description_, by default 3
origin (Optional[np.ndarray], optional) – _description_, by default None
maximum (Optional[np.ndarray], optional) – _description_, by default None
nsteps (Optional[np.ndarray], optional) – _description_, by default None
- __init__(origin: ndarray | None = None, maximum: ndarray | None = None, global_origin: ndarray | None = None, nsteps: ndarray | None = None, step_vector: ndarray | None = None, dimensions: int | None = 3)#
A bounding box for a model, defined by the origin, maximum and number of steps in each direction
- Parameters:
dimensions (int, optional) – _description_, by default 3
origin (Optional[np.ndarray], optional) – _description_, by default None
maximum (Optional[np.ndarray], optional) – _description_, by default None
nsteps (Optional[np.ndarray], optional) – _description_, by default None
Methods
__init__
([origin, maximum, global_origin, ...])A bounding box for a model, defined by the origin, maximum and number of steps in each direction
cell_centers
([order])Get the cell centers of a regular grid
fit
(locations[, local_coordinate])Initialise the bounding box from a set of points.
get_value
(name)is_inside
(xyz)project
(xyz)Project a point into the bounding box
regular_grid
([nsteps, shuffle, order, local])Get the grid of points from the bounding box
reproject
(xyz)Reproject a point from the bounding box to the global space
structured_grid
([cell_data, vertex_data, name])to_dict
()Export the defining characteristics of the bounding box to a dictionary for json serialisation
vtk
()Export the model as a pyvista RectilinearGrid
with_buffer
([buffer])Create a new bounding box with a buffer around the existing bounding box
Attributes
bb
Returns the corners of the bounding box in local coordinates
Returns the corners of the bounding box in the original space
global_maximum
global_origin
length
maximum
nelements
origin
step_vector
valid
volume
- cell_centers(order: str = 'F') ndarray #
Get the cell centers of a regular grid
- Parameters:
order (str, optional) – order of the grid, by default “C”
- Returns:
np.ndarray – array of cell centers
- property corners: ndarray#
Returns the corners of the bounding box in local coordinates
- Returns:
np.ndarray – array of corners in clockwise order
- property corners_global: ndarray#
Returns the corners of the bounding box in the original space
- Returns:
np.ndarray – corners of the bounding box
- fit(locations: ndarray, local_coordinate: bool = False) BoundingBox #
Initialise the bounding box from a set of points.
- Parameters:
locations (np.ndarray) – xyz locations of the points to fit the bbox
local_coordinate (bool, optional) – whether to set the origin to [0,0,0], by default False
- Returns:
BoundingBox – A reference to the bounding box object, note this is not a new bounding box it updates the current one in place.
- Raises:
LoopValueError – _description_
- project(xyz)#
Project a point into the bounding box
- Parameters:
xyz (np.ndarray) – point to project
- Returns:
np.ndarray – projected point
- regular_grid(nsteps: list | ndarray | None = None, shuffle: bool = False, order: str = 'C', local: bool = True) ndarray #
Get the grid of points from the bounding box
- Parameters:
nsteps (Optional[Union[list, np.ndarray]], optional) – number of steps, by default None uses self.nsteps
shuffle (bool, optional) – Whether to return points in order or random, by default False
order (str, optional) – when flattening using numpy “C” or “F”, by default “C”
local (bool, optional) – Whether to return the points in the local coordinate system of global , by default True
- Returns:
np.ndarray – numpy array N,3 of the points
- reproject(xyz)#
Reproject a point from the bounding box to the global space
- Parameters:
xyz (np.ndarray) – point to reproject
- Returns:
np.ndarray – reprojected point
- to_dict() dict #
Export the defining characteristics of the bounding box to a dictionary for json serialisation
- Returns:
dict – dictionary with origin, maximum and nsteps
- vtk()#
Export the model as a pyvista RectilinearGrid
- Returns:
pv.RectilinearGrid – a pyvista grid object
- Raises:
ImportError – If pyvista is not installed raise import error
- with_buffer(buffer: float = 0.2) BoundingBox #
Create a new bounding box with a buffer around the existing bounding box
- Parameters:
buffer (float, optional) – percentage to expand the dimensions by, by default 0.2
- Returns:
BoundingBox – The new bounding box object.
- Raises:
LoopValueError – if the current bounding box is invalid