Skip to content

webknossos.geometry.bounding_box

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[Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]], Iterable[str], int], size: Union[Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]], Iterable[str], int], axes: Tuple[str, str, str] = ('x', 'y', 'z'), index: webknossos.geometry.vec3_int.Vec3Int = Vec3Int(1,2,3), 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.

axes: Tuple[str, str, str]
name: Union[str, NoneType]
is_visible: bool
color: Union[Tuple[float, float, float, float], NoneType]
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:

Create an instance of NDBoundingBox from a dictionary representation.

Args:

  • bbox (Dict): The dictionary representation of the bounding box.

Returns:

  • NDBoundingBox: An instance of NDBoundingBox.

Raises:

  • AssertionError: If additionalAxes are present but axisOrder is not provided.
@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 empty(cls) -> webknossos.geometry.bounding_box.BoundingBox:
def to_wkw_dict(self) -> dict:

Converts the bounding box object to a json dictionary.

Returns:

  • dict: A json dictionary representing the bounding box.
def to_config_dict(self) -> dict:

Returns a dictionary representation of the bounding box.

Returns:

  • dict: A dictionary representation of the bounding box.
def to_checkpoint_name(self) -> str:

Returns a string representation of the bounding box that can be used as a checkpoint name.

Returns:

  • str: A string representation of the bounding box.
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 is_empty(self) -> bool:

Boolean check whether the boundung box is empty.

Returns:

  • bool: True if the bounding box is empty, False otherwise.

Returns the bounding box in the given mag.

Args:

  • mag (Mag): The magnification to convert the bounding box to.

Returns:

  • NDBoundingBox: The bounding box in the given magnification.

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 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 offset( self, vector: Union[webknossos.geometry.vec3_int.Vec3Int, Tuple[int, int, int], numpy.ndarray, Iterable[int]]) -> webknossos.geometry.bounding_box.BoundingBox:

Returns a new NDBoundingBox object with the specified offset.

Args:

  • vector (VecIntLike): The offset to apply to the bounding box.

Returns:

  • NDBoundingBox: A new NDBoundingBox object with the specified offset.