routing.core.core#

Core classes for routing.

class routing.core.core.GridPath(path: list[SmartGridNode], pipe: Pipe | None = None, cost: float = 0.0, indicators: dict[str, Any] | None = None, runs: int = 0, runtime: float = 0.0, name: str = '')[source]#

Bases: DessiaObject

A class representing a routing path through the voxel grid with associated metadata.

This class inherits from DessiaObject, and contains a sequence of grid nodes forming a path from start to end, along with the corresponding Pipe object, cost metrics, and routing indicators.

Parameters:
  • path – The list of SmartGridNode objects forming the routing path.

  • pipe – The optional Pipe object representing the path geometry. If None, can be created later using to_pipe() method. Defaults to None.

  • cost – The total cost of the path (lower is better). Used for ranking multiple path options. Defaults to 0.0.

  • indicators – The optional dictionary of routing metrics and indicators. Defaults to None.

  • runs – The number of pathfinding iterations/runs that generated this path. Defaults to 0.

  • runtime – The time taken to compute the path in seconds. Defaults to 0.0.

  • name – The name to identify this path. Defaults to ‘’.

classmethod dict_to_object(dict_: Dict[str, Any], **kwargs) SerializableObject[source]#

Deserialize a dictionary to a GridPath object.

Reconstructs a GridPath from its serialized dictionary representation, including path nodes, pipe geometry, and all metadata.

Parameters:
  • dict – Serializable dictionary containing GridPath data.

  • kwargs – Additional keyword arguments for deserialization.

Returns:

Reconstructed GridPath object.

classmethod from_grid_result(path: list[SmartGridNode], cost: float, indicators: dict[str, list[tuple[int, int, int]]], runs: int, runtime: float, input_port: Port, output_port: Port, pipe_type: PipeType) GridPath[source]#
property is_direct: bool#

Check if the path is direct (no intermediate waypoints).

A direct path has only 2 nodes (start and end), indicating a straight connection without turns.

Returns:

True if path is direct, False otherwise.

light_str() str[source]#

Get compact string representation of GridPath.

Returns a shorter string showing only start and end nodes, cost, length, runs, runtime, and indicators.

Returns:

Compact string representation of the GridPath.

static nodes_to_points(nodes: list[GridNode]) list[Point3D][source]#

From GridNodes to 3D points coords.

path_to_points(voxel_size: float, min_center: tuple[float, float, float]) list[Point3D][source]#

Convert path nodes to 3D point coordinates.

Extracts 3D positions from the grid nodes in the path.

Parameters:
  • voxel_size – Voxel size (used for coordinate conversion, though nodes already contain positions)

  • min_center – Grid origin (used for coordinate conversion, though nodes already contain positions)

Returns:

List of Point3D objects representing the path waypoints

string_indicators() str[source]#

Get formatted string representation of routing indicators.

Formats all indicators in the indicators dictionary as a multi-line string for display in string representations.

Returns:

Formatted string containing all indicators and their values.

to_dict(use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None, **kwargs) Dict[str, Any][source]#

Convert the GridPath object to a serializable dictionary.

Serializes the GridPath to a JSON-compatible dictionary format, including path node identifiers, pipe geometry, cost, indicators, and metadata.

Parameters:
  • use_pointers – Flag to use object pointers in serialization. Defaults to True.

  • memo – Memoization dictionary for circular reference handling.

  • path – JSON path string for nested serialization.

  • id_method – Flag to use identifier method. Defaults to True.

  • id_memo – Memoization dictionary for identifiers.

  • kwargs – Additional keyword arguments for serialization.

Returns:

Serializable dictionary representation of the GridPath.

to_pipe(input_port: Port, output_port: Port, pipe_type: PipeType, voxel_size: float, voxel_origin: tuple[float, float, float]) Pipe[source]#

Generate Pipe from GridPath.

Creates a Pipe object from the grid path, connecting input and output ports with the path waypoints.

Parameters:
  • input_port – Start port of the pipe

  • output_port – End port of the pipe

  • pipe_type – PipeType defining pipe characteristics

  • voxel_size – Voxel size for coordinate conversion

  • voxel_origin – Grid origin for coordinate conversion

Returns:

Pipe instance representing the routed path

to_pipe_lines() list[PipeLine][source]#

Convert GridPath to list of PipeLines.

Automatically detects if all nodes are in the same grid and uses the optimized single-grid method when possible, otherwise uses the multi-grid method. This handles grid transitions correctly when the path crosses multiple grids.

Returns:

List of PipeLine objects, one per segment in the path

to_samples(index: int, reference_path: str = '#') Sample[source]#

Get plot_data equivalent Sample.

volmdlr_primitives(name: str = '') list[Primitive3D][source]#

Get volmdlr primitives representing this grid path.

Returns the 3D geometric primitives from the associated pipe, with an optional name applied to all primitives.

Parameters:

name – Optional name to assign to all primitives. Defaults to ‘’.

Returns:

List of Primitive3D objects representing the path geometry.

class routing.core.core.OptimizedPipe(pipe: Pipe, pipe_lines: list[PipeLine], cost: float = 0.0, name: str = '')[source]#

Bases: Object3D

A class representing an optimized pipe with discrete line segments and cost.

Contains a Pipe object along with its discrete PipeLine segments and optimization cost. This is the result of post-routing optimization.

Parameters:
  • pipe – The Pipe object representing the optimized continuous path.

  • pipe_lines – The list of PipeLine objects representing discrete segments of the optimized pipe.

  • cost – The optimization cost (lower is better). Used for ranking multiple optimized solutions. Defaults to 0.0.

  • name – The name to identify this optimized pipe. Defaults to ‘’.

distance_to_voxels(room_voxels: RoomVoxelization) ndarray[source]#
classmethod from_grid_path(grid_path: GridPath, name: str = '') OptimizedPipe[source]#
classmethod from_pipe_lines(pipe_lines: list[PipeLine], pipe_type: PipeType, cost: float, name: str = '') OptimizedPipe[source]#

Build OptimizedPipe from list of PipeLine.

get_crossed_voxels()[source]#
pipelines_to_costs() tuple[dict[str, Any], dict[str, Any]][source]#
to_sample(index: int, reference_path: str = '') Sample[source]#

Get plot_data Samples from OptimizedPipe.

update_crossed_voxels(room_voxelization: RoomVoxelization, pooling_rule: PoolingRule, type_: str) None[source]#
volmdlr_primitives(name: str = '', **kwargs)[source]#

Get Primitive3D objects representing the 3D geometry.

This method must be implemented by subclasses to provide their 3D geometric representation.

Returns:

List of Primitive3D objects

Raises:

NotImplementedError – If not implemented by subclass

class routing.core.core.OptimizedPipes(grid_path: GridPath, optimized_pipes: list[OptimizedPipe], name: str = '')[source]#

