volmdlr_tools.shapes.recognizers package#

Shape recognizers for identifying and abstracting specific shape types.

Submodules#

volmdlr_tools.shapes.recognizers.sheet_metal module#

Module for recognizing sheet metal shapes in a B-Rep CAD model.

This module implements a SheetMetalRecognizer that uses the Attributed Adjacency Graph (AAG) to identify main faces and thickness faces in sheet metal parts. The main strategy is to: 1. Find the face with the greatest area as a seed face 2. Propagate through neighbors with smooth angles to identify the first main face group 3. Find the largest remaining face as the opposite face from the remaining faces 4. Propagate from the opposite face to identify the second main face group 5. Identify remaining faces as thickness faces 6. Validate that removing thickness faces creates two connected components

class volmdlr_tools.shapes.recognizers.sheet_metal.SheetMetalRecognizer(shape: Shell | Solid, aag: AttributedAdjacencyGraph | None = None, name: str = '')#

Bases: DessiaObject

Recognize sheet metal shapes.

This recognizer uses the Attributed Adjacency Graph (AAG) to separate main faces from thickness faces in sheet metal parts. The algorithm works by: 1. Finding the face with the greatest area as a seed face 2. Propagating through neighbors with smooth angles to identify the first main face group 3. Finding the largest remaining face as the opposite face from the remaining faces 4. Propagating from the opposite face to identify the second main face group 5. Identifying remaining faces as thickness faces 6. Validating that removing thickness faces creates two connected components

Responsibility: ONLY classification. All feature extraction is handled by SheetMetalShape.

property main_face_group_1: list[int]#

Get the first main face group (first side of sheet metal).

property main_face_group_2: list[int]#

Get the second main face group (second side of sheet metal).

property main_faces: list[int]#

Get the main faces identified by the recognizer.

property opposite_face_id: int#

Get the opposite face ID found during recognition.

perform() → bool#

Perform the sheet metal recognition.

Returns:

True if the shape can be considered as a sheet metal part, False otherwise.

property refusal_reason: str | None#

Say why the shape is not a sheet metal part.

Returns:

What keeps the shape from being two sides joined by walls, or None when it is a sheet metal part.

property result: SheetMetalShape | None#

Get the recognition result as SheetMetalShape.

This property provides access to the shape abstraction after recognition. Automatically calls perform() if not yet executed.

Returns:

SheetMetalShape if recognized, None otherwise

property seed_face_id: int#

Get the seed face ID used for recognition.

property sheet_metal: SheetMetalShape | None#

Get the sheet metal shape (type-specific alias for result).

Provides better typing and IDE support compared to generic ‘result’ property.

Returns:

SheetMetalShape if recognized, None otherwise

property thickness_faces: list[int]#

Get the thickness faces identified by the recognizer.

volmdlr_tools.shapes.recognizers.swept_shape module#

A dedicated module for pipe recognition from a BRep model.

class volmdlr_tools.shapes.recognizers.swept_shape.SweptShapeRecognizer(shape: Shell | Solid, aag: AttributedAdjacencyGraph | None = None, name: str = '')#

Bases: DessiaObject

A class to identify if a BRep model is a Swept face.

A Swept shape has a face that defines it start and end. A Swept shape should be smooth (The neutral fiber has C1 continuity).

A round pipe that carries parts of its own at its ends, such as flanges with holes, chamfers at the bore mouth and blends where the tube meets a flange, is no longer a body that is only a sweep. It is read from the chain of cylinders and tori that wall the tube (see recognise_pipes()), and what stands across its ends is left out of the sweep: pipe holds the pipe, and the neutral fiber and the radii answer for it.

flange_face(flange: PipeFlange) → Face#

Return the face a plate is drawn on: its cap, less the opening the pipe’s bore makes in it.

Parameters:

flange – A plate from flanges().

flanges(pipe: Pipe) → tuple[list[PipeFlange], list[PipeRefusal]]#

Return the plate across each end of a pipe of this shape, and the ends whose cap stands on none, with why.

Parameters:

pipe – A pipe from pipes.

get_radius() → dict#

Calculate the radius of the swept shape based on its contours.

This method returns the radius of the outer and inner contours of the section If the contour contains an Arc2D or FullArc2D primitive, return its radius directly.

Returns:

A dictionary with two keys: - “outer_contour”: The radius of the outer contour if it is round, or None if not applicable. - “inner_contours”: A list containing the radii of the inner contours, where each radius is

either a float (if the contour is round) or None (if the contour is not round or could not be fit).

property neutral_fiber: Wire3D#

Get the neutral fiber of the sweep.

perform() → bool#

Perform the recognition.

Returns:

Return True if the shape can be considered as a swept shape and False otherwise.

property pipe: Pipe | None#

The round pipe the shape is read as, when its ends carry parts of their own; None otherwise.

property pipes: tuple[list[Pipe], list[PipeRefusal]]#

Every round pipe the faces of the shape show, with the bends that could not be read as one and why.

This reads the faces alone and does not need the adjacency graph.

Raises:

ShapeTypeError – If the shape is not one solid, alone or as the only thing in a compound.

property section: Face3D#

Get the transversal section of the sweep; for a pipe, the ring of its tube where its spine begins.

Raises:

ValueError – When the shape is neither a sweep nor a pipe.

volmdlr_tools.shapes.recognizers.gear module#

class volmdlr_tools.shapes.recognizers.gear.GearShapeRecognizer(shape: Shell | Solid, aag: AttributedAdjacencyGraph | None = None, linear_tolerance: float | None = None, name: str = '')#

Bases: DessiaObject

Recognize spur and helical gears, external and internal.

