Straight Prisms#

Read the straight extrusions a part is made of along one direction, from the walls each one leaves on the part’s surface.

Note

Prerequisites: Attributed Adjacency Graph (AAG)

Straight Prisms#

A part built from extrusions along several directions has no section that is one extrusion’s: a plane cut across a plate also cuts the boss standing on it and the lug running through it. What each extrusion leaves of itself is its walls: the faces that run along its direction, planes that contain it and cylinders about it. Each wall stands over a range of levels along the direction, and the walls that stand over the same range chain into the extrusion’s profile.

recognise_prisms(reading, direction), in volmdlr_tools.reverse_engineering.techniques.straight_prisms, reads the straight prisms of a part along one direction that way, given the part’s PartReading. It returns the prisms, material ones and voids, and the reasons for the walls it could not close into a profile.


Quick Start#

A block 30 by 20 and 10 high, centred on the origin, with a bore of radius 4 through it along Z:

import numpy as np
from volmdlr.shapes import Solid

from volmdlr_tools.features.part_reading import PartReading
from volmdlr_tools.reverse_engineering.techniques.straight_prisms import recognise_prisms

block = Solid.from_brep("data/brep/straight_prisms/bored_block.brep")
prisms, refusals = recognise_prisms(PartReading(block), np.array((0.0, 0.0, 1.0)))
for prism in prisms:
    print(prism.additive, prism.start, prism.end, round(prism.closures[0].signed_area, 2), prism.chords)
# False -5.0 5.0 -50.27 0
# True -5.0 5.0 600.0 0
print(refusals)
# ()

The bore is one void, its circle running clockwise, and the block one material prism, its 30 by 20 outline running counter-clockwise.


Prism#

Member

Description

direction

The unit direction of the extrusion

frame

The sketch plane at start, its third axis the direction

start / end / height

Where the extrusion starts and ends along the direction, and its length

closures

The profile in frame, as Loop2Ds: the first is the best guess, the others close the same walls another way

additive

Whether the prism is material (its first closure runs counter-clockwise) rather than a void cut from the part

face_ids

The wall faces the first closure runs along

chords

How many straight joints the first closure draws where no wall is

A profile whose walls do not close, because its other walls stand inside the part, is closed by straight chords with material on their left. A void open to the outside is closed across its mouth. Walls that cannot be closed that way give a reason in refusals instead of a prism.

Every range of levels the walls stand over gives its prisms, so a part reads as several prisms along one direction, some of them overlapping. Pick the ones you need by their levels, as the examples below do with this helper:

def over(prisms, start, end, additive=True):
    """Return the prisms of one kind standing from *start* to *end*."""
    return [p for p in prisms if p.additive == additive and (round(p.start, 6), round(p.end, 6)) == (start, end)]

A wall two stacked prisms share#

A boss standing on a plate and trimmed to the plate’s round end shares that end with it: one cylindrical face runs on, unbroken, over the plate’s levels and the boss’s. The stretch of it that runs from where one of a prism’s walls stops to where the next begins is that prism’s wall, so the plate and the boss each take their own arc of it, and neither profile is closed by a chord. An arc the boss’s sides cut into three pieces is joined back into one.

Here the plate is a slot 100 long and 40 wide, 10 thick. The boss on it, 10 high and 16 wide, is rounded at its inner end about the centre of one of the plate’s round ends, and runs out to that end:

part = Solid.from_brep("data/brep/straight_prisms/boss_on_a_round_end.brep")
prisms, _ = recognise_prisms(PartReading(part), np.array((0.0, 0.0, 1.0)))
(plate,), (boss,) = over(prisms, 0, 10), over(prisms, 10, 20)
print([primitive.kind for primitive in plate.closures[0].primitives], plate.chords)
# ['arc', 'line', 'arc', 'line'] 0
print([primitive.kind for primitive in boss.closures[0].primitives], boss.chords)
# ['line', 'arc', 'line', 'arc'] 0
print(len(set(plate.face_ids) & set(boss.face_ids)))
# 1