Bases: Object3D

A class representing a container for multiple optimized pipe solutions from a single grid path.

Groups multiple optimization results (OptimizedPipe) that were generated from the same initial GridPath. This allows comparison and selection of the best optimized solution.

Parameters:
  • grid_path – The original GridPath that was optimized.

  • optimized_pipes – The list of OptimizedPipe objects representing different optimization results from the same path.

  • name – The name to identify this set of optimized pipes. Defaults to ‘’.

static best_optimized_pipe(optimized_pipes: list[OptimizedPipe]) OptimizedPipe[source]#
property best_pipe: OptimizedPipe#
plot_data#
to_samples(init_index: int = 1, reference_path: str = '#') list[Sample][source]#

Get plot_data Samples from all OptimizedPipe.

volmdlr_primitives(name: str = '')[source]#

Get Primitive3D objects representing the 3D geometry.

This method must be implemented by subclasses to provide their 3D geometric representation.

Returns:

List of Primitive3D objects

Raises:

NotImplementedError – If not implemented by subclass

class routing.core.core.Pipe(wire: Wire, pipe_type: PipeType | None = None, points: list[Point3D] | None = None, mutualization_pipe_type: MutualizationPipeType | None = None, radius_curvature_dico: list[RadiusCurvaturePipe] | None = None, name: str = '')[source]#

Bases: Pipe

A class representing a complete pipe with 3D path and properties.

This class inherits from piping.Pipe, and extends it with routing-specific functionality. It represents a complete pipe path defined by waypoints, with associated pipe type and routing metadata.

Parameters:
  • wire – The Wire object defining the 3D path of the pipe.

  • pipe_type – The PipeType defining characteristics and constraints. Defaults to None.

  • points – The optional list of 3D waypoints. If provided, used for path representation. Defaults to None.

  • mutualization_pipe_type – The optional mutualization pipe type for shared routing. Defaults to None.

  • radius_curvature_dico – The optional list of radius curvature definitions for variable curvature along the path. Defaults to None.

  • name – The name identifying this pipe. Defaults to ‘’.

static build_end_frames(ports: PortCouple) tuple[ndarray, ndarray][source]#

Build coordinate frames at the pipe’s ends with port direction as main vector.

Creates transformation frames at both start and end ports, where the z-axis is aligned with the port’s orientation direction. These frames are used for optimization and geometric operations.

Parameters:

ports – PortCouple containing start and end ports.

Returns:

Tuple of (start_frame, end_frame) as 4x4 transformation matrices.

distance_to_voxels(room_voxels: RoomVoxelization) ndarray[source]#

Calculate distances from voxel centers to pipe centerline.

Calculates the signed distance from each voxel center to the pipe centerline. Returns a distance matrix where values represent how far each voxel is from the pipe, with negative values indicating voxels inside the pipe radius.

Parameters:

room_voxels – RoomVoxelization containing the voxel grid.

Returns:

Distance matrix of same shape as room_voxels.matrix, with distances from each voxel center to the pipe. Values are adjusted to account for pipe radius (negative distances inside pipe are set to 0).

classmethod from_optimizer(points: list[Point3D], pipe_type: PipeType, tol: float = 0.01) Pipe[source]#

Create a Pipe from optimizer output points.

Creates a Pipe from points (typically from optimization), removing duplicates and using the pipe type’s name.

Parameters:
  • points – List of 3D waypoints from optimizer

  • pipe_type – PipeType defining pipe characteristics

  • tol – Tolerance for removing duplicate points

Returns:

Pipe instance with cleaned path

classmethod from_points(points: list[Point3D], pipe_type: PipeType, name: str = '') Pipe[source]#

Create a Pipe from a list of points and pipe type.

Creates a Pipe by building a Wire from the points and associating it with the given pipe type. Validates curvature constraints.

Parameters:
  • points – List of 3D waypoints defining the pipe path

  • pipe_type – PipeType defining pipe characteristics

  • name – Name for the pipe

Returns:

Pipe instance with validated curvature

get_wire_points() ndarray[source]#

Get points of equivalent Wire as numpy array.

Extracts all waypoints from the pipe’s wire path and converts them to a numpy array format for numerical operations.

Returns:

Array of shape (n_points, 3) containing (x, y, z) coordinates of waypoints.

static remove_duplicated_nodes(points: list[Point3D], tol: float = 0.01) list[Point3D][source]#

Remove duplicate points from a pipe path.

Removes points that are within tolerance distance from the previous point, simplifying the path while preserving its shape.

Parameters:
  • points – List of 3D waypoints

  • tol – Tolerance distance for considering points as duplicates

Returns:

List of points with duplicates removed

to_3d_global_parameters(ports: PortCouple) tuple[ndarray, ndarray, tuple[ndarray, ndarray]][source]#

From turn points to an array of variable for optimizing in global 3d context.

Converts the pipe’s turn points into a flattened array format suitable for 3D global optimization. Points are 3-component vectors, where initial_values for the 3D global optimizer is a flattened array built as follows: [input port extension length, X2, Y2, Z2, …, Xn-1, Yn-1, Zn-1, output port extension length] where n is the number of points that are not ports. Port extensions are the length of vectors (input port, input extension) and (output extension, output port) along the port direction vector.

Parameters:

ports – PortCouple defining the start and end ports.

Returns:

Tuple of (points, initial_values, end_frames) where: - points: Array of intermediate waypoints (excluding ports) - initial_values: Flattened array for optimizer initialization - end_frames: Tuple of (start_frame, end_frame) transformation matrices

to_pipe_lines(grid_id: int) list[PipeLine][source]#

Create PipeLines when all nodes are in the same grid.

Optimized version for single-grid case - no grid transition detection needed.

Parameters:

grid_id – Common grid ID for all nodes

Returns:

List of PipeLines with consistent grid_id

to_pipe_lines_multi_grid(nodes: list[GridNode]) list[PipeLine][source]#

Create PipeLines ensuring each stays within a single grid and splits at grid boundaries.

Converts the pipe path into multiple PipeLine segments, ensuring that each segment remains within a single grid. If the path crosses grid boundaries, it is split at the transition points.

Parameters:

nodes – List of GridNode objects representing the path through multiple grids.

Returns:

List of PipeLine objects, each within a single grid.

volmdlr_primitives() list[Primitive3D][source]#

Get volmdlr primitives representing this pipe.

Returns the 3D geometric primitives (typically cylinders) representing the pipe segments, with colors set according to the pipe type.

Returns:

List of Primitive3D objects (typically Cylinder) with pipe type color applied.

class routing.core.core.PipeLine(points: ndarray, dot_product: float, length: float, vector: ndarray, voxels: tuple[tuple[int, int, int], tuple[int, int, int]], min_length: float, radius: float, type_: str, name: str = '', grid_id: int | None = None)[source]#

