routing.core.functions#

Base file for storing all useful functions.

class routing.core.functions.CompressedArray(data: bytes, shape: tuple, dtype: dtype)[source]#

Bases: object

A compressed numpy array using zlib.

data: bytes#
dtype: dtype#
property nbytes: int#

Return compressed size in bytes.

shape: tuple#
routing.core.functions.build_frame(node: tuple[float, float, float], next_node: tuple[float, float, float]) ndarray[source]#

Build a standard default frame from two points.

routing.core.functions.build_frame_from_vector(node: ndarray, vector: ndarray) ndarray[source]#

Build a standard default frame from origin node and main axis vector.

routing.core.functions.build_frame_vectorized(node: ndarray, next_node: ndarray) ndarray[source]#

Build a standard default frame from two points (vectorized).

routing.core.functions.build_voxel_primitive(voxels: MatrixBasedVoxelization, frame: Frame3D = None, name: str = '') Primitive3D[source]#

Build a 3D primitive from voxelization with optional frame transformation.

routing.core.functions.compress_array(array: ndarray | CompressedArray | None) CompressedArray | None[source]#

Compress a numpy array using zlib compression.

routing.core.functions.coord_to_voxel_index(point: tuple[float, float, float], voxel_origin: tuple[float, float, float], voxel_size: float) tuple[int, int, int][source]#

Gives the voxel containing a point.

routing.core.functions.coord_to_voxel_index_continuous(point: tuple[float, float, float], voxel_origin: tuple[float, float, float], voxel_size: float) tuple[float, float, float][source]#

Gives the voxel containing a point.

routing.core.functions.csv_to_dicts(path: str) list[dict][source]#

Read a CSV file into a list of dicts, parsing numeric values and skipping empty cells.

routing.core.functions.dot(a: tuple, b: tuple) float[source]#

Compute the dot product of two 3D vectors.

routing.core.functions.extract_point_carrier_voxels(voxels: MatrixBasedVoxelization, point: ndarray) MatrixBasedVoxelization[source]#

Get the connex MatrixBasedVoxelization that carry a point from a non-connex MatrixBasedVoxelization.

routing.core.functions.filter_voxels_by_axis_range(voxels: ndarray, axis: int, min_val: float, max_val: float) ndarray[source]#

Filter voxels by coordinate range on a specified axis (0=x, 1=y, 2=z).

routing.core.functions.filter_voxels_by_x_range(voxels: ndarray, x_min: float, x_max: float) ndarray[source]#

Filter voxels by x-coordinate range.

routing.core.functions.filter_voxels_by_y_range(voxels: ndarray, y_min: float, y_max: float) ndarray[source]#

Filter voxels by y-coordinate range.

routing.core.functions.filter_voxels_by_z_range(voxels: ndarray, z_min: float, z_max: float) ndarray[source]#

Filter voxels by z-coordinate range.

routing.core.functions.from_bounding_rectangles(bounding_rectangles: list[BoundingRectangle], name: str = '') BoundingRectangle[source]#

Create a bounding rectangle that contains multiple bounding rectangles.

Parameters:
  • bounding_rectangles – A list of bounding rectangles that need to be contained.

  • name – A name for the bounding rectangles, optional.

Returns:

A new bounding rectanglesthat contains all the input bounding rectangles.

routing.core.functions.get_all_neighbors(index: tuple[int, int, int], diagonal: bool = False) list[tuple[int, int, int]][source]#

Gives all neighbors of a node.

routing.core.functions.get_bounding_rectangle(center: tuple[float, float], radius: float) BoundingRectangle[source]#

Compute the bounding rectangle for a circle.

Args:

center (tuple): The (x, y) center of the circle. radius (float): Radius of the circle.

Returns:

BoundingRectangle: The bounding box around the circle.

routing.core.functions.get_crossed_voxels(weights: ndarray, node1: tuple[int, int, int], node2: tuple[int, int, int]) ndarray[source]#