The plate and the boss on it sharing the plate's round end

Left, the part: the plate’s walls in blue, the boss’s in orange, and the round end they share in green. Right, the two outlines read along Z, each wall drawn in its face’s colour: the plate’s outline takes the whole round end as one arc, the boss’s takes the part of it beside the boss.

The round end, standing from 0 to 20, is also read on its own as a prism over those levels, closed by two chords: that is one of the overlapping readings to pick out by level.

A plate whose round end runs on down a hub under it is read the same way: the plate’s outline takes the arc of the hub between its own straight sides, and the hub stays a circle of its own.


Across a slot#

A slot cut through a plate splits each of its walls in two: a round corner becomes one face above the slot and one below, and so does a hole through both prongs. The two faces of one wall are the same wall seen across the slot, so the plate is one prism through both prongs, with round corners as well as flat sides, and the hole is one void through both.

Here the plate is 60 by 40 with corners of radius 8, and 20 thick from -10 to 10 along Z, with a hole of radius 4 through it. A slot 6 wide, from -3 to 3 along Z, runs in from one long side through the hole, as far as the hole’s centre:

part = Solid.from_brep("data/brep/straight_prisms/plate_split_by_a_slot.brep")
prisms, refusals = recognise_prisms(PartReading(part), np.array((0.0, 0.0, 1.0)))
(plate,), (hole,) = over(prisms, -10, 10), over(prisms, -10, 10, additive=False)
print(len(plate.closures[0].primitives), plate.chords, round(hole.closures[0].signed_area, 2))
# 8 0 -50.27
print(refusals)
# ('the open wall chains over levels -3 to 3 cannot be joined with material on the left of every chord',)

A rounded plate cut in two prongs by a slot, read as one prism with one hole

Left, the part: the faces of the plate’s walls, in two pieces each across the slot, are blue; the two pieces of the hole are orange. Right, the outlines read along Z from -10 to 10: one rounded rectangle and one circle, with no chord.

Each prong’s piece of the hole is also read over the prong’s own levels. The slot’s walls, open to the outside on both of its sides, cannot be closed with material on the left of every chord, and say so in refusals.

A round wall that a taller prism shares is taken only over the stretch between the open ends of the prism’s own walls. A flat wall is taken only whole: two arms standing on a plate are not joined along the plate’s top, which runs on under and between them.


Plates that share side planes#

A base plate, an upright standing at its end and a leg leaning out below the upright, all as wide as one another, share their two side planes: one face on each side carries all three outlines. Within it, the edges that stay level mark where each plate starts and ends, so the piece of the side face beside each plate is a wall of that plate, and each plate is read whole along its own direction. Where a plate runs on under a taller one, its wall is carried on to its end before the profile is closed.

The upright’s round top and the bolt holes through the base and the upright run across the side planes, so no single extrusion makes the part: ExtrusionShapeRecognizer finds none, and the plates have to be read one by one.

Here the base runs from -50 to 0 along X, 40 wide and 10 thick, with a bolt hole of radius 5 along Z. The upright stands on its end, from -10 to 0 along X and 40 high, its top corners rounded to radius 10, with a bolt hole of radius 5 along X. The leg, 6 thick, leans out at 45 degrees from the upright’s outer foot, down and away from the base:

from volmdlr_tools.shapes.recognizers import ExtrusionShapeRecognizer

solid = Solid.from_brep("data/brep/straight_prisms/bracket_with_a_leg.brep")
print(ExtrusionShapeRecognizer(solid).result)
# None