Bases: Object3D

A class representing a straight line segment of a pipe in 3D space.

Represents a fundamental building block for a single straight segment of a pipe between two points. Multiple PipeLines form a complete pipe path.

Parameters:
  • points – The array of shape (2, 3) containing [start_point, end_point] coordinates.

  • dot_product – The dot product value (used for optimization and cost calculations).

  • length – The length of the line segment in length units.

  • vector – The unit direction vector of shape (3,) indicating the line direction.

  • voxels – The tuple of (start_voxel, end_voxel) as (i, j, k) indices.

  • min_length – The minimum length constraint for this segment.

  • radius – The pipe radius for this segment (same unit as length).

  • type – The pipe type identifier for grouping/pooling.

  • name – The name to identify this pipe line. Defaults to ‘’.

  • grid_id – The optional grid identifier for multi-grid routing scenarios. Defaults to None.

static bbox_intersections_segment(start: ndarray, end: ndarray, bounding_boxes: ndarray)[source]#

Find intersections between a line segment and multiple bounding boxes.

Computes the intersection parameters (t values) for a line segment with multiple axis-aligned bounding boxes. Returns t_min and t_max for each bounding box.

Parameters:
  • start – Start point of the line segment as (x, y, z) array.

  • end – End point of the line segment as (x, y, z) array.

  • bounding_boxes – Array of shape (n_boxes, 2, 3) containing bounding boxes. Each box is defined by [min_point, max_point].

Returns:

Tuple of (t_min, t_max) arrays, each of shape (n_boxes,). t_min[i] and t_max[i] define the intersection range for bounding_boxes[i].

bounding_box(offset: float = 0.0) ndarray[source]#

Get the bounding box of the pipe line.

Computes the axis-aligned bounding box that encompasses the pipe line, including the pipe radius and an optional offset.

Parameters:

offset – Additional offset to add to the bounding box. Defaults to 0.0.

Returns:

Array of shape (2, 3) containing [[min_x, min_y, min_z], [max_x, max_y, max_z]].

static compute_local_frame(start_voxel: tuple[float, float, float], end_voxel: tuple[float, float, float]) ndarray[source]#

Compute local frame from start and end voxel indices.

Creates a transformation frame aligned with the direction from start_voxel to end_voxel, and returns its inverse for projecting voxels into this frame.

Parameters:
  • start_voxel – Start voxel index as (i, j, k) tuple.

  • end_voxel – End voxel index as (i, j, k) tuple.

Returns:

4x4 inverse transformation matrix for projecting into local frame.

contains_point_projection(point: ndarray) bool[source]#

Check if a point’s projection onto the line is between endpoints.

Projects the point onto the line segment and checks if the projection falls within the segment bounds [0, 1].

Parameters:

point – The 3D point to check as (x, y, z) array.

Returns:

True if the projection is between endpoints, False otherwise.

property direction: ndarray#

Get unit direction vector as numpy array.

Computes the normalized direction vector from start to end point.

Returns:

Unit direction vector of shape (3,).

classmethod from_dict(attribute_dict: dict[str, Any], radius: float, type_: str) PipeLine[source]#

Create PipeLine from a dictionary of attributes.

Parameters:
  • attribute_dict – Dictionary with keys: points, dot_product, length, vector, voxels, min_length.

  • radius – The pipe radius.

  • type – The pipe type identifier.

Returns:

PipeLine instance.

classmethod from_list(attribute_values: list[Any], radius: float, type_: str) PipeLine[source]#

Create PipeLine from a list of attribute values.

Parameters:
  • attribute_values – List containing [points, dot_product, length, vector, voxels, min_length].

  • radius – The pipe radius.

  • type – The pipe type identifier.

Returns:

PipeLine instance.

classmethod from_points(start: Point3D, end: Point3D, radius: float, input_voxel: tuple[int, int, int], output_voxel: tuple[int, int, int], type_: str, grid_id: int | None = None) PipeLine[source]#

Create PipeLine from start and end points.

Convenience method to create a PipeLine from two 3D points, automatically computing length, direction vector, and other geometric properties.

Parameters:
  • start – The start point as Point3D.

  • end – The end point as Point3D.

  • radius – The pipe radius.

  • input_voxel – The start voxel index as (i, j, k) tuple.

  • output_voxel – The end voxel index as (i, j, k) tuple.

  • type – The pipe type identifier.

  • grid_id – The optional grid identifier. Defaults to None.

Returns:

PipeLine instance.

get_crossed_voxels() ndarray[source]#

Get voxels crossed by this pipe line.

Returns the array of voxel indices that this pipe line passes through. Must call update_crossed_voxels() first to compute this.

Returns:

Array of shape (n_voxels, 3) with voxel indices [i, j, k].

get_end_voxels(room_voxelization: RoomVoxelization) tuple[tuple[float, float, float], tuple[float, float, float]][source]#

Get the voxel indices for the start and end points of this pipe line.

Converts the 3D coordinates of the pipe line endpoints to their corresponding voxel indices in the room voxelization grid.

Parameters:

room_voxelization – The RoomVoxelization containing the voxel grid.

Returns:

Tuple of (start_voxel, end_voxel) as continuous voxel coordinates.

get_halo(halo_radius: float, voxels_shape: tuple[int, int, int], check_validity: bool = True) ndarray[source]#

Get voxels within a halo radius around crossed voxels.

Optimized alternative version without a KD-tree, for small radii. Returns all voxels within the specified radius from any voxel crossed by this pipe line.

Parameters:
  • halo_radius – Radius of the halo in voxel units.

  • voxels_shape – Shape of the voxel grid as (width, height, depth).

  • check_validity – Flag indicating whether to check if voxels are within grid bounds. Defaults to True.

Returns:

Array of shape (3, n_voxels) containing voxel indices within the halo.

get_support_surface_vectors(min_distances: ndarray, voxel_size: float) list[ndarray][source]#

Get support surface vectors for the object based on minimum distances in voxel space.

Parameters:
  • min_distances – 3D array containing minimum distance values for each voxel

  • voxel_size – size of each voxel in the voxelization grid

Returns:

list of normal vectors representing valid support surfaces, defaults to frame vectors if none found

get_vector()[source]#

Get direction vector as volmdlr.Vector3D.

Returns the unit direction vector. If vector is not set, computes it from points.

Returns:

Vector3D representing the unit direction of this pipe line.

static get_voxels_in_obb(voxel_indices: ndarray, projected_voxels: ndarray, bounds: ndarray, radius_y: float = 1, radius_z: float = 1) ndarray[source]#

Get voxels within an oriented bounding box (OBB) around a pipe line.

Filters voxels that fall within a rectangular box aligned with the pipe line’s local frame. The box extends along the pipe direction (x-axis) and has specified radii in the perpendicular directions (y and z axes).

