Skip to content

webknossos.geometry.bounding_box

class BoundingBox:

This class is used to represent an axis-aligned cuboid in 3D. The top-left coordinate is inclusive and the bottom-right coordinate is exclusive.

A small usage example:

from webknossos import BoundingBox

bbox_1 = BoundingBox((0, 0, 0), (100, 100, 100))
bbox_2 = BoundingBox((75, 75, 75), (100, 100, 100))

assert bbox_1.intersected_with(bbox_2).size == (25, 25, 25)
BoundingBox( topleft: Union[int, Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]], size: Union[int, Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]], name: Union[str, NoneType] = 'Unnamed Bounding Box', is_visible: bool = True, color: Union[Tuple[float, float, float, float], NoneType] = None)

Method generated by attrs for class BoundingBox.

name: Union[str, NoneType]
is_visible: bool
color: Union[Tuple[float, float, float, float], NoneType]
def with_topleft( self, new_topleft: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]) -> webknossos.geometry.bounding_box.BoundingBox:
def with_size( self, new_size: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]) -> webknossos.geometry.bounding_box.BoundingBox:
def with_name( self, name: Union[str, NoneType]) -> webknossos.geometry.bounding_box.BoundingBox:
def with_is_visible(self, is_visible: bool) -> webknossos.geometry.bounding_box.BoundingBox:
def with_color( self, color: Union[Tuple[float, float, float, float], NoneType]) -> webknossos.geometry.bounding_box.BoundingBox:
def with_bounds_x( self, new_topleft_x: Union[int, NoneType] = None, new_size_x: Union[int, NoneType] = None) -> webknossos.geometry.bounding_box.BoundingBox:

Returns a copy of the bounding box with topleft.x optionally replaced and size.x optionally replaced.

def with_bounds_y( self, new_topleft_y: Union[int, NoneType] = None, new_size_y: Union[int, NoneType] = None) -> webknossos.geometry.bounding_box.BoundingBox:

Returns a copy of the bounding box with topleft.y optionally replaced and size.y optionally replaced.

def with_bounds_z( self, new_topleft_z: Union[int, NoneType] = None, new_size_z: Union[int, NoneType] = None) -> webknossos.geometry.bounding_box.BoundingBox:

Returns a copy of the bounding box with topleft.z optionally replaced and size.z optionally replaced.

@classmethod
def from_wkw_dict(cls, bbox: Dict) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def from_config_dict(cls, bbox: Dict) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def from_tuple6( cls, tuple6: Tuple[int, int, int, int, int, int]) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def from_tuple2( cls, tuple2: Tuple[Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]], Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]]) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def from_points( cls, points: Iterable[Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]]) -> webknossos.geometry.bounding_box.BoundingBox:

Returns a bounding box exactly containing all points.

@classmethod
def from_checkpoint_name( cls, checkpoint_name: str) -> webknossos.geometry.bounding_box.BoundingBox:

This function extracts a bounding box in the format x_y_z_sx_sy_xz which is contained in a string.

@classmethod
def from_csv(cls, csv_bbox: str) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def from_auto( cls, obj: Union[webknossos.geometry.bounding_box.BoundingBox, str, Dict, List, Tuple]) -> webknossos.geometry.bounding_box.BoundingBox:
@classmethod
def group_boxes_with_aligned_mag( cls, bounding_boxes: collections.abc.Iterable[webknossos.geometry.bounding_box.BoundingBox], aligning_mag: webknossos.geometry.mag.Mag) -> dict[webknossos.geometry.bounding_box.BoundingBox, list[webknossos.geometry.bounding_box.BoundingBox]]:

Groups the given BoundingBox instances by aligning each bbox to the given mag and using that as the key. For example, bounding boxes of size 2563 could be grouped into the corresponding 10243 chunks to which they belong by using aligning_mag = Mag(1024).

@classmethod
def empty(cls) -> webknossos.geometry.bounding_box.BoundingBox:
def to_wkw_dict(self) -> dict:
def to_config_dict(self) -> dict:
def to_checkpoint_name(self) -> str:
def to_tuple6(self) -> Tuple[int, int, int, int, int, int]:
def to_csv(self) -> str:
def padded_with_margins( self, margins_left: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]], margins_right: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None) -> webknossos.geometry.bounding_box.BoundingBox:
def intersected_with( self, other: webknossos.geometry.bounding_box.BoundingBox, dont_assert: bool = False) -> webknossos.geometry.bounding_box.BoundingBox:

If dont_assert is set to False, this method may return empty bounding boxes (size == (0, 0, 0))

def is_empty(self) -> bool:

Rounds the bounding box, so that both topleft and bottomright are divisible by mag.

:argument ceil: If true, the bounding box is enlarged when necessary. If false, it's shrinked when necessary.

def contains( self, coord: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]) -> bool:

Check whether a point is inside of the bounding box. Note that the point may have float coordinates in the ndarray case

def contains_bbox(self, inner_bbox: webknossos.geometry.bounding_box.BoundingBox) -> bool:
def chunk( self, chunk_shape: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]], chunk_border_alignments: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int], NoneType] = None) -> collections.abc.Generator[webknossos.geometry.bounding_box.BoundingBox, NoneType, NoneType]:

Decompose the bounding box into smaller chunks of size chunk_shape.

Chunks at the border of the bounding box might be smaller than chunk_shape. If chunk_border_alignment is set, all border coordinates between two chunks will be divisible by that value.

def volume(self) -> int:
def slice_array(self, array: numpy.ndarray) -> numpy.ndarray:
def to_slices(self) -> Tuple[slice, slice, slice]:
def offset( self, vector: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]) -> webknossos.geometry.bounding_box.BoundingBox: