Swept Shapes#

Recognize swept profiles (pipes, tubes, extruded channels) from BRep models.

Note

Prerequisites: Attributed Adjacency Graph (AAG)

Tip

Tutorial Data File: cable.step

Cable model used in this tutorial

Swept Shape Recognition#

This module identifies swept shapes (extruded profiles) from BRep models. It recognizes pipes, tubes, and other shapes formed by sweeping a cross-section along a path.


Overview#

A swept shape is characterized by:

  • Extremity faces: The start and end faces of the sweep

  • Neutral fiber: The centerline path along which the profile was swept

  • Section: The cross-sectional profile perpendicular to the sweep path

  • Smoothness: The neutral fiber has C1 continuity (no sharp corners)

Common examples:

  • Circular pipes and tubes

  • Extruded profiles (channels, I-beams)

  • Cable routing paths

  • Duct sections


Quick Start#

from volmdlr.model import VolumeModel
from volmdlr_tools.shapes.recognizers import SweptShapeRecognizer

# Load a STEP file
volume_model = VolumeModel.from_step("data/step/cable.step")
shape = volume_model.primitives[0]

# Recognize swept shape
recognizer = SweptShapeRecognizer(shape=shape)

if recognizer.perform():
    # Get sweep properties
    neutral_fiber = recognizer.neutral_fiber
    section = recognizer.section
    radius_info = recognizer.get_radius()

    print(f"Neutral fiber length: {neutral_fiber.length()}")
    print(f"Outer radius: {radius_info['outer_contour']}")
else:
    print("Not a valid swept shape")

Core Class: SweptShapeRecognizer#

The main entry point for swept shape recognition. It analyzes a BRep shape to determine if it’s a swept profile and extracts its geometric properties.

Constructor#

SweptShapeRecognizer(
    shape: Union[shapes.Shell, shapes.Solid],
    aag: Optional[AttributedAdjacencyGraph] = None,
    name: str = ""
)

Parameters:

  • shape: The BRep shape to analyze (Shell or Solid)

  • aag: (Optional) Pre-computed AttributedAdjacencyGraph

  • name: (Optional) Name for the recognizer instance

Methods#

perform() -> bool#

Execute the recognition algorithm.

recognizer = SweptShapeRecognizer(shape=my_shape)
is_swept = recognizer.perform()

Returns: True if the shape is a valid swept shape, False otherwise.

Only a shape that is one solid, alone or as the only thing in a compound, is read as a round pipe: on any other shape, such as a shell, perform() answers from the swept-profile reading alone, and pipes, flanges() and flange_face() raise ShapeTypeError.

get_radius() -> dict#

Get the radius information for circular sweeps.

radius_info = recognizer.get_radius()
print(f"Outer radius: {radius_info['outer_contour']}")
print(f"Inner radii: {radius_info['inner_contours']}")

Returns: Dictionary with keys:

  • outer_contour: Radius of outer contour (or None if not circular)

  • inner_contours: List of radii for inner contours (holes)

Properties#

Property

Type

Description

neutral_fiber

Wire3D

The centerline path of the sweep

section

Face3D

The cross-sectional profile; for a pipe, the ring of its tube where its spine begins. Raises ValueError when the shape is neither a sweep nor a pipe

pipe

Pipe or None

The round pipe the shape is read as, when its ends carry parts of their own (see below)

pipes

(list[Pipe], list[PipeRefusal])

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

shape

Shell/Solid

The input BRep shape

aag

AttributedAdjacencyGraph

The face adjacency graph

Pipes#

A round pipe that carries parts of its own at its ends, such as flanges with holes, chamfers at the bore mouth or blends where the tube meets a flange, is not a body that is only a sweep. SweptShapeRecognizer reads it instead from the faces that wall the tube: one spine of straight legs joined by circular bends, lying in one plane, and a round section carried along it. The faces standing across its ends are left out of the sweep.

perform() returns True for such a shape when its faces show exactly one pipe. pipe then holds it, and the other answers speak for the tube: neutral_fiber is the spine as lines and arcs, section is the ring of the tube (its outside less its bore) where the spine begins, square to the first leg, and get_radius() gives the outside radius and the bore.

A pipe read as a spine of legs and bends with a flange at one end

How a pipe is read: the outside of the tube is its skin faces (blue), the bore its bore faces (purple), the spine runs as dashed legs and a circular bend (magenta) from the cap at the start to the cap at the end, and the plate across the end is a flange (orange), left out of the pipe.