Parameters:
  • voxel_indices – Array of shape (4, n_voxels) containing homogeneous voxel indices.

  • projected_voxels – Array of shape (4, n_voxels) containing voxels projected into local frame.

  • bounds – Array defining the bounding box along x-axis in local frame.

  • radius_y – Half-width of the bounding box in y direction (voxel units). Defaults to 1.

  • radius_z – Half-height of the bounding box in z direction (voxel units). Defaults to 1.

Returns:

Array of shape (n_crossed_voxels, 3) containing (i, j, k) indices of voxels within OBB.

is_facing_other(other: PipeLine) bool[source]#

Check if this pipe line is facing another pipe line.

Two pipe lines are considered “facing” if they share an endpoint or if their projections overlap in a way that suggests they are aligned and could potentially be merged or grouped together.

Parameters:

other – The other PipeLine to check against.

Returns:

True if the pipe lines are facing each other, False otherwise.

local_frame()[source]#

Get the local coordinate frame for this pipe line.

Computes an orthonormal frame where the x-axis is aligned with the pipe line direction, and y and z axes are perpendicular. This frame is used for geometric operations like voxel projection.

Returns:

4x4 transformation matrix representing the local frame (homogeneous coordinates).

merge_with(other: PipeLine, coefficient: float, offset: float, min_distance: float, min_size: float) bool[source]#

Check if other PipeLine can merge in a Pack with self.

Merge is True when:
  • both PipeLine lengths are more than min_size

  • PipeLines are approximately aligned

  • coefficient is a pooling coefficient

  • distance between the two PipeLines is less than the radius_self + radius_other + offset + min_distance

Parameters:
  • other – Other PipeLine to check for merging

  • coefficient – Pooling coefficient

  • offset – Offset value for distance calculation

  • min_distance – Minimum distance threshold

  • min_size – Minimum size threshold for both PipeLines

Returns:

True if the PipeLines can merge, False otherwise

pipe_line_distance(other_line: PipeLine) float[source]#

Calculate the minimum distance between two 3D line segments.

The algorithm finds the closest points between two segments by: 1. Parameterizing each segment as P1(s) = P1_0 + s * u and P2(t) = P2_0 + t * v 2. Minimizing |P1(s) - P2(t)|² with respect to s and t 3. Clamping s and t to [0,1] to stay within segment bounds

Parameters:

other_line – The other PipeLine to compute distance to.

Returns:

The minimum distance between the two pipe lines.

static points_from_optim_lines(optim_lines: list[PipeLine])[source]#

Extract waypoints from a list of optimized pipe lines.

Combines start and end points from multiple pipe lines into a single list of waypoints, removing duplicates at connection points.

Parameters:

optim_lines – List of PipeLine objects to extract points from.

Returns:

List of Point3D waypoints connecting all pipe lines.

points_matrix(offset: float = 0.0) ndarray[source]#

Get bounding box matrix of points with radius and offset.

Computes the minimum and maximum points of the pipe line, expanded by the pipe radius and an optional offset.

Parameters:

offset – Additional offset to add to the bounding box. Defaults to 0.0.

Returns:

Array of shape (2, 3) containing [min_point, max_point] with radius and offset applied.

project_voxels(room_voxelization: RoomVoxelization) tuple[ndarray, ndarray][source]#

Project all voxels from room voxelization into the local frame of this pipe line.

Transforms all voxel coordinates into the pipe line’s local coordinate system, where the x-axis is aligned with the pipe direction. Also computes bounding box bounds in this local frame.

Parameters:

room_voxelization – The RoomVoxelization containing voxels to project.

Returns:

Tuple of (projected_voxels, bounds) where projected_voxels is array of shape (4, n_voxels) in homogeneous coordinates, and bounds defines the bounding box in local frame.

shape(**kwargs) Cylinder[source]#

Get the 3D shape representation of this pipe line as a Cylinder.

Creates a Cylinder primitive connecting the start and end points with the pipe line’s radius.

Parameters:

kwargs – Optional keyword arguments passed to Cylinder.from_end_points (e.g., ‘name’, ‘color’).

Returns:

Cylinder primitive representing this pipe line.

to_list() list[Any][source]#

Convert PipeLine to a list of attribute values.

Returns a list containing the main attributes of the pipe line in order: [points, dot_product, length, vector, voxels, min_length].

Returns:

List containing [points, dot_product, length, vector, voxels, min_length].

update_crossed_voxels(room_voxelization: RoomVoxelization) None[source]#

Update the list of voxels crossed by this pipe line.

Computes which voxels in the room voxelization are intersected by this pipe line, storing both the neutral fiber voxels (centerline) and the full crossed voxels (including pipe radius).

Parameters:

room_voxelization – RoomVoxelization to compute voxel intersections with.

Returns:

None

volmdlr_primitives(*args, **kwargs) list[Cylinder][source]#

Get list of volmdlr primitives representing this pipe line.

Returns a list containing a single Cylinder primitive representing the pipe line geometry.

Parameters:
  • args – Optional positional arguments (not used).

  • kwargs – Optional keyword arguments passed to shape() method.

Returns:

List containing a single Cylinder primitive.

class routing.core.core.PipeType(section: Section, name: str, priority_index: int | None = None, radius_of_curvature_ratio_min: float = 1.0, sub_environment: VolumeModel | None = None, all_sub_environment: bool = False, radius_of_curvature_ratio_max: float = 1.0, length_before_turn_min: float | None = None, length_before_turn_max: float | None = None, user_properties: list[UserProperty] | None = None, user_constraints: list[ConstraintRule] | None = None, min_slope: float | None = None, max_slope: float | None = None, number_turn_max: int = 0, color: tuple[float, float, float] = (0.1, 0.1, 0.1), type_: str = 'None')[source]#

Bases: PipeType

A class defining characteristics and constraints of a pipe type for routing.

This class inherits from piping.PipeType, and encapsulates all physical properties and design constraints for a specific pipe type (hydraulic, electrical, etc.). It defines dimensions, curvature constraints, slope rules, and custom properties.

Parameters:
  • section – The pipe section defining the equivalent radius.

  • name – The name identifying this pipe type.

  • priority_index – The routing priority (lower = more priority). Defaults to None.

  • radius_of_curvature_ratio_min – The minimum ratio of curvature radius to pipe radius. Defaults to None.

  • sub_environment – The optional VolumeModel defining a sub-environment where this pipe type can be routed. Defaults to None.

  • all_sub_environment – Flag indicating whether the pipe must remain entirely within sub_environment. Defaults to False.

  • radius_of_curvature_ratio_max – The maximum ratio of curvature radius. Defaults to None.

  • length_before_turn_min – The minimum length before a turn is allowed. Defaults to None.

  • length_before_turn_max – The maximum length before a turn. Defaults to None.

  • user_properties – The list of UserProperty to define attributes based on distance. Defaults to None.

  • user_constraints – The list of ConstraintRule for custom constraints. Defaults to None.

  • min_slope – The minimum allowed slope (negative for gravity systems). Defaults to None.

  • max_slope – The maximum allowed slope. Defaults to None.

  • number_turn_max – The maximum number of turns allowed (0 = unlimited). Defaults to 0.

  • color – The RGB color tuple (r, g, b) between 0 and 1 for visualization. Defaults to (0.1, 0.1, 0.1).

  • type – The pipe type for grouping/pooling. Defaults to ‘None’.