Get all crossed voxels by a line segment from node1 to node2 (Cython-optimized).

Uses the compiled version internally for consistency and performance. Returns [node1] + intermediate voxels.

routing.core.functions.get_direction(start: ndarray, end: ndarray) tuple[ndarray, float, ndarray][source]#

Get vector, length and unit_vector of a vector defined with start and end points.

routing.core.functions.get_nearest_active_voxel(coord: tuple[float, float, float], voxels: MatrixBasedVoxelization) tuple[int, int, int][source]#

Get the nearest voxel with nonnull weight from coordinates.

routing.core.functions.get_node_neighbors_coords(coords: tuple[float, float, float], weights: ndarray, prospect_distance: float = 3) list[tuple[int, int, int]][source]#

Get all voxels neighboring a point at max prospect_distance with distance computation.

routing.core.functions.get_voxels_in_bounding_box(voxels: list[tuple[int, int, int]]) list[tuple[int, int, int]][source]#

Compute all voxel coordinates inside the axis-aligned bounding box that contains all crossed voxels.

routing.core.functions.h_coord(coords: ndarray) ndarray[source]#

Convert coordinates to homogeneous coordinates by adding a row of ones.

routing.core.functions.invert_frame(frame: ndarray) ndarray[source]#

Invert a HTM frame with inverse movement instead of inverse matrix.

routing.core.functions.ordinal_suffix(number: int) str[source]#
routing.core.functions.parse_csv_value(value: str) int | float | str[source]#

Parse a CSV string value to int, float, or str.

routing.core.functions.point_to_local_frame(point: ndarray, frame: ndarray) ndarray[source]#

Project a point into a new frame.

routing.core.functions.points_to_homogeneous_matrix(points: list) ndarray[source]#

Convert a list of points to a homogeneous transformation matrix.

routing.core.functions.points_to_local_frames(points: ndarray, frames: list[ndarray]) list[ndarray][source]#

Project a list of points into a list of frames.

routing.core.functions.reduce_cylinder_radius_3d_fast(voxel_indices: ndarray, radius_reduction: int = 2) ndarray[source]#

Fast version using 6-connectivity (direct neighbors only). Faster but erosion is less round.

routing.core.functions.set_primitives_name(primitives: list[Primitive3D], name: str) None[source]#

Add an indexed name to primitives when a name is defined as argument.

routing.core.functions.sheet_to_dicts(sheet: openpyxl.worksheet.worksheet.Worksheet) list[dict][source]#

Convert an openpyxl worksheet to a list of dicts using the first row as headers.

Empty cells are excluded from each dict so that callers can rely on dict.get(key, default).

routing.core.functions.tensor_to_non_zero_indices(ndarray: ndarray) ndarray[source]#

Get matrix of all non-seros elements in ndarray.

routing.core.functions.unflat_coords(flatten_coords: ndarray) ndarray[source]#

Get a matrix of shape (n_points, 3) from a vector of flatten coords (shape (3.n_points, )).

routing.core.functions.voxel_index_to_coord(index: tuple[int, int, int], voxel_origin: tuple[float, float, float], voxel_size: float) tuple[float, float, float][source]#

Gives the coordinates of a voxel.

routing.core.functions.voxel_offsets_in_radius(radius_voxel: float) set[tuple[int, int, int]][source]#

Return the set of integer voxel offsets (dx, dy, dz) within Euclidean radius.

Used to precompute which voxel indices can be within a given world distance of a bifurcation or port, so that shortest-path checks are only done for candidates.

Parameters:

radius_voxel – Maximum distance in voxel units (e.g. world_distance / voxel_size).

Returns:

Set of (di, dj, dk) offsets.

routing.core.functions.voxelize_box_domain(block: Block, shell: OpenTriangleShell3D, voxel_size: float = 0.1) MatrixBasedVoxelization[source]#

Voxelize space inside a bounding box.