Parameters:
  • shape – The part to analyze.

  • aag – Optional pre-computed AttributedAdjacencyGraph.

  • linear_tolerance – Tolerance on lengths; defaults to a small share of the part’s size.

  • name – Optional name.

perform() → bool#

Perform gear recognition.

Returns:

True if the part is a gear, False otherwise.

property refusal: NotAGear | None#

Get why the part is not a gear.

Returns:

The refusal, or None when the part is a gear.

property result: GearShape | None#

Get the recognised gear.

Returns:

The GearShape, or None when the part is not a gear.

class volmdlr_tools.shapes.recognizers.gear.NotAGear(reason: str, face_ids: tuple[int, ...] = (), area: float | None = None, reader: str = '')#

Bases: FaceRefusal

Why a part is not read as a gear.

Parameters:

reason – What keeps the part from being a ring of identical teeth with mirrored flanks.

volmdlr_tools.shapes.recognizers.revolved module#

class volmdlr_tools.shapes.recognizers.revolved.RevolvedShapeRecognizer(shape: Solid, aag: AttributedAdjacencyGraph | None = None, min_revolved_face_ratio: float = 0.5, min_revolved_area_ratio: float = 0.5, require_external_features: bool = True, linear_tolerance: float = 0.0001, angular_tolerance: float = 0.0175, max_uncovered_arc: float = 2.0943951023931953, name: str = '', mask: tuple[int, ...] | None = None)#

Bases: DessiaObject

Recognize revolution/lathe shapes.

A revolution shape is characterized by surfaces of revolution (cylinders, cones, tori) that all share a common axis. This recognizer: 1. Extracts all revolution features using RevolutionFacesExtractor 2. Validates that external features are coaxial 3. Classifies remaining faces (end caps, transitions) 4. Returns a RevolvedShape if the shape qualifies

Parameters:
  • shape – The solid to analyze. A shell, or a compound of several solids, is not read as turned: perform() answers False.

  • aag – Optional pre-computed AttributedAdjacencyGraph.

  • min_revolved_face_ratio – Minimum ratio of faces that must be revolution surfaces (0.0 to 1.0). Judges only a part whose faces outside the skin are not all features standing on it.

  • min_revolved_area_ratio – Minimum ratio of surface area that must be coaxial revolution surface. Used as a fallback gate when the face-count ratio misses, so revolution-dominant parts whose face count is inflated by thin non-revolved features (such as spokes) are not rejected (0.0 to 1.0).

  • require_external_features – If True, at least one external revolution feature is required.

  • linear_tolerance – Tolerance for axis position comparison.

  • angular_tolerance – Tolerance for axis direction comparison (radians).

  • max_uncovered_arc – Largest gap (radians) a set of co-surface arcs may leave around the axis, as the turn the part is read about reads their gap, and still count as a single revolved band.

  • name – Optional name.

  • mask – Faces to leave out when the part is read as turned (see turned_part) — the faces of the features proposed on it — which are then neither its skin, nor its features, nor left unexplained. None reads every face.

property common_axis: gp_Ax1 | None#

Get the common axis of revolution.

Returns:

The gp_Ax1 axis or None if not a revolution shape.

property external_features: list[Feature]#

Get the external revolution features.

Returns:

List of external features (bosses, chamfers, rounded edges).

property internal_features: list[Feature]#

Get the coaxial internal revolution features.

These are internal features that share the main revolution axis (e.g., center bores, countersinks on axis).

Returns:

List of coaxial internal features.

perform() → bool#

Perform revolution shape recognition.

The part is read about the first of its turns, the one turning the most of its wall first, that the revolution features found on it stand on. A shape no reading can be made of, a shell or several solids, and a part with no turn answer False.

Returns:

True if shape is a valid revolution part, False otherwise.

property result: RevolvedShape | None#

Get the recognition result as RevolvedShape.

Automatically calls perform() if not yet executed.

Returns:

RevolvedShape if recognized, None otherwise.

property secondary_cones: list[Cone]#

Get non-coaxial conical features.

Returns:

List of non-coaxial internal cones.

property secondary_cylinders: list[Cylinder]#

Get non-coaxial cylindrical features (radial holes, cross-drilled holes).

Returns:

List of non-coaxial internal cylinders.

property secondary_tori: list[Torus]#

Get non-coaxial toroidal features.

Returns:

List of non-coaxial internal tori.

property turned_hypothesis: int | None#

Get the turn the part is read as turned about, as a position in technique_fits.hypotheses.

Returns:

The position of the revolution hypothesis, or None when the part is not read as turned.

property turned_part: TurnedPart | None#

Get the part read as a profile turned about its axis with features standing on it.

The reading is available whether or not the part is recognised: its refusals say which groups of faces are not features, and why. It does not depend on perform().

Returns:

The reading, or None when no axis is shared by enough faces to read it about, or when the part is not read at all (see turned_refusal).

property turned_refusal: FaceRefusal | None#

Get why the part was not read as a profile turned about an axis at all, when it was not.

Returns:

The faces that stopped the reading and why, or None when the part was read or has no axis.

use_reading(reading: PartReading, fits: TechniqueFits | None = None) → None#

Read the part as turned from a reading of it made by the caller, instead of making one.

The axes the part is read about are those of its technique fits, so a caller that has read them already hands them in and they are not read again.

Parameters:
  • reading – The reading of this recognizer’s shape.

  • fits – How the faces of the part fit each way it may have been built; read from reading when omitted.

Raises:

ValueError – When the part has been read already, by perform() or as turned; when reading is not a reading of this recognizer’s shape; or when fits does not cover the faces of reading.

Module contents#

Shape recognizers.