property max_slope: float#

Get max_slope requirement for current PipeType.

Returns the maximum allowed slope. If not set, returns negative infinity (no constraint).

Returns:

Maximum slope value, or float(“-inf”) if not constrained

property min_slope: float#

Get min_slope requirement for current PipeType.

Returns the minimum allowed slope. If not set, returns infinity (no constraint).

Returns:

Minimum slope value, or float(“inf”) if not constrained

property plot_data_color: str#

Get equivalent color in plot_data format (rgb(255)).

Converts the color tuple to plot_data RGB format. If color values are between 0 and 1, they are scaled to 0-255 range.

Returns:

Color string in format “rgb(r, g, b)” with values 0-255.

property volmdlr_color: tuple[float, float, float]#

Get equivalent color in plot_data (rgb(255)).

class routing.core.core.Port(coordinates: tuple[float, float, float], direction: tuple[float, float, float], length: float = 0.0, permitted_departure_angle: list[float] | None = None, len_adaptable_with_environment: bool = False, name: str = 'Port')[source]#

Bases: Object3D

A class representing a connection point for pipe routing.

Defines a point in 3D space where a pipe can start or end, with an orientation direction and optional constraints on the departure angle.

Parameters:
  • coordinates – The 3D position of the port as (x, y, z) tuple in global coordinates.

  • direction – The non-normalized direction vector indicating the port orientation.

  • length – The minimum extension length before the first turn (in length units). Defaults to 0.0.

  • permitted_departure_angle – The optional list of angles (in radians) allowed for pipe departure from this port. If None, all angles are permitted. Defaults to None.

  • len_adaptable_with_environment – Flag indicating whether the length can be automatically adjusted according to environment constraints. Defaults to False.

  • name – The name to identify this port. Defaults to ‘Port’.

classmethod from_xlsx_stream(stream: BinaryFile)[source]#

Create a list of Ports from an Excel file.

Reads port definitions from an Excel file with the following columns: name | coordinates_x | coordinates_y | coordinates_z | direction_x | direction_y | direction_z | length

Parameters:

stream – Binary file stream containing the Excel file.

Returns:

List of Port instances created from the Excel data.

property orientation: Point3D#

Get direction of Port as a volmdlr.Point3D.

Returns the direction vector as a Point3D (not normalized).

Returns:

Point3D object representing the port’s direction vector.

property position: Point3D#

Get position of Port as a volmdlr.Point3D.

Returns:

Point3D object representing the port’s 3D position.

property unit_orientation: Point3D#

Get unit direction of Port as a volmdlr.Point3D.

Returns the normalized direction vector (unit length).

Returns:

Point3D object representing the port’s normalized direction vector

volmdlr_primitives(*args, **kwargs) list[Primitive3D][source]#

Get Primitive3D representation of Port for visualization.

Creates a 3D solid primitive representing the port as a revolved shape, useful for CAD visualization.

Parameters:
  • args – Optional positional arguments (not used).

  • kwargs – Optional keyword arguments, including ‘radius’ for the port visualization radius (default: 0.01).

Returns:

List containing a single Solid primitive representing the port.

class routing.core.core.PortCouple(start: Port, end: Port, name: str = '')[source]#

Bases: DessiaObject

A class representing a pair of ports defining a path to route.

This class inherits from DessiaObject, and links two ports (start and end) to define a pipe path to create. This is the basic input for a routing problem.

Parameters:
  • start – The start port (where the pipe begins).

  • end – The end port (where the pipe terminates).

  • name – The name to identify this port couple. Defaults to ‘’.

class routing.core.core.RoomVoxelization(primitives: list[Primitive3D], voxel_matrix: ndarray[Any, dtype[bool_]], voxel_size: float, voxel_origin: tuple[float, float, float], name: str = '')[source]#

Bases: MatrixBasedVoxelization, VolumeModel

A class representing a voxelization of a room with associated CAD primitives.

This class inherits from MatrixBasedVoxelization and VolumeModel, and combines a voxelized representation (3D boolean matrix) with the original CAD geometric primitives. It allows working with both discrete representation (for pathfinding) and continuous representation (for visualization).

Parameters:
  • primitives – The list of 3D CAD primitives representing the room geometry.

  • voxel_matrix – The 3D numpy boolean array where True indicates a traversable/active voxel.

  • voxel_size – The size of a voxel in length units (same unit as primitives).

  • voxel_origin – The origin point of the voxel grid as (x, y, z) tuple in global coordinates.

  • name – The name to identify this voxelization. Defaults to ‘’.

coord_to_voxel_index(point: ndarray) tuple[int, int, int][source]#

Convert a world coordinate point to its corresponding voxel index.

Parameters:

point – The world coordinate point as (x, y, z) array.

Returns:

The voxel index as (i, j, k) tuple.

property coords: ndarray#

Get world coordinates of non-zero voxels.

Converts voxel indices to their corresponding world coordinates.

Returns:

Array of shape (3, n_voxels) containing (x, y, z) world coordinates for each active voxel center.

static from_voxels(voxels: MatrixBasedVoxelization, build_cad: bool = False) RoomVoxelization[source]#

Crée une RoomVoxelization à partir d’une voxélisation existante.

Cette méthode permet de convertir une MatrixBasedVoxelization en RoomVoxelization, avec la possibilité optionnelle de reconstruire les primitives CAD à partir des voxels.

Parameters:
  • voxels – La voxélisation source (sans primitives CAD)

  • build_cad – Si True, reconstruit les primitives CAD à partir des voxels. Si False, la liste de primitives sera vide (gain de performance)

Returns:

Une nouvelle instance de RoomVoxelization

Example:
>>> voxels = MatrixBasedVoxelization.from_volume_model(volume, voxel_size=0.01)
>>> room_vox = RoomVoxelization.from_voxels(voxels, build_cad=True)
property homogeneous_indices: ndarray#

Get homogeneous indices of non-zero voxels.

Returns the indices in homogeneous coordinates (with added 1 for the w component).

Returns:

Array of shape (4, n_voxels) containing (i, j, k, 1) for each active voxel.

property indices: ndarray#

Get indices of non-zero voxels.

Returns the indices of all active (non-zero) voxels in the voxel matrix.

Returns:

