Feature-Driven Pipeline#

While the Defeaturer gives you manual, step-by-step control, the feature-driven pipeline defeatures a part in one call: it recognises the part’s features, decides which to remove, removes them in dependency order, and reports what it did.

Note

Prerequisites: Defeaturing Concepts and Defeaturer.

When to use it#

Reach for the pipeline when you want the whole part simplified to its base shape (its stock) without choosing features by hand — for example, before recognising the manufacturing operations that produced the part. Use the Defeaturer directly when you want to remove specific features yourself.

Running the pipeline#

from volmdlr.shapes import Solid
from volmdlr_tools.shape_editing import BRepDefeaturerProcessor

shape = Solid.from_brep("ANC101.brep")
result = BRepDefeaturerProcessor(shape).run()

print(result.defeatured_shape)           # the simplified solid
print(result.stock_type)                 # "extrusion", "revolved", or None

The pipeline runs in two stages:

  1. Identify — every feature is recognised on the original part without changing it, and each is tagged with a remove-or-keep decision. Additive material (bosses, stock) is kept; subtractive detail (holes, pockets, blends, chamfers) is marked for removal. A boss is recognised from the loop its root closes on the face it stands on, over one face or several, sharp or rounded, and is kept. Material left standing on a pocket or slot floor is part of that cut and is removed with it, and a hole drilled through a boss stays a hole.

    Left, a plate with a rounded boss kept (orange) and a pocket marked for removal (purple); right, a block whose pocket and the island standing on its floor are both marked for removal (purple)

    Left: the boss standing on the plate is kept (orange); the pocket beside it is removed (purple). Right: the walls of the island left standing on a pocket’s floor are part of the cut, and come off with it; its top, level with the block’s, stays.#

  2. Defeature — the features marked for removal are removed innermost-first, so a detail nested inside another is removed before its parent. A cut lying inside the faces around it may be taken off on its own; a cut reaching their outer boundary, such as a step, goes to the general removal only. A cut that no removal takes off is filled back with the material it cut away. Bosses are then split off and the remaining base shape is recognised as stock.

Telling the pipeline the body#

Left to itself, the pipeline works out which faces belong to the body the part’s cuts are taken from. When you have already read that body — for example the turned faces of a lathe part — pass their face ids as stock_faces:

from volmdlr.shapes import Solid
from volmdlr_tools.shape_editing import BRepDefeaturerProcessor

shape = Solid.from_brep("doc/_data/brep/ANC101.brep")
result = BRepDefeaturerProcessor(shape, stock_faces=[0, 1, 6, 7, 8]).run()

print(len(result.holes), result.stock_type)
# 17 extrusion

Given the body, the pipeline reads it this way:

  • only a concave edge between two faces that are both off the body counts as evidence of a cut, so a concave corner the body itself has — the foot of a shoulder on a turned part — is not read as a cut;

  • the body’s faces are kept through every removal.

ANC101 with the body faces passed as stock_faces in blue and the faces of the cuts read in orange

ANC101 read with stock_faces=[0, 1, 6, 7, 8]: the body faces given are blue, the faces of the cuts and holes the pipeline reads are orange, and the rest of the part is sand.#

A face id the part does not have raises ValueError:

BRepDefeaturerProcessor(shape, stock_faces=[0, 999])
# ValueError: stock faces [999] are not faces of the part

For a turned part, turned_body_faces reads the body for you: the faces the lathe swept a full turn. It gives None for a part with no turned body, which leaves the pipeline to find the machining stock, so pass the result on as it comes. An empty stock_faces raises ValueError: omit it instead.

from volmdlr_tools.features.part_reading import PartReading
from volmdlr_tools.graph.faces import AttributedAdjacencyGraph
from volmdlr_tools.reverse_engineering.techniques.turns import turned_body_faces

aag = AttributedAdjacencyGraph(turned_part, allow_smooth=False)
stock = turned_body_faces(PartReading(turned_part))
result = BRepDefeaturerProcessor(turned_part, aag=aag, stock_faces=stock).run()

The body of a turned part shows which faces it takes, with examples.

Taking blends off only where the part stays sound#

By default every blend left once the features are off is handed to whole-face removal. Blends whose faces meet, directly or through another blend, make a network, taken off in one operation: its result is kept only when it took faces off, kept every other face of the part, and left the part with no more defects than it had before that removal. A network refused is retried one chain at a time; when it was refused for adding defects, each chain is held to that same rule. Any other result that took faces off is kept, whether the part is still a sound solid or not. Pass euler_blend_removal=True when a sound part matters more than a part with no blend left — for example before measuring the stock, or before handing the part to another tool:

processor = BRepDefeaturerProcessor(shape, euler_blend_removal=True)
result = processor.run()

for refusal in processor.blend_removal_refusals:
    print(refusal.reason, refusal.face_count, refusal.message)

With it, the blends come off one chain at a time, the faces around each extended over the gap it leaves. A blend comes off only where the part left has no more defects than the part had when it came in: none, for a sound part. A chain that cannot come off that way is offered to whole-face removal, and that result is kept only when no other face of the part went with the chain. A part that already fails the validity check is returned no worse than it came, not mended. The rounded ends of slots, half rounds between two faces facing opposite ways, are left in place on purpose: they belong to the profile the slot was cut with, and their two sides never meet, so there is no sharp edge to give back.

Other blends that cannot come off stay on the part too. blend_removal_refusals lists each, in the order it happened, with its reason, the number of faces concerned and a message; each is also logged as a warning when it may have left blends (refusal.leaves_blends). A network refused whole ("network_refused", "network_no_valid_result", "network_adds_defects" or "network_took_other_faces") is logged at info level instead: it left no blend by itself, its chains being retried one at a time, and a chain left gives a refusal of its own. The list is of the last run only; the rounded ends of slots, left on purpose, are not in it.

A part with fourteen blend faces in orange, and the same part with four left after the blends come off

Front: the part as it comes in, its 14 blend faces in orange. Back: the same part with only its blends taken off this way. The fillets along the foot of the walls are gone; the 4 faces still round the ends of slots are left on purpose, as part of the profile the slots were cut with.#

Reading the result#

DefeaturingResult collects everything the pipeline produced. The most useful fields:

  • defeatured_shape — the simplified solid, the pipeline’s headline output.

  • defeatured_aag and face_map — the simplified part’s face graph and a mapping from each surviving face back to the original face it came from.

  • holes — the holes that were recognised and removed, every bore of the part among them, a plate’s only one included. Whether a bore was drilled or drawn in the profile the body was made from is the designer’s choice, which the part does not show. To rebuild a part the way it is most often modelled, pass profile_bores=True: a bore the body is made with then stays on the stock instead. That is a bore every face of which belongs to the body and none of which is a cone (the bore or a shoulder of a turned profile), or the one plain bore that runs from one end of the part to the opposite one along the direction the part is extruded, square to both ends. A part with several such bores, a stepped or blind hole, and a hole drilled across a turned part still give holes.

  • boss_extrusions and stock_shape — the additive bosses split off and the base stock the part was built on. A part made of bodies joined along a seam that starts and stops — an arm leaving the end face of a block, with a blend along the seam — gives one boss_extrusions entry for each body standing on another, cut off along the seam.

  • registry — face-claim coverage (see below).

Face-claim coverage#

As the pipeline recognises and removes features, it records which original faces each one accounts for in a FaceNodeRegistry. Every face is awarded to the first feature that claims it, so overlapping recognitions never double-count. result.registry.claimed_ratio() reports the fraction of the part’s faces accounted for, and is_fully_claimed() tells you whether every face was explained — a quick health check that the part was fully understood.

See Also#