A Pipe gives:

Attribute

Description

start / end

Where the spine begins and ends, at the planar faces that close its two legs

bends

The bends from the start to the end, as PipeBends (centre, axis, radius of the centreline, and the start, mid and end points of the arc)

skin_radius / bore_radius

The radius of the outside of the tube, and of its bore (None for a solid tube)

skin_faces / bore_faces / faces

The faces of the part that wall the outside, the bore, and both

caps

The planar faces the two end legs run out to, at the start and at the end

pipes reads every pipe of the shape from its faces alone, without the adjacency graph, so it also answers for a shape that holds several. For each pipe, two more calls read what stands across its ends:

  • flanges(pipe) returns the plate across each end that has one, as a PipeFlange, and the ends whose cap stands on no plate, as PipeRefusals with the reason. A PipeFlange gives its cap (the plate’s outer face), its underside, its thickness, the normal out of the material at the cap, the centre where the spine meets the cap, the walls round the plate and the hole_walls of its holes other than the pipe’s bore.

  • flange_face(flange) returns the face the plate is drawn on: its cap, keeping its outline and its holes, less the opening the pipe’s bore makes in it.

A pipe must be round, with straight legs and circular bends in one plane; a tube bent along a free-form path is not read as a pipe. The cable of this page is such a tube: its walls are free-form surfaces, so it shows no pipe and is read as a sweep.

from volmdlr.model import VolumeModel
from volmdlr_tools.shapes.recognizers import SweptShapeRecognizer

shape = VolumeModel.from_step("data/step/cable.step").primitives[0]
recognizer = SweptShapeRecognizer(shape=shape)
pipes, refusals = recognizer.pipes
print(len(pipes), len(refusals), recognizer.pipe)
# 0 0 None

On a part that holds pipes, each one leads to its plates:

for pipe in pipes:
    print(len(pipe.bends), pipe.skin_radius, pipe.bore_radius)
    flanges, bare_ends = recognizer.flanges(pipe)
    for flange in flanges:
        print(flange.thickness, len(flange.hole_walls))
        sketch_face = recognizer.flange_face(flange)
for refusal in refusals:
    print(refusal.reason, refusal.face_ids)

Pipes from a part reading#

The same pipes and plates can be read straight off the part’s PartReading, the one reading of a part every reverse-engineering technique takes, without a SweptShapeRecognizer. In volmdlr_tools.reverse_engineering.techniques.pipe:

  • recognise_pipes(reading) returns every pipe the faces show, and the bends that could not be read as part of one, as PipeRefusals;

  • recognise_flanges(reading, pipe) returns the plate across each end of a pipe that has one, and the ends whose cap stands on no plate, with the reason;

  • flange_profile(reading, flange) returns the face the plate is drawn on, less the opening the pipe’s bore makes in it.

They give the same Pipe, PipeFlange and PipeRefusal as pipes, flanges() and flange_face() above.

The elbow below is a tube of radius 6 with a bore of radius 4.5. It drops 25 along Z, turns through a bend of radius 15, and runs 25 along X. Across its top end stands a round plate of radius 16, 4 thick, with two holes of radius 2, 11 either side of its centre (download flanged_elbow.step, in millimetres):

from volmdlr.model import VolumeModel

from volmdlr_tools.features.part_reading import PartReading
from volmdlr_tools.reverse_engineering.techniques.pipe import flange_profile, recognise_flanges, recognise_pipes

solid = VolumeModel.from_step("flanged_elbow.step", reading_unit="MM").primitives[0]
reading = PartReading(solid)
(pipe,), refusals = recognise_pipes(reading)
print(len(pipe.bends), pipe.bends[0].radius, pipe.skin_radius, pipe.bore_radius, refusals)
# 1 15.0 6.0 4.5 []
print(sorted(pipe.skin_faces), sorted(pipe.bore_faces), pipe.caps)
# [4, 7, 9] [6, 8, 10] (2, 11)

(flange,), bare_ends = recognise_flanges(reading, pipe)
print(flange.cap, flange.thickness, flange.centre, sorted(flange.hole_walls))
# 2 4.0 (0.0, 0.0, 40.0) [3, 5]
print(bare_ends[0].reason)
# the walls round the cap meet 0 planes under it, not one
print(round(flange_profile(reading, flange).area(), 2))
# 779.11

An elbow with a plate across one end, read from its part reading

The skin of the tube in blue, its bore in purple, and the plate across its top end in orange: its cap, its underside, its rim and its two holes. The bare end of the tube stays grey.

