Sweeps, Channels and Lofts#

Read the profiles a part carries along a path, round a closed outline in a plane or along a helix, and the surfaces it draws through outlines on parallel planes.

Sweeps, Channels and Lofts#

Not every part is made of straight extrusions and revolutions. A bent bar is a profile carried round a bend, a gasket is a profile carried once round a closed outline, a seal groove is the same profile cut into a plate, a spring is a profile carried along a helix, and a duct that turns from round to square is a surface drawn through two outlines. Each of these leaves its own mark on the part’s faces, and each has its own technique to read it back:

Technique

Reads

Returns

recognise_sweeps

A profile carried along a path that turns, from one flat end face to another

Sweeps, and the end faces it refused

recognise_planar_sweep

A whole part that is a profile carried once round a closed path in one plane

A PlanarSweep, or None

recognise_channels

A groove cut once round a closed path in one plane

ChannelSweeps

recognise_helical_sweeps

A profile carried along a helix, as the wire of a coil spring

HelicalSweeps, and the bands it refused

recognise_lofts

A band of free-form faces drawn through outlines on parallel planes

Lofts, and the bands it refused

Each lives in its own module of volmdlr_tools.reverse_engineering.techniques: sweep, planar_sweep, channel_sweep, helical_sweep and loft. Each takes the part’s PartReading, the one reading of the part every technique shares, and numbers faces the way the part’s adjacency graph does.

A whole part made by sweeping one round section along a path, such as a pipe, is read by SweptShapeRecognizer instead (see Swept Shapes). The region of a mixed part that a sweep makes is found by technique_domains.


Quick Start#

A 4 by 2 bar carried round a quarter turn of radius 20, then 10 straight on (download bent_bar.step, in millimetres):

from volmdlr.model import VolumeModel

from volmdlr_tools.features.part_reading import PartReading
from volmdlr_tools.reverse_engineering.techniques.sweep import cap_outline, fit_planar_path, recognise_sweeps

solid = VolumeModel.from_step("bent_bar.step", reading_unit="MM").primitives[0]
reading = PartReading(solid)
(bent,), refusals = recognise_sweeps(reading)
print(bent.caps, bent.constant, round(bent.length, 2))
# (6, 7) True 41.41
chain = fit_planar_path(bent)
print([(piece.kind, round(piece.length, 2)) for piece in chain.primitives], round(chain.primitives[0].radius, 2))
# [('arc', 31.41), ('line', 10.0)] 20.0
profile = cap_outline(reading, bent.caps[0], (0.0, 1.0, 0.0))
print([piece.kind for piece in profile.primitives], round(abs(profile.signed_area), 2))
# ['line', 'line', 'line', 'line'] 8.0

The bar is one sweep from face 6 to face 7, its profile the same all along the path. The path is an arc of radius 20 followed by a line of 10, and the profile, read on the first end face, is the 4 by 2 rectangle.

The bent bar read as one sweep: its two end faces in amber, the faces its profile cuts in blue

The bent bar: the two end faces the sweep runs between are amber, the side faces its profile cuts are blue.


Sweeps along a path#

recognise_sweeps(reading) tries every flat face of the part with a single outline as an end of a sweep, a cap. From each cap it follows the path the profile takes, cutting the part square to the path step after step, until the path lands square on a second cap. A path that does not turn is an extrusion or, under a changing profile, a loft; neither is read here. Every cap that is not the end of a sweep is returned with the reason, so the bar above also says why its flat sides are not the ends of a sweep:

for refusal in refusals:
    print(refusal.face, refusal.reason)
# 1 the path does not turn: an extrusion
# 3 the path does not turn: an extrusion
# 4 the path turns abruptly
# 5 the face is not the whole profile just inside it: no sweep ends on it

A refusal whose straight is True marks a path that does not turn: read that part of the body with straight prisms or as a loft.

Sweep member

Description

caps

The two flat faces the sweep starts and ends on, in that order

faces

The faces the sweep accounts for: the caps and the side faces its profile cuts

stations

The profile at points along the path, first to last: each Station holds its arc_length, point (the profile’s area centre), tangent, area and perimeter

constant

Whether the profile is the same all along the path

section_lengths

Where along the path the profile is drawn: the two ends, and where the profile comes to rest in between; just (0.0,) for a constant profile

length

Length of the path

points / tangents

The stations’ points and path directions as arrays