Array of shape (3, n_voxels) containing (i, j, k) indices for each active voxel.

points_are_in_voxels(voxels: list[tuple[int, int, int]]) bool[source]#

Check if all given voxel indices correspond to active voxels in the matrix.

Validates that all provided voxel indices are within bounds and point to active (True) voxels in the matrix.

Parameters:

voxels – List of voxel indices as (i, j, k) tuples or arrays

Returns:

True if all voxel indices are valid and active, False otherwise (including if indices are out of bounds or negative).

set_distances_direct(distances_array: ndarray) ndarray[source]#

Assign distance values directly to active voxels, returning a full distance matrix.

Creates a full 3D distance matrix where only active voxels have their distance values, and inactive voxels are set to infinity.

Parameters:

distances_array – Array of distance values for active voxels, with length equal to the number of active voxels.

Returns:

Full 3D distance matrix of same shape as voxel matrix, with distances for active voxels and infinity for inactive ones.

to_matrix_based_voxelization() MatrixBasedVoxelization[source]#

Convert RoomVoxelization to MatrixBasedVoxelization.

Extracts only the voxel matrix representation, discarding CAD primitives. Useful when CAD geometry is no longer needed and only discrete representation is required.

Returns:

MatrixBasedVoxelization instance without CAD primitives, containing only the voxel matrix, size, and origin information.

property voxel_origin: tuple[float, float, float]#

Get the origin of the voxel grid.

Returns the origin point of the voxel grid in global coordinates.

Returns:

The origin point as (x, y, z) tuple in global coordinates.

class routing.core.core.RuledVolume(primitives: list[Primitive3D], global_rules: list[InstanceOf[DesignRule]], in_border: bool = True, voxel_inside: bool = False, name: str = '')[source]#

Bases: VolumeModel

A class representing a 3D volume with associated design rules for routing.

This class inherits from VolumeModel, and combines 3D geometry (primitives) with design rules that define how pipes can interact with this volume. These rules can include distance penalties, placement constraints, weighting factors, etc.

Parameters:
  • primitives – The list of 3D primitives defining the volume geometry.

  • global_rules – The list of design rules that apply to all pipes passing near this volume.

  • in_border – Flag indicating whether this volume is used to compute the bounding box of the routing problem in CadMap. Defaults to True.

  • voxel_inside – Flag indicating whether enclosed voxels will be filled during voxelization. Useful for hollow volumes. Defaults to False.

  • name – The name to identify this volume. Defaults to ‘’.

static compose_weights(weights: list[ndarray]) ndarray[source]#

Compose multiple weight arrays into a single weight array.

Sums all weight arrays element-wise. Used to combine weights from multiple design rules.

Parameters:

weights – List of weight arrays (must have compatible shapes).

Returns:

Combined weight array (sum of all input weights).

compute_voxels(voxel_size: float | None = None) None[source]#

Compute RuledVolume MatrixBasedVoxelization from meshes.

Voxelizes the volume geometry and caches the result. If voxel_inside is True, enclosed voxels are also filled.

Parameters:

voxel_size – Size of voxels for voxelization. If None, uses a default size based on the volume’s bounding box. Defaults to None.

Returns:

None

compute_weights(distances: ndarray) ndarray[source]#

Compute weights from a distance matrix using all design rules.

Applies all design rules (global and pipe-specific) to compute weights based on distances. Weights from all rules are combined by summation.

Parameters:

distances – Distance matrix or array from which to compute weights.

Returns:

Combined weight array representing the total weight/cost at each distance value based on all applicable design rules.

property design_rules#

Get all design rules (global and pipe-specific) for this volume.

Combines global_rules and pipe_rules into a single list. Returns empty list if both are None or empty.

Returns:

List of all DesignRule instances applicable to this volume.

distance_from_points(points: ndarray, exact: bool) ndarray[source]#

Compute distances from a point cloud to this volume.

Calculates the distance from each point to the nearest surface of this volume. Can use either exact mesh-based calculation or faster voxel-based approximation.

Parameters:
  • points – Array of shape (n_points, 3) containing 3D points.

  • exact – Flag indicating whether to use exact mesh distance calculation. If True, uses exact calculation (slower but accurate). If False, uses voxel-based approximation (faster but less accurate).

Returns:

Array of shape (n_points,) with distances from each point to the volume surface. Negative distances indicate points inside the volume.

distance_matrix_from_voxelization(voxelization: MatrixBasedVoxelization, exact: bool) ndarray[source]#

Compute distance matrix from a voxelization to this volume.

Calculates distances from each voxel center in the given voxelization to this volume. Returns a matrix with the same shape as the voxelization’s matrix.

Parameters:
  • voxelization – MatrixBasedVoxelization to compute distances from.

  • exact – Flag indicating whether to use exact mesh distance calculation. If True, uses exact calculation. If False, uses voxel-based approximation.

Returns:

Distance matrix of same shape as voxelization.matrix, with distances from each voxel center to this volume. np.inf for inactive voxels.

duplicate() RuledVolume[source]#

Create a duplicate of this RuledVolume with the same geometry and rules.

Creates a copy including pipe_rules. Note that open_shell cache is not copied and will be recomputed if needed.

Returns:

A new RuledVolume instance with the same primitives, rules, and properties.

empty_duplicate() RuledVolume[source]#

Create a duplicate without pipe-specific rules.

Creates a copy with only global rules, useful when pipe_rules should not be inherited.

Returns:

A new RuledVolume instance with the same primitives and global_rules, but without pipe_rules.

classmethod from_intersecting_faces(faces: list[dict[Any, list]], volumes: list[RuledVolume]) list[RuledVolume][source]#

Create RuledVolumes from a dictionary of intersecting faces.

Converts a dictionary mapping face identifiers to face lists into RuledVolume objects representing the intersection regions.

Parameters:
  • faces – List of dictionaries mapping face identifiers to lists of faces.

  • volumes – List of RuledVolume objects corresponding to the faces.

Returns:

List of RuledVolume instances representing intersecting face regions.

classmethod from_ruled_volume(ruled_volume: RuledVolume, design_rules: list[InstanceOf[DesignRule]]) RuledVolume[source]#

Create a new RuledVolume from an existing one with different design rules.

This method creates a copy of a RuledVolume while preserving its geometric primitives, name, and border status, but applying a new set of design rules. The open shell representation is also preserved to avoid recomputation.

Parameters:
  • ruled_volume – The source RuledVolume to copy from.

  • design_rules – New list of design rules (DesignRule instances) to apply.

Returns:

A new RuledVolume instance with the same geometry but different design rules.

classmethod from_volume_model(volume_model: VolumeModel, design_rules: list[InstanceOf[DesignRule]], in_border: bool = True, voxel_inside: bool = False, name: str | None = None) RuledVolume[source]#

Create a RuledVolume from a VolumeModel with associated design rules.