The tube is read as one leg, one bend and one leg, its skin and its bore three faces each. The plate across the top end is 4 thick, and holds two holes besides the bore. The bottom end is bare: its cap is the tube’s own end, which stands on no plate, so it comes back as a refusal. The plate is drawn as the disc of radius 16 less its two holes.


Recognition Algorithm#

The recognition process:

  1. Find extremity candidates: Identify planar or BSpline faces that could be sweep endpoints

    • Faces with only convex neighbors

    • At most 1-2 smooth angles depending on neighbor count

  2. Validate extremities: Group candidates into two coplanar groups (start and end faces)

  3. Find shortest path: Compute the graph path between extremity faces

    • Uses the AAG to find the path through adjacent faces

    • Path represents the sweep body faces

  4. Validate path: Verify the path represents a valid sweep

    • All intermediate faces should be smooth-connected

    • Path should be continuous

  5. Extract properties: Compute neutral fiber and section from validated path


Examples#

Basic Pipe Recognition#

from volmdlr.model import VolumeModel
from volmdlr_tools.shapes.recognizers import SweptShapeRecognizer

# Load pipe model
volume_model = VolumeModel.from_step("data/step/cable.step")
pipe_shape = volume_model.primitives[0]

# Recognize
recognizer = SweptShapeRecognizer(shape=pipe_shape)

if recognizer.perform():
    # Get neutral fiber (centerline)
    centerline = recognizer.neutral_fiber
    print(f"Pipe length: {centerline.length():.2f} mm")

    # Get cross-section
    section = recognizer.section
    print(f"Section area: {section.area():.2f} mm²")

    # Get radius for circular pipes
    radii = recognizer.get_radius()
    if radii['outer_contour']:
        outer_r = radii['outer_contour']
        inner_r = radii['inner_contours'][0] if radii['inner_contours'] else 0
        wall_thickness = outer_r - inner_r
        print(f"Wall thickness: {wall_thickness:.2f} mm")

Visualizing Results#

from volmdlr.model import VolumeModel

# After recognition
neutral_fiber = recognizer.neutral_fiber
section = recognizer.section

# Create visualization primitives
prims = [pipe_shape]

if neutral_fiber:
    # Display neutral fiber as colored wire
    neutral_fiber.color = (1.0, 0.0, 0.0)  # Red
    prims.append(neutral_fiber)

if section:
    # Display section face
    section.color = (0.0, 1.0, 0.0)  # Green
    prims.append(section)

VolumeModel(prims).babylonjs()

Working with Non-Circular Sections#

# For non-circular extruded profiles
recognizer = SweptShapeRecognizer(shape=channel_shape)

if recognizer.perform():
    section = recognizer.section

    # Get section contour
    outer_contour = section.surface2d.outer_contour

    # Analyze contour geometry
    print(f"Contour perimeter: {outer_contour.length()}")
    print(f"Number of edges: {len(outer_contour.primitives)}")

    # Check for holes
    inner_contours = section.surface2d.inner_contours
    print(f"Number of holes: {len(inner_contours)}")

Use Cases#

Pipe Routing Analysis#

def analyze_pipe_routing(shapes):
    """Analyze a collection of pipes for routing information."""
    pipe_data = []

    for shape in shapes:
        recognizer = SweptShapeRecognizer(shape=shape)
        if recognizer.perform():
            fiber = recognizer.neutral_fiber
            radii = recognizer.get_radius()

            pipe_data.append({
                'length': fiber.length(),
                'outer_radius': radii['outer_contour'],
                'start_point': fiber.primitives[0].start,
                'end_point': fiber.primitives[-1].end,
            })

    return pipe_data

Cable Tray Identification#

def is_cable_tray(shape):
    """Check if a shape is a cable tray (open channel profile)."""
    recognizer = SweptShapeRecognizer(shape=shape)

    if not recognizer.perform():
        return False

    section = recognizer.section
    if section is None:
        return False

    # Cable trays typically have U-shaped open profiles
    # Check if section has no inner contours (not a closed tube)
    inner_contours = section.surface2d.inner_contours
    return len(inner_contours) == 0

Limitations#

  • Works best with smooth sweeps (C1 continuous neutral fiber)

  • Extremity faces must be planar or BSpline surfaces

  • Complex multi-branch sweeps are not supported

  • Very short sweeps (fewer than 3 faces) may have limited property extraction


See Also#

See Also#