volmdlr_tools.graph package#
Subpackages#
- volmdlr_tools.graph.utils package
- volmdlr_tools.graph.kinematics package
- Submodules
- volmdlr_tools.graph.kinematics.findjoint module
JointFinderJointFinder.analyse_intersection_result()JointFinder.analysis()JointFinder.check_direction()JointFinder.check_displacement()JointFinder.construct_matrix_dof()JointFinder.count_dof_constraints()JointFinder.create_torsor_from_unconstrained()JointFinder.detect_minimal_constraints()JointFinder.equivalent_torsor()JointFinder.find_subspace_intersection()JointFinder.get_dict_constraints_name()JointFinder.get_kinematic_list()JointFinder.get_most_unknown()JointFinder.get_torsor_kinematic_list()JointFinder.get_torsor_static_list()JointFinder.joint_torsor()JointFinder.merge_torsors()JointFinder.should_merge_torsors()
- volmdlr_tools.graph.kinematics.torsor module
DynamicTorsorGeometricTorsorGeometricTorsor.from_kinematic_torsor()GeometricTorsor.geometric_torsor_matrix()GeometricTorsor.geometric_torsor_rotation_x()GeometricTorsor.geometric_torsor_rotation_y()GeometricTorsor.geometric_torsor_rotation_z()GeometricTorsor.geometric_torsor_translation_x()GeometricTorsor.geometric_torsor_translation_y()GeometricTorsor.geometric_torsor_translation_z()GeometricTorsor.type()
KinematicTorsorKineticTorsorStaticTorsorTorsorTorsor.addition()Torsor.check_direction_dof()Torsor.check_rotary()Torsor.comparison_unknown()Torsor.compute_norm()Torsor.copy()Torsor.dict_to_object()Torsor.equivalent_torsor()Torsor.get_unknown()Torsor.moment_dual()Torsor.resultant_dual()Torsor.to_dict()Torsor.to_dual()Torsor.torsor_to_column()Torsor.transport_moment()Torsor.transport_resultant()
- Module contents
Submodules#
volmdlr_tools.graph.assembly module#
Specific module to create and manipulate assembly graphs of volmdlr volume model.
- class volmdlr_tools.graph.assembly.GraphAssembly(graph: Graph, root_compound: Compound = None, name: str = '')#
Bases:
GraphClass to create, manipulate and plot volmdlr assembly graphs.
- are_siblings(list_nodes: list[int]) bool#
Return True if all nodes in the given list children of the same parent and False otherwise.
- Parameters:
list_nodes – A list containing the node IDs.
- Returns:
True if all nodes share a common parent, False otherwise.
- calculate_gravity_center(nodes: list[int]) None#
Calculate the center of gravity for given list of node in the assembly.
- Parameters:
nodes – list of nodes.
- classmethod dict_to_object(dict_: dict[str, Any], **kwargs) SerializableObject#
Deserialize a dictionary to a Graph object. Custom to handle networkx graph.
- property directed_acyclic_graph: DiGraph#
Return the directed acyclic graph of the assembly tree.
- classmethod from_compound(compound: Compound) GraphAssembly#
Create a GraphAssembly from a compound.
- classmethod from_volume_model(volume_model: VolumeModel) GraphAssembly#
Create a GraphAssembly from a volume model.
- get_aag(node: int, smooth_angular_tol: float = 1e-06) graph_faces.AttributedAdjacencyGraph#
Get agg for corresponding node solid.
- get_all_children(node: int) GraphAssembly#
Get all levels of children until the leaf of the given parent ID and return as a subgraph.
- Parameters:
node – The parent node ID.
- Returns:
A GraphAssembly instance containing the subgraph.
- get_children(node: int) list[int]#
Get all first-level children IDs of the given parent ID.
- Parameters:
node – The parent node ID.
- Returns:
A list of child node IDs.
- get_close_solids(solid_node_id: int, maximum_distance: float) NodeView#
Get the close solids from a solid.
- Parameters:
solid_node_id – The node id of the solid.
maximum_distance – The maximum distance to consider a solid as close.
- Returns:
A dict of the close solids with their attributes.
- get_disconected_subassemblies() list[GraphAssembly]#
Identifies and retrieves disconnected subassemblies of a graph-based structure.
This function isolates separate subassemblies by analyzing the connected components of the graph where specific edge properties and node attributes are used for filtering. It calculates bounding box proximity and determines proximity distances on edges to filter and identify interconnections between nodes classified as “Solid”. The result is a list of subassemblies, each represented as its own graph structure.
- Returns:
A list of subassemblies represented as graph objects. If the graph is connected, the method returns a single-item list containing the original graph.
- Return type:
list
- get_mesh(node_id: int) Shape#
Get the mesh from a node id.
- Parameters:
node_id – The node id to get the mesh from.
- Returns:
The mesh corresponding to the node id.
- get_node_id(shape: Shape) int | None#
Get the NodeID in the graph from a given shape.
- Parameters:
shape – The shape to search in the graph.
- Returns:
The ID of the given shape.
- get_parent(node: int) int#
Get the parent node of a given node.
- Parameters:
node – The node ID to query.
- Returns:
The parent node ID, or None if no parent exists.
- get_path(node: int) list[int]#
Return the path from the root to get in the specified node.
- get_shape(node_id: int) Shape#
Get the shape from a node id.
- Parameters:
node_id – The node id to get the shape from.
- Returns:
The shape corresponding to the node id.
- get_solids_by_radius_proximity(solid_node_id: int, radius: float) NodeView#
Get all the solids whose center of mass is within a specified radius of the center of mass of a target solid.
- Parameters:
solid_node_id – The node ID of the target solid.
radius – The radius within which to search for nearby solids.
- Returns:
A NodeView where keys are node IDs of solids whose center of mass is within a specified radius.
- get_solids_inside_sphere(center: Point3D, radius: float) NodeView#
Get all the solids that are inside a sphere defined by a center point and a radius.
The solid will be considered inside the sphere if its center_of_mass is inside of the sphere.
- Parameters:
center – The center point of the sphere.
radius – The radius of the sphere.
- Returns:
A NodeView where keys are node IDs of solids inside the sphere.
- markdown_tree#
Implementation of a tag for displays.
- print_tree() None#
Print the XPDM XML tree.
- process_geom_constraint_to_joints(constraints: list[GeometricConstraint], edge: tuple[int, int])#
Converts geometric constraints between two solids into appropriate joint types.
This function analyzes the given geometric constraints between two solids and determines the appropriate joint type to represent their mechanical relationship.
- set_bounding_box_attribute() None#
Set the bounding box attribute for all nodes.
- set_center_of_mass_attribute() None#
Set the center of mass attribute for all nodes.
- set_connection_geometry(tol: float = 1e-06)#
Set the connection geometry attribute for all solids. The edge attribute “” will be set.
- Parameters:
tol – The tolerance to consider two solids as connected.
- set_distance_attribute(exact: bool = True) None#
Set a distance attribute between all solids in the assembly graph.
This method calculates the pairwise distances between all solids and assigns them to the edges in the graph as an attribute named “distance.”
- Parameters:
exact – If True, uses exact geometry for distance calculations. If False, uses discretized shapes for faster but approximate calculations.
- Returns:
None. The method modifies the graph in-place by adding a “distance” attribute to edges between solids.
- set_distance_siblings_attribute(exact: bool = True) None#
Set the distance attribute for edges between sibling shapes in the assembly graph.
This method calculates distances between shapes that share a common parent and assigns them as an attribute named “distance_siblings” to the corresponding edges.
- Parameters:
exact – If True, uses exact geometry for distance calculations. If False, uses discretized shapes for faster but approximate calculations.
- Returns:
None. The method modifies the graph in-place by adding a “distance_siblings” attribute to edges between sibling shapes.
- set_edges_between_all_solids()#
Establishes edges between all nodes classified as “Solid” within the graph.
This function utilizes a filter to identify edges connecting nodes where both nodes are of the class “Solid”. It ensures that such connections are established across the graph through the create_edges method.
- Returns:
None
- set_geometric_constraints(tol: float = 1e-06) None#
Configure geometric constraints for edges between solids.
This method sets connections between all solids in the system and assigns geometric constraints attributes to the edges based on the conditions defined by the distance and class of the solids.
- Parameters:
tol – A tolerance value used to filter edges by distance.
- set_parent_attribute() None#
Set parent attribute for nodes of the graph.
- to_dict(use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None, **kwargs) dict[str, Any]#
Convert the Graph object to a serializable dictionary. Custom to handle networkx graph.
volmdlr_tools.graph.core module#
Generic graph class.
- class volmdlr_tools.graph.core.Graph(graph: Graph, name: str = '')#
Bases:
DessiaObjectGeneric graph class, with serialization and plotting capabilities.
This class is composed of a networkx graph, and provides methods to manipulate it. This class can be overridden to create specific graph classes, with specific creation methods.
- create_edge(edge: tuple[int, int], attributes: dict[str, Any] = None) None#
Create an edge with attributes, if not already existing.
- Parameters:
edge – The edge to create.
attributes – The attributes of the edge, optional.
- create_edges(filter_function: Callable[[tuple[int, int]], bool], attributes: dict[str, Any] = None) None#
Create edges between all nodes that satisfy the filter function, that takes an Edge as argument.
- Parameters:
filter_function – The function to filter the edges to create, based on the two nodes of the edge.
attributes – The attributes of the edges to create, optional.
- classmethod dict_to_object(dict_: dict[str, Any], **kwargs) SerializableObject#
Deserialize a dictionary to a Graph object. Custom to handle networkx graph.
- edge_subgraph(filter_function: Callable[[tuple[int, int]], bool]) Graph#
Create a subgraph from the edges that satisfy the filter function, that takes an Edge as argument.
- Parameters:
filter_function – A callable to filter the edges to create the subgraph from.
- Returns:
The subgraph created.
- property edges: EdgeView#
Return a read-only view of the eges of the graph.
You can get EdgeDataView object from it, by passing data=True argument to the NodeView object.
- get_connected_components(filter_function: Callable[[int], bool] | None = None) list[set[int]]#
Get connected components of the graph, optionally filtered.
- Parameters:
filter_function – Optional filter function to apply to nodes before finding components.
- Returns:
List of sets, where each set contains node IDs in a connected component.
- get_edge_attribute(edge: tuple[int, int], attribute: str) Any#
Get a specific attribute of a specific Edg. If the attribute does not exist, return None.
- Parameters:
edge – The edge to get the attribute from.
attribute – The key of the attribute to get.
- Returns:
The attribute of the edge.
- get_edge_data(node1: int, node2: int, default: Any = None) Any#
Get edge data between two nodes, with optional default value.
- Parameters:
node1 – First node ID.
node2 – Second node ID.
default – Default value to return if edge doesn’t exist.
- Returns:
Edge data dictionary or default value.
- get_edges(filter_function: ~typing.Callable[[tuple[int, int]], bool] = <function Graph.<lambda>>) EdgeView#
Get all edges that satisfy the filter function, that takes an Edge as argument.
- Parameters:
filter_function – A callable that take an Edge and return a bool (for filtering).
- Returns:
The edges that satisfy the filter function.
- get_node_attribute(node: int, attribute: str) Any#
Get a specific attribute of a specific node. If the attribute does not exist, return None.
- Parameters:
node – The node id to get the attribute from.
attribute – The key of the attribute to get.
- Returns:
The attribute of the node.
- get_nodes(filter_function: ~typing.Callable[[int], bool] = <function Graph.<lambda>>) NodeView#
Get all nodes that satisfy the filter function, that takes a NodeID as argument.
- Parameters:
filter_function – A callable that take a NodeID and return a bool (for filtering).
- Returns:
The nodes that satisfy the filter function.
- has_edge(node1: int, node2: int) bool#
Check if an edge exists between two nodes.
- Parameters:
node1 – First node ID.
node2 – Second node ID.
- Returns:
True if edge exists, False otherwise.
- property n_edges: int#
Get the number of edges of the graph.
- Returns:
The number of edges.
- property n_nodes: int#
Get the number of nodes of the graph.
- Returns:
The number of nodes.
- neighbors(node: int, filter_function: ~typing.Callable[[tuple[int, int]], bool] = <function Graph.<lambda>>) NodeView#
Get the neighbors of a node.
- Parameters:
node – The node id to get the neighbors from.
filter_function – The function to filter the neighbors to get based on the edge between the node and the neighbor.
- Returns:
The neighbors of the node.
- property nodes: NodeView#
Return a read-only view of the nodes of the graph.
You can get NodeDataView object from it, by passing data=True argument to the NodeView object.
- plot_data(reference_path: str = '#', **kwargs) list[NetworkxGraph]#
Return the plot_data object for local plot_data usage.
- plot_graph#
Specific display tag for PlotData. Add a picture argument.
- set_edge_attribute(edge: tuple[int, int], attribute: str, value: Any) None#
Set an attribute to an edge.
- Parameters:
edge – The edge to set the attribute to.
attribute – The key of the attribute to set.
value – The value of the attribute.
- set_edges_attribute(attribute: str, attribute_function: Callable[[tuple[int, int]], Any], filter_function: Callable[[tuple[int, int]], bool] | None = None) None#
Set a dynamically computed attribute on all the edges that satisfy the filtering function.
- Parameters:
attribute – The key of the attribute to set.
attribute_function – A callable that take an Edge and return a value, to compute the attribute value.
filter_function – An optional callable to filter the edges to apply the attribute to.
- set_node_attribute(node: int, attribute: str, value: Any) None#
Set an attribute to a node.
- Parameters:
node – The node id to set the attribute to.
attribute – The key of the attribute to set.
value – The value of the attribute.
- set_nodes_attribute(attribute: str, attribute_function: Callable[[int], Any], filter_function: Callable[[int], bool] | None = None) None#
Set a dynamically computed attribute on all the nodes that satisfy the filtering function.
- Parameters:
attribute – The key of the attribute to set.
attribute_function – A callable that take a NodeID and return a value, to compute the attribute value.
filter_function – An optional callable to filter the nodes to apply the attribute to. Default is all nodes.
- subgraph(filter_function: Callable[[int], bool]) Graph#
Create a subgraph from the nodes that satisfy the filter function, that takes a NodeID as argument.
- Parameters:
filter_function – A callable to filter the nodes to create the subgraph from.
- Returns:
The subgraph created.
- to_dict(use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None, **kwargs) dict[str, Any]#
Convert the Graph object to a serializable dictionary. Custom to handle networkx graph.
volmdlr_tools.graph.faces module#
Attributed Adjacency Graph (AAG) Module for CAD Feature Recognition.
References: - Joshi S., Chang T.C. Graph-based heuristics for recognition of machined
features from a 3D solid model // Comput. Des. 1988. Vol. 20, N 2. P. 58-66.
- class volmdlr_tools.graph.faces.AttributedAdjacencyGraph(shape: Solid | Shell, graph: Graph | None = None, allow_smooth: bool = True, smooth_angular_tol: float = 1e-06, name: str = '')#
Bases:
GraphAttributed Adjacency Graph (AAG) for faces of a BRep model.
The AAG provides a formal graph structure that captures the adjacency relationships between faces of a BRep model, along with attributes such as surface type, angles between faces, and geometric properties. The AAG extends a B-Rep (Boundary Representation) model with semantics, allowing for graph-based traversal and feature recognition.
Advantages of using an AAG: - Provides a formal graph view of the CAD model for applying graph algorithms. - Caches serial indices of sub-shapes, avoiding repeated use of TopExp utilities
for an unchanged CAD model.
Enables the representation of features and semantics through graph attributes.
Explicitly defines the adjacency relationships between faces, making it useful for feature recognition and geometric analysis.
The AAG is based on the work by Joshi and Chang (1988), who proposed a graph-based approach for recognizing machined features in 3D solid models.
- aag_overall_weight() int#
Create a sort of signature for an aag.
In general, it uses the graph structure and faces relationship to create a value that could be used as some sort of id. The node weights are defined using the networkx graph degree of each node, and the edge weights are calculated using the angle in degrees between two adjacent faces.
Add face related attributes.
- add_mates(mate_faces: list[TopoDS_Shape]) None#
Add adjacency relationships (mates) between pairs of faces in the graph.
Helper function to build_adjacency_graph. For each pair of adjacent faces, this method computes the angle between them, assigns surface types and colors to the nodes, and adds edges between the faces in the graph. The adjacency edge is attributed with the angle, common-edge indices, and edge color based on whether the angle is concave, convex, or neutral.
- Parameters:
mate_faces – A list of faces that share a common edge.
- build_adjacency_graph() None#
Construct an adjacency graph of the faces in a B-Rep (Boundary Representation) model.
This method builds the adjacency graph by iterating over the edges of the TopoDS_Shape. Each node in the resulting graph represents a TopoDS_Face, and each edge in the graph represents an adjacency relation between two TopoDS_Face instances that share a common TopoDS_Edge.
The algorithm proceeds as follows: 1. For each edge in the shape, the method retrieves the adjacent faces that share
the current edge.
These adjacent faces are passed to the add_mates method, which handles the creation of nodes and edges in the graph based on the adjacency relationships.
- calculate_face_angle(face1_id: int, face2_id: int) None#
Update aag graph edges with the angle information between two faces.
- calculate_faces_angles() None#
Update aag graph edges with the angle information between two faces.
- copy(deep=True, memo=None) AttributedAdjacencyGraph#
Copy of AttributtedAdjacencyGraph.
- Returns:
return a copied instance of the AttributtedAdjacencyGraph.
- classmethod dict_to_object(dict_: dict[str, Any], **kwargs) SerializableObject#
Deserialize a dictionary to a AttributedAdjacencyGraph object.
- get_bounding_box(face: TopoDS_Shape = None, index: int = None) BoundingBox#
Get the bounding box of a face or an index.
- get_common_edges(face1_idx: int, face2_idx: int) list[TopoDS_Shape]#
Get common edges between two faces by their indices.
This is the primary efficient method that works directly with face indices. Uses the AAG’s pre-computed common_edges_indices for O(1) lookup.
- Parameters:
face1_idx – First face index (node ID)
face2_idx – Second face index (node ID)
- Returns:
List of common edges (TopoDS_Shape) or empty list if none found
- get_common_edges_between_faces(face1: TopoDS_Shape, face2: TopoDS_Shape) list[TopoDS_Shape]#
Get common edges between two faces (convenience method).
This method provides convenience when working directly with TopoDS_Shape objects. It converts faces to indices and delegates to get_common_edges().
- Parameters:
face1 – First face (TopoDS_Shape)
face2 – Second face (TopoDS_Shape)
- Returns:
List of common edges (TopoDS_Shape) or empty list if none found
- get_edge(edge_index: int) TopoDS_Shape | None#
Retrieve an edge from the indexed map by its index.
- Parameters:
edge_index – The index of the edge to retrieve (1-based).
- Returns:
The edge corresponding to the given index, or default if invalid.
- get_edge_index(edge: Edge | TopoDS_Shape) int#
Retrieve an edge index from a edge object.
- get_face(face_index: int) TopoDS_Shape#
Retrieve a face from the indexed map by its index.
- Parameters:
face_index – The index of the face to retrieve.
- Returns:
The face corresponding to the given index.
- get_face_index(face: Face | TopoDS_Shape) int#
Retrieve a face index from a face object.
This method handles both volmdlr shapes.Face objects and OCP TopoDS_Shape objects. For shapes.Face objects, it uses the wrapped TopoDS_Face. For TopoDS_Shape objects, it uses them directly.
- Parameters:
face – The face object (shapes.Face or TopoDS_Shape) to get the index for.
- Returns:
The index corresponding to the given face, or -1 if not found.
- get_faces_on_concave_angles() list[TopoDS_Shape]#
Get all faces that are connected to edges with concave angles.
Calculates face angles if not already computed, then finds all edges with concave angles and returns the faces connected to those edges.
- Returns:
List of face objects that are adjacent to concave angle edges.
- get_faces_on_convex_angles() list[TopoDS_Shape]#
Get all faces that are connected to edges with convex angles.
Calculates face angles if not already computed, then finds all edges with convex angles and returns the faces connected to those edges.
- Returns:
List of face objects that are adjacent to convex angle edges.
- get_neighbors_thru(face_index: int, edge: TopoDS_Shape) list[int]#
Get the neighboring faces of a given face that share a specific edge.
- Parameters:
face_index – The index of the face to find neighbors for.
edge – The edge shared by neighboring faces.
- Returns:
A list of indices representing neighboring faces that share the specified edge.
- get_neighbors_thru_edge_ids(face_index: int, edge_ids: TColStd_PackedMapOfInteger) list[int]#
Get neighboring faces of a given face that share common edges, identified by their edge indices.
- Parameters:
face_index – The index of the face to find neighbors for.
edge_ids – A packed map of edge indices to check for commonality.
- Returns:
A list of indices representing neighboring faces that share the specified edges.
- init_attributes() None#
Create the Attributed Adjacency Graph from a given shape.
- is_angle_concave(edge: tuple[int, int]) bool#
Check if the angle at a given edge is concave.
- Parameters:
edge – The edge to check for concave angle.
- Returns:
True if the angle at the edge is concave, False otherwise.
- is_angle_convex(edge: tuple[int, int]) bool#
Check if the angle at a given edge is convex.
- Parameters:
edge – The edge to check for convex angle.
- Returns:
True if the angle at the edge is convex, False otherwise.
- plot_data(reference_path: str = '#', **kwargs) list#
Create the plot_data object used to represent the graph.
- to_dict(use_pointers: bool = True, memo=None, path: str = '#', id_method=True, id_memo=None, **kwargs) dict[str, Any]#
Convert the AttributedAdjacencyGraph object to a serializable dictionary.
Module contents#
Graph module.