Depression and Protrusion Feature Recognition#
Find the holes, pockets and bosses of a part from the loops where they leave their base, including loops that run over several faces, and read each hole as its steps.
Note
Prerequisites: Attributed Adjacency Graph (AAG)
The recognition works on an Attributed Adjacency Graph (AAG) representation of the shape. If you’re new to AAG, start with the concepts documentation.
Tip
Tutorial Data Files:
Depressions and Protrusions#
Holes, pockets, slots and bosses make up most of the features of a machined or moulded part. Each one leaves the face it sits on, its base, along a closed loop of edges: the rim of a hole, the mouth of a pocket, the root of a boss. volmdlr_tools finds those loops first, then reads each one as the feature it bounds.
A feature does not have to sit on a single face for its loop to be found. A boss can stand across a rounded edge, a hole can be drilled into the seam between a flat and a rounded corner, and a pocket can be cut through an edge. In each case the loop runs over several faces, and no single face records it.
Running the Recognition#
recognise_loops finds the loops of a part, and recognise_depressions_and_protrusions reads the
features from them. Both work on an Attributed Adjacency Graph. Blends are recognised when they are not
marked on the graph yet, so nothing else has to run first.
from volmdlr.model import VolumeModel
from volmdlr_tools.features.extractors.depression_protrusion import recognise_depressions_and_protrusions
from volmdlr_tools.features.extractors.virtual_loops import recognise_loops
from volmdlr_tools.graph.faces import AttributedAdjacencyGraph
solid = VolumeModel.from_step("features_on_a_plate.step").primitives[0]
aag = AttributedAdjacencyGraph(shape=solid)
loops = recognise_loops(aag)
features = recognise_depressions_and_protrusions(aag, loops)
for feature in features:
print(feature.kind, feature.subtype, sorted(feature.enclosed_face_ids))
loops can be left out: recognise_depressions_and_protrusions(aag) finds the loops itself. Pass them
in when you need them as well, for instance to look at the loop of each feature.
A part’s PartReading finds them once, with the part’s blends, as its loops, so that every reader of the part
shares one reading: recognise_depressions_and_protrusions(reading.sharp_aag, loops=reading.loops). The recognition that finds
the loops also reads what lies around them. For a loop, sense says whether it bounds a boss, at a concave corner or
where a concave blend runs on into its base, or a pocket, at a convex corner or a convex blend; it answers None
where the corners along the loop disagree. faces_beyond gives the faces across the loop, and root_blends the
blends rounding the feature where it leaves its base. open_junctions lists the seams between two bodies of the
part that start and stop instead of closing into a loop, each with the chord that closes it across the flat face
its ends lie on.
Depressions and Protrusions#
The example part below is a plate with seven features on it. Each feature in the figure is coloured by what was recognised:
blue: a counterbored hole running through the plate;
light blue: a blind hole drilled into the side of the plate, across the seam between a flat side and a rounded corner;
purple: a pocket, with its rim fillets in dark purple;
orange and yellow: a round pad and a gusset standing against it;
green: a rib with a half-round top;
teal: a pin, with the fillet at its foot in dark teal.

Each feature is a DepressionProtrusion:
kindis"depression"for material taken away from the base and"protrusion"for material standing on it. It is read from the corner the base makes with the feature along the loop: convex where the base turns down into a hole or a pocket, concave where a boss stands up from it. A blend on the loop counts by the side it rounds. The corners along a loop must all agree: a loop that runs along the mouth of a pocket and down the inside corners of one of its walls bounds no feature.subtypeis"through_hole","blind_hole","pocket","slot"or"groove"for a depression, and"protrusion"otherwise. A depression that does not run through is a blind hole when it is round and a pocket otherwise.circulartells whether the feature is round: its side faces turn about one axis, or its loop is one circle.base_face_idsare the faces the feature sits on,side_face_idsthe faces it meets its base with, andblend_face_idsthe blends rounding its root or its rim.enclosed_face_idsare every face of the feature: what the loop cuts off from the rest of the part. A hole running through the part is cut off by its two loops together.parentis the index, in the returned tuple, of the smallest feature holding this one, such as a boss a hole is drilled into.
Loops Over Several Faces#
recognise_loops returns every loop of the part as a RecognisedLoop. Its kind says how many faces
it runs over:
a single loop is a loop of one face, as that face records it: the rim of a hole drilled into a flat top, for example;
a virtual loop runs over several faces joined tangentially, none of them a blend;
a multivirtual loop runs over several groups of faces that meet along sharp edges or through blends.
Its role is "inner" when it bounds something its faces surround (a hole, a pocket or the root of a
boss) and "outer" when it bounds its faces from outside. Features are read from the inner loops.
Seven of the eight inner loops on the plate above are single loops. On the part below, every feature but the lug leaves its base along a loop over two or more faces.
orange: a boss standing across a rounded edge. Its root runs over the top and over the round;
purple: a pocket cut through the same rounded edge;
light blue: a blind hole drilled into the front, across the seam between the flat front and a rounded corner;
blue: a hole running through the part, its upper mouth across the edge between the top and the chamfer at the back;
green: a lug drawn as a slot and extruded up. Its walls are two flats and two half-rounds, all tangent;
magenta: a blind hole drilled into the lug, across the seam between a flat and a half-round. The half-round is part of the lug’s profile, not a fillet, so it is read as a wall, and the hole’s loop is a virtual one.