The path is read by one of two functions:

  • fit_planar_path(sweep) returns a PlanarPath when the path lies in a plane and a short chain of lines and arcs, each tangent to the one before, holds to it: its frame stands at the path’s start and its primitives are the pieces in that frame. It returns None otherwise.

  • fit_spline_path(sweep) returns a SplinePath, a smooth curve through a few points that leaves along start_tangent and arrives along end_tangent, with the deviation of the stations from it.

cap_outline(reading, face, x_dir) reads a cap’s outline as lines and arcs, and section_at(reading, origin, tangent, x_dir) the profile anywhere along the path. recognise_sweeps also takes max_cuts, how many cuts the search may make in all, and deadline, a moment on time.perf_counter() past which the caps left are refused as out of time.

A profile that changes along a curve#

A handle drawn through seven sections, evenly spread along a curve that runs from (-10, 0, 0) through (0, 0, 5) to (10, 0, 0), leaving straight up and arriving straight down, each end direction weighted 1.5: a circle of radius 1 at each end, and a 1.25 by 3 rectangle with corners rounded to 0.2 at the five sections in between (download handle.step, in millimetres).

from volmdlr_tools.reverse_engineering.techniques.sweep import fit_spline_path

solid = VolumeModel.from_step("handle.step", reading_unit="MM").primitives[0]
(grip,), _ = recognise_sweeps(PartReading(solid))
print(grip.caps, grip.constant, [round(length, 2) for length in grip.section_lengths])
# (9, 10) False [0.0, 3.51, 22.82, 25.92]
print(fit_planar_path(grip))
# None
curve = fit_spline_path(grip)
print([tuple(round(c, 3) + 0.0 for c in point) for point in curve.points], curve.scalars)
# [(-10.0, 0.0, 0.0), (0.0, 0.0, 5.0), (10.0, 0.0, 0.0)] (1.5, 1.5)

The profile changes, so it is drawn at four places: the circle at each end, and the rounded rectangle where it comes to rest, 3.51 along the path, and where it leaves it, 22.82 along. The path is no chain of lines and arcs; it is read as a curve through the three points it was drawn through.

The handle read as a sweep whose profile changes, seen from below

The handle from below: its two round end faces are amber, the side faces its profile cuts are blue.


A closed sweep in a plane#

A gasket, a seal or a ring is a profile carried once round a closed path that lies in one plane. Cut by that plane, it shows two outlines that are offsets of each other. recognise_planar_sweep(reading) reads the path as the outline midway between them, and the profile from a plane standing on the path. It checks that the same profile is found at four places along the path at least, and returns None when the part is not such a sweep.

Here a 3 by 2 profile, its corners rounded to 0.5, is carried round a slot-shaped path in the XY plane: two straights of 30 joined by half circles of radius 10 (download gasket.step, in millimetres).

from volmdlr_tools.reverse_engineering.techniques.planar_sweep import recognise_planar_sweep

solid = VolumeModel.from_step("gasket.step", reading_unit="MM").primitives[0]
ring = recognise_planar_sweep(PartReading(solid))
print([piece.kind for piece in ring.path.primitives], round(ring.path_length, 2))
# ['arc', 'line', 'arc', 'line'] 122.83
print([piece.kind for piece in ring.profile.primitives], round(ring.profile_area, 3), round(ring.wall_offset, 2))
# ['arc', 'line', 'arc', 'line', 'arc', 'line', 'arc', 'line'] 5.785 3.0
print(ring.interruptions)
# ()

The path is 60 + 20π long, and the profile is the rounded rectangle, 3 across the wall. A tab or a boss standing on the wall shows as outline with no partner across it: it is reported in interruptions, and the profile is read away from it. A tube and a torus are read too, as a rectangle and a circle carried round a circle, though they are just as well revolutions.

PlanarSweep member

Description

plane_frame

The plane of the path; its third axis is the normal the path runs counter-clockwise about

path / path_length

The path, as lines and arcs in plane_frame, and its length

profile / profile_area

The profile, as lines and arcs in station_frame, and its area

station_frame / station_parameter

The plane standing on the path where the profile was read, and how far along the path it stands

path_start_frame()

The plane standing on the start of the path, in which the same profile holds

wall_offset

The distance between the two outlines, across the wall

interruptions

Pieces of outline that have no partner across the wall

invariance_deviation / stations_checked

How far the profiles read along the path differ from one another, and at how many places they were read

path_edge_tuples() / profile_edge_tuples()

The path and the profile as sketch edges


A channel round a closed path#

