volmdlr_tools.features.extractors package#
Feature extractors for identifying specific features in BRep models.
Submodules#
volmdlr_tools.features.extractors.core module#
Module for the base feature extractor class.
- class volmdlr_tools.features.extractors.core.FeatureExtractor(aag: AttributedAdjacencyGraph, name: str = '')#
Bases:
DessiaObjectBase class for feature extractors.
- is_not_entire_shape(new_feature_faces: list[TopoDS_Shape], new_feature_indices: list[int]) bool#
Validate whether the recognized feature is a subset of the entire CAD model.
This method ensures that the newly identified feature does not encompass the entire model, which would indicate that the feature recognition failed to isolate a distinct feature. The method compares the size of the feature to the total number of faces in the AAG.
- Parameters:
new_feature_faces – A list of faces belonging to the newly recognized feature.
new_feature_indices – A list of indices for the faces in the recognized feature.
- Returns:
Returns True if the recognized feature is smaller than the entire CAD model, indicating successful isolation of a distinct feature.
- perform() bool#
Perform the feature extraction.
- class volmdlr_tools.features.extractors.core.InnerFeaturesExtractor(aag: AttributedAdjacencyGraph, max_number_feature_faces: float = 20, name: str = '')#
Bases:
FeatureExtractorBase class for inner features extractors.
This class provides a base implementation for extracting inner features from a CAD model. Subclasses must implement the is_invalid_base_neighbor and recognize methods.
Inner features are features that are inside a shape’s face, connected to its inner wires.
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
name (str) – The name of the Extractor.
- Returns:
The Extractor.
- Return type:
- extract() list[list[int]]#
Recognize feature faces in BRep model.
The method first identifies seed faces by finding inner wires (loops of edges inside a face). Each seed is checked for convexity/smoothness based on the angle between adjacent faces. If the inner wire is convex or smooth, the method propagates to neighboring faces, ensuring the identified feature doesn’t exceed the maximum allowable number of faces (max_number_feature_faces).
The algorithm proceeds as follows: 1. For each inner wire in a seed face, find adjacent faces through common edges and check whether the adjacency
relationships between each pair of faces are classified as convex.
Propagate through adjacent faces to form a feature, ensuring the feature is valid.
Return the recognized features as collections of faces and their corresponding indices.
Note: This method accumulates all valid feature faces. The post-processing step (e.g., _collect_cavities) should handle grouping by connected components.
- get_features_faces(nodes: list[int]) list[Face]#
Get features faces for a set of nodes.
- is_angle_type_valid(angle_validator: callable, face_index: int, wire: TopoDS_Shape) bool#
Check whether the edges of a wire are of a given type, based on the angles between adjacent faces.
This method iterates over the edges of a given wire (which can represent part of a face) and evaluates the type of the edges based on the angles between the current face and its neighboring faces. If all angles are of the given type, the method returns True, indicating that the wire forms a feature boundary of the given type.
- Parameters:
angle_validator – A function that validates the angle type.
face_index – The index of the face being evaluated for the angle type.
wire – The wire (loop of edges) to check for the angle type.
- Returns:
Returns True if all edges in the wire are of the given type; otherwise, False.
- is_concave_through(face_index: int, wire: TopoDS_Shape) bool#
Check whether the edges of a wire are concave, based on the angles between adjacent faces.
This method iterates over the edges of a given wire (which can represent part of a face) and evaluates the concavity of the edges based on the angles between the current face and its neighboring faces. If all angles are concave, the method returns True, indicating that the wire forms a concave feature boundary.
- Parameters:
face_index – The index of the face being evaluated for concavity.
wire – The wire (loop of edges) to check for concavity.
- Returns:
Returns True if all edges in the wire are concave; otherwise, False.
- is_convex_through(face_index: int, wire: TopoDS_Shape) bool#
Check whether the edges of a wire are convex, based on the angles between adjacent faces.
This method iterates over the edges of a given wire (which can represent part of a face) and evaluates the convexity of the edges based on the angles between the current face and its neighboring faces. If all angles are convex, the method returns True, indicating that the wire forms a convex feature boundary.
- Parameters:
face_index – The index of the face being evaluated for convexity.
wire – The wire (loop of edges) to check for convexity.
- Returns:
Returns True if all edges in the wire are convex; otherwise, False.
- is_feature_valid(new_feature_faces: list[TopoDS_Shape], new_feature_indices: list[int], seed_face_id: int) bool#
Check if the feature is valid.
- is_invalid_base_neighbor(start_id: int, neighbor_id: int) bool#
Check if the base neighbor is invalid.
- propagate(start_id: int, seed_neighbors_ids: list[int], feature_faces: list[TopoDS_Shape], feature_indices: list[int], is_ok: bool = True) bool#
Propagates through the AAG starting from a seed face, identifying adjacent faces that form a feature.
This method is a recursive traversal that collects neighboring faces into a feature. For each seed face, the method checks whether its adjacent faces meet the necessary geometric conditions (e.g., sharing common edges on the outer wire and having convexity in the adjacent angles).
The propagation continues until no more valid adjacent faces can be added to the feature, or the maximum allowable number of faces is reached.
- Parameters:
start_id – The index of the starting face for the propagation.
seed_neighbors_ids – List of neighboring face indices to be evaluated.
feature_faces – A list to collect faces that are part of the recognized feature.
feature_indices – A list to collect indices of faces that form the feature.
is_ok – (optional) A flag indicating whether the feature remains valid throughout propagation (default is True).
- Returns:
Returns True if the propagation is successful and the feature remains valid.
volmdlr_tools.features.extractors.blend module#
A module for recognition of fillets in a BRep model.
- class volmdlr_tools.features.extractors.blend.BlendExtractor(aag: AttributedAdjacencyGraph, max_radius: float | None = None, free_form_curvature: bool = False)#
Bases:
FeatureExtractorExtract blend/fillet features from AAG.
A class for recognizing and analyzing blends in a geometric model using an adjacency attribute graph (AAG). Supports recognition of edge-based and vertex-based blends.
The blends a reading finds are recorded on the graph’s faces, and stay there for the readings that follow. A reading lists only the blends within its own radius bound, but it does not clear what an earlier reading of the same graph recorded: a reading with a smaller bound than an earlier one still meets the earlier one’s larger blends among the neighbours of its own while it tells their edges apart, though it does not list them.
- calculate_chain_length(feature: list[int]) float#
Compute the total length of a blend chain based on the blend candidate attributes of each face.
The total length is the sum of the lengths of each blend face in the chain, as stored in their blend candidate attributes.
- Parameters:
feature – A list of face IDs representing the blend chain.
- Returns:
The computed total length of the blend chain.
- compute_blend_length(edges_indices: list[int]) float#
Compute the total length of the blend chain.
- Parameters:
edges_indices – A list of edges indexes from the blend chain.
- Returns:
The sum of the lengths of all edges in edges_indices list.
- display_result() dict#
Implementation of a tag for displays.
- dye_blending_faces(color: tuple = (0, 1, 1)) None#
Change the colors of blending faces.
- Parameters:
color – Derired color
- find_cross_edges(face_id: int, smooth_edges_ids: list[int], spring_edges_ids: list[int], candidate_radius: float) tuple#
Identify and return cross edges on a given face, based on curvature evaluation and a specified candidate radius.
Cross edges are those that satisfy certain curvature conditions compared to the provided radius and are not in the excluded categories (smooth or spring edges).
The method evaluates curvature at the midpoint of each remaining edge, which is smooth but is not a spring edge.
The edge is classified as a cross edge if its curvature-derived radius matches the candidate radius within a tolerance threshold — it curves around the blend.
The edge is classified as a junction instead if the blend does not curve along it at all. The blend runs along such an edge rather than across it, continuing into whatever lies beyond, so the edge marks no end of the blend.
- Parameters:
face_id – The index or ID of the face for which to find cross edges.
smooth_edges_ids – A list of edge IDs that represent “smooth” edges to be excluded.
spring_edges_ids – A list of edge IDs that represent “spring” edges to be excluded.
candidate_radius – The target radius value used to compare the curvature of the edges.
- Returns:
cross_edges: A list of edge objects that qualify as cross edges based on the curvature evaluation.
cross_edges_ids: A list of IDs corresponding to the cross edges.
junction_edges_ids: A list of IDs of the edges the blend runs along.
- Raises:
Issues a warning if the curvature cannot be evaluated along the edge.
- find_smooth_edges() tuple[list[TopoDS_Shape], list[int]]#
Find all smooth edges across all faces in the adjacency attribute graph (AAG).
- Returns:
A tuple containing the list of all smooth edges and their corresponding indices.
- find_smooth_edges_for_face(face_id: int) tuple[list[TopoDS_Shape], list[int]]#
Find smooth edges for a given face based on adjacent faces in the graph.
- Parameters:
face_id – The ID of the face to analyze.
- Returns:
A tuple containing the list of smooth edges and their corresponding indices.
- find_spring_edges(face_id: int, smooth_edge_ids: TColStd_PackedMapOfInteger) tuple[list[TopoDS_Shape], list[int], bool, float, list[float]]#
Find the spring edges for a given face, considering the smooth edge indices.
- Parameters:
face_id – The ID of the face to analyze.
smooth_edge_ids – The indices of the smooth edges.
- Returns:
A tuple containing the spring edges, their indices, whether it’s a candidate blend, the candidate radius, and the per-spring-edge candidate radii.
- find_terminating_edges(face_id: int, smooth_edges_ids: list[int], spring_edges_ids: list[int], cross_edges_ids: list[int]) tuple[list[TopoDS_Shape], list[int], list[TopoDS_Shape], list[int]]#
Identify terminating and seam edges of a given face.
A terminating edge is one that does not belong to any of the provided exclusion lists AND crosses to a real neighbour face — i.e. bounds the blend against another face. A wire edge with no external neighbour through this face is a seam of the underlying periodic surface (a torus fillet’s meridian, for example): topologically it is an internal artifact of the parameter domain, not a boundary against another face, so it goes into the seam set instead of the terminating one — leaving a full-round fillet with the clean
2 spring / 0 cross / 0 termsignature its Euler condition expects, while still exposing the seam through the AAG for consumers that need to detect a closed / loop blend (e.g. profile extraction and the full-round Euler condition).- Parameters:
face_id – The index or ID of the face for which to find terminating edges.
smooth_edges_ids – A list of edge IDs that represent “smooth” edges to be excluded.
spring_edges_ids – A list of edge IDs that represent “spring” edges to be excluded.
cross_edges_ids – A list of edge IDs that represent “cross” edges to be excluded.
- Returns:
(terminating_edges, terminating_edges_ids, seam_edges, seam_edges_ids).
- get_blending_chains_faces() list[list[Face]]#
Return a list containing all identified faces grouped by connectivity and radius.
- get_blending_faces() list[Face]#
Return a list containing all identified faces.
- get_chains(r_dev_perc: float = 5.0) list[BlendChain]#
Identify and return chains of adjacent blend faces of one radius.
Blends are joined where they are adjacent along any edge, sharp ones included, then split by fillet radius; each chain carries the cross-edge length of its radius group. So a fillet that continues round a corner whose blend has another radius comes back as several chains, and two blends of one radius meeting at a sharp edge as one;
tangent_chains()joins blends along smooth edges only, whatever their radii. The method first extracts connected components from the adjacency graph based on recognized blend candidates. It then distributes faces into groups based on their fillet radii and evaluates connected components within each group. Afterward, it normalizes these chains by removing any dangling vertex blends.These chains join blends of one radius however they meet, at a mitre too; the rounds of a part reading, each made in one go, are
BlendReading.chains().- Parameters:
r_dev_perc – The allowed percentage deviation when comparing fillet radii. This value controls the tolerance for how close radii need to be considered part of the same chain. A typical default value is 5.0%.
- Returns:
A list of BlendChain objects, each containing faces, properties, and spring edges.
- property ids: list[int]#
Return the ids of blend faces.
- Returns:
Ids of blend faces.
- classmethod of_reading(aag: AttributedAdjacencyGraph, blends: BlendReading) BlendExtractor#
Return an extractor holding blends already read, marked on aag as reading them there would mark them.
Nothing is recognised again: the blends, their chains and the marks a reader of the graph’s nodes finds are exactly blends. Any blend marks aag carried before are replaced.
- Parameters:
aag – The adjacency graph of the part the blends were read from, numbered the same.
blends – The part’s blends.
- perform() None#
Execute the blend recognition process over all faces in the adjacency attribute graph (AAG).
- property shape: Shape#
Return the shape.
- terminating_edges_to_cross_edges() None#
Convert terminating edges to cross edges if the terminating edges connect blend candidate faces.
- class volmdlr_tools.features.extractors.blend.BlendReading(attributes: Mapping[int, BlendAttribute], supports: frozenset[int], max_radius: float)#
Bases:
Mapping[int,BlendAttribute]The blends of a part, read once and handed to every reader of the part as a value.
It maps each blend face, numbered as the part’s adjacency graph numbers its faces, to what it blends. Reading the blends leaves no mark on the graph read: a reader that reads blends off a graph’s nodes is handed
marked(), a copy of its own carrying exactly these blends, so that what one reader reads never depends on which reader ran before it.Made by
read_blends().- chains(aag: AttributedAdjacencyGraph) list[BlendChain]#
Return one blend chain per round made in one go, ordered by their smallest face.
A round run along edges that follow on from one another tangentially, such as the rim of an obround slot, is made of several faces: one per edge it rounds, and one per corner it turns. They run on into one another tangentially, round the same side of the part, and have one radius; blends that differ in any of these, such as two fillets meeting at a mitre, or a small round running past a larger one, are apart. A chain’s radius and cross length are the median of its faces’, its length their sum.
BlendExtractor.get_chains()joins blends of one radius however they meet instead.- Parameters:
aag – The adjacency graph of the part read.
- property faces: frozenset[int]#
The blend faces.
- features(aag: AttributedAdjacencyGraph) list[Blend]#
Return one blend feature per blend face, smallest face first.
- Parameters:
aag – The adjacency graph of the part read.
- marked(aag: AttributedAdjacencyGraph) AttributedAdjacencyGraph#
Return a copy of aag of its own, numbered the same, its nodes marked with exactly these blends.
aag itself is left as it was. The copy is for a reader that reads blends off a graph’s nodes.
- Parameters:
aag – The adjacency graph of the part read.
- property max_radius: float#
The largest blend radius counted, in model units; a blend whose radius varies is within any bound.
- property supports: frozenset[int]#
The faces a blend runs along, on either side of it.
- within(max_radius: float | None) BlendReading#
Return the blends whose radius is at most max_radius: the same reading, counted up to a smaller bound.
- Parameters:
max_radius – The largest radius counted, in model units;
Nonekeeps this reading’s bound.- Raises:
ValueError – When max_radius is larger than the bound the blends were read up to, so that blends above that bound were never read.
- class volmdlr_tools.features.extractors.blend.RecognizeBlends(aag: AttributedAdjacencyGraph, max_radius: float = 0.5)#
Bases:
BlendExtractorDeprecated: Use BlendExtractor instead.
This class is maintained for backward compatibility and will be removed in version 1.0.0. Please update your code to use BlendExtractor.
- volmdlr_tools.features.extractors.blend.faces_beyond_blends(aag: AttributedAdjacencyGraph, blends: Iterable[int], excluding: Iterable[int] = ()) set[int]#
Return the faces blends round an edge into: the faces tangent to them that are no blends.
Only blends are looked past: a blend tangent to them that is not among them (an edge round of the part, a fillet of another feature) is neither returned nor followed, so the faces past it are never reached.
- Parameters:
aag – The part’s graph, its blends read.
blends – The blends to look past: a feature’s rim blends.
excluding – Faces never returned: the faces of the feature the blends round, or of every feature.
- Returns:
The faces, no blends, that blends are tangent to.
- volmdlr_tools.features.extractors.blend.fills_the_foot(aag: AttributedAdjacencyGraph, blend: int, base: int) bool#
Whether blend is a fillet at the foot of what stands inside face base.
It meets base tangentially, filling the corner rather than rounding an edge off, and inside base’s outline. A round rolled over the rim of an opening turns round a convex edge, and a fillet rounding a floor into the walls round it meets the floor along the floor’s outline: neither is a foot fillet. A blend meeting base at a sharp edge is none either: it rounds a corner of what stands there, as a side of it does.
- Parameters:
aag – The part’s graph, its edge angles computed.
blend – The blend asked about.
base – The face it may stand on.
- volmdlr_tools.features.extractors.blend.is_blend_face(aag: AttributedAdjacencyGraph, face_id: int, max_radius: float = inf) bool#
Whether blend recognition read a face as a blend, within a radius bound.
A face is a blend when it carries a blend reading, an uncertain one included, whose radius is within the bound; a blend whose radius varies is within any bound. This is what
BlendExtractor.idslists and what interacting feature recognition takes for a blend.- Parameters:
aag – The graph of the part, its blends read.
face_id – The face (0-based).
max_radius – The largest radius counted, in model units; by default, every radius.
- volmdlr_tools.features.extractors.blend.is_tangent_to(aag: AttributedAdjacencyGraph, face: int, others: Iterable[int]) bool#
Whether face meets one of others along a smooth edge, by the rule of
tangent_neighbors().- Parameters:
aag – The part’s graph, its edge angles computed.
face – The face.
others – The faces it may be tangent to.
- volmdlr_tools.features.extractors.blend.read_blends(aag: AttributedAdjacencyGraph, *, max_radius: float | None = None, free_form_curvature: bool = True) BlendReading#
Read the blends of a part once, as a value, leaving aag as it was.
- Parameters:
aag – The adjacency graph of the part; its face angles are calculated when missing.
max_radius – The largest blend radius read, in model units; omitted, a share of the part’s size, as for
BlendExtractor. A smaller bound is a filter on the reading: seeBlendReading.within().free_form_curvature – Whether free-form faces are read by their curvature over their whole extent, so that the blends of a moulded part are found as well as those of a machined one; see
BlendExtractor.
- Returns:
The blends.
- volmdlr_tools.features.extractors.blend.rim_blends_among_faces(aag: AttributedAdjacencyGraph, faces: Iterable[int], floor_nodes: Iterable[int], blends: Iterable[int]) set[int]#
Return the blends among a feature’s own faces that round its rim, by the rule stated on
Feature.rim_blend_nodes.They are tangent to the face the feature opens through (the face whose inner boundary rings it,
get_cavity_base_faces()) and to no piece of its floor.- Parameters:
aag – The part’s graph, its edge angles computed.
faces – The faces of the feature.
floor_nodes – The pieces of its floor, none for a feature with no floor.
blends – The blends of the part, or of the feature.
- Returns:
The blends among faces rounding the feature’s rim.
- volmdlr_tools.features.extractors.blend.tangent_blends(aag: AttributedAdjacencyGraph, faces: Iterable[int], blends: Iterable[int]) set[int]#
Return those of blends tangent to one of faces, by the rule of
tangent_neighbors().- Parameters:
aag – The part’s graph, its edge angles computed.
faces – The faces.
blends – The blends asked about.
- volmdlr_tools.features.extractors.blend.tangent_chains(aag: AttributedAdjacencyGraph, blend_nodes: Iterable[int], tangent: Mapping[int, set[int]] | None = None) list[set[int]]#
Return the chains of blends joined by smooth edges, whatever their radii.
A fillet that continues round a corner whose blend has another radius is one chain: the fillet along an edge, the torus at the corner and the round down the corner’s edge.
BlendExtractor.get_chains()groups blends otherwise: it joins blends adjacent along any edge, sharp ones too, then splits them by radius. So the fillet above is several of its chains, and two blends of one radius meeting at a sharp edge are one of its chains but two tangent chains.- Parameters:
aag – The part’s graph.
blend_nodes – The blend faces.
tangent – The tangent neighbours of each blend, as
tangent_neighbors()gives them; read from aag when omitted.
- Returns:
One set of faces per chain; a blend tangent to no other is a chain of its own.
- volmdlr_tools.features.extractors.blend.tangent_neighbors(aag: AttributedAdjacencyGraph, faces: Iterable[int]) dict[int, set[int]]#
Return, for each face, the faces it meets along a smooth (tangent) edge.
This is the one rule
tangent_chains()joins blends by, so a caller that also needs a chain’s tangent faces outside it reads them here and agrees with the chains.- Parameters:
aag – The part’s graph. Requires its edge angles to be computed: an edge without an angle counts as not smooth.
faces – The faces whose tangent neighbours are asked for.
- Returns:
Each face of faces with the set of its tangent neighbours, any face of the part.
volmdlr_tools.features.extractors.blend_roots module#
Tell the blends that root a boss or rim a pocket from every other blend.
A boss standing on a base is usually blended into it all the way round, and a pocket sunk into a base has its rim rounded the same way. Such a blend is not an edge fillet to be removed in isolation: together with everything the boss or pocket holds it is cut off from the rest of the part along one closed loop, the place where the blend leaves the base. Any other blend chain fails that test: a fillet along an open step edge ends on the faces at its ends, a blend between two base faces has its loop on both of them, and a boss running off the edge of its base has no closed loop at all.
A chain is taken for a root when, in this order:
its faces are all concave, which makes a boss root, or all convex, which makes the rim of a pocket. Blends of the other sort that share its cross edges, such as the rounding of a boss’s top, are left out, and blends of the same sort stacked against it are crossed;
its boundary against the rest of the part is made of closed loops, and cutting the part along one of them separates an enclosed component, which holds every blend face;
along that loop the blend faces are on the enclosed side and the faces across it are not: a chain whose sides switch partway is two features touching.
Which side of a loop is enclosed follows from the base when the loop is a hole in one of its faces: the side without that face, however large, as a tall pin set in a thin plate stands on the plate, unless that side holds, in a hole of its own, the other end of a post joining two bases. A loop that runs over several base faces joined tangentially is a hole in none of them; its enclosed side is then the side of the smaller area, which must be a clear minority of the part, at most half the area of the rest. The enclosed side must also turn over, which tells a boss from the floor of a pocket: a boss holds something convex, and a pocket holds something concave.
- class volmdlr_tools.features.extractors.blend_roots.OpenBlendRun(blend_face_ids: frozenset[int], side_chains: tuple[tuple[int, ...], ...])#
Bases:
objectA run of concave blends that stops against a face instead of closing into a ring.
A boss that meets a wall along a blended seam, and whose seam is cut short by the plane its top lies in, leaves the wall along a run of this kind: its two sides are open chains of edges that start and stop on that plane.
- Parameters:
blend_face_ids – The faces of the run, numbered as the faces of the part’s adjacency graph are.
side_chains – The two chains of edges along which the run leaves the faces it blends, each as sorted edge ids.
- blend_face_ids: frozenset[int]#
- side_chains: tuple[tuple[int, ...], ...]#
- class volmdlr_tools.features.extractors.blend_roots.PartTopology(aag: AttributedAdjacencyGraph)#
Bases:
objectThe faces of a part measured once, with the blends recognised on it, for cutting it along many loops.
Where a loop cuts the part is read from its adjacency graph (see
volmdlr_tools.graph.edge_loops); this keeps what weighing the cuts needs, the area of each face and the side of each blend, so that each is measured once however many loops are tried. Faces are numbered as in the part’s adjacency graph.- Parameters:
aag – The adjacency graph of the part, with the face angles calculated.
- area(face_ids: Iterable[int]) float#
Return the total area of some faces.
- property blends: _Blends#
The blends recognised on the part, with the side of each.
- chain_ends(chain: Iterable[int]) tuple[int, int]#
Return the two corners an open chain starts and stops at, as vertex ids of the part’s graph.
- Raises:
ValueError – if the edges are not an open chain.
- closed_loops(edge_ids: Iterable[int]) list[tuple[int, ...]] | None#
Split edge_ids into the closed loops they form, as
closed_edge_loops().
- concave_edges() list[int]#
Return the edges between two faces whose angle is concave. The graph must carry its face angles.
- cut_off(loop_edge_ids: Iterable[int]) frozenset[int] | None#
Return the faces cut off from the rest of the part when the loop’s edges are cut.
A loop that is an inner wire of a face beside it, a hole in that face, cuts off the side without that face, whatever the sizes of the two sides: a pin stands in the hole of the plate it is set in, however long the pin. A loop that is no wire of one face, as where it runs over several faces joined tangentially, cuts off the side of the smaller total area, and only when that side is a clear minority: at most half the area of the rest. Two bodies of comparable size joined through such a loop are a bridge, and neither stands on the other; so is a side cut off along a hole that holds, in a hole of its own, the other end of a post whose first end the loop is.
- Returns:
the faces of the side cut off, or
Nonewhen the cut does not part the faces in two, parts off one end of a bridge, or, along a loop that is no inner wire, a side too big to be a feature.
- edges_around(face_id: int) list[tuple[int, int]]#
Return each edge a face shares with a neighbouring face, with that face, as
edges_around().
- holder(loop_edge_ids: Iterable[int]) int | None#
Return the face across the loop that holds it as one of its inner wires, a hole in the face.
- Returns:
the face, or
Nonewhen the loop is no inner wire of a face beside it, as where it runs over several faces joined tangentially, or when it is one of both faces beside it.
- open_chains(edge_ids: Iterable[int]) list[tuple[int, ...]]#
Split edge_ids into the open chains they form: runs of edges that start and stop at two corners.
Edges that close into a loop, or that meet three at a corner, are no chain and are left out.
- Returns:
each chain as its sorted edge ids.
- reach(start_face_ids: Iterable[int], cut_edge_ids: Iterable[int]) list[int]#
Return the faces still joined to the given ones once the part is cut along some edges.
See
reach(): the given faces first, then the others in the order a walk spreading out from them meets them.
- sides(loop_edge_ids: Iterable[int]) tuple[frozenset[int], frozenset[int]] | None#
Return the two sets of faces the part falls into when the loop’s edges are removed.
- Returns:
the smaller set, by area, and the larger one;
Nonewhen the part does not fall into exactly two.
- sized_as_feature(loop_edge_ids: Iterable[int], cut_off_face_ids: Iterable[int]) bool#
Tell whether faces cut off along a loop are of a size to be a feature of the rest of the part.
Any size is, when the loop is a hole in a face beside it (see
holder()) and the faces lie away from that face: a pin stands in the hole of the plate it is set in, however long the pin. Otherwise the faces must be a clear minority of the part (seeis_feature_sized()): along a loop that is no inner wire of one face, as where it runs over several faces joined tangentially, and at one end of a bridge, faces holding in a hole of their own the other end of a post whose first end the loop is.cut_off()cuts nothing off a bridge; read by size, a bore opening into an undercut below it is a feature with the undercut, and the rest of the part, joined to the undercut through the bore, is none.
- class volmdlr_tools.features.extractors.blend_roots.RootBlendChain(blend_face_ids: frozenset[int], base_face_ids: frozenset[int], enclosed_face_ids: frozenset[int], kind: Literal['boss', 'pocket'], radius: float | None, radii: tuple[float, ...], base_loop_edge_ids: tuple[int, ...])#
Bases:
objectThe blends where a boss stands on its base, or where a pocket opens in it.
- Parameters:
blend_face_ids – The faces of the root blend only, numbered as the faces of the part’s adjacency graph are.
base_face_ids – The faces across the base loop: the base the boss or pocket belongs to, which may be several faces joined tangentially.
enclosed_face_ids – Every face the loop cuts off: the boss or the pocket, blends included.
kind –
"boss"for a concave root and"pocket"for a convex rim.radius – The radius of the blend,
Nonewhen it varies.radii – The distinct radii met along the blend, ascending.
base_loop_edge_ids – The edges along which the blend leaves the base, forming one closed loop.
- base_face_ids: frozenset[int]#
- base_loop_edge_ids: tuple[int, ...]#
- blend_face_ids: frozenset[int]#
- enclosed_face_ids: frozenset[int]#
- kind: Literal['boss', 'pocket']#
- radii: tuple[float, ...]#
- radius: float | None#
- volmdlr_tools.features.extractors.blend_roots.blend_radii(aag: AttributedAdjacencyGraph, face_id: int) list[float]#
Return the radii a recognised blend is matched on: its own radius, or for a corner patch the radii it was read from.
An edge blend is matched on the one radius it was read with, not on the radius read along each of its spring edges: a variable or free-form round reads a range of radii there, and would carry on any blend of a radius within that range.
- Returns:
the radii, empty for a face that is no blend or has none read.
- volmdlr_tools.features.extractors.blend_roots.blend_rings(aag: AttributedAdjacencyGraph, blend_face_ids: Iterable[int]) list[set[int]]#
Split blends into rings, each the blends that carry on one another (see
blends_continue()).Two blends that meet along a crease rather than tangentially, or with another radius, belong to two features that happen to touch, such as the roots of two bosses standing close enough for their fillets to run into each other.
- Returns:
the rings, ordered by their lowest face.
- volmdlr_tools.features.extractors.blend_roots.blends_continue(aag: AttributedAdjacencyGraph, face_id: int, other_id: int) bool#
Tell whether a blend carries on the blend it touches: it meets it tangentially and shares one of its radii.
A blend with no radius read carries on none.
- volmdlr_tools.features.extractors.blend_roots.copy_without_blends(aag: AttributedAdjacencyGraph) AttributedAdjacencyGraph#
Copy an adjacency graph, leaving out the blends recognised on it.
The copy shares the part’s shape and the face angles of aag, so its faces and edges are numbered as those of aag; blends recognised on the copy are written on it alone.
- Parameters:
aag – the adjacency graph of the part.
- Returns:
the copy, carrying no blend.
- volmdlr_tools.features.extractors.blend_roots.is_feature_sized(cut_off_area: float, total_area: float) bool#
Tell whether what a loop cuts off a part is small enough beside the rest to be a feature of it.
It must be a clear minority: at most half the area of the rest. Two bodies of comparable size joined through the loop are a bridge, and neither stands on the other.
- Parameters:
cut_off_area – The area of the faces the loop cuts off.
total_area – The area of every face of the part.
- volmdlr_tools.features.extractors.blend_roots.open_blend_runs(aag: AttributedAdjacencyGraph, chains: Iterable[BlendChain], topology: PartTopology | None = None) tuple[OpenBlendRun, ...]#
Find the runs of concave blends that stop against a face, with the two chains they leave their faces along.
Concave blends that touch one another belong to one run, whatever their radii. A run is open when its boundary against the rest of the part is a single closed loop of which two edges lie on one and the same face: those are where the run is cut short, and without them the loop falls into its two sides.
- Parameters:
aag – the adjacency graph of the part, with angles calculated and blends recognised.
chains – the blend chains recognised on aag.
topology – the part’s
PartTopology, built when omitted.
- Returns:
the open runs, ordered by their lowest blend face id.
- volmdlr_tools.features.extractors.blend_roots.open_runs_among(topology: PartTopology, candidate_face_ids: Iterable[int]) tuple[OpenBlendRun, ...]#
Find the runs of concave blends among the candidate faces that stop against a face, with their two side chains.
A run is open when its boundary against the rest of the part is a single closed loop of which two edges lie on one and the same face: those are where the run is cut short, and without them the loop falls into its two sides.
- Parameters:
topology – the part’s
PartTopology, built on a graph that carries the blends.candidate_face_ids – the faces to look among; those of them that are concave blends, vertex blends or cliff blends form the runs.
- Returns:
the open runs, ordered by their lowest blend face id.
- volmdlr_tools.features.extractors.blend_roots.recognise_free_form_blends(aag: AttributedAdjacencyGraph, max_radius: float | None = None) tuple[AttributedAdjacencyGraph, list[BlendChain]]#
Recognise the blends of a part, moulded ones by their curvature, on a copy of its adjacency graph.
The copy shares the part’s shape and the face angles of aag, so its faces and edges are numbered as those of aag; the blends are written on the copy alone, whatever recognition aag has been through. Asking twice recognises twice and gives the same blends.
- Parameters:
aag – the adjacency graph of the part. Its face angles are calculated when missing.
max_radius – the largest blend radius recognised, in the model’s units; by default a share of its size.
- Returns:
the copy, carrying the blends, and the blend chains recognised on it.
- volmdlr_tools.features.extractors.blend_roots.root_blend_chains(aag: AttributedAdjacencyGraph, chains: Iterable[BlendChain] | None = None, topology: PartTopology | None = None) tuple[RootBlendChain, ...]#
Find every boss root and pocket rim among the blends of a part.
- Parameters:
aag – the adjacency graph of the part. Its face angles are calculated when missing.
chains – the blend chains recognised on aag. When omitted, blends are recognised on a copy of aag (see
recognise_free_form_blends()), and aag gains none.topology – the part’s
PartTopology, built when omitted; pass one built on the graph chains were recognised on.
- Returns:
the roots, ordered by their lowest blend face id; a root found through several chains appears once.
- Raises:
ValueError – when topology is given without the chains recognised on its graph.
- volmdlr_tools.features.extractors.blend_roots.root_of_chain(chain: BlendChain, aag: AttributedAdjacencyGraph, topology: PartTopology | None = None) RootBlendChain | None#
Keep of a blend chain the part that roots a boss or rim a pocket.
As
roots_of_chain(), for a chain that holds at most one feature’s root.- Returns:
the root, or
Nonewhen the chain has none. A chain that holds the roots of several features gives the one with the lowest blend face id; useroots_of_chain()to get them all.
- volmdlr_tools.features.extractors.blend_roots.roots_of_chain(chain: BlendChain, aag: AttributedAdjacencyGraph, topology: PartTopology | None = None) tuple[RootBlendChain, ...]#
Keep of a blend chain the parts that root a boss or rim a pocket.
The chain is read as grouped by blend recognition, which may join a root to the rounding of a boss’s top through the corner blends they share, or the roots of neighbouring features through blends they both touch; only the roots are kept, one per feature. The adjacency graph must carry the angles between its faces and the blends recognition found.
- Parameters:
chain – a chain of blends recognised on aag.
aag – the adjacency graph of the part, with angles calculated and blends recognised.
topology – the part’s
PartTopology, built when omitted; pass one when examining many chains.
- Returns:
the roots, ordered by their lowest blend face id. A ring of blend qualifies when it is cut off from the rest of the part along a closed loop, with its blend faces on one side and the base on the other; nothing else is returned.
- volmdlr_tools.features.extractors.blend_roots.turns_over(topology: PartTopology, enclosed: Iterable[int], kind: Literal['boss', 'pocket']) bool#
Tell whether a set of faces cut off from a part can be a boss or a pocket.
A boss, cut off along a concave loop, holds something convex such as its top edge. A pocket, cut off along a convex loop, holds something concave such as the corner of its floor. A set of faces that does not turn over is a plain face or a corner blend, not a feature.
- Parameters:
topology – the part’s
PartTopology, whose graph carries angles and recognised blends.enclosed – the faces cut off.
kind –
"boss"or"pocket".
volmdlr_tools.features.extractors.blend_roles module#
Tell the blends that were applied to a part from the rounds that belong to its profile.
Blend recognition marks every face that rounds a corner between two faces it meets tangentially. Some of those are fillets applied to an edge, which a model would draw as a fillet and which could be taken off again: the two faces they join, extended, meet at a sharp edge close by. Others are arcs of a profile, drawn in a sketch: the half-round top of a rib, the arch of a U-shaped web, the rounded corners of a swept section. Taking those off leaves no sharp edge to go back to.
Each recognised blend is given a role:
"applied_fillet": the faces it joins turn by at most 160 degrees across it, so they meet at a virtual sharp edge at R (1/cos(a/2) - 1) from the round, a turning angle a; that edge lies inside the part’s bounding box, and, when the supports turn by more than 95 degrees, in the material for a concave round and out of it for a convex one;"profile_round": part of a profile. First, before any other test, a convex cylinder about the axis of a hole or boss wall that is not a blend and runs beside it along that axis: the wall of material round the hole, such as the ligament round a bore or a plate corner drawn about a hole, where a rounded hole edge would be a torus. Its axis is taken as the wall’s when their directions agree to half a degree and their lines pass within a thousandth of the part’s diagonal. Then, when the faces it joins turn by 170 degrees or more (a full round, or supports near parallel; a radius as large as half the width between its supports is this case), or when the virtual sharp edge would lie outside the part or in the wrong material;"uncertain": when its turning lies between 160 and 170 degrees or under 2 degrees, when it meets a face tangentially on one side only (its sharp edge cannot be placed), or when the faces it joins cannot be read; the reason says which.
A corner patch where edge blends meet takes the role most of those blends of its own side have.
- class volmdlr_tools.features.extractors.blend_roles.BlendRole(role: Literal['applied_fillet', 'profile_round', 'uncertain'], reason: str, turning: float | None = None, virtual_edge_distance: float | None = None, ends: int | None = None)#
Bases:
objectWhat a recognised blend is for.
- Parameters:
role –
"applied_fillet","profile_round"or"uncertain".reason – Why, in a few words.
turning – The angle the faces it joins turn by across it, in radians,
Nonewhen it was not read.virtual_edge_distance – How far the sharp edge its supports would meet at lies from the round,
Nonewhen it was not read.ends – How many ends an edge blend has besides the two sides it runs along, once the mouths of holes piercing it are left out: two for a round running from one end to the other,
Nonefor a corner patch.
- ends: int | None = None#
- reason: str#
- role: Literal['applied_fillet', 'profile_round', 'uncertain']#
- turning: float | None = None#
- virtual_edge_distance: float | None = None#
- volmdlr_tools.features.extractors.blend_roles.blend_roles(aag: AttributedAdjacencyGraph) dict[int, BlendRole]#
Give each blend recognised on aag its role: an applied fillet, a round of the profile, or uncertain.
- Parameters:
aag – The adjacency graph of the part, with blends recognised.
- Returns:
The role of each face carrying a blend attribute, by face id.
volmdlr_tools.features.extractors.virtual_loops module#
Find the loops of edges that bound regions of a part, including loops that run over several faces.
A face knows its own boundary: one outer loop and one inner loop per hole in it. A feature, though, seldom sits on a single face. A hole may cut a wall made of two tangent faces, a pocket may open across the sharp edge between two faces, and a boss may stand across a rounded edge. The loop that bounds such a feature runs over several faces, and no face records it.
Loops are found in three kinds:
a single loop is a loop of one face, as that face records it;
a virtual loop runs over several faces joined tangentially. The faces of a part that are not blends are gathered into groups of faces joined by tangent edges, and each group’s boundary is read as a set of closed chains of edges. Blends are gathered apart, into chains of blends running on into one another tangentially, those rounding a corner off separately from those filling one. The rounded corners of a window are not chained to a fillet they meet along a sharp edge;
a multivirtual loop runs over several groups, which meet along sharp edges or through blends. It is found by joining a group’s outer boundary with that of a neighbouring group across a sharp edge, or with the blends it meets tangentially and the groups beyond them; whatever closed chains the joined boundary leaves that turn as inner loops are loops enclosed by the joined groups. It is found as well where a ring of blends rounding the root of a boss or the rim of a pocket leaves its base: the base’s side of that ring’s boundary is an inner loop, over whatever faces and blends the base is made of.
Each loop is an outer loop, bounding its region from outside, or an inner loop, bounding something the region surrounds: a hole, a pocket, or the root of a boss. A group with one chain has only an outer loop, and a group with two chains of equal length is a band bounded by two outer loops, unless they turn clearly opposite ways, as the outline of a face and a window in it of the same length do. Otherwise a chain is read by its turning: walking along a boundary the region lies to its left, so an outer loop turns counterclockwise about the region’s normal and an inner loop clockwise. A chain that turns neither way clearly, such as the rim of a band wrapped round an axis, is taken as outer. So is a chain going once round the axis that every face of its group turns about, however it turns, where the band turns down over it onto faces that are not walls turned towards the axis: the narrow rim of a cone, such as a chamfer on the rim of a boss or the flank of a truncated cone, bounds the band and is no mouth. The root of a boss standing on such a band, or a bore opening at its rim, is read by its turning, and so is a hole drilled into its flank, which does not go round its axis.
Inner loops are what features are recognised from. Loops that run over blends alone are left out, save the mouth of a hole drilled into one blend face: the hole meets the blend at a sharp angle, where the blend’s own rails run tangentially into the faces it joins. A loop found more than once is kept once.
A loop is read for more than where it runs. Its sense says what it bounds: walking along it, a corner that is concave, or where a concave blend runs on tangentially, is the root of a boss, and one that is convex, or where a convex blend runs on tangentially, is the rim of a pocket; the corners vote, each weighted by the length of its edge, and the loop has no sense where none tells or they disagree. The faces beyond it are those across its edges, and its root blends are the blends of the side its sense calls for among them, grown through the blends of that side that touch them inside what the loop cuts off. A blend patch read with no side of its own, such as the corner where a ring of root blends meets the rounds of its base, takes that of the blends it runs on into, since it is a piece of their ring, and of every blend it touches only when it runs on into none. These facts are asked of the recognition that found the loops, which keeps the graph it read them on.
A seam between two bodies of a part may start and stop instead of closing into a loop: where an arm leaves the end face of a block, the seam is an open chain of concave edges whose ends lie on the one flat face the arm and the block share the top of. Such a seam is an open junction when it is the side of a run of concave blends that stops against a face, and the straight line across that face between its ends, its chord, stays on the face. The recognition lists them, with the blends each runs along, found on the part as it is, with no face split.
- class volmdlr_tools.features.extractors.virtual_loops.FaceGroup(face_ids: frozenset[int], kind: Literal['blend', 'base'])#
Bases:
objectFaces gathered together before their loops are read.
- Parameters:
face_ids – The faces of the group.
kind –
"blend"for blends joined to one another,"base"for faces that are not blends, joined across tangent edges.
- face_ids: frozenset[int]#
- kind: Literal['blend', 'base']#
- class volmdlr_tools.features.extractors.virtual_loops.LoopRecognition(groups: tuple[~volmdlr_tools.features.extractors.virtual_loops.FaceGroup, ...], loops: tuple[~volmdlr_tools.features.extractors.virtual_loops.RecognisedLoop, ...], face_groups: tuple[int, ...], blend_face_ids: frozenset[int], blend_sides: dict[int, ~typing.Literal['concave', 'convex']] = <factory>, blend_roles: dict[int, ~volmdlr_tools.features.extractors.blend_roles.BlendRole] = <factory>, graph: ~volmdlr_tools.graph.faces.AttributedAdjacencyGraph | None = None)#
Bases:
objectThe groups of faces of a part and the loops found on them.
- Parameters:
groups – Blend groups first, then groups of faces that are not blends.
loops – Every loop found, the loops of each group first, then the loops over several groups.
face_groups – The group of each face, indexed by face id;
-1for a face in no group.blend_face_ids – The faces read as blends.
blend_roles – The role of every blend recognition marked, when the blends were not given: the rounds of a profile are left out of blend_face_ids and read as walls.
blend_sides – The side of each blend whose side is known:
"concave"for a blend filling a corner,"convex"for one rounding an edge off. A corner patch read with no side takes the side of the blends it touches over the greater length.graph – The adjacency graph the loops were read on: a copy of the graph given to
recognise_loops(), marked with the blends, numbered as that graph is (the graph itself when the blends were given as faces). Its faces and edges are those of every loop. The facts that read a loop’s surroundings (faces_beyond(),sense(),root_blends()) andopen_junctionsneed it and raiseValueErrorwhen a recognition was built without it.
- blend_face_ids: frozenset[int]#
- blend_sides: dict[int, Literal['concave', 'convex']]#
- face_groups: tuple[int, ...]#
- faces_beyond(loop: RecognisedLoop) frozenset[int] | None#
Return the faces on the other side of the loop’s trims.
- Returns:
The faces, or
Nonewhen an edge of the loop is bounded once only, so that nothing lies beyond it.- Raises:
ValueError – When the recognition holds no graph.
- graph: AttributedAdjacencyGraph | None = None#
- group_of(face_id: int) int#
Return the index of the group holding face_id.
- inner_loops() tuple[RecognisedLoop, ...]#
Return the loops that enclose something: what features are recognised from.
- length_of(edge_id: int) float#
Return the length of an edge of the part, in the model’s own units.
- Raises:
ValueError – When the recognition holds no graph.
- loops: tuple[RecognisedLoop, ...]#
- loops_along(edge_id: int) tuple[RecognisedLoop, ...]#
Return the loops that run along an edge.
- loops_of_group(group_id: int) tuple[RecognisedLoop, ...]#
Return the loops that run over one group, alone or with others.
- property open_junctions: tuple[OpenJunction, ...]#
The seams of the part that stop short of closing into a loop and can be closed with a chord, read once.
They are found on the part as it is, and no face is split. Each of the two sides of a run of concave blends that stops against a face is one. A seam whose ends do not lie on one flat face, or whose straight line between them leaves that face, is not a junction. They come ordered by the lowest edge of their seam.
The junctions are read from the blends marked on the graph the loops were read on, which
PartReading.loopsmarks with the part’s blends. On a graph that carries none, such as one given torecognise_loops()with the blends as bare faces, there are no junctions.- Raises:
ValueError – When the recognition holds no graph.
- outer_loops() tuple[RecognisedLoop, ...]#
Return the loops that bound their region from outside.
- root_blends(loop: RecognisedLoop, enclosed: frozenset[int]) frozenset[int]#
Return the blends rounding a feature where it leaves its base, of the side the loop’s sense calls for.
They are the blends across the loop of that side, grown through the blends of that side touching them within enclosed: a concave blend for a boss, a convex one for a pocket.
- Parameters:
loop – The loop where the feature leaves its base.
enclosed – The faces of the feature: those the loop cuts off the part.
- Returns:
The blends; none when the loop has no sense or has an edge bounded once only.
- Raises:
ValueError – When the recognition holds no graph.
- sense(loop: RecognisedLoop) Literal['boss', 'pocket'] | None#
Read which way a loop bounds a feature, by the corners along it, each weighted by the edge’s length.
A corner that is concave, or where a concave blend runs on tangentially, is the root of a boss; a corner that is convex, or where a convex blend runs on tangentially, is the rim of a pocket. Across a sharp edge the corner is read from the edge, even where the face across is a blend rounding a corner of the feature.
- Returns:
"boss"or"pocket", orNonewhen no corner along the loop tells, when the corners disagree, when an edge of the loop is bounded once only, or when the loop runs back onto its own faces.- Raises:
ValueError – When the recognition holds no graph.
- sense_and_faces_beyond(loop: RecognisedLoop) tuple[Literal['boss', 'pocket'] | None, frozenset[int] | None]#
Return the loop’s
sense()and itsfaces_beyond(), read in one walk along its trims.- Raises:
ValueError – When the recognition holds no graph.
- exception volmdlr_tools.features.extractors.virtual_loops.LoopRecognitionError#
Bases:
ValueErrorRaised when the boundary of a region of a part does not close into loops.
- class volmdlr_tools.features.extractors.virtual_loops.OpenJunction(chain_edge_ids: tuple[int, ...], chord: JunctionChord, blend_face_ids: frozenset[int])#
Bases:
objectA seam between two bodies of a part that starts and stops instead of closing, and the chord closing it.
The seam is one side of a run of concave blends where a body leaves the face of another and is cut short by a flat face both its ends lie on, such as the top shared by an arm and the block built against its end. Nothing is split: the chord is only found, and both it and the seam are numbered on the part as it is.
- Parameters:
chain_edge_ids – The edges of the seam, sorted, numbered as the edges of the adjacency graph are.
chord – The straight line across a face of the part that closes the seam.
blend_face_ids – The blends the seam runs along: the run of concave blends of which the seam is one side.
- blend_face_ids: frozenset[int]#
- chain_edge_ids: tuple[int, ...]#
- chord: JunctionChord#
- class volmdlr_tools.features.extractors.virtual_loops.RecognisedLoop(kind: Literal['single', 'virtual', 'multivirtual'], role: Literal['inner', 'outer'], trims: tuple[Trim, ...], group_ids: tuple[int, ...], face_ids: frozenset[int], length: float)#
Bases:
objectA closed loop of edges bounding a region of a part.
- Parameters:
kind –
"single"when the loop lies on one face,"virtual"when it runs over several tangent faces of one group,"multivirtual"when it runs over several groups.role –
"inner"when the region surrounds what the loop encloses,"outer"when the loop bounds the region from outside.trims – The loop’s trims, in order along it, each on the face the region holds.
group_ids – The groups the loop runs over, ascending.
face_ids – The faces owning the loop’s trims.
length – The length of the loop.
- property edge_ids: tuple[int, ...]#
The edges of the loop, in order along it.
- face_ids: frozenset[int]#
- group_ids: tuple[int, ...]#
- kind: Literal['single', 'virtual', 'multivirtual']#
- length: float#
- role: Literal['inner', 'outer']#
- class volmdlr_tools.features.extractors.virtual_loops.Trim(face_id: int, edge_id: int, forward: bool)#
Bases:
objectOne side of an edge: the edge as the boundary of one of its two faces.
- Parameters:
face_id – The face the trim bounds, numbered as the faces of the adjacency graph are.
edge_id – The edge, numbered as the edges of the adjacency graph are.
forward – Whether the face’s boundary runs along the edge’s own direction.
- edge_id: int#
- face_id: int#
- forward: bool#
- class volmdlr_tools.features.extractors.virtual_loops.TrimIndex(aag: AttributedAdjacencyGraph)#
Bases:
objectThe trims of every face of a part, with the vertices each one runs between.
Faces, edges and vertices are numbered as in the part’s adjacency graph. A degenerate edge, such as the apex of a cone, bounds nothing and has no trim.
- Parameters:
aag – The adjacency graph of the part.
- across(chain: Sequence[int]) list[int] | None#
Return the chain on the faces across a chain of trims, running the other way along the same edges.
- Returns:
the twin trims,
Nonewhen an edge of the chain is bounded once only.
- edge_length(edge_id: int) float#
Return the length of an edge.
- edge_trims: dict[int, list[int]]#
- ends: list[int]#
- face_trims: list[list[int]]#
- length(trim_ids: Iterable[int]) float#
Return the total length of some trims.
- samples(trim_id: int) tuple[ndarray, ndarray]#
Return points along a trim in its own direction, last point left out, and the face normal at each.
- starts: list[int]#
- twin(trim_id: int) int | None#
Return the trim on the other side of the edge,
Nonefor an edge not bounded twice.
- volmdlr_tools.features.extractors.virtual_loops.boundary_chains(index: TrimIndex, trim_ids: Iterable[int]) list[list[int]]#
Read the boundary of a region given by its trims as closed chains of trims.
An edge whose two trims are both in the region is inside it and bounds nothing. The trims left are chained end to start; a chain that passes twice through a vertex is split there into two loops, since two regions touching at a single point bound each other nowhere.
- Parameters:
index – The trims of the part.
trim_ids – The trims of the region, from whole faces or from loops already found.
- Returns:
The chains, each a list of trim ids in order along it.
- Raises:
LoopRecognitionError – when the trims left do not close, which a region of a well-formed part never does.
- volmdlr_tools.features.extractors.virtual_loops.chain_loop(index: TrimIndex, chain: Sequence[int], role: Literal['inner', 'outer'], face_groups: Sequence[int]) RecognisedLoop#
Return the loop a closed chain of trims makes, of the kind the faces and groups it runs over give it.
- Parameters:
face_groups – The group of each face, indexed by face id.
- volmdlr_tools.features.extractors.virtual_loops.loop_turning(index: TrimIndex, chain: Sequence[int]) float#
Tell which way a chain turns about the normal of the faces it bounds.
The faces’ normal is averaged along the chain by length, each edge weighing as much as it is long however many points are read on it, and without being rescaled, so that faces whose normals point every way round the chain, as those of a band do, give no direction to turn about.
- Returns:
the component, along the chain’s turning axis (counterclockwise positive), of the mean normal of its faces along it: near 1 for an outer loop on a flat region, near -1 for an inner one, near 0 when the chain does not turn about the faces’ normal, as the rim of a band does not.
- volmdlr_tools.features.extractors.virtual_loops.loops_met(topology: PartTopology, faces: Iterable[int], cut_edge_ids: set[int], loops_by_edge: dict[int, Sequence[int]]) list[int]#
Return the loops running along the edges of some faces that are not cut, in the order the faces are given.
- Parameters:
faces – The faces, as a walk over the part met them (see
PartTopology.reach()).loops_by_edge – The loops running along each edge, by any numbering the caller keeps.
- volmdlr_tools.features.extractors.virtual_loops.recognise_loops(aag: AttributedAdjacencyGraph, *, blends: BlendReading | Iterable[int] | None = None) LoopRecognition#
Find the single, virtual and multivirtual loops of a part.
Nothing is marked on aag.
- Parameters:
aag – The adjacency graph of the part. Its face angles are calculated when missing.
blends – The part’s blends. Read here, free-form faces by their curvature, when omitted; when omitted or given as a
BlendReading, each blend is given its role (seeblend_roles()) and the rounds of a profile are read as the walls they are, so that applied fillets, and blends whose role could not be told, stay blends. Given as faces, those faces are the blends, as they are.
- Returns:
The groups of faces and the loops found on them, with the role of every blend when the blends were read. Its
graphis the graph the loops were read on: a copy of aag marked with the blends, numbered as aag is, or aag itself when the blends were given as faces.- Raises:
LoopRecognitionError – when the boundary of a group does not close, which happens only on a part whose faces are not oriented consistently.
volmdlr_tools.features.extractors.depression_protrusion module#
Recognise the depressions and protrusions of a part from the inner loops that bound them.
A hole, a pocket or a boss is surrounded by the face it sits on, its base, and meets it along a
closed loop: an inner loop of the base, which may run over several faces (see
volmdlr_tools.features.extractors.virtual_loops). Each inner loop is read as follows.
The faces across the loop’s edges are the feature’s side faces. Where the base meets the feature tangentially, the face across the edge is a blend rounding the root of the feature, and the side face is the one beyond it.
The corner the base makes with each side face tells the two sorts apart: a feature whose base turns down into it, the corner convex, is a depression, and a feature standing up from its base, the corner concave, is a protrusion. A blend across the loop is read by the side it rounds. Every corner that tells must agree: a loop running along the mouth of a pocket and down the inside corners of one of its walls, as where an open slot cuts that wall, bounds no feature.
The feature holds every face the loop cuts off from the rest of the part. A hole running through the part is not cut off by one loop, since its wall reaches the other side: it is cut off by that loop together with the one at its other end, and it is a through hole; a hole seen from both its ends is one hole. What a loop that is a hole in one face cuts off is a feature whatever its size, as a pin set in a plate stands on the plate however long the pin; along a loop running over several faces, or where what it cuts off holds the far end of the loop’s own bore in a hole, as the rest of a part does round a bore opening into an undercut, it must be a clear minority of the part, the rule the root blend chains follow. Anything made of blends alone is not a feature, and neither is a protrusion that reaches through to another base, which bridges two faces rather than standing on one.
A depression that does not run through is a blind hole when it is round, and a pocket otherwise. A feature is round when its side faces turn about one axis, or when its loop is one circle. A round depression is walled by faces turned towards its axis: a flat wall, or a cylinder or a cone seen from outside, is the top or the side of a boss read from the narrow rim of a band round it, such as a chamfer on its rim, and is no feature.
Two bosses standing close enough for their root blends to run into each other share one loop; they come out as two protrusions, one per body the root blends join. A feature found inside another, such as lettering on a raised plaque, keeps a link to the smallest feature holding it.
Protrusions standing against one another, such as a gusset against the side of a pad, meet along sharp concave edges. When one loop goes round both, the protrusion it bounds is split along those edges into one protrusion per piece standing on the base. When none does, because the root of one is cut through by the other and they stand on different faces, the part is cut along its sharp concave edges and concave blends, and each piece standing against another is a protrusion of its own, its loop running round it. Both keep the edges they share as their junction.
A rib or a boss running off the edge of its base has no loop of its own on the base and is not reported: its root reaches the base’s outer boundary. Nor is a lobe of a part’s outline, such as a round boss bulging out of the side of a plate over its whole height: its boundary is closed only by the top and bottom faces it shares with the rest of the outline, along edges no different from the outline’s own. What tells it apart is the profile of the outline, a convex arc between two concave turns, and that belongs with reading the outline, not with reading loops.
- class volmdlr_tools.features.extractors.depression_protrusion.DepressionProtrusion(kind: Literal['depression', 'protrusion'], loop: RecognisedLoop, base_face_ids: frozenset[int], side_face_ids: frozenset[int], blend_face_ids: frozenset[int], enclosed_face_ids: frozenset[int], subtype: Literal['through_hole', 'blind_hole', 'pocket', 'slot', 'groove', 'protrusion'], circular: bool, parent: int | None = None, junction_edge_ids: tuple[int, ...] = (), steps: tuple[HoleStep, ...] = (), interruption_face_ids: frozenset[int] = frozenset({}), end_face_ids: frozenset[int] = frozenset({}), through: bool = False, rim_chamfer_face_ids: frozenset[int] = frozenset({}))#
Bases:
objectA hole, a pocket or a boss, and the loop it was recognised from.
- Parameters:
kind –
"depression"for material taken away from the base,"protrusion"for material standing on it.loop – The inner loop where the feature leaves its base.
base_face_ids – The faces the feature sits on: those owning the loop.
side_face_ids – The faces the feature meets its base with, across the loop or beyond the blends on it.
blend_face_ids – The blends between the base and the side faces, rounding the feature’s root or rim.
enclosed_face_ids – Every face of the feature: what the loop cuts off from the rest of the part.
subtype –
"through_hole","blind_hole"or"pocket"for a depression,"protrusion"otherwise.circular – Whether the feature is round: its side faces turn about one axis, or its loop is one circle.
parent – The index, among the features returned with it, of the smallest feature holding this one.
steps – For a hole whose faces all turn about one axis, its steps in order from the mouth: one hole with a countersink, a counterbore or a drill point, however many loops it was seen from. Empty otherwise.
interruption_face_ids – For a hole that a slit or a cavity crosses, the faces where it stops on either side of the gap and goes on; for a groove breaking through into a cavity, the faces it opens onto there; empty for a feature running on unbroken.
junction_edge_ids – The sharp concave edges along which this protrusion stands against another one it touches, such as a gusset against the side of a pad; empty for a feature that touches none.
end_face_ids – The faces among enclosed_face_ids that close the feature: the floor of a pocket, the bottom of a blind hole, the top of a protrusion. Empty for a feature that runs through, and for one whose base is not flat. The other faces are its sides.
through – Whether the feature, of whatever subtype, runs through onto another base, so that nothing closes it.
rim_chamfer_face_ids – The chamfer run round the rim of a pocket, a slot or a cut where its walls meet its base, or round the top of a boss where its walls meet its top: an operation of its own, worked after the feature as a rim round is, so none of enclosed_face_ids. A hole keeps the bevel at its mouth, its countersink, and gives none back.
- base_face_ids: frozenset[int]#
- blend_face_ids: frozenset[int]#
- circular: bool#
- enclosed_face_ids: frozenset[int]#
- end_face_ids: frozenset[int] = frozenset({})#
- interruption_face_ids: frozenset[int] = frozenset({})#
- junction_edge_ids: tuple[int, ...] = ()#
- kind: Literal['depression', 'protrusion']#
- loop: RecognisedLoop#
- parent: int | None = None#
- rim_chamfer_face_ids: frozenset[int] = frozenset({})#
- side_face_ids: frozenset[int]#
- subtype: Literal['through_hole', 'blind_hole', 'pocket', 'slot', 'groove', 'protrusion']#
- through: bool = False#
- volmdlr_tools.features.extractors.depression_protrusion.recognise_depressions_and_protrusions(aag: AttributedAdjacencyGraph, loops: LoopRecognition | None = None, *, blends: BlendReading | None = None) tuple[DepressionProtrusion, ...]#
Find the holes, pockets and bosses of a part from the inner loops bounding them.
Nothing is marked on aag.
- Parameters:
aag – The adjacency graph of the part. Its face angles are calculated when missing.
loops – The loops found on aag; found here when omitted.
blends – The part’s blends, which the loops are found with when they are found here; read here when omitted. See
recognise_loops().
- Returns:
The features, ordered by their lowest face id. A feature found through several loops, such as a through hole seen from both its ends, appears once. Each feature’s
parentindexes this tuple.- Raises:
ValueError – When loops is given without the graph it was read on, which it needs to read its loops.
volmdlr_tools.features.extractors.hole_steps module#
Read the faces of a part about the axes they turn about, and a hole as the steps it makes along its axis.
A hole is a stack of faces turning about one axis: cylinders, cones, flat floors square to the axis and the rounds between them. Read from its mouth, each face is a step of the hole, named by its surface, by where it lies along the axis and by how wide it is. Two holes on one axis and of one bore are one hole broken by a gap when nothing at all lies between them along the axis.
The same readings serve every feature turning about an axis, holes, grooves and bores broken open alike, so each face and edge of the part is read once, however many features ask about it.
- class volmdlr_tools.features.extractors.hole_steps.HoleGeometry(aag: AttributedAdjacencyGraph, blends: frozenset[int])#
Bases:
objectThe faces and edges of a part read about the axes they turn about, each one once.
- axis(face: int) tuple[ndarray, ndarray] | None#
Return the axis a cylinder or a cone turns about,
Nonefor any other face.
- common_axis(faces: Iterable[int]) tuple[ndarray, ndarray] | None#
Return the axis the cylinders and cones among some faces share.
- Returns:
the axis of the first of them,
Nonewhen there are none or they turn about different axes.
- edge_points(edge: int) ndarray#
Return points spread along an edge, from one end to the other.
- face_points(face: int) ndarray#
Return points spread along the boundary of a face.
- gap_faces(first: HoleSpan, second: HoleSpan, ends: frozenset[int]) frozenset[int]#
Return the faces, among where two pieces of one hole end, that lie in the gap between them.
- hole_wall(face: int, origin: ndarray, direction: ndarray) bool#
Tell whether a face turning about an axis faces it, as the wall of a hole does, rather than away.
- is_torus(face: int) bool#
Tell whether a face lies on a torus.
- one_hole(first: HoleSpan, second: HoleSpan) bool#
Tell whether two pieces of hole are one hole broken by a gap: one axis, one bore, nothing between them.
- radius_range(face: int, origin: ndarray, direction: ndarray) tuple[float, float]#
Return how near to and how far from an axis the boundary of a face lies.
- same_axis(axes: list[tuple[ndarray, ndarray]]) bool#
Tell whether axes all lie on one line, to the part’s size.
- span(faces: frozenset[int], steps: tuple[HoleStep, ...]) HoleSpan | None#
Return where a hole with these faces and steps lies along its axis.
The axis is read from a wall of the hole, or failing one from any step turning about it, such as a cone; a round or a floor has none.
- Returns:
the span,
Nonewhen no step turns about an axis.
- step_shape(face: int, origin: ndarray, direction: ndarray) Literal['cylinder', 'cone', 'plane', 'blend'] | None#
Return the sort of surface a face of a hole is,
Nonewhen it does not turn about the hole’s axis.
- steps(faces: frozenset[int], axis: tuple[ndarray, ndarray], mouth_edge_ids: list[int]) tuple[HoleStep, ...]#
Read faces turning about an axis as the steps of one hole, from the mouth along the given edges.
A mouth on a curved face, such as a hole drilled across a round bar, is measured from its crown.
- Parameters:
axis – The axis the faces share (see
common_axis()).- Returns:
the steps from the mouth inward, none when a face does not turn about the axis.
- surface(face: int) BRepAdaptor_Surface#
Return the surface of a face.
- class volmdlr_tools.features.extractors.hole_steps.HoleSpan(origin: ndarray, direction: ndarray, bore: float, low: float, high: float)#
Bases:
objectWhere a piece of a hole lies: its axis, its bore and how far along the axis its faces reach.
- Parameters:
origin – A point of the axis.
direction – The unit direction of the axis.
bore – The radius of the hole’s narrowest step.
low – The lowest reach of its faces along direction, from the origin of coordinates.
high – The highest reach likewise.
- bore: float#
- direction: ndarray#
- high: float#
- low: float#
- origin: ndarray#
- class volmdlr_tools.features.extractors.hole_steps.HoleStep(kind: Literal['counterbore', 'countersink', 'chamfer', 'bore', 'taper', 'drill_point', 'recess', 'floor', 'blend'], face_ids: frozenset[int], radius: float, start: float, end: float)#
Bases:
objectOne step of a hole, along its axis from the mouth.
- Parameters:
kind –
"counterbore", a wider cylinder at the mouth, with no narrower one before it;"countersink"or"chamfer", a cone at the mouth or at the far end of a hole running through, a chamfer when it widens the bore by at most a third of its radius;"bore", the narrowest cylinder;"taper", a cone between two cylinders;"drill_point", a cone closing the far end;"recess", a wider cylinder past a narrower one;"floor", a flat face square to the axis;"blend", a round between two steps.face_ids – The faces of the step.
radius – The largest radius of the step.
start – Where the step starts, as a distance along the axis from the mouth.
end – Where the step ends, likewise.
- end: float#
- face_ids: frozenset[int]#
- kind: Literal['counterbore', 'countersink', 'chamfer', 'bore', 'taper', 'drill_point', 'recess', 'floor', 'blend']#
- radius: float#
- start: float#
- volmdlr_tools.features.extractors.hole_steps.name_steps(readings: list[tuple[int, str, float, float, float, float]], tolerance: float) tuple[HoleStep, ...]#
Name the steps of a hole from its faces’ surfaces and their extents along and around the axis.
A cone is named by where it lies along the hole and how wide it is, not by the faces next to it: at the mouth or at the far end of a through hole it is a chamfer or a countersink, at the far end of a blind hole closing to a point it is the drill point, and between the two a taper. A hole’s faces are found here from its loop, so that, unlike reading a hole from the faces round its mouth, a cone is placed even where the hole opens on several faces or on none that is flat.
- Parameters:
readings – For each face, its id, its shape (
"cylinder","cone","plane"or"blend"), where it starts and ends along the axis from the mouth, and how near to and how far from the axis it lies.tolerance – The length to which steps are told apart.
volmdlr_tools.features.extractors.isolated_boss_splitter module#
Separate a shape into the isolated bosses standing on it, and the pockets sunk into it.
A boss raised on a single base face, enclosed by an inner contour of that face, can be told apart from what it stands on. Each piece comes back naming the faces it holds and the piece it grew out of, so a shape reads as a base and the protrusions it carries rather than as one undifferentiated set of faces.
A feature that leaves its base through a ring of blends is cut off along the loop where the blend meets the base, not along an inner contour of a face, and a pocket is cut off along a convex loop. Asked for, the splitter cuts along those as well, so that a glyph on a plaque on a neck comes back as a tree: the glyph is a piece whose parent is the plaque’s piece, whose parent is the neck’s.
Asked for, the splitter also cuts along a junction that does not close: where an arm leaves the end face of a block, the seam is an open chain of concave edges whose two ends lie on the one flat face the arm and the block share the top of. The face is split along the straight line between the ends, which closes the seam into a loop.
- class volmdlr_tools.features.extractors.isolated_boss_splitter.ShapeIsolatedBossSplitter(shape: Shape, aag: AttributedAdjacencyGraph | None = None, blend_max_radius: float | None = None, boundaries: Literal['inner_wires', 'inner_wires_and_root_blends'] = 'inner_wires', boundary_filter: Callable[[SplitBoundary], bool] | None = None, *, open_junctions: bool = False, loops: LoopRecognition | None = None)#
Bases:
objectSplit a defeatured BRep shape into isolated boss components.
Isolated bosses are protrusions built upon a single base face, isolated into an inner contour of that face. This class splits the part into manifold shapes — one per isolated boss plus the base — without boolean operations.
- Algorithm:
Find seed faces with concave inner wires (boss boundaries).
Remove the concave boundary edges from the AAG to disconnect it.
Register connected components as split sets with parent-child relationships.
Rebuild faces (removing concave inner wires from seeds) and assemble shapes.
With
boundaries="inner_wires_and_root_blends"the boundaries are wider. The loops are not searched for by the splitter: they are read once, with the part’s blends, asPartReading.loopsreads them, and the splitter decides which of them cut off a feature. Pass the reading’s loops as loops to share it with the other readers of the part. Every loop of the part that turns one way, a concave one for a boss and a convex one for a pocket, is a candidate. It may be an inner wire of a face, meet its base tangentially along some of its edges and sharply along others, run over several faces of its base, or be the loop where a ring of blends leaves its base, which cuts off the boss or pocket that ring roots. A loop that is an inner wire of a face cuts off the side without that face, as the default split does, however large that side; one that runs over several faces joined tangentially cuts off a clear minority of the part (seecut_off()). What it cuts off must turn over, as a boss holds something convex and a pocket something concave, and must not be one end of a post joining two bases. Boundaries that overlap only in part are not all kept, the smaller winning, so that features stand apart or nest. Each set then names the kind of feature it is, the faces it hangs from and the blends at its root.With
open_junctions=Truea concave seam that starts and stops is closed across the flat face its ends lie on, and is cut along when what it cuts off turns over, whatever the sizes of the two sides: the smaller is the piece cut off. The face is then really split in two, so the shape and graph the result is numbered against are those of the split part:aagandshapeanswer for them, andface_mapsays which faces of the graph given stand for each face of it.- property aag: AttributedAdjacencyGraph#
The Attributed Adjacency Graph, computed lazily if not provided.
- property blends: Mapping[int, BlendAttribute]#
The blends of the part, by face, as its loops were read with them; empty when cutting along inner wires.
Profile rounds are among them, which the loops themselves leave out of their blends. Faces are numbered as those of
aag.
- property face_map: dict[int, tuple[int, ...]]#
For each face of the graph the splitter was given, the faces of
aagthat stand for it.A face stands for itself, unless it was split along a junction, when two faces stand for it; the faces that were not are numbered as the graph that came after the split numbers them.
- get_extruded_features(split_set: SplitSet, parent_aag: AttributedAdjacencyGraph | None = None) object | None#
Try to classify a boss split set as an extrusion.
Builds a shape from the split set, runs
ExtrusionShapeRecognizer, and returns anExtrusionif confirmed.- Parameters:
split_set – The SplitSet to classify.
parent_aag – AAG of the parent shape (for base node resolution). Defaults to
self.aag.
- Returns:
An Extrusion if confirmed, None otherwise.
- get_shape(split_set: SplitSet) Shape#
Build a shape (shell or solid) from a split set’s faces.
Seed faces have the inner wires the cut ran along removed before assembly, so a base whose features each stand on one of its faces comes back closed. A set cut off is open where it was cut, and so is a base where a feature’s loop runs over several faces joined tangentially, since that loop is no wire of a face.
- Parameters:
split_set – The SplitSet to build a shape for.
- Returns:
The assembled Shape.
- get_shapes() list[Shape] | None#
Get shapes for all split sets.
- Returns:
List of Shape objects (one per split set), or None if shape is not splittable.
- property loops: LoopRecognition#
The closed loops of the part, with its blends, read the first time they are asked for.
A split with root blends as boundaries cuts along them. They are those given, until a face of the part is split along an open junction: they are then those of the part split.
- Raises:
ValueError – When the split is along inner wires alone, which reads no loops.
- merge_into_parent(indices: Iterable[int]) list[SplitSet] | None#
Stop cutting along the boundaries of some sets, which then belong to the sets they were cut from.
The sets the dropped ones contain move up to their nearest remaining parent, and every set is numbered anew. Only a split with root blends as boundaries can be merged.
- Parameters:
indices – Indices, in the current result, of the sets to merge into their parents.
- Returns:
The new result, which
resultnow returns as well;Nonewhen nothing is left to split.- Raises:
ValueError – If the split was made along inner wires alone.
- property open_junctions_cut: int#
How many open junctions the part was cut along, as faces of the part were split to close them.
- perform() None#
Split the shape into isolated boss components.
Populates result and internal wire mapping for shape rebuilding.
- property result: list[SplitSet] | None#
The split sets resulting from the decomposition, or None if shape is not splittable.
- property seam_face_ids: frozenset[int]#
The faces on either side of every seam the part was cut along, blends left out.
A seam between two bodies is concave on both of its sides, and that concavity is not a cut: the faces that meet at it belong to the bodies. They are numbered as the faces of the graph given are, and a face that was split to close a junction stands for both of its halves.
- Raises:
ValueError – If the split was made along inner wires alone.
- class volmdlr_tools.features.extractors.isolated_boss_splitter.SplitBoundary(kind: Literal['boss', 'pocket'], loop_edge_ids: tuple[int, ...], enclosed_face_ids: frozenset[int], base_face_ids: frozenset[int], root_blend_face_ids: frozenset[int] = frozenset({}))#
Bases:
objectA closed loop of edges along which a part is cut, and what the cut takes off it.
- Parameters:
kind –
"boss"when the loop is concave,"pocket"when it is convex.loop_edge_ids – The edges of the loop, numbered as the edges of the part’s adjacency graph are.
enclosed_face_ids – Every face the loop cuts off, those of the features it contains included.
base_face_ids – The faces across the loop: the base the feature belongs to, which may be several faces joined tangentially.
root_blend_face_ids – The blend faces where the feature leaves its base, empty when the loop is sharp.
- base_face_ids: frozenset[int]#
- enclosed_face_ids: frozenset[int]#
- kind: Literal['boss', 'pocket']#
- loop_edge_ids: tuple[int, ...]#
- root_blend_face_ids: frozenset[int] = frozenset({})#
- class volmdlr_tools.features.extractors.isolated_boss_splitter.SplitSet(index: int, face_indices: set[int], seed_face_indices: set[int] = <factory>, parent_index: int | None = None, kind: ~typing.Literal['boss', 'pocket'] | None = None, base_face_ids: frozenset[int] = frozenset({}), root_blend_face_ids: frozenset[int] = frozenset({}), loop_edge_ids: tuple[int, ...] = (), enclosed_face_ids: frozenset[int] = frozenset({}))#
Bases:
objectA connected component resulting from splitting a shape along boss boundaries.
- Parameters:
index – Position in the result list.
face_indices – AAG node indices belonging to this set.
seed_face_indices – Indices of seed faces in this component.
parent_index – Index of the parent SplitSet (None if base/root).
kind –
"boss"or"pocket"for a set cut off along a boundary of a split with root blends as boundaries,Nonefor what remains of the shape once every feature is cut off and for every set of a split along inner wires alone.base_face_ids – The faces of its parent that the set hangs from, empty for a base.
root_blend_face_ids – The blend faces where it leaves its base, empty when it does so along a sharp edge or is a base.
loop_edge_ids – The edges of the loop that cuts it off, empty for a base.
enclosed_face_ids – The faces the loop cuts off, those of the sets it contains included; empty for a base.
- base_face_ids: frozenset[int] = frozenset({})#
- property boundary: SplitBoundary | None#
The boundary that cuts this set off,
Nonefor a base or for any set of a split along inner wires alone.
- enclosed_face_ids: frozenset[int] = frozenset({})#
- face_indices: set[int]#
- index: int#
- property is_base: bool#
Whether this set is a base (has seed faces and no parent).
- property is_boss: bool#
Whether this set is a boss (has a parent).
- kind: Literal['boss', 'pocket'] | None = None#
- loop_edge_ids: tuple[int, ...] = ()#
- parent_index: int | None = None#
- root_blend_face_ids: frozenset[int] = frozenset({})#
- seed_face_indices: set[int]#
- take_boundary(boundary: SplitBoundary) None#
Record the boundary that cuts this set off, which
boundarythen returns.
volmdlr_tools.features.extractors.cavity module#
Module for recognizing geometric features, specifically cavities and pockets, in a B-Rep CAD model.
This module operates on a CAD model’s Attributed Adjacency Graph (AAG), an extension of B-Rep that encodes adjacency information and feature semantics. The main class, CavityExtractor, provides methods to traverse the AAG and recognize features like cavities and pockets, leveraging graph algorithms and geometric queries.
- class volmdlr_tools.features.extractors.cavity.CavityExtractor(aag: AttributedAdjacencyGraph, max_number_feature_faces: int = 100, name: str = '')#
Bases:
InnerFeaturesExtractorExtract cavity and pocket features from AAG.
A class for recognizing cavities and pockets in a CAD model using an Attributed Adjacency Graph (AAG). The AAG is traversed to find “seed” faces that are part of these features. From the seeds, the algorithm propagates to identify connected faces that share specific geometric characteristics such as convexity of edges and angles.
- Parameters:
aag (AttributedAdjacencyGraph) – The Attributed Adjacency Graph (AAG) representation of the CAD model
max_number_feature_faces (int) – Maximum allowable number of faces in a recognized feature (used to filter overly large features), defaults to 20
- display_result() dict#
Implementation of a tag for displays.
- find_seeds() list[int]#
Find potential seed faces in the CAD model that can be used to start the feature recognition process.
This method scans the faces in the Attributed Adjacency Graph (AAG) to locate candidate seed faces. For a cavity, a seed face is typically a face with inner wires, where the neighboring faces, adjacent to this seed face through the inner wires, have a convex relationship with respect to the seed face.
- Returns:
A list of face indices that are valid seed candidates for further feature recognition.
- get_cavities() list[Cavity]#
Return a list containing all identified cavities with their base faces.
- property ids_pockets: list[list[int]]#
Return the ids of blend faces.
- Returns:
Ids of blend faces.
- is_angle_valid(seed_id: int, neighbor_id: int) bool#
Check if the angle is valid.
- is_feature_valid(new_feature_faces: list[TopoDS_Shape], new_feature_indices: list[int], seed_face_neighbors: list[int]) bool#
Check if the feature is valid.
- is_invalid_base_neighbor(start_id: int, neighbor_id: int) bool#
Check if the base neighbor is invalid.
- is_seed_valid(face_index: int, wire: TopoDS_Shape) bool#
Check if the seed node is valid.
- perform() bool#
Perform the cavity feature extraction.
- recognize_cavities() None#
Recognize cavity features in the CAD model by analyzing the Attributed Adjacency Graph (AAG).
(Under construction)
- property shape: Shape#
Return the shape.
- class volmdlr_tools.features.extractors.cavity.RecognizeCavities(aag: AttributedAdjacencyGraph)#
Bases:
CavityExtractorDeprecated: Use CavityExtractor instead.
This class is maintained for backward compatibility and will be removed in version 1.0.0. Please update your code to use CavityExtractor.
volmdlr_tools.features.extractors.sharp_edge module#
A module for sharp edges identification.
- class volmdlr_tools.features.extractors.sharp_edge.SharpEdgeExtractor(aag: AttributedAdjacencyGraph, name: str = '')#
Bases:
FeatureExtractorExtract sharp edge features from AAG.
A class for recognizing and analyzing sharp edges in a geometric model using an adjacency attribute graph. Sharp edges are identified by analyzing convex angles between adjacent faces along linear edges.
- display_result() dict#
Implementation of a tag for displays.
- get_edges_shapes() list[Edge]#
Return a list containing all identified edges shapes.
- property ids: list[int]#
Return the ids of sharp edges.
- Returns:
Ids of sharp edges.
- perform() None#
Perform sharp edge identification and cache the result.
- property shape: Shape#
Return the shape.
- class volmdlr_tools.features.extractors.sharp_edge.SharpEdgeRecognizer(aag: AttributedAdjacencyGraph, name: str = '')#
Bases:
SharpEdgeExtractorDeprecated: Use SharpEdgeExtractor instead.
This class is maintained for backward compatibility and will be removed in version 1.0.0. Please update your code to use SharpEdgeExtractor.
volmdlr_tools.features.extractors.deformation module#
volmdlr_tools.features.extractors.sheet_metal module#
Sheet-metal feature extractors.
- class volmdlr_tools.features.extractors.sheet_metal.DeformationExtractor(sheet_metal: SheetMetalShape, name: str = '')#
Bases:
FeatureExtractorExtractor for recognizing deformation features in a B-Rep CAD model.
Whichever strategy reads the deformations, the gussets pressed across the folds of the sheet are found first, from the sheet’s own reading of them (see
SheetMetalShape.get_gusset_skins()). This wire-seeded strategy then drops any deformation that takes a gusset face, whole;RegionDeformationExtractorinstead counts the gusset faces as panel and still judges what lies beside them.- static get_entire_set_center_of_mass(deformation_set: list[int], aag_side: AttributedAdjacencyGraph) ndarray#
Compute the center of mass for an entire deformation set by averaging face centers.
- Parameters:
deformation_set – List of node indices in the deformation set.
aag_side – The AAG representation of one side.
- Returns:
The averaged center of mass as a numpy array.
- perform() bool#
Perform deformation recognition by matching deformations from both sides of the sheet metal.
- Returns:
True if any gusset or deformation was found, False otherwise.
- class volmdlr_tools.features.extractors.sheet_metal.RegionDeformationExtractor(sheet_metal: SheetMetalShape, name: str = '')#
Bases:
DeformationExtractorDeformation extractor driving the region-based helper on both sides.
Reuses the wire-based extractor’s pairing plumbing (mutual-nearest matching, gravity centers, feature construction) over region-based candidates.
- MAX_PAIR_FACE_RATIO = 3.0#
- OPENING_FEATURES: ClassVar[dict[str, tuple[type[FlangedCutout], str]]] = {'extrusion_hole': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.ExtrusionHole'>, 'Extrusion Hole'), 'flanged_cutout': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.FlangedCutout'>, 'Flanged Cutout'), 'louvre': (<class 'volmdlr_tools.features.feature_types.sheet_metal.louvres.Louvre'>, 'Louvre')}#
- SHAPE_FEATURES: ClassVar[dict[str, tuple[type[Emboss], str]]] = {'bead': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Bead'>, 'Bead'), 'dimple': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Dimple'>, 'Dimple'), 'emboss': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Emboss'>, 'Emboss')}#
- perform() bool#
Run region-based extraction on both sides, pair the pooled results, classify per pair.
Emboss-like and cutout-like regions are pooled per side before pairing: the free-boundary class is a per-side observation that the two sides can disagree on (a region may fade into a cutout rim on one side only), and pairing within a class would then silently drop the deformation. The class is decided from the matched pair instead.
A pair whose two sides both touch a free boundary is an opening: an ExtrusionHole or a Louvre when both skins have that shape, a FlangedCutout otherwise, holding the walls of its cut. Any other pair stays inside the sheet: a Dimple or a Bead when both skins have that shape, an Emboss otherwise.
A gusset pressed across a bend is found first, from the pieces it cuts the bend into (see
SheetMetalShape.get_gusset_skins()); its faces count as panel, like the folds (seeRegionDeformationExtractionHelper), so no region reads it, with the flats around it, as an emboss or a flanged cutout.- Returns:
True if any gusset or deformation was found, False otherwise.
- class volmdlr_tools.features.extractors.sheet_metal.SheetMetalFeatureClassifier(aag: AttributedAdjacencyGraph)#
Bases:
objectClassifier for sheet metal features using thickness face chains.
This class implements the classification logic from Yang Yang et al. (2021), using the Characteristics Matrix approach with rule-based pattern matching.
Classification uses three rule tables: - CUT_RULES: For cut features (Slot, Notch, CornerRelief) - COMPOSITE_RULES: For bend/composite features (Bend, Jog, Lance, Clip) - DEFORM_RULES: For deform features (Emboss)
- classify(tfc_group: TFCGroup) Feature#
Classify a thickness face chain group into a specific feature type.
Uses the Characteristics Matrix approach from Yang Yang et al. (2021): 1. Extract properties from the TFC group 2. Match against rules in order of priority 3. Return first matching feature type 4. Otherwise, a closed chain with no bend in it whose walls run straight
through the sheet is a pierced cutout of some other outline; anything else is an UnknownFeature
- class volmdlr_tools.features.extractors.sheet_metal.SheetMetalFeatureExtractor(sheet_metal: SheetMetalShape, name: str = '', claimed_cut_walls: tuple[int, ...] = (), formed_faces: tuple[int, ...] = ())#
Bases:
FeatureExtractorExtractor for sheet metal features using Yang Yang et al. (2021) algorithm.
This extractor orchestrates the feature extraction process: 1. Extracts sub-chains from ThicknessFaceChains 2. Delegates classification to SheetMetalFeatureClassifier
Responsibilities: - Extraction: Get sub-chains using three methods (binary, concavity, convexity) - Orchestration: Use classifier for feature identification
The classifier handles all pattern matching and feature creation logic.
- FLAT_HEM_GAP_RATIO = 0.1#
- FOLD_END_TOLERANCE_RATIO = 0.05#
- FOLD_READINGS = (<class 'volmdlr_tools.features.feature_types.sheet_metal.bends.Bend'>, <class 'volmdlr_tools.features.feature_types.sheet_metal.jogs.Jog'>, <class 'volmdlr_tools.features.feature_types.unknown.UnknownFeature'>)#
- FOLD_SKINS = 2#
- HEM_ANGLE_TOLERANCE = 0.08726646259971647#
- MINIMUM_CURL_ANGLE = 1.658062789394613#
- MIN_FACES_FOR_MIRRORING = 5#
- extract_all_bendings(chain: ThicknessFaceChain) list[Bend]#
Extract all bend features from a thickness face chain.
Identifies fan-shaped faces and pairs, creating a Bend for each fold zone. Only the fan-shaped faces that end a bend of the sheet count: a deformation running off the sheet edge shows one too. Whether a fold is a bend, a hem or a curl is decided once its pieces are merged, from its whole geometry (see
_as_fold()).- Parameters:
chain (ThicknessFaceChain) – The thickness face chain to extract bends from
- Returns:
List of Bend features
- Return type:
list[Bend]
- extract_boundary_features() list#
Extract and classify features from boundary thickness face chains.
The outer contour shows a bend as a pair of fan-shaped faces and the run of edge faces between them. Where a fold of the sheet is found from those fan-shaped faces and its cylinders, that fold is the bend, with its radius and angle; the contour’s reading of it adds only the plain edge of the sheet, and is left out. The same goes for a run of folds the contour reads as one feature — a jog, or nothing it knows — when every fan-shaped face in it ends a fold: the folds are found one by one, and whether two of them make a jog is told from their geometry (see
JogFinder). A contour reading no fold covers is kept. The folds themselves are not among these features.- Returns:
List of classified boundary features
- Return type:
list[Feature]
- extract_internal_features() list#
Extract and classify features from internal thickness face chains.
A cut whose walls read as a lance, a jog or a louvre is still a plain opening when it is cut across a fold of the sheet rather than formed from the material inside it (see
_cuts_across_a_fold()).- Returns:
List of classified internal features, with no claimed cut wall in any of them
- Return type:
list[Feature]
- static get_connected_concave_subchains(fan_shaped_faces_subchains: list[ThicknessFaceChain], concave_subchains: list[ThicknessFaceChain], main_chain: ThicknessFaceChain) list[TFCGroup]#
Group fan-shaped face subchains with their connected concave subchains.
For each fan-shaped face subchain, finds adjacent concave subchains of equal length and groups them together. Unpaired subchains are returned as single-element groups, and so is a subchain that more than two such concave subchains touch: an outer bend enclosing sibling bends is bordered by every relief of its siblings, and no single pair of them belongs to it.
- Parameters:
fan_shaped_faces_subchains (list[ThicknessFaceChain]) – Subchains containing fan-shaped faces
concave_subchains (list[ThicknessFaceChain]) – All concave subchains from the main chain
main_chain (ThicknessFaceChain) – The parent thickness face chain
- Returns:
List of TFCGroup objects
- Return type:
list[TFCGroup]
- get_external_subchains_groups() list[TFCGroup]#
Extract and group subchains from the boundary thickness face chain.
Combines fan-shaped face subchains with connected concave subchains, and adds each corner and each cut into the edge as a group of its own. A run turning into the material that is no cut into the edge, such as the inside corner where a tab stands out of the sheet, makes no group.
The runs a cut into the edge holds are left out of the pairing, the rounded corners it holds out of the corners, and the faces a cut holds at the ends of a bend’s stretch of the contour — the end face it took whole, a set-back part of it and the step behind — are left out of that stretch (see
ThicknessFaceChain.without_ends()). A face a cut holds inside a stretch, between its two ends, stays in it.- Returns:
List of TFCGroup objects representing boundary feature candidates
- Return type:
list[TFCGroup]
- get_internal_subchains_groups() list[TFCGroup]#
Extract and group subchains from internal thickness face chains.
- Returns:
List of TFCGroup objects representing internal feature candidates
- Return type:
list[TFCGroup]
- get_mirror_internal_subchains(internal_chains: list[ThicknessFaceChain]) list[TFCGroup]#
Group internal thickness face chains into mirror pairs or individual groups.
Chains with < 5 faces are always treated as individual groups, and so is a chain with no fan-shaped face: nothing is formed along it, so it is a cut complete on its own — two holes pierced in one wall share that wall without being one feature. Other chains are paired when a curved face borders both: a bridge’s two cuts end on its leg bends, a jog’s on its two bends. A flat face they share proves nothing — every cut in a flat borders that flat’s skins, so two lances side by side would otherwise pair into one feature. Unpaired chains are added as individual groups.
- Parameters:
internal_chains – List of internal thickness face chains
- Returns:
List of chain groups (pairs or singles)
- property internal_features: list[Feature]#
Get the internal features extracted from the sheet metal.
- perform() bool#
Perform feature extraction using Yang Yang algorithm.
Extracts sub-chains from boundary and internal thickness face chains and classifies features using the classifier. A jog and a lance own the bends they are formed with, so those folds are reported in them, not as features of their own. A tab holds the faces of its tip, so the corners read from them are left out; its bend and its hole stay features of their own (see
TabFinder). The holes of a perforated field are gathered into one perforation, which owns them, once every internal feature is read (seePerforationReader).- Returns:
True if any features were found
- Return type:
bool
volmdlr_tools.features.extractors.feature_classifier module#
volmdlr_tools.features.extractors.ribs module#
Rib feature extractor.
Recognizes rib features (thin protruding walls) in a BRep model, following the recognition half (§4.2) of Lai et al. (2017), Recognition and decomposition of rib features in thin-shell plastic parts for finite element analysis.
The extractor works directly against the existing
AttributedAdjacencyGraph (AAG): the paper’s
bespoke “Edge AAG” / “Face AAG” databases map onto the AAG’s edge angle
classification (convex/concave/smooth) and node attributes (surface type,
plane normal, wires).
Recognition is built up incrementally (see the rib-extractor plan):
Implemented: end-face-pair detection (Rules 2, 4, 5, 6), shell/base collection (union of both ends, so faces touching only one end are kept), fillet (blend) pass-over, and rib-structure (junction) grouping of connected segments.
A rib (a protrusion) is told apart from a depression (slot/pocket) of the same thickness by two checks: the material-side test (material lies between the two end faces, not void) and the directly-opposing test (the faces face each other).
Pending: Rule 3 (inner-loop convexity), and ribs whose shell is fully split with no spanning face (the paper’s virtual-face / different-height cases).
- class volmdlr_tools.features.extractors.ribs.RibExtractor(aag: AttributedAdjacencyGraph, max_thickness: float | None = None, blend_max_radius: float | None = None, pair_finder: Literal['edge_driven', 'face_pair', 'nearly_planar'] = 'edge_driven', name: str = '')#
Bases:
FeatureExtractorRecognize rib features on a BRep model from its AAG.
A rib is a thin protruding wall: two opposing end faces a thin gap apart, standing on the surrounding part walls and capped by a shell. By default the end-face pairs are found edge-driven (Lai et al. §4.2.1) — see
perform()for the pipeline and__init__for thepair_finderselector.All constructor parameters are documented on
__init__.- property applied_max_thickness: float#
The wall-thickness threshold recognition actually used.
Equal to
max_thickness(or its scale-aware default) unless the default was tightened to the part’s measured wall population — see_tighten_max_thickness(). Report this, notmax_thickness.
- perform() bool#
Recognize ribs and store them in
self._result.End-face pairs come from the finder the constructor flags select — by default
_find_end_face_pairs_edge_driven(), which derives each wall’s two sides from matched parallel boundary edges of a host face and admits nearly-planar sides, not only true planes.For each pair, collect the shell faces that join the two ends through convex edges and the base faces that meet them through concave edges. Pairs that are fragments of the same physical wall (coplanar sides split by the modeller) are then merged into one candidate before each candidate is materialized into a
Rib. A pair with no connecting shell face is not a rib and is dropped.- Returns:
True once recognition has run (idempotent).
- property rib_structures: list[RibStructure]#
Return rib structures: groups of >=2 segments connected at junctions.
volmdlr_tools.features.extractors.rib_edge_pairs module#
Edge-driven rib pair finding (Lai et al. 2017, §4.2.1-4.2.2).
The paper derives a rib’s two end faces from a host face crossed by the wall: parallel boundary edges of the host are matched at minimum distance, and the faces adjacent across the matched edges are the wall’s two sides. This module holds the pure geometry (no extractor state): boundary-edge extraction, parallel grouping, and minimum-distance matching. Deriving end faces and applying the rib rules stays in RibExtractor.
Deriving pairs this way collapses the candidate space from every anti-parallel
face pair on the part to those bound by an actual host face, and puts material
between the two sides by construction rather than by a ray test. Benchmarked on
the A-Pillar reference part at equal recognition quality and appreciably faster
than the face-pair search, which is why pair_finder="edge_driven" is the
RibExtractor default; the
face-pair finders remain available via the other pair_finder names. See the
CHANGELOG for the measured figures behind that comparison.
- class volmdlr_tools.features.extractors.rib_edge_pairs.BoundaryEdge(start: Point3D, end: Point3D, neighbor_node: int, direction: Vector3D, length: float)#
Bases:
objectOne boundary edge of a host face, with the face adjacent across it.
Positions describe the edge’s chord, not its curve: a subdivided curved edge is represented as several BoundaryEdge instances, one per sub-chord.
- direction: Vector3D#
Unit vector along the chord, from
starttoend.
- end: Point3D#
Chord end point.
- length: float#
Chord length (straight-line, so a lower bound on the arc length).
- neighbor_node: int#
AAG node index of the face on the other side of this edge.
- start: Point3D#
Chord start point.
- volmdlr_tools.features.extractors.rib_edge_pairs.boundary_edges(aag: AttributedAdjacencyGraph, node: int, subdivide: bool = False) list[BoundaryEdge]#
Return the face’s boundary edges as chords, each with its adjacent face.
The adjacent face comes from the AAG’s cached edge adjacency (
get_edge_index+get_common_edge_indices) — the AAG is the owner of edge->face knowledge, and the lookup is O(1) per edge instead of a TopoDS identity scan over every neighbor’s edges. Edges with a degenerate chord (closed or seam edges) or with no identified neighbor (free boundaries, edges unknown to the AAG) are dropped: they cannot span a rib wall.With
subdivide=Trueopen curved edges are split into local chord segments (_edge_sample_points()) so matching compares local directions instead of end-to-end chords — what recovers walls whose crossing edges twist together. Subdivision is offered as a separate pass rather than the default because segment matching is not a superset of whole-chord matching: mutual-nearest is winner-take-all per edge, and short arc segments parallel to a straight edge can steal its single best slot from the true wall partner (measured on eft_sensor_mount: 4 walls lost). The caller unions the pairs of both passes instead.
- volmdlr_tools.features.extractors.rib_edge_pairs.match_parallel_edges(edges: list[BoundaryEdge], max_distance: float) list[tuple[BoundaryEdge, BoundaryEdge, float]]#
Match each boundary edge with its NEAREST parallel, overlapping partner.
Nearest-partner matching is what makes the pairing safe: a wall’s two crossing edges are closer to each other than to any other parallel edge on the host face, so a pair spanning two walls plus the gap between them never forms (the paper’s minimum-distance rule). Pairs are returned once (symmetric duplicates removed) and only when their separation is within
max_distanceand their spans overlap.
Module contents#
Feature extractors.
- class volmdlr_tools.features.extractors.BlendExtractor(aag: AttributedAdjacencyGraph, max_radius: float | None = None, free_form_curvature: bool = False)#
Bases:
FeatureExtractorExtract blend/fillet features from AAG.
A class for recognizing and analyzing blends in a geometric model using an adjacency attribute graph (AAG). Supports recognition of edge-based and vertex-based blends.
The blends a reading finds are recorded on the graph’s faces, and stay there for the readings that follow. A reading lists only the blends within its own radius bound, but it does not clear what an earlier reading of the same graph recorded: a reading with a smaller bound than an earlier one still meets the earlier one’s larger blends among the neighbours of its own while it tells their edges apart, though it does not list them.
- calculate_chain_length(feature: list[int]) float#
Compute the total length of a blend chain based on the blend candidate attributes of each face.
The total length is the sum of the lengths of each blend face in the chain, as stored in their blend candidate attributes.
- Parameters:
feature – A list of face IDs representing the blend chain.
- Returns:
The computed total length of the blend chain.
- compute_blend_length(edges_indices: list[int]) float#
Compute the total length of the blend chain.
- Parameters:
edges_indices – A list of edges indexes from the blend chain.
- Returns:
The sum of the lengths of all edges in edges_indices list.
- display_result() dict#
Implementation of a tag for displays.
- dye_blending_faces(color: tuple = (0, 1, 1)) None#
Change the colors of blending faces.
- Parameters:
color – Derired color
- find_cross_edges(face_id: int, smooth_edges_ids: list[int], spring_edges_ids: list[int], candidate_radius: float) tuple#
Identify and return cross edges on a given face, based on curvature evaluation and a specified candidate radius.
Cross edges are those that satisfy certain curvature conditions compared to the provided radius and are not in the excluded categories (smooth or spring edges).
The method evaluates curvature at the midpoint of each remaining edge, which is smooth but is not a spring edge.
The edge is classified as a cross edge if its curvature-derived radius matches the candidate radius within a tolerance threshold — it curves around the blend.
The edge is classified as a junction instead if the blend does not curve along it at all. The blend runs along such an edge rather than across it, continuing into whatever lies beyond, so the edge marks no end of the blend.
- Parameters:
face_id – The index or ID of the face for which to find cross edges.
smooth_edges_ids – A list of edge IDs that represent “smooth” edges to be excluded.
spring_edges_ids – A list of edge IDs that represent “spring” edges to be excluded.
candidate_radius – The target radius value used to compare the curvature of the edges.
- Returns:
cross_edges: A list of edge objects that qualify as cross edges based on the curvature evaluation.
cross_edges_ids: A list of IDs corresponding to the cross edges.
junction_edges_ids: A list of IDs of the edges the blend runs along.
- Raises:
Issues a warning if the curvature cannot be evaluated along the edge.
- find_smooth_edges() tuple[list[TopoDS_Shape], list[int]]#
Find all smooth edges across all faces in the adjacency attribute graph (AAG).
- Returns:
A tuple containing the list of all smooth edges and their corresponding indices.
- find_smooth_edges_for_face(face_id: int) tuple[list[TopoDS_Shape], list[int]]#
Find smooth edges for a given face based on adjacent faces in the graph.
- Parameters:
face_id – The ID of the face to analyze.
- Returns:
A tuple containing the list of smooth edges and their corresponding indices.
- find_spring_edges(face_id: int, smooth_edge_ids: TColStd_PackedMapOfInteger) tuple[list[TopoDS_Shape], list[int], bool, float, list[float]]#
Find the spring edges for a given face, considering the smooth edge indices.
- Parameters:
face_id – The ID of the face to analyze.
smooth_edge_ids – The indices of the smooth edges.
- Returns:
A tuple containing the spring edges, their indices, whether it’s a candidate blend, the candidate radius, and the per-spring-edge candidate radii.
- find_terminating_edges(face_id: int, smooth_edges_ids: list[int], spring_edges_ids: list[int], cross_edges_ids: list[int]) tuple[list[TopoDS_Shape], list[int], list[TopoDS_Shape], list[int]]#
Identify terminating and seam edges of a given face.
A terminating edge is one that does not belong to any of the provided exclusion lists AND crosses to a real neighbour face — i.e. bounds the blend against another face. A wire edge with no external neighbour through this face is a seam of the underlying periodic surface (a torus fillet’s meridian, for example): topologically it is an internal artifact of the parameter domain, not a boundary against another face, so it goes into the seam set instead of the terminating one — leaving a full-round fillet with the clean
2 spring / 0 cross / 0 termsignature its Euler condition expects, while still exposing the seam through the AAG for consumers that need to detect a closed / loop blend (e.g. profile extraction and the full-round Euler condition).- Parameters:
face_id – The index or ID of the face for which to find terminating edges.
smooth_edges_ids – A list of edge IDs that represent “smooth” edges to be excluded.
spring_edges_ids – A list of edge IDs that represent “spring” edges to be excluded.
cross_edges_ids – A list of edge IDs that represent “cross” edges to be excluded.
- Returns:
(terminating_edges, terminating_edges_ids, seam_edges, seam_edges_ids).
- get_blending_chains_faces() list[list[Face]]#
Return a list containing all identified faces grouped by connectivity and radius.
- get_blending_faces() list[Face]#
Return a list containing all identified faces.
- get_chains(r_dev_perc: float = 5.0) list[BlendChain]#
Identify and return chains of adjacent blend faces of one radius.
Blends are joined where they are adjacent along any edge, sharp ones included, then split by fillet radius; each chain carries the cross-edge length of its radius group. So a fillet that continues round a corner whose blend has another radius comes back as several chains, and two blends of one radius meeting at a sharp edge as one;
tangent_chains()joins blends along smooth edges only, whatever their radii. The method first extracts connected components from the adjacency graph based on recognized blend candidates. It then distributes faces into groups based on their fillet radii and evaluates connected components within each group. Afterward, it normalizes these chains by removing any dangling vertex blends.These chains join blends of one radius however they meet, at a mitre too; the rounds of a part reading, each made in one go, are
BlendReading.chains().- Parameters:
r_dev_perc – The allowed percentage deviation when comparing fillet radii. This value controls the tolerance for how close radii need to be considered part of the same chain. A typical default value is 5.0%.
- Returns:
A list of BlendChain objects, each containing faces, properties, and spring edges.
- property ids: list[int]#
Return the ids of blend faces.
- Returns:
Ids of blend faces.
- classmethod of_reading(aag: AttributedAdjacencyGraph, blends: BlendReading) BlendExtractor#
Return an extractor holding blends already read, marked on aag as reading them there would mark them.
Nothing is recognised again: the blends, their chains and the marks a reader of the graph’s nodes finds are exactly blends. Any blend marks aag carried before are replaced.
- Parameters:
aag – The adjacency graph of the part the blends were read from, numbered the same.
blends – The part’s blends.
- perform() None#
Execute the blend recognition process over all faces in the adjacency attribute graph (AAG).
- property shape: Shape#
Return the shape.
- terminating_edges_to_cross_edges() None#
Convert terminating edges to cross edges if the terminating edges connect blend candidate faces.
- class volmdlr_tools.features.extractors.CavityExtractor(aag: AttributedAdjacencyGraph, max_number_feature_faces: int = 100, name: str = '')#
Bases:
InnerFeaturesExtractorExtract cavity and pocket features from AAG.
A class for recognizing cavities and pockets in a CAD model using an Attributed Adjacency Graph (AAG). The AAG is traversed to find “seed” faces that are part of these features. From the seeds, the algorithm propagates to identify connected faces that share specific geometric characteristics such as convexity of edges and angles.
- Parameters:
aag (AttributedAdjacencyGraph) – The Attributed Adjacency Graph (AAG) representation of the CAD model
max_number_feature_faces (int) – Maximum allowable number of faces in a recognized feature (used to filter overly large features), defaults to 20
- display_result() dict#
Implementation of a tag for displays.
- find_seeds() list[int]#
Find potential seed faces in the CAD model that can be used to start the feature recognition process.
This method scans the faces in the Attributed Adjacency Graph (AAG) to locate candidate seed faces. For a cavity, a seed face is typically a face with inner wires, where the neighboring faces, adjacent to this seed face through the inner wires, have a convex relationship with respect to the seed face.
- Returns:
A list of face indices that are valid seed candidates for further feature recognition.
- get_cavities() list[Cavity]#
Return a list containing all identified cavities with their base faces.
- property ids_pockets: list[list[int]]#
Return the ids of blend faces.
- Returns:
Ids of blend faces.
- is_angle_valid(seed_id: int, neighbor_id: int) bool#
Check if the angle is valid.
- is_feature_valid(new_feature_faces: list[TopoDS_Shape], new_feature_indices: list[int], seed_face_neighbors: list[int]) bool#
Check if the feature is valid.
- is_invalid_base_neighbor(start_id: int, neighbor_id: int) bool#
Check if the base neighbor is invalid.
- is_seed_valid(face_index: int, wire: TopoDS_Shape) bool#
Check if the seed node is valid.
- perform() bool#
Perform the cavity feature extraction.
- recognize_cavities() None#
Recognize cavity features in the CAD model by analyzing the Attributed Adjacency Graph (AAG).
(Under construction)
- property shape: Shape#
Return the shape.
- class volmdlr_tools.features.extractors.ChamferExtractor(aag: AttributedAdjacencyGraph, mode: Literal['convex', 'convex_and_inside_bevels', 'any'] = 'convex_and_inside_bevels', max_offset_ratio: float = 0.5, min_angle_degrees: float = 5.0, name: str = '')#
Bases:
FeatureExtractorExtract chamfer features from an Attributed Adjacency Graph.
A chamfer is an angled face, straight across (planar, conical, or a free-form strip run along a curved edge), that replaces a sharp edge between two “under” faces. The extractor identifies candidate faces, filters them, builds chains of adjacent chamfers, resolves conflicts when a face is both a chamfer and an under-face, and produces Chamfer and ChamferChain feature objects.
- Parameters:
aag – The Attributed Adjacency Graph to analyze.
mode – Which chamfers are read.
"convex": those of a convex edge only."convex_and_inside_bevels"(default): also inside bevels, the chamfers of a concave edge filling the square corner two faces make, as where a pocket wall meets its floor."any": the chamfers of any edge, whatever their corner.max_offset_ratio – Maximum ratio of chamfer offset to model diagonal. Default 0.5.
min_angle_degrees – Minimum angle between under-faces in degrees. Default 5.0.
name – Optional name.
- get_chains() list[ChamferChain]#
Return ChamferChain feature objects.
- Returns:
List of ChamferChain instances.
- get_chamfers() list[Chamfer]#
Return Chamfer feature objects for all confirmed chamfer faces.
- Returns:
List of Chamfer instances.
- property ids: list[int]#
Return the face IDs of confirmed chamfer faces.
- property inside_bevel_ids: frozenset[int]#
Return the confirmed chamfer faces that are inside bevels, each in a chain whose vexity is “concave”.
- property inside_bevels: dict[int, frozenset[int]]#
Return each inside bevel among the confirmed chamfers, with the two faces it bevels.
- perform() None#
Execute the full chamfer recognition pipeline.
- property shape: Shape#
Return the shape being analyzed.
- class volmdlr_tools.features.extractors.CoaxialFeatureExtractorMixin#
Bases:
ABCMixin providing common infrastructure for extracting coaxial features.
This mixin encapsulates the seed-based extraction pattern used by: - ConeExtractor (cones - internal countersinks or external tapers) - TorusExtractor (tori - internal fillets or external rounds)
Supports both EXTERNAL and INTERNAL extraction modes: - EXTERNAL: Extract features with outward-pointing normals (bosses, shafts).
Propagates through CONVEX/SMOOTH edges.
- INTERNAL: Extract features with inward-pointing normals (bores, fillets).
Propagates through CONCAVE/SMOOTH edges.
Subclasses must implement abstract methods for surface-specific logic: - Surface type detection - Property extraction - Property matching for neighbor validation - Mode-aware surface validation
Attributes expected on the class using this mixin: - aag: AttributedAdjacencyGraph - linear_tolerance: float - angular_tolerance: float - feature_class: the RevolutionFeature subclass built for each face group - _ids_features, _cap_faces, _support_faces, _isolated_faces: empty lists, one entry per feature - _feature_properties: empty dict of surface values keyed by sorted feature faces
- abstract property extraction_mode: ExtractionMode#
Return the extraction mode (INTERNAL or EXTERNAL).
- Returns:
ExtractionMode enum value.
- feature_class: type[RevolutionFeature]#
- perform() bool#
Perform feature extraction for the configured extraction mode.
- Returns:
True if extraction completed successfully.
- abstract property surface_type_name: str#
Return the OCP surface type string.
- Returns:
Surface type string (e.g., ‘ConicalSurface’, ‘ToroidalSurface’).
- class volmdlr_tools.features.extractors.ConeExtractor(aag: AttributedAdjacencyGraph, max_semi_angle: float = 1.5707963267948966, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, extraction_mode: ExtractionMode = ExtractionMode.EXTERNAL, name: str = '')#
Bases:
CoaxialFeatureExtractorMixin,FeatureExtractorExtract conical features from an Attributed Adjacency Graph (AAG).
This class recognizes cones by identifying conical faces and propagating to collect all coaxial conical neighbors with the same semi-angle through appropriate edges.
Supports both extraction modes: - EXTERNAL (default): Extract tapered bosses, chamfers (surface normal points away from axis).
Propagates through CONVEX/SMOOTH edges.
- INTERNAL: Extract countersinks, bore chamfers (surface normal points toward axis).
Propagates through CONCAVE/SMOOTH edges.
Key differences from CylinderExtractor: - Surface type: ConicalSurface - Property matching: Same semi-angle (NOT radius - cones taper!)
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
max_semi_angle – Maximum semi-angle in radians (default: 90 degrees).
linear_tolerance – Tolerance for position comparisons.
angular_tolerance – Tolerance for angle comparisons (radians).
extraction_mode – Whether to extract EXTERNAL or INTERNAL cones.
name – Name for the extractor instance.
- property extraction_mode: ExtractionMode#
Return the extraction mode (INTERNAL or EXTERNAL).
- feature_class#
alias of
Cone
- get_cones() list[Cone]#
Create Cone objects from extracted face groups.
- Returns:
List of Cone feature objects.
- property ids_cones: list[list[int]]#
Return the face IDs of identified cones.
- Returns:
List of face ID lists, one per cone.
- property surface_type_name: str#
Return the OCP surface type string for cones.
- class volmdlr_tools.features.extractors.CylinderExtractor(aag: AttributedAdjacencyGraph, max_radius: float = inf, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, extraction_mode: ExtractionMode = ExtractionMode.EXTERNAL, name: str = '')#
Bases:
FeatureExtractorExtract cylindrical features from an Attributed Adjacency Graph (AAG).
This class recognizes cylinders by identifying cylindrical faces and propagating to collect all coaxial cylindrical neighbors through appropriate edges.
Supports both extraction modes: - EXTERNAL (default): Extract bosses, shafts, pins (surface normal points away from axis).
Propagates through CONVEX/SMOOTH edges.
- INTERNAL: Extract bores, holes (surface normal points toward axis).
Propagates through CONCAVE/SMOOTH edges.
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
max_radius – Maximum radius for cylinder recognition (filters large cylinders).
linear_tolerance – Tolerance for radius and position comparisons.
angular_tolerance – Tolerance for axis direction comparisons (radians).
extraction_mode – Whether to extract EXTERNAL or INTERNAL cylinders.
name – Name for the extractor instance.
- get_cylinders() list[Cylinder]#
Create Cylinder objects from extracted face groups.
- Returns:
List of Cylinder feature objects.
- property ids_cylinders: list[list[int]]#
Return the face IDs of identified cylinders.
- Returns:
List of face ID lists, one per cylinder.
- perform() bool#
Perform the cylinder feature extraction.
Main entry point for cylinder recognition. Iterates through faces, identifies cylindrical seed faces, propagates to collect coaxial neighbors, validates angular coverage, and processes floating isolations.
- Returns:
True if extraction completed successfully.
- class volmdlr_tools.features.extractors.DeformationExtractor(sheet_metal: SheetMetalShape, name: str = '')#
Bases:
FeatureExtractorExtractor for recognizing deformation features in a B-Rep CAD model.
Whichever strategy reads the deformations, the gussets pressed across the folds of the sheet are found first, from the sheet’s own reading of them (see
SheetMetalShape.get_gusset_skins()). This wire-seeded strategy then drops any deformation that takes a gusset face, whole;RegionDeformationExtractorinstead counts the gusset faces as panel and still judges what lies beside them.- static get_entire_set_center_of_mass(deformation_set: list[int], aag_side: AttributedAdjacencyGraph) ndarray#
Compute the center of mass for an entire deformation set by averaging face centers.
- Parameters:
deformation_set – List of node indices in the deformation set.
aag_side – The AAG representation of one side.
- Returns:
The averaged center of mass as a numpy array.
- perform() bool#
Perform deformation recognition by matching deformations from both sides of the sheet metal.
- Returns:
True if any gusset or deformation was found, False otherwise.
- class volmdlr_tools.features.extractors.ExtractionMode(*values)#
Bases:
str,EnumMode for coaxial feature extraction.
Controls whether to extract internal (bores, fillets) or external (bosses, shafts) coaxial features.
- Attributes:
- EXTERNAL: Extract external features (bosses, shafts, external rounded edges).
Surface normal points away from axis. Propagates through CONVEX edges.
- INTERNAL: Extract internal features (bores, holes, internal fillets).
Surface normal points toward axis. Propagates through CONCAVE edges.
- EXTERNAL = 'external'#
- INTERNAL = 'internal'#
- class volmdlr_tools.features.extractors.HoleExtractor(aag: AttributedAdjacencyGraph, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, name: str = '')#
Bases:
FeatureExtractorExtract hole features from an Attributed Adjacency Graph (AAG).
This class recognizes holes by grouping coaxial cylindrical/conical faces, building connected components, merging vertex-sharing fragments from intersecting holes, and splitting non-monotonic radius profiles.
Key differences from CavityExtractor: - Seed type: Coaxial face groups (vs. faces with inner wires) - Propagation: Through coaxial groups + neighbor intersection (vs. outer wire neighbors) - Validation: Angular coverage per radius level (vs. connected components)
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
linear_tolerance – Tolerance for radius and position comparisons.
angular_tolerance – Tolerance for axis direction comparisons (radians).
name (str) – Name for the extractor instance.
- bores_of(hole_faces: Collection[int]) tuple[frozenset[int], ...]#
Return a hole’s faces as they own their edges: the arcs of each of its bores together, every other face alone.
Notches cut along a bore part its cylinder into arcs side by side; those arcs are one bore. Lengths of a bore of one size apart along its axis are two. Worked out once for each set of faces.
- Parameters:
hole_faces – The faces of a hole.
- Returns:
The groups, in the order of their first face.
- get_holes() list[Hole]#
Create Hole objects from extracted face groups.
- Returns:
List of Hole feature objects.
- property ids_holes: list[list[int]]#
Return the face IDs of identified holes.
- Returns:
List of face ID lists, one per hole.
- perform() bool#
Perform the hole feature extraction.
Main entry point for hole recognition. Groups coaxial cylindrical faces, finds connected components (merging vertex-sharing fragments from intersecting holes), splits non-monotonic radius profiles into separate holes, and adds ending faces.
- Returns:
True if extraction completed successfully.
- class volmdlr_tools.features.extractors.InteractingFeatureExtractor(aag: AttributedAdjacencyGraph, max_radius: float | None = None, name: str = '', *, stock_convention: Literal['extruded_profile', 'supporting_plane', 'convex_hull'] = 'convex_hull', stock_faces: tuple[int, ...] | None = None, seam_faces: tuple[int, ...] = (), profile_bores: bool = False, blends: BlendReading | None = None)#
Bases:
FeatureExtractorExtract interacting machining features using Sunil et al. (2010) algorithm.
- property befg_classifications: list[Classification]#
Return each BEFG’s verdict together with the rule that reached it.
Aligned index for index with
befgs. Read it when a feature comes out labelled unexpectedly: the rule name says which rung of the classification ladder answered, so one rule can be checked instead of the whole ladder.Under the
"convex_hull"convention two readings run after the ladder (read_off_the_bar()) and overwrite verdicts: a BEFG an outline cut took in is named by that reading (rule"outline_cut"), and a blind step whose floor runs out into an outline cut, and whose faces are those of its BEFG, is classified again with the cut’s faces counted as stock. When that second verdict is a step, the step’s entry holds it, which the ladder run against the stock alone does not reproduce; otherwise the entry keeps the ladder’s verdict.
- property befgs: list[BEFG]#
Return the filtered list of Base Extended Feature Graphs.
- property blend_extractor: BlendExtractor | None#
Return the underlying BlendExtractor (for radius / kind / vexity inspection);
Nonewhen blends were given.
- property blend_node_ids: set[int]#
Return AAG node ids that BlendExtractor recognized as blend faces.
- property chamfer_node_ids: set[int]#
Return AAG node ids of the part’s chamfer faces.
Like blends, chamfers bevel an edge rather than cut a feature, so their faces take no part in feature formation and appear in no feature of
result. A bevel at a hole’s mouth is not among them: it is the hole’s countersink and belongs to the hole. Nor is an inside bevel, filling the corner of a concave edge: like a round in that corner, it is read with the cut whose corner it fills (ChamferExtractor.inside_bevel_ids). This is the extractor’s one answer on chamfers; for their offsets and chains, runChamferExtractor(asFeatureProcessordoes), which knows nothing of holes and reports countersinks too.
- property feature_nodes: set[int]#
Return the set of face indices that are part of features.
A face in neither this set nor
stock_facesis either a plain outside face of the part or a blend rounding the stock: a fillet, or a chain of tangent fillets, tangent to nothing but stock faces (seeFeatureGraphBuilder.get_feature_nodes). Such a blend is inblend_node_idsbut belongs to no feature.
- property hierarchy: FeatureHierarchy#
Return the parent/child
FeatureHierarchyoverresult.Built lazily on first access and cached. Use this for any non-trivial traversal (leaf-first removal order, ancestor walks, etc.); iterate
interactionsdirectly only when you need the raw edge list.
- property interactions: list[tuple[int, int]]#
Return parent-child interactions as
(parent_idx, child_idx)tuples intoresult.
- property nefg_classifications: list[Classification]#
Return each NEFG’s verdict together with the rule that reached it.
Aligned index for index with
nefgs; seebefg_classifications.
- property nefgs: list[NEFG]#
Return the feature graphs with no floor (NEFGs), grooves split out.
- perform() bool#
Perform the interacting feature extraction.
Idempotent: repeat calls return without re-running the pipeline.
- Returns:
True if extraction was successful.
- property shape: Shape#
Return the shape.
- property stock_end_faces: set[int]#
Return the faces the stock’s extrusion ends on, opposite its base.
They belong to the stock as much as
stock_facesdo, but stay in the graph features are read from, since a feature is often cut into them. Empty when the stock was given, or is not told as an extrusion.
- property stock_faces: set[int]#
Return the face indices identified as stock (raw material) faces.
Stock faces are removed from the graph before feature extraction, so no extracted feature ever contains them. Inspect this set when a face is unexpectedly absent from every feature. Blends rounding the stock are absent from every feature too but are not in this set: look for them in
blend_node_idsoutsidefeature_nodes.
- class volmdlr_tools.features.extractors.IsolatedFeatureExtractor(aag: AttributedAdjacencyGraph)#
Bases:
objectExtractor for isolated features given seed faces.
Takes seed face(s) as input and identifies the isolated feature component that lies “inside” the seeds.
The algorithm: 1. Check separability: removing seeds must increase connected components 2. Extract contours: outer edges (boundary) and inner edges (feature candidates boundaries) 3. Find forbidden neighbors: faces adjacent to seeds via outer edges 4. Select valid component: not intersecting forbidden, adjacent to inner edges
- check_inner_boundary_inclusion(inner_edge_sets: list[set[int]], component: set[int]) bool#
Check if component covers at least one complete inner contour.
Based on asiAlgo_RecognizeIsolated::checkInnerBoundaryInclusion (lines 249-304).
- Parameters:
inner_edge_sets – List of inner edge index sets.
component – Set of face indices in the component.
- Returns:
True if component covers at least one inner contour.
- extract_contours(seeds: list[int]) tuple[set[int], list[set[int]]]#
Extract outer and inner edge contours from seed faces.
Dispatches to single or multi-seed implementation.
- Parameters:
seeds – List of seed face indices.
- Returns:
Tuple of (outer_edge_indices, list of inner_edge_index_sets).
- extract_contours_multi_seed(seeds: list[int]) tuple[set[int], list[set[int]]]#
Extract contours for multiple seed faces.
Based on asiAlgo_RecognizeIsolated::extractContours multibase case (lines 322-408). Uses naked edges analysis to find outer/inner boundaries.
- Parameters:
seeds – List of seed face indices.
- Returns:
Tuple of (outer_edge_indices, list of inner_edge_index_sets).
- extract_contours_single_seed(seed_id: int) tuple[set[int], list[set[int]]]#
Extract contours for a single seed face.
Based on asiAlgo_RecognizeIsolated::getFaceEdges (lines 204-245).
- Parameters:
seed_id – The seed face index.
- Returns:
Tuple of (outer_edge_indices, list of inner_edge_index_sets).
- get_boundary_wires_from_seeds(seeds: list[int]) list | None#
Get boundary wires from multiple seed faces, sorted by length (longest first).
Builds a shell from the seed faces and finds naked (open) edges, then connects them into wires. The longest wire is the outer boundary, the rest are inner boundaries (holes/features).
- Parameters:
seeds – List of seed face indices.
- Returns:
List of (wire, length) tuples sorted by length descending, or None if < 2 wires.
- get_components_if_separable(seeds: list[int]) list[set[int]] | None#
Get connected components after removing seeds, if separable.
Based on asiAlgo_RecognizeIsolated lines 110-124.
- Parameters:
seeds – List of seed face indices.
- Returns:
List of components if separable, None otherwise.
- get_edge_vertices(edge_idx: int) set[tuple]#
Extract vertex coordinates from an edge by index.
- Parameters:
edge_idx – Edge index in the AAG (0-based).
- Returns:
Set of (x, y, z) coordinate tuples (rounded to 6 decimals).
- get_face_wires(seed_id: int) tuple#
Get outer and inner wires from a single face.
- Parameters:
seed_id – The seed face index.
- Returns:
Tuple of (outer_wire, list of inner_wires).
- get_forbidden_neighbors(seeds: list[int], outer_edges: set[int]) set[int]#
Get faces adjacent to seeds through outer edges (forbidden for feature).
Based on asiAlgo_RecognizeIsolated lines 140-149.
- Parameters:
seeds – List of seed face indices.
outer_edges – Set of outer edge indices.
- Returns:
Set of forbidden face indices.
- get_inner_wires(seeds: list[int]) list#
Get cached inner wires for the given seeds.
For multi-seed cases, inner wires are the shorter boundary wires (everything except the longest/outer wire).
- Parameters:
seeds – List of seed face indices.
- Returns:
List of inner TopoDS_Wire objects.
- static get_wire_vertices(wire: TopoDS_Wire) set[tuple]#
Extract vertex coordinates from a wire.
- Parameters:
wire – TopoDS_Wire to extract vertices from.
- Returns:
Set of (x, y, z) coordinate tuples (rounded to 6 decimals).
- recognize(seeds: list[int]) set[int] | None#
Recognize isolated feature from seeds.
- Parameters:
seeds – List of seed face indices.
- Returns:
Set of feature face indices, or None if no valid feature.
- class volmdlr_tools.features.extractors.PlanarTrimExtractor(aag: AttributedAdjacencyGraph, tol: float | None = None, name: str = '')#
Bases:
FeatureExtractorExtract the planes that leave the whole part on one side, each with the faces the part has on it.
Every planar face is tested; the faces lying on one such plane make one
PlanarTrim.- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the part.
tol – How far the part may reach past a plane that still leaves it on one side; defaults to 1e-4 of the bounding box diagonal.
name – Name for the extractor instance.
- Raises:
ValueError – If tol is not positive.
- perform() bool#
Find the planar trims, ordered by their lowest face index.
- class volmdlr_tools.features.extractors.RegionDeformationExtractor(sheet_metal: SheetMetalShape, name: str = '')#
Bases:
DeformationExtractorDeformation extractor driving the region-based helper on both sides.
Reuses the wire-based extractor’s pairing plumbing (mutual-nearest matching, gravity centers, feature construction) over region-based candidates.
- MAX_PAIR_FACE_RATIO = 3.0#
- OPENING_FEATURES: ClassVar[dict[str, tuple[type[FlangedCutout], str]]] = {'extrusion_hole': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.ExtrusionHole'>, 'Extrusion Hole'), 'flanged_cutout': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.FlangedCutout'>, 'Flanged Cutout'), 'louvre': (<class 'volmdlr_tools.features.feature_types.sheet_metal.louvres.Louvre'>, 'Louvre')}#
- SHAPE_FEATURES: ClassVar[dict[str, tuple[type[Emboss], str]]] = {'bead': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Bead'>, 'Bead'), 'dimple': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Dimple'>, 'Dimple'), 'emboss': (<class 'volmdlr_tools.features.feature_types.sheet_metal.deformations.Emboss'>, 'Emboss')}#
- perform() bool#
Run region-based extraction on both sides, pair the pooled results, classify per pair.
Emboss-like and cutout-like regions are pooled per side before pairing: the free-boundary class is a per-side observation that the two sides can disagree on (a region may fade into a cutout rim on one side only), and pairing within a class would then silently drop the deformation. The class is decided from the matched pair instead.
A pair whose two sides both touch a free boundary is an opening: an ExtrusionHole or a Louvre when both skins have that shape, a FlangedCutout otherwise, holding the walls of its cut. Any other pair stays inside the sheet: a Dimple or a Bead when both skins have that shape, an Emboss otherwise.
A gusset pressed across a bend is found first, from the pieces it cuts the bend into (see
SheetMetalShape.get_gusset_skins()); its faces count as panel, like the folds (seeRegionDeformationExtractionHelper), so no region reads it, with the flats around it, as an emboss or a flanged cutout.- Returns:
True if any gusset or deformation was found, False otherwise.
- class volmdlr_tools.features.extractors.RevolutionFacesExtractor(aag: AttributedAdjacencyGraph, extract_internal: bool = True, extract_external: bool = True, max_radius: float = inf, max_semi_angle: float = 1.5707963267948966, max_major_radius: float = inf, max_minor_radius: float = inf, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, name: str = '')#
Bases:
FeatureExtractorExtract all revolution surface features (cylinders, cones, tori) from a CAD model.
This extractor combines CylinderExtractor, ConeExtractor, and TorusExtractor to extract all revolution-based features in a single operation. It supports extracting internal, external, or both feature types.
Features are categorized as: - Internal: Bores (cylinders), countersinks (cones), fillets (tori) - External: Bosses (cylinders), chamfers (cones), rounded edges (tori)
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
extract_internal – Whether to extract internal features (default: True).
extract_external – Whether to extract external features (default: True).
max_radius – Maximum radius for cylinder recognition.
max_semi_angle – Maximum semi-angle in radians for cone recognition.
max_major_radius – Maximum major radius for torus recognition.
max_minor_radius – Maximum minor radius for torus recognition.
linear_tolerance – Tolerance for radius and position comparisons.
angular_tolerance – Tolerance for axis direction comparisons (radians).
name – Name for the extractor instance.
- property cones: list[Cone]#
Get all extracted cone features.
- Returns:
List of Cone features (both internal and external if both modes enabled).
- property cylinders: list[Cylinder]#
Get all extracted cylinder features.
- Returns:
List of Cylinder features (both internal and external if both modes enabled).
- property external_features: list[Feature]#
Get all external features (bosses, chamfers, rounded edges).
- Returns:
List of all external features.
- property internal_features: list[Feature]#
Get all internal features (bores, countersinks, fillets).
- Returns:
List of all internal features.
- perform() bool#
Perform the revolution features extraction.
Runs CylinderExtractor, ConeExtractor, and TorusExtractor for each enabled extraction mode (internal and/or external).
- Returns:
True if extraction completed successfully.
- class volmdlr_tools.features.extractors.RibExtractor(aag: AttributedAdjacencyGraph, max_thickness: float | None = None, blend_max_radius: float | None = None, pair_finder: Literal['edge_driven', 'face_pair', 'nearly_planar'] = 'edge_driven', name: str = '')#
Bases:
FeatureExtractorRecognize rib features on a BRep model from its AAG.
A rib is a thin protruding wall: two opposing end faces a thin gap apart, standing on the surrounding part walls and capped by a shell. By default the end-face pairs are found edge-driven (Lai et al. §4.2.1) — see
perform()for the pipeline and__init__for thepair_finderselector.All constructor parameters are documented on
__init__.- property applied_max_thickness: float#
The wall-thickness threshold recognition actually used.
Equal to
max_thickness(or its scale-aware default) unless the default was tightened to the part’s measured wall population — see_tighten_max_thickness(). Report this, notmax_thickness.
- perform() bool#
Recognize ribs and store them in
self._result.End-face pairs come from the finder the constructor flags select — by default
_find_end_face_pairs_edge_driven(), which derives each wall’s two sides from matched parallel boundary edges of a host face and admits nearly-planar sides, not only true planes.For each pair, collect the shell faces that join the two ends through convex edges and the base faces that meet them through concave edges. Pairs that are fragments of the same physical wall (coplanar sides split by the modeller) are then merged into one candidate before each candidate is materialized into a
Rib. A pair with no connecting shell face is not a rib and is dropped.- Returns:
True once recognition has run (idempotent).
- property rib_structures: list[RibStructure]#
Return rib structures: groups of >=2 segments connected at junctions.
- class volmdlr_tools.features.extractors.ShapeIsolatedBossSplitter(shape: Shape, aag: AttributedAdjacencyGraph | None = None, blend_max_radius: float | None = None, boundaries: Literal['inner_wires', 'inner_wires_and_root_blends'] = 'inner_wires', boundary_filter: Callable[[SplitBoundary], bool] | None = None, *, open_junctions: bool = False, loops: LoopRecognition | None = None)#
Bases:
objectSplit a defeatured BRep shape into isolated boss components.
Isolated bosses are protrusions built upon a single base face, isolated into an inner contour of that face. This class splits the part into manifold shapes — one per isolated boss plus the base — without boolean operations.
- Algorithm:
Find seed faces with concave inner wires (boss boundaries).
Remove the concave boundary edges from the AAG to disconnect it.
Register connected components as split sets with parent-child relationships.
Rebuild faces (removing concave inner wires from seeds) and assemble shapes.
With
boundaries="inner_wires_and_root_blends"the boundaries are wider. The loops are not searched for by the splitter: they are read once, with the part’s blends, asPartReading.loopsreads them, and the splitter decides which of them cut off a feature. Pass the reading’s loops as loops to share it with the other readers of the part. Every loop of the part that turns one way, a concave one for a boss and a convex one for a pocket, is a candidate. It may be an inner wire of a face, meet its base tangentially along some of its edges and sharply along others, run over several faces of its base, or be the loop where a ring of blends leaves its base, which cuts off the boss or pocket that ring roots. A loop that is an inner wire of a face cuts off the side without that face, as the default split does, however large that side; one that runs over several faces joined tangentially cuts off a clear minority of the part (seecut_off()). What it cuts off must turn over, as a boss holds something convex and a pocket something concave, and must not be one end of a post joining two bases. Boundaries that overlap only in part are not all kept, the smaller winning, so that features stand apart or nest. Each set then names the kind of feature it is, the faces it hangs from and the blends at its root.With
open_junctions=Truea concave seam that starts and stops is closed across the flat face its ends lie on, and is cut along when what it cuts off turns over, whatever the sizes of the two sides: the smaller is the piece cut off. The face is then really split in two, so the shape and graph the result is numbered against are those of the split part:aagandshapeanswer for them, andface_mapsays which faces of the graph given stand for each face of it.- property aag: AttributedAdjacencyGraph#
The Attributed Adjacency Graph, computed lazily if not provided.
- property blends: Mapping[int, BlendAttribute]#
The blends of the part, by face, as its loops were read with them; empty when cutting along inner wires.
Profile rounds are among them, which the loops themselves leave out of their blends. Faces are numbered as those of
aag.
- property face_map: dict[int, tuple[int, ...]]#
For each face of the graph the splitter was given, the faces of
aagthat stand for it.A face stands for itself, unless it was split along a junction, when two faces stand for it; the faces that were not are numbered as the graph that came after the split numbers them.
- get_extruded_features(split_set: SplitSet, parent_aag: AttributedAdjacencyGraph | None = None) object | None#
Try to classify a boss split set as an extrusion.
Builds a shape from the split set, runs
ExtrusionShapeRecognizer, and returns anExtrusionif confirmed.- Parameters:
split_set – The SplitSet to classify.
parent_aag – AAG of the parent shape (for base node resolution). Defaults to
self.aag.
- Returns:
An Extrusion if confirmed, None otherwise.
- get_shape(split_set: SplitSet) Shape#
Build a shape (shell or solid) from a split set’s faces.
Seed faces have the inner wires the cut ran along removed before assembly, so a base whose features each stand on one of its faces comes back closed. A set cut off is open where it was cut, and so is a base where a feature’s loop runs over several faces joined tangentially, since that loop is no wire of a face.
- Parameters:
split_set – The SplitSet to build a shape for.
- Returns:
The assembled Shape.
- get_shapes() list[Shape] | None#
Get shapes for all split sets.
- Returns:
List of Shape objects (one per split set), or None if shape is not splittable.
- property loops: LoopRecognition#
The closed loops of the part, with its blends, read the first time they are asked for.
A split with root blends as boundaries cuts along them. They are those given, until a face of the part is split along an open junction: they are then those of the part split.
- Raises:
ValueError – When the split is along inner wires alone, which reads no loops.
- merge_into_parent(indices: Iterable[int]) list[SplitSet] | None#
Stop cutting along the boundaries of some sets, which then belong to the sets they were cut from.
The sets the dropped ones contain move up to their nearest remaining parent, and every set is numbered anew. Only a split with root blends as boundaries can be merged.
- Parameters:
indices – Indices, in the current result, of the sets to merge into their parents.
- Returns:
The new result, which
resultnow returns as well;Nonewhen nothing is left to split.- Raises:
ValueError – If the split was made along inner wires alone.
- property open_junctions_cut: int#
How many open junctions the part was cut along, as faces of the part were split to close them.
- perform() None#
Split the shape into isolated boss components.
Populates result and internal wire mapping for shape rebuilding.
- property result: list[SplitSet] | None#
The split sets resulting from the decomposition, or None if shape is not splittable.
- property seam_face_ids: frozenset[int]#
The faces on either side of every seam the part was cut along, blends left out.
A seam between two bodies is concave on both of its sides, and that concavity is not a cut: the faces that meet at it belong to the bodies. They are numbered as the faces of the graph given are, and a face that was split to close a junction stands for both of its halves.
- Raises:
ValueError – If the split was made along inner wires alone.
- class volmdlr_tools.features.extractors.SharpEdgeExtractor(aag: AttributedAdjacencyGraph, name: str = '')#
Bases:
FeatureExtractorExtract sharp edge features from AAG.
A class for recognizing and analyzing sharp edges in a geometric model using an adjacency attribute graph. Sharp edges are identified by analyzing convex angles between adjacent faces along linear edges.
- display_result() dict#
Implementation of a tag for displays.
- get_edges_shapes() list[Edge]#
Return a list containing all identified edges shapes.
- property ids: list[int]#
Return the ids of sharp edges.
- Returns:
Ids of sharp edges.
- perform() None#
Perform sharp edge identification and cache the result.
- property shape: Shape#
Return the shape.
- class volmdlr_tools.features.extractors.SplitAdjacencyExtractor(aag: AttributedAdjacencyGraph, name: str = '')#
Bases:
FeatureExtractorExtract material addition features detected via the split adjacency pattern.
Seed pairs classified as CUT (predominantly convex dihedral angles) are discarded — cuts are handled by
InteractingFeatureExtractor.- Algorithm:
Find seed pairs: faces sharing N >= 2 edges in the AAG.
For each seed pair, remove seeds and find connected components.
Select the N-1 smallest-distance vertex pairs between adjacent common edges (N common edges always yield N-1 features).
Components containing those vertices are features.
Drop features whose angles indicate a cut.
- property failures: tuple[FailedReading, ...]#
The regions the extrusion recognition raised on, each with the faces, the reason and the exception.
The regions are those that stayed an
UnknownFeaturefor that reason: a region that recognition merely does not confirm as an extrusion is not listed, and nor is one that recognition read from its material alone after raising on the region as a whole. Reading them runsperform()when it has not run.
- find_seed_pairs() list[tuple[int, int]]#
Find face pairs exhibiting the split adjacency pattern.
- Returns:
List of (face1_idx, face2_idx) tuples identifying seed pairs.
- perform() bool#
Execute the split adjacency feature extraction and classification.
For each detected ADDITION candidate, run
ExtrusionShapeRecognizeron its shell. Confirmed shapes becomeExtrusion; the rest stay asUnknownFeaturetagged withheuristic_source="split_adjacency"for later study. Both carryseed_nodesso downstream consumers can trace back to the originating split adjacency. A region on which recognition itself failed, and which no recognition of its material read either, is also listed infailures.- Returns:
True if at least one ADDITION feature was detected.
- select_feature_components(components: list[set[int]], seed_pair: tuple[int, int]) list[set[int]]#
Select graph components that represent manufacturing features.
After removing seed faces, the AAG splits into multiple components. A component is a feature when it contains at least one of the feature-marker vertices.
- Parameters:
components – Connected components from the AAG after seed removal.
seed_pair – Tuple of (face1_idx, face2_idx) identifying the seed faces.
- Returns:
List of sets of face indices, each set forming a distinct feature.
- class volmdlr_tools.features.extractors.SplitSet(index: int, face_indices: set[int], seed_face_indices: set[int] = <factory>, parent_index: int | None = None, kind: ~typing.Literal['boss', 'pocket'] | None = None, base_face_ids: frozenset[int] = frozenset({}), root_blend_face_ids: frozenset[int] = frozenset({}), loop_edge_ids: tuple[int, ...] = (), enclosed_face_ids: frozenset[int] = frozenset({}))#
Bases:
objectA connected component resulting from splitting a shape along boss boundaries.
- Parameters:
index – Position in the result list.
face_indices – AAG node indices belonging to this set.
seed_face_indices – Indices of seed faces in this component.
parent_index – Index of the parent SplitSet (None if base/root).
kind –
"boss"or"pocket"for a set cut off along a boundary of a split with root blends as boundaries,Nonefor what remains of the shape once every feature is cut off and for every set of a split along inner wires alone.base_face_ids – The faces of its parent that the set hangs from, empty for a base.
root_blend_face_ids – The blend faces where it leaves its base, empty when it does so along a sharp edge or is a base.
loop_edge_ids – The edges of the loop that cuts it off, empty for a base.
enclosed_face_ids – The faces the loop cuts off, those of the sets it contains included; empty for a base.
- base_face_ids: frozenset[int] = frozenset({})#
- property boundary: SplitBoundary | None#
The boundary that cuts this set off,
Nonefor a base or for any set of a split along inner wires alone.
- enclosed_face_ids: frozenset[int] = frozenset({})#
- face_indices: set[int]#
- index: int#
- property is_base: bool#
Whether this set is a base (has seed faces and no parent).
- property is_boss: bool#
Whether this set is a boss (has a parent).
- kind: Literal['boss', 'pocket'] | None = None#
- loop_edge_ids: tuple[int, ...] = ()#
- parent_index: int | None = None#
- root_blend_face_ids: frozenset[int] = frozenset({})#
- seed_face_indices: set[int]#
- take_boundary(boundary: SplitBoundary) None#
Record the boundary that cuts this set off, which
boundarythen returns.
- class volmdlr_tools.features.extractors.TorusExtractor(aag: AttributedAdjacencyGraph, max_major_radius: float = inf, max_minor_radius: float = inf, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, extraction_mode: ExtractionMode = ExtractionMode.EXTERNAL, name: str = '')#
Bases:
CoaxialFeatureExtractorMixin,FeatureExtractorExtract toroidal features from an Attributed Adjacency Graph (AAG).
This class recognizes tori by identifying toroidal faces and propagating to collect all coaxial toroidal neighbors with the same radii through appropriate edges.
Supports both extraction modes: - EXTERNAL (default): Extract rounded edges, torus protrusions (surface normal points outward).
Propagates through CONVEX/SMOOTH edges.
- INTERNAL: Extract internal fillets (surface normal points inward).
Propagates through CONCAVE/SMOOTH edges.
Key differences from CylinderExtractor: - Surface type: ToroidalSurface - Property matching: Same major AND minor radii (both must match) - Geometry: Has two radii parameters
- Parameters:
aag – The Attributed Adjacency Graph (AAG) representation of the CAD model.
max_major_radius – Maximum major radius for torus recognition.
max_minor_radius – Maximum minor radius for torus recognition.
linear_tolerance – Tolerance for radius and position comparisons.
angular_tolerance – Tolerance for axis direction comparisons (radians).
extraction_mode – Whether to extract EXTERNAL or INTERNAL tori.
name – Name for the extractor instance.
- property extraction_mode: ExtractionMode#
Return the extraction mode (INTERNAL or EXTERNAL).
- get_tori() list[Torus]#
Create Torus objects from extracted face groups.
- Returns:
List of Torus feature objects.
- property ids_tori: list[list[int]]#
Return the face IDs of identified tori.
- Returns:
List of face ID lists, one per torus.
- property surface_type_name: str#
Return the OCP surface type string for tori.