from collections import Counter
solid = VolumeModel.from_step("features_across_faces.step").primitives[0]
aag = AttributedAdjacencyGraph(shape=solid)
loops = recognise_loops(aag)
inner = [loop for loop in loops.loops if loop.role == "inner"]
print(Counter(loop.kind for loop in inner)) # 4 multivirtual, 2 single, 1 virtual
for feature in recognise_depressions_and_protrusions(aag, loops):
print(feature.subtype, feature.loop.kind, sorted(feature.loop.face_ids))
All six features are found. Cavity recognition (CavityExtractor), which starts from the inner loops of
single faces, finds none of them. The hole through the part is reported once, although two loops bound it:
one on the bottom face and one over the top and the chamfer. The hole in the lug is reported with the
lug as its parent.
Cuts Beside a Web#
A cut made through a plate right beside a web, a rib or a wall bites into the fillet at the web’s root, so its mouth runs over the plate and over that fillet. The part below has a web standing on a plate and two windows through the plate:
blue: a window with rounded corners, cut so close to the web that it takes away part of the root fillet. Its rounded corners are walls of the window, not fillets of the plate, and what is left of the root fillet between them is a wall as well;
light blue: a drafted window, much narrower where it comes out under the plate than at its mouth. Its walls run from one mouth to the other, so it is read as running through, not as a pocket with a hole in its floor.

solid = VolumeModel.from_step("windows_beside_a_web.step").primitives[0]
for feature in recognise_depressions_and_protrusions(AttributedAdjacencyGraph(shape=solid)):
print(feature.subtype, len(feature.enclosed_face_ids)) # through_hole 9, through_hole 4
Hole Steps#
A hole whose faces all turn about one axis is read as a stack of steps from its mouth. steps lists them
as HoleStep objects, in order. Each step has a kind ("counterbore", "countersink", "chamfer",
"bore", "taper", "drill_point", "recess", "floor" or "blend"), its faces, its largest
radius, and where it starts and ends along the axis, measured from the mouth.
In the figure, the counterbored hole is a red counterbore, a yellow floor and a blue bore. The blind hole in the side is a bore ending on a flat floor.

for feature in features:
for step in feature.steps:
print(feature.subtype, step.kind, step.radius, step.start, step.end)
A hole is one feature however many loops it is seen from, countersinks at both ends included. A hole
crossed by a slit or a cavity is one hole as well, and interruption_face_ids gives the faces where it
stops and goes on.
Protrusions Standing Against One Another#
The gusset in the first figure stands against the side of the pad, and one loop on the plate goes round
both of them together. They come out as two protrusions, and each one’s junction_edge_ids are the sharp
concave edges along which it stands against the other. Two bosses whose root blends run into each other are two protrusions
as well, one per body the blends join.
Applied Fillets and Profile Rounds#
A round can be a fillet applied to an edge, or an arc drawn in a profile, like the half-round top of the
rib or the ends of the lug. The two look alike but play different parts: an applied fillet can be taken
off to recover a sharp edge, while a profile round is a wall of the feature. blend_roles gives every
recognised blend a BlendRole:
"applied_fillet": the faces it joins would meet at a sharp edge close by, inside the part;"profile_round": an arc of the profile. Its faces turn by 170 degrees or more across it, as across the top of a rib, or would meet outside the part or in the wrong material;"uncertain": the faces it joins cannot tell.reasonsays why.
recognise_loops uses these roles: profile rounds are read as walls, while applied fillets and
uncertain rounds stay blends. The figure shows the applied fillets in green and the rib’s
half-round top, a profile round, in magenta.