A seal groove or a cooling channel is the same sweep taken out of a part. Cut across the channel, the part shows an outer wall and, inside it, an island of material, offsets of each other seen from the groove. recognise_channels(reading, direction) cuts the part by planes square to direction, reads the path midway between the wall and the island, and reads the profile as the notch a plane standing on the path cuts in the part, between the two flat stretches of land on either side. Every channel the planes cross is returned, once each. A raised ring is no channel, and neither is a void sealed inside the part, which the plane standing on the path cuts as a hole and not as a notch.

Here the same slot-shaped path carries a groove 2 wide and 4 deep, its floor corners rounded to 0.5, into the top of a 70 by 40 plate 10 thick (download grooved_plate.step, in millimetres):

from volmdlr_tools.reverse_engineering.techniques.channel_sweep import recognise_channels

solid = VolumeModel.from_step("grooved_plate.step", reading_unit="MM").primitives[0]
(seal,) = recognise_channels(PartReading(solid), (0, 0, 1))
print(round(seal.width, 2), round(seal.depth, 2), round(seal.path_length, 2), round(seal.profile_area, 3))
# 2.0 4.0 122.83 7.893
print([piece.kind for piece in seal.walls], seal.plane_frame.w.z, len(seal.face_ids))
# ['line', 'arc', 'line', 'arc', 'line'] 1.0 17

The groove’s walls, its rounded floor corners and its floor are one chain of five pieces, and the channel opens upwards, along +Z. Its 17 faces are those of the groove; the plate keeps the rest.

A gasket and a seal groove, each a profile carried round a closed path

Left, the gasket: every face of it is the sweep, in blue. Right, the plate: the faces the channel reports, its walls, rounded corners and floor, are blue.

ChannelSweep member

Description

plane_frame

The plane of the path; its third axis points out of the channel’s open side

path / path_length

The path, as lines and arcs in plane_frame, and its length

profile / profile_area

The groove’s cross section, closed across its open side, in station_frame, and its area

mouth_index / walls

Which piece of profile closes it across the open side, and the other pieces: walls, blends and floor

width

The distance between the two walls, halfway down

floor_height / mouth_height / depth

Heights of the floor and of the land along the plane’s third axis, and the distance between them

station_frame / station_parameter

The plane standing on the path where the profile was read, and how far along the path it stands

face_ids

The faces that bound the channel

interruptions

Pieces of outline with no partner across the channel, a slot through a wall for instance

deviation / stations_checked

How far the profiles read along the path differ from one another, and at how many places they were read

recognise_channels also takes tol, the fitting tolerance of the cuts, and levels, the distances along direction at which to cut; by default it cuts once between each pair of heights where flat faces stand.


Helical sweeps#

A profile carried along a helix, as the wire of a coil spring is, makes a body that one screw motion, a turn about an axis together with an advance along it, carries onto itself. recognise_helical_sweeps(reading) looks for a band of curved faces joined to the rest of the part by exactly two flat end faces, reads the one screw motion that slides every face of the band along itself, and checks that the helix it draws runs square from one end face to the other. A body that more than one motion carries onto itself, a cylinder or a straight bar, is refused, and so is a profile that twists as it goes round.

A circle of radius 0.8 carried two and a half turns round a helix of radius 5 and pitch 4 (download coil_spring.step, in millimetres), and a plain cylinder of radius 3 and height 10 (download cylinder.step):

from volmdlr_tools.reverse_engineering.techniques.helical_sweep import recognise_helical_sweeps

spring = VolumeModel.from_step("coil_spring.step", reading_unit="MM").primitives[0]
(coil,), refusals = recognise_helical_sweeps(PartReading(spring))
print(coil.caps, round(coil.pitch, 3), round(coil.height, 3), round(coil.radius, 3), round(coil.turns, 3))
# (1, 2) 4.0 10.0 5.0 2.5
print(tuple(round(c, 6) + 0.0 for c in coil.axis), coil.lefthand, refusals)
# (0.0, 0.0, 1.0) False []

cylinder = VolumeModel.from_step("cylinder.step", reading_unit="MM").primitives[0]
_, refusals = recognise_helical_sweeps(PartReading(cylinder))
print(refusals[0].reason)
# the faces between the caps are carried onto themselves by more than one motion

A coil spring read as a helical sweep

The spring’s two end faces are amber; the face carried along the helix between them is blue.

HelicalSweep member

Description

caps

The two flat end faces, the one the helix starts on first

faces

The faces the sweep accounts for: the end faces and the faces between them

axis / axis_origin

The helix’s axis, pointing the way it advances, and the point of the axis level with its start