This method extracts the geometric primitives from a VolumeModel and associates them with design rules to create a RuledVolume that can be used in routing and CAD mapping.

Parameters:
  • volume_model – The VolumeModel to convert, containing geometric primitives.

  • design_rules – List of design rules (DesignRule instances) to apply to the volume.

  • in_border – Flag indicating whether the volume is used to build the BoundingBox of routing problem in CadMap. Defaults to True.

  • voxel_inside – Flag indicating whether voxelization will fill enclosed voxels. Defaults to False.

  • name – Optional name for the RuledVolume. If None, uses volume_model.name. Defaults to None.

Returns:

A new RuledVolume instance with the volume model’s primitives and design rules.

classmethod get_bounding_box(volume_models: list[VolumeModel], border_rule: list[InstanceOf[DesignRule]] | None = None, margin: float = 0.0) RuledVolume[source]#

Build a RuledVolume from the bounding box of all listed volumes.

If border_rule is not empty, the bounding box will be considered as material walls.

get_faces_in_shell(closed_shell: ClosedShell3D) dict[Any, list][source]#

Get all faces contained in a ClosedShell3D.

Finds intersecting faces between this volume’s shell and the given closed shell, and identifies faces that are completely inside the closed shell.

Parameters:

closed_shell – ClosedShell3D to check for intersections and containment.

Returns:

Dictionary with keys for different types of face relationships: - Intersecting faces between the two shells - Faces of this volume that are inside the closed shell (key: “inside”)

property open_shell: OpenTriangleShell3D#

Get the open shell representation of this volume.

The shell is computed from the volume’s mesh and cached for subsequent access. This is used for geometric operations like intersection detection.

Returns:

OpenTriangleShell3D representing the surface of the volume.

remove_from_voxels(free_voxels: MatrixBasedVoxelization, voxel_size: float) MatrixBasedVoxelization[source]#

Remove this volume from free_voxels.

Subtracts this volume’s voxels from the given free voxelization, effectively marking voxels occupied by this volume as non-traversable.

Parameters:
  • free_voxels – MatrixBasedVoxelization representing free/traversable space.

  • voxel_size – Voxel size for voxelizing this volume (if not already computed).

Returns:

New MatrixBasedVoxelization with this volume’s voxels removed.

reset_pipe_rules() None[source]#

Reset all rules specific to a pipe.

Clears the pipe_rules list, removing any pipe-specific design rules that were added dynamically. Global rules are not affected.

Returns:

None

to_shell() OpenTriangleShell3D[source]#

Convert the volume to an open triangle shell representation.

Creates a mesh from the volume primitives and converts it to an OpenTriangleShell3D. The result is cached in _open_shell for subsequent access.

Returns:

OpenTriangleShell3D representing the surface of the volume.

voxels(voxel_size: float | None = None) MatrixBasedVoxelization[source]#

Get voxels of the RuledVolume.

Returns the voxelization, computing it if necessary. The result is cached for subsequent calls.

Parameters:

voxel_size – Size of voxels for voxelization. Required if voxels haven’t been computed yet. Defaults to None.

Returns:

MatrixBasedVoxelization representing the volume in discrete space.

Raises:

ValueError – If voxel_size is not provided and voxels haven’t been computed.

class routing.core.core.Solution(optimized_pipes: list[OptimizedPipes], input_port: Port, output_port: Port, pipe_type: PipeType, name: str = '')[source]#

Bases: Object3D

A class representing a complete routing solution with multiple path options and optimizations.

Contains all routing results for a single pipe specification, including multiple generated paths (GridPath) and their optimized versions (OptimizedPipe). It provides methods to access the best path and best optimized pipe.

Parameters:
  • optimized_pipes – The list of OptimizedPipes objects, each containing optimization results from a different generated path.

  • input_port – The start port of the routing path.

  • output_port – The end port of the routing path.

  • pipe_type – The PipeType defining pipe characteristics and constraints.

  • name – The name to identify this solution. Defaults to ‘’.

apply_properties_on_volumes() None[source]#

From UserProperties to DesignRules on ruled_volumes.

property best_path: GridPath#
property best_path_index: int#
property best_pipe: OptimizedPipe#
property curvature_radius: float#
classmethod from_pipe_definition(ports: PortCouple, pipe_type: PipeType, curvature_radius: float | None = None) Solution[source]#

Create a Solution from port couple and pipe type.

Factory method to create a Solution from a PortCouple and PipeType. Computes port extension lengths and constraints based on pipe properties.

Parameters:
  • ports – PortCouple defining start and end ports

  • pipe_type – PipeType defining pipe characteristics

  • curvature_radius – Optional curvature radius. If None, computed from pipe type’s radius_of_curvature_ratio_min

Returns:

Solution instance ready for routing

get_best_path() int[source]#

Get index of the best path among generated pipes.

Finds the GridPath with the lowest cost among all OptimizedPipes in the solution.

Returns:

Index of the best path in the optimized_pipes list

static get_equivalent_curvature_radius(solutions: list[Solution]) float[source]#
get_global_constraints(radius_equivalent: float = 0) list[InstanceOf[DesignRule]][source]#

Get all constraints specific to a PipeType as DesignRules.

property is_gravity: bool#

Check if this solution requires gravity constraints.

A solution is considered gravity-based if the pipe type has slope constraints (min_slope < 0 or max_slope > -inf).

Returns:

True if gravity constraints apply, False otherwise

property is_well_optimized: bool#

Check if a solution is optimized and if optimized solution is feasible.

A solution is well-optimized if: - Optimization has been performed (is_optimized = True) - The best pipe does not have “failed” in its name

Returns:

True if solution is optimized and feasible, False otherwise

static plot_data_attributes_optimized() list[str][source]#

Get displayed attributes on ParallelPlot.

property plot_data_color: str#

Get equivalent color in plot_data (rgb(255)).

plot_data_generated#
plot_data_optimized#
property ports: PortCouple#

Get port couple from input and output ports.

Returns:

PortCouple linking input and output ports

set_direct_connection_as_optimized(pipe_index: int) OptimizedPipes[source]#
set_for_optim(radius_factor: float = 1.0) Solution[source]#

Create a copy of this solution with modified radius for optimization.

Creates a new Solution with the same ports but with pipe radius scaled by radius_factor. Useful for optimization workflows where different radius values need to be tested.

Parameters:

radius_factor – Factor to multiply the pipe radius by (default: 1.0)

Returns:

New Solution instance with modified pipe type radius

set_optimized_pipes(optimized_pipes: list[OptimizedPipe], pipe_index: int) OptimizedPipes[source]#
set_properties(curvature_radius: float | None = None) None[source]#
to_mesh(merge_vertices: bool = False, merge_triangles: bool = False)[source]#
to_samples_generated(reference_path: str = '#') list[Sample][source]#
to_samples_optimized(reference_path: str = '#') list[Sample][source]#
to_shell()[source]#
update_with_grid_paths(grid_paths: list[GridPath]) None[source]#