from volmdlr_tools.features.extractors.blend_roles import blend_roles
for face_id, role in blend_roles(aag).items():
print(face_id, role.role, role.reason)
Loops or Interacting Cuts?#
Interacting feature recognition (InteractingFeatureExtractor) also finds holes and pockets, but it
answers a different question: which cuts, made into the raw material, produced the part. The loop
reading asks which features sit on the part.
Stock. Interacting recognition first decides which faces belong to the stock, the material the part
was cut from, and reads everything else as cut away. How the stock is read is a choice
(stock_convention), and a wrong choice changes what is found. The loop reading needs no stock: each
feature is read from its own loop and the corners along it. It reads a moulded part, which was never cut
from a block, in the same way as a machined one.
Protrusions. Interacting recognition describes material taken away, so a boss is not a feature for it but a wall of the cut made round it. On the plate above, the pad, the gusset, the rib and the pin come out as the walls of one open pocket, together with the top of the plate. The loop reading reports each of them as a protrusion.
Cuts that run into one another. Here interacting recognition goes further. It splits cuts that meet
into single features and records how they interact. The loop reading reports one feature per loop, so two
slots crossing each other share one loop and come out as one pocket. A feature sunk into the floor of
another does have a loop of its own, and comes out as a feature with the outer one as its parent. The
outer feature’s enclosed_face_ids still include the faces of the features it holds.
The part below has two crossing slots, a pocket with a smaller pocket in its floor and a hole through that floor, and an open slot running from the pocket out through the side of the part. The loop reading (left) finds the crossing slots as one pocket (orange), and the pocket together with the open slot as one pocket (purple): the slot breaks the pocket’s mouth open, so one loop goes round both. Interacting recognition (right) splits them into two slots (orange and yellow), a pocket (purple) and an open slot (green). Both find the inner pocket (dark purple) and the hole (blue).

from volmdlr_tools.features.extractors.interacting_features import InteractingFeatureExtractor
solid = VolumeModel.from_step("interacting_cuts.step").primitives[0]
by_loops = recognise_depressions_and_protrusions(AttributedAdjacencyGraph(shape=solid))
interacting = InteractingFeatureExtractor(AttributedAdjacencyGraph(shape=solid))
interacting.perform()
print(len(by_loops), len(interacting.result)) # 4 and 6
On the part with features across several faces, both find the pocket cut through the rounded edge and the hole running through. Interacting recognition, though, reads the top of the block, its rounded edge, the boss and the lug together as one slot running through the part.
In short, use the loop reading for bosses, ribs and moulded parts, and for features that stand across several faces. Use interacting recognition to break the cuts of a machined part into the single operations that made them.
A Machined Bracket#
The parts above were drawn to show one thing at a time. The bracket below comes from a CAD system as it was designed: 199 faces, 86 of them blends, with lugs, webs and mounting bosses all rounded into the body. Every cut in it is found, 19 features in all:
teal: ten windows through the body, with rounded corners, many of them cut into the root fillets of the webs beside them;
blue: four mounting holes, each a counterbore whose floor is rounded off into its wall, then a bore through the boss below, and one bore running through both lugs, chamfered at all four ends;
purple: two pockets, one of them the gap between the two lugs;
orange: two blind holes in the underside.

from collections import Counter
solid = VolumeModel.from_step("machined_bracket.step").primitives[0]
features = recognise_depressions_and_protrusions(AttributedAdjacencyGraph(shape=solid))
# 15 through_hole, 2 pocket, 2 blind_hole
print(Counter(feature.subtype for feature in features))
# a mounting hole: counterbore, blend, blend, floor, bore
for feature in features:
if feature.steps:
print([step.kind for step in feature.steps])
The lugs, webs and bosses are not reported: each one stands at the edge of the body, so no loop on its base goes round it alone (see the first limitation below).
Current Limitations#
A rib or boss running off the edge of its base is not reported. Its root reaches the base’s outer boundary, so no loop on the base goes round it.
A lobe of the outline is not reported. A round boss bulging out of the side of a plate over its whole height is bounded only by the top and bottom faces it shares with the rest of the outline. Nothing along those edges sets it apart from the outline.
What a loop over several faces cuts off must be a clear minority of the part. It must be at most half the area of the rest. A hole in one face is a feature whatever its size, as a pin is a boss however long, but a large region bounded by a loop over several faces is read as part of the body, not as a feature on it.
A protrusion’s root includes every concave blend tangent to it. Where protrusions stand against one another, the concave blends tangent to each one are counted as its root, even a blend that only touches it and does not go round it.
Uncertain rounds stay blends. A round whose faces turn by between 160 and 170 degrees across it, or that meets a face tangentially on one side only, is neither an applied fillet nor a profile round. Loops treat it as a blend, even where it is an arc of the profile.
See Also#
Blend Feature Recognition - Blend recognition
Hole Feature Recognition - Hole recognition
Cavity Feature Recognition - Cavity recognition
Attributed Adjacency Graph (AAG) - Attributed Adjacency Graph