reading = PartReading(solid)
along_z = recognise_prisms(reading, np.array((0.0, 0.0, 1.0)))[0]
along_x = recognise_prisms(reading, np.array((1.0, 0.0, 0.0)))[0]
(base,), (base_hole,) = over(along_z, 0, 10), over(along_z, 0, 10, additive=False)
(upright,), (upright_hole,) = over(along_x, -10, 0), over(along_x, -10, 0, additive=False)
(leaning,) = over(recognise_prisms(reading, np.array((1.0, 0.0, 1.0)) / np.sqrt(2.0))[0], 0, 6)
for prism in (base, upright, leaning):
    print(round(prism.closures[0].signed_area, 2), prism.chords)
# 2000.0 1
# 1557.08 1
# 1765.69 1
print([primitive.kind for primitive in upright.closures[0].primitives])
# ['line', 'arc', 'line', 'arc', 'line', 'line']
print(round(base_hole.closures[0].signed_area, 2), round(upright_hole.closures[0].signed_area, 2))
# -78.54 -78.54
print(len(set(base.face_ids) & set(upright.face_ids) & set(leaning.face_ids)))
# 2

A bracket whose base, upright and leaning leg share their side planes

Left, the bracket: the side plane the three plates share is green, the bolt holes orange. Right, the three outlines, each in its own plate’s sketch plane: the two sides along the shared planes in green, the plate’s own walls in blue, the hole in orange, and dashed the one chord where the plate runs into another.

The upright’s outline takes its round top from its own walls and its sides from the shared planes. The leg’s sides run back along the shared planes to the upright’s inner corner, hidden in the plates it stands out from, so its outline is 30 + 10√2 long and 40 wide.

A chord never runs out and straight back along a line: a rib standing on a plate whose top runs on beside the rib’s foot is closed along its foot alone, not out along the plate’s top and back.


The envelope#

Some parts are not built by stacking extrusions but by cutting one extrusion with another: the outline seen from above is extruded, the outline seen from the side is extruded, and the part is what the two bodies share. Neither extrusion is a prism of the part: each is larger than it, and none of the part’s walls stands over its whole length.

recognise_envelope(reading, direction), in the same module, reads such an extrusion: the envelope of the part along a direction. Its profile is the outline the part casts along the direction, drawn from the stretches of the walls that lie on that outline, and closed by straight chords where a face leaning across the direction casts the outline instead. It runs over the part’s whole length. The part lies inside it, so it is a body to intersect with others, not one to build the part from alone. Only the outer outline is read: holes through the part are its voids.

It returns the envelope as a Prism, with an empty reason, or None with the reason it could not be read: no wall lies on the outline, the walls on it cannot be joined, the part casts more than one outline, or it has no length along the direction.

Here a rounded plate, 40 by 20 with corners of radius 5 and 30 tall along Z, is cut by a trapezoid drawn on the YZ plane, 20 wide at its foot and 8 wide at its top (download rounded_plate_cut_to_a_trapezoid.step, in millimetres):

from volmdlr.model import VolumeModel

from volmdlr_tools.reverse_engineering.techniques.straight_prisms import recognise_envelope

solid = VolumeModel.from_step("rounded_plate_cut_to_a_trapezoid.step", reading_unit="MM").primitives[0]
reading = PartReading(solid)
for direction in ((0.0, 0.0, 1.0), (1.0, 0.0, 0.0)):
    envelope, reason = recognise_envelope(reading, np.array(direction))
    print(round(envelope.start, 6), round(envelope.end, 6), round(envelope.closures[0].signed_area, 2), envelope.chords)
# -0.0 30.0 778.54 2
# -20.0 20.0 420.0 0

A rounded plate cut to a trapezoid, the walls of its two envelopes coloured

The part, which both envelopes enclose: the walls on the outline it casts along Z, its rounded corners and its two ends, in blue; the walls on the outline it casts along X, the faces of the trapezoid, in orange.

Along Z the envelope is the rounded rectangle, from 0 to 30. Its long sides lie on no wall: the trapezoid’s leaning faces cast them, so they are drawn as two chords. Along X it is the trapezoid, from -20 to 20, with no chord. Intersecting the two envelopes gives the part back.


See Also#