start / end

Where the helix starts and ends: the centres of the two end faces

radius / pitch / height

Distance of the helix from its axis, its advance in one turn, and its advance from start to end

turns

How many turns the helix makes

lefthand

Whether the helix turns clockwise seen with its axis pointing at the viewer

slide

How far, at worst, the motion leaves the faces, as the sine of an angle


Lofts#

A loft is a surface drawn through outlines that lie on parallel planes. recognise_lofts(reading) takes each band of free-form faces of the part and reads the outlines it ends on as its sections, ordered along the planes’ normal. A section is read as lines and arcs. The sections are where the band’s surfaces end, not only the edges of the part: a loft grown on another body keeps its whole surface, and its first section may lie inside that body. A band whose ends do not lie on parallel planes, or whose sections are not lines and arcs, is refused with the reason.

A neck lofted from a circle of radius 25 on the bottom of an 80 by 80 by 10 block up to a 16 by 10 rectangle, 45 above it (download lofted_neck.step, in millimetres):

from volmdlr_tools.reverse_engineering.techniques.loft import recognise_loft_wall, recognise_lofts, resampled

solid = VolumeModel.from_step("lofted_neck.step", reading_unit="MM").primitives[0]
(neck,), refusals = recognise_lofts(PartReading(solid))
print(tuple(round(c, 6) + 0.0 for c in neck.direction), sorted(neck.faces), sorted(neck.caps), neck.ruled, neck.void)
# (0.0, 0.0, 1.0) [6, 7, 8, 9, 10] [11] True False
for section in neck.sections:
    loop = section.loop
    print(round(section.level, 2), [piece.kind for piece in loop.primitives], round(abs(loop.signed_area), 2))
# -5.0 ['arc'] 1963.5
# 40.0 ['line', 'line', 'line', 'line'] 160.0

The neck’s five faces run straight from the circle to the rectangle. The circle lies on the block’s bottom face, not on any edge of the part; the rectangle is closed by face 11.

The neck lofted on its block: the lofted faces in blue, the face closing the top section in amber

The neck: its lofted faces are blue and the face closing its top section is amber; the block is grey.

Loft member

Description

direction

The normal of the sections’ planes, pointing from the first section to the last

faces

The free-form faces of the band

sections

The sections, first to last: each LoftSection holds its level along direction and its loop of lines and arcs

ruled

Whether the band runs straight from one section to the next

caps

The flat faces of the part bounded by nothing but a section’s edges, which close the loft

void

Whether the band bounds a hollow, with the material outside it, as the walls of a tapered pocket do

section_count

How many sections a smooth band was most likely drawn through; two for a ruled band

A smooth band does not show the sections it was drawn through as edges. resampled(reading, loft, count) cuts it at count evenly spread levels, keeping its two ends. recognise_loft_wall(reading, loft) reads a wall of constant thickness grown on a loft, and returns None when no face of the part is an offset of the band.

Here a vase is lofted smoothly through seven circles, 3 apart, of radii 5, 10, 13.66, 15, 13.66, 10 and 5, and given a wall 0.5 thick, open at both ends (download vase.step, in millimetres):

solid = VolumeModel.from_step("vase.step", reading_unit="MM").primitives[0]
reading = PartReading(solid)
(body,), _ = recognise_lofts(reading)
print(sorted(body.faces), body.ruled, body.section_count, body.void)
# [0] False 7 True
through = resampled(reading, body, body.section_count)
print([round(section.loop.primitives[0].radius, 2) for section in through.sections])
# [5.0, 10.0, 13.66, 15.0, 13.66, 10.0, 5.0]
wall = recognise_loft_wall(reading, body)
print(wall.thickness, sorted(wall.faces), wall.open_ends)
# 0.5 [1, 2, 3] (True, True)

The lofted face is the inside skin of the vase, with the material outside it. Cut at its seven most likely levels, it gives back the seven circles it was drawn through. The wall is the outside skin and the two rings that join it to the inside one, and no face covers either end.

The vase: its lofted inside skin in blue, the wall grown on it in teal

The vase: the lofted inside skin, seen through the top opening, is blue; the faces of the wall grown on it, its outside skin and the rings at its ends, are teal.

LoftWall member

Description

thickness

The distance between the loft’s band and its offset

faces

The faces of the wall: the offset skin and the flat faces that join it to the band

open_ends

Whether the wall is open at the loft’s first and last sections

recognise_lofts also takes deadline, a moment on time.perf_counter() past which the bands left are refused as out of time.

See Also#