LoopStructural.datatypes.BoundingBox#
- class LoopStructural.datatypes.BoundingBox(origin: ndarray | None = None, maximum: ndarray | None = None, global_origin: ndarray | None = None, global_maximum: ndarray | None = None, nsteps: ndarray | None = None, step_vector: ndarray | None = None, dimensions: int | None = 3)#
Bases:
objectA 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, global_maximum: 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_centres([order])Get the cell centres of a regular grid
fit(locations[, local_coordinate])Initialise the bounding box from a set of points.
from_dict(data)Create a bounding box from a dictionary
get_value(name)is_inside(xyz)matrix([normalise])Get the transformation matrix from local to global coordinates
project(xyz[, inplace])Project a point into the bounding box
regular_grid([nsteps, shuffle, order, local])Get the grid of points from the bounding box
reproject(xyz[, inplace])Reproject a point from the bounding box to the global space
scale_by_projection_factor(value)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
Get a numpy array containing origin and maximum coordinates.
Returns the corners of the bounding box in local coordinates
Returns the corners of the bounding box in the original space
Get the global maximum coordinates of the bounding box.
Get the global origin of the bounding box.
lengthGet the maximum coordinates of the bounding box.
Get the total number of elements in the bounding box.
Get the origin coordinates of the bounding box.
step_vectorCheck if the bounding box has valid origin and maximum values.
Calculate the volume of the bounding box.
- property bb#
Get a numpy array containing origin and maximum coordinates.
- Returns:
np.ndarray – Array with shape (2, n_dimensions) containing [origin, maximum]
- cell_centres(order: str = 'F') ndarray#
Get the cell centres of a regular grid
- Parameters:
order (str, optional) – order of the grid, by default “C”
- Returns:
np.ndarray – array of cell centres
- 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_
- classmethod from_dict(data: dict) BoundingBox#
Create a bounding box from a dictionary
- Parameters:
data (dict) – dictionary with origin, maximum and nsteps
- Returns:
BoundingBox – bounding box object
- property global_maximum#
Get the global maximum coordinates of the bounding box.
- Returns:
np.ndarray – The global maximum coordinates (local maximum + global origin)
- property global_origin#
Get the global origin of the bounding box.
- Returns:
np.ndarray – The global origin coordinates
- matrix(normalise: bool = False) ndarray#
Get the transformation matrix from local to global coordinates
- Returns:
np.ndarray – 4x4 transformation matrix
- property maximum: ndarray#
Get the maximum coordinates of the bounding box.
- Returns:
np.ndarray – Maximum coordinates
- Raises:
LoopValueError – If the maximum is not set
- property nelements#
Get the total number of elements in the bounding box.
- Returns:
int – Total number of elements (product of nsteps)
- property origin: ndarray#
Get the origin coordinates of the bounding box.
- Returns:
np.ndarray – Origin coordinates
- Raises:
LoopValueError – If the origin is not set
- project(xyz, inplace=False)#
Project a point into the bounding box
- Parameters:
xyz (np.ndarray) – point to project
inplace (bool, optional) – Whether to modify the input array in place, by default False
- Returns:
np.ndarray – projected point
- regular_grid(nsteps: list | ndarray | None = None, shuffle: bool = False, order: str = 'F', 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, inplace=False)#
Reproject a point from the bounding box to the global space
- Parameters:
xyz (np.ndarray) – point to reproject
inplace (bool, optional) – Whether to modify the input array in place, by default False
- 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
- property valid#
Check if the bounding box has valid origin and maximum values.
- Returns:
bool – True if both origin and maximum are set, False otherwise
- property volume#
Calculate the volume of the bounding box.
- Returns:
float – Volume of the bounding box
- 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