Build a Solution from a list of GridPaths.

Adds new OptimizedPipes objects to the solution, each containing a GridPath but no optimized pipes yet. The optimized pipes can be added later using set_optimized_pipes().

Parameters:

grid_paths – List of GridPath objects to add to the solution

volmdlr_primitives() list[Primitive3D][source]#

Get primitives for babylonjs method.

class routing.core.core.SpecInterface(input_position: tuple[float, float, float], input_vector: tuple[float, float, float], input_length: float, output_position: tuple[float, float, float], output_vector: tuple[float, float, float], output_length: float, radius: float, name: str, radius_of_curvature_ratio: float | None = None, min_straight_length: float | None = None, min_slope: float | None = None, max_slope: float | None = None, pooling_type: str = 'None', color: tuple[float, float, float] = (0.1, 0.1, 0.1))[source]#

Bases: DessiaObject

A class for defining pipe specifications with input/output ports and pipe properties.

This class inherits from DessiaObject, and provides a simplified interface for creating pipe routing specifications by directly specifying port positions, directions, and pipe characteristics without requiring separate Port and PipeType objects.

Parameters:
  • input_position – The 3D position of input port as (x, y, z) tuple.

  • input_vector – The direction vector of input port (non-normalized).

  • input_length – The extension length of input port before first turn.

  • output_position – The 3D position of output port as (x, y, z) tuple.

  • output_vector – The direction vector of output port (non-normalized).

  • output_length – The extension length of output port before first turn.

  • radius – The pipe equivalent radius.

  • name – The name identifying this specification.

  • radius_of_curvature_ratio – The minimum ratio of curvature radius to pipe radius. Defaults to None.

  • min_straight_length – The minimum straight length before turns. Defaults to None.

  • min_slope – The minimum allowed slope (negative for gravity systems). Defaults to None.

  • max_slope – The maximum allowed slope. Defaults to None.

  • pooling_type – The type for grouping/pooling. Defaults to ‘None’.

  • color – The RGB color tuple (r, g, b) between 0 and 1 for visualization. Defaults to (0.1, 0.1, 0.1).

property input_port: Port#

Get equivalent Input Port from SpecInterface attributes.

Creates a Port object from the input position, vector, and length attributes of this SpecInterface.

Returns:

Port object representing the input connection point.

property output_port: Port#

Get equivalent Output Port from SpecInterface attributes.

Creates a Port object from the output position, vector, and length attributes of this SpecInterface.

Returns:

Port object representing the output connection point.

property pipe_type: PipeType#

Get equivalent PipeType from SpecInterface attributes.

Creates a PipeType object from the radius, curvature, slope, and other attributes of this SpecInterface.

Returns:

PipeType object with all constraints and properties from this spec.

class routing.core.core.Specification(start: Port, end: Port, pipe_type: PipeType, name: str = '')[source]#

Bases: DessiaObject

A class to associate a port couple with a pipe type.

This class inherits from DessiaObject, and defines a complete routing requirement: a path between two ports using a specific pipe type. This is the main input for creating routing solutions.

Parameters:
  • start – The start port of the path (where the pipe begins).

  • end – The end port of the path (where the pipe terminates).

  • pipe_type – The PipeType defining the characteristics of the pipe to route.

  • name – The name of the Specification. Defaults to ‘’.

classmethod from_complete_definition(start: Port, end: Port, radius: float, name: str, radius_of_curvature_ratio: float | None = None, min_straight_length: float | None = None, min_slope: float | None = None, max_slope: float | None = None, pooling_type: str = 'None', color: tuple[float, float, float] = (0.1, 0.1, 0.1)) Specification[source]#

Create specification from ports and all requirements for the pipe type.

Creates a Specification by building a PipeType from individual parameters. Useful when pipe properties are specified directly rather than using a pre-existing PipeType.

Parameters:
  • start – Start port

  • end – End port

  • radius – Pipe equivalent radius

  • name – Name for the specification and pipe type

  • radius_of_curvature_ratio – Minimum ratio of curvature radius to pipe radius

  • min_straight_length – Minimum straight length before turns

  • min_slope – Minimum allowed slope (negative for gravity systems)

  • max_slope – Maximum allowed slope

  • pooling_type – Type for grouping/pooling

  • color – RGB color tuple for visualization

Returns:

Specification instance with a newly created PipeType

classmethod from_ports(start: Port, end: Port, pipe_type: PipeType) Specification[source]#

Create specification for a couple of ports and a pipe type.

Convenience method to create a Specification using the pipe type’s name.

Parameters:
  • start – The start port.

  • end – The end port.

  • pipe_type – The PipeType for the specification.

Returns:

Specification instance with name from pipe_type.name.

classmethod from_spec_interfaces(specifications: list[SpecInterface])[source]#

Build list of Specifications from list of SpecInterface objects.

Converts a list of SpecInterface objects (simplified specification format) into a list of Specification objects (full format with Port and PipeType objects).

Parameters:

specifications – The list of SpecInterface objects to convert.

Returns:

List of Specification instances, one per SpecInterface.

property port_couple: PortCouple#

Get port couple object from start and end ports.

Creates a PortCouple from the specification’s ports.

Returns:

PortCouple instance linking start and end ports.

class routing.core.core.UserProperty(attribute: str = 'user_defined', min_distance: float = 0.0, max_distance: float | None = None, ruled_volumes: list[RuledVolume] | None = None, name: str = '')[source]#

Bases: DessiaObject

A class to build User Defined Property on voxels.

This class inherits from DessiaObject, and creates a property based on proximity rule: while the voxel is in a distance range defined by [min_distance, max_distance] from the ruled volumes, the property named attribute of these voxels will be True. Outside they will be False. This property is used to build a DistanceAttributeToggler, that is used by ConstraintRules.

Parameters:
  • attribute – The name of the attribute to apply on voxels. Defaults to ‘user_defined’.

  • min_distance – The minimum distance from ruled volumes for a voxel to have the property set to True. Defaults to 0.0.

  • max_distance – The maximum distance from ruled volumes for a voxel to have the property set to True. If None, no maximum distance limit. Defaults to None.

  • ruled_volumes – The list of RuledVolume objects to consider for distance computation. Defaults to None.

  • name – The name to identify this UserProperty. Defaults to ‘’.

to_rule_on_volumes() None[source]#

Push the current UserProperty as a DesignRule on its RuledVolumes.

Converts this UserProperty into a DistanceAttributeToggler rule and adds it to the pipe_rules of each associated RuledVolume. This allows the property to be used as a constraint during routing.

The rule will be added to pipe_rules, which are pipe-specific design rules that can be applied dynamically.