volmdlr_tools.features.measurements package#
Geometric measurements taken on recognized features. Measurement functions are pure geometry — they quantify a feature without judging it; design-rule checks (material factors, tolerances, verdicts) belong to the caller.
Submodules#
volmdlr_tools.features.measurements.ribs module#
Rib thickness measurements.
Three quantities on a recognized Rib,
matching the dimensions of injection-molding rib design rules (b <= e x rib_factor):
root thickness (the rule’s
b): the wall thickness of the rib itself, measured at the rib’s bottom — just above the junction with the part wall, above the fillet tangency when root fillets exist, so the fillet radius is not part of the value. Ribs are drafted, so the root is the thickest section and the one design rules dimension.tip thickness (the rules’ “rib tip dimension”): the rib’s thickness at its top — just below the tip edge, below the fillet tangency when top fillets exist. On a drafted rib it is the thinnest section.
wall thickness (the rule’s
e): the thickness of each part wall the rib stands on (rib.base_face_nodes), measured by ray casting from the wall face, next to the rib’s attachment, through the solid to the far skin.
Both measurements sample per-location surface normals, so curved and nearly-planar (BSpline) faces are handled correctly. The rule check itself (material factor, tolerance, verdict) is client policy and deliberately NOT part of this module.
- class volmdlr_tools.features.measurements.ribs.RibThicknessMeasurement(root_thickness: float | None, root_thickness_samples: list[float], wall_thickness_by_base_node: dict[int, float], end_face_nodes: list[int], note: str = '', rib: Rib | None = None, tip_thickness: float | None = None, tip_thickness_samples: list[float] | None = None, name: str = '')#
Bases:
DessiaObjectThe measured thicknesses of one rib: its root (b), its tip, and the walls it stands on (e).
Pure measurement record — it carries no verdict. Design rules compare
root_thicknessagainstwall_thickness(or the per-face dict, for a stricter aggregation) with their own material factor and tolerance.The measured rib is identified by its AAG face indexes (
end_face_nodesand the keys ofwall_thickness_by_base_node); the liveRibobject itself is kept only as a convenience for in-process callers and is not serialized — features are managed by theirFeatureProcessorand do not round-trip on their own.- Parameters:
root_thickness – The rib’s thickness at its root (median of samples), or None when it could not be measured.
root_thickness_samples – The individual root ray measurements.
wall_thickness_by_base_node – Thickness of each part wall the rib stands on, keyed by AAG face index.
end_face_nodes – AAG face indexes of the measured rib’s end faces.
note – Non-empty when a fallback was used (e.g. the root could not be sampled and
root_thicknessechoes the extractor’s whole-wall value) or a value is missing (e.g. the tip could not be sampled).rib – The measured rib feature (in-process convenience, not serialized).
tip_thickness – The rib’s thickness at its tip (median of samples), or None when it could not be measured.
tip_thickness_samples – The individual tip ray measurements.
name – Optional name.
- classmethod from_rib(aag: AttributedAdjacencyGraph, rib: Rib, root_maximum_hit: float | None = None, wall_maximum_hit: float | None = None, ray_caster: FaceRays | None = None, name: str = '') RibThicknessMeasurement#
Measure a rib’s root, tip and wall thicknesses.
- Parameters:
aag – The model’s attributed adjacency graph.
rib – The rib to measure.
root_maximum_hit – Far cutoff for the root and tip rays, in model units; defaults to a few times the rib’s own wall thickness.
wall_maximum_hit – Far cutoff for the wall rays; defaults to half the model’s bounding-box diagonal (a wall cannot be thicker).
ray_caster – Optional pre-loaded caster over the whole model (
FaceRays(aag.shape.wrapped)); pass one when measuring many ribs so the model is loaded once.name – Optional name for the measurement.
- Returns:
The populated measurement.
- property wall_thickness: float | None#
Median wall thickness over the attached walls, or None when unmeasured.
The median is the robust default: a rib usually stands on one physical wall split into several faces, and a single face with a grazing ray exit would make a min unrepresentative. Clients wanting a stricter aggregation (e.g. the thinnest attached wall) can aggregate
wall_thickness_by_base_nodethemselves.
- volmdlr_tools.features.measurements.ribs.measure_rib_root_thickness(aag: AttributedAdjacencyGraph, rib: Rib, maximum_hit: float | None = None) tuple[float | None, list[float], str]#
Measure the rib’s thickness at its root (the design rules’
b).For each end face, samples points on its root edges (shared with base faces, or with root fillets when the junction is filleted), lifts them slightly above the root onto the end face, and ray-casts along the local inward normal to the opposite side’s end faces. The result is the median of the samples.
Convention: the value is taken just above the root junction — above the fillet tangency when root fillets exist — so the fillet radius is not part of it, matching how rib design rules dimension
b.- Parameters:
aag – The model’s attributed adjacency graph.
rib – The rib to measure.
maximum_hit – Far cutoff for accepted ray hits, in model units; defaults to
_ROOT_MAXIMUM_HIT_THICKNESS_FACTORtimes the rib’s own wall thickness (a root measurement past a few times the wall is noise).
- Returns:
(root_thickness, samples, note). When the root cannot be sampled,root_thicknessfalls back torib.thicknessand the note says so; the function never raises for a degenerate rib.
- volmdlr_tools.features.measurements.ribs.measure_rib_tip_thickness(aag: AttributedAdjacencyGraph, rib: Rib, maximum_hit: float | None = None) tuple[float | None, list[float], str]#
Measure the rib’s thickness at its tip (the design rules’ “rib tip dimension”).
For each end face, finds the boundary points farthest from the root (the top of the rib, whatever face or fillet lies there), moves them slightly down into the end face, and ray-casts along the local inward normal to the opposite side’s end faces. The result is the median of the samples.
Convention: the value is taken just below the tip edge — below the top fillet tangency when top fillets exist — by
RIB_TIP_OFFSET_FACTORtimes the rib’s thickness, kept small because draft makes the reading grow with the distance from the tip.- Parameters:
aag – The model’s attributed adjacency graph.
rib – The rib to measure.
maximum_hit – Far cutoff for accepted ray hits, in model units; defaults to
_ROOT_MAXIMUM_HIT_THICKNESS_FACTORtimes the rib’s own wall thickness.
- Returns:
(tip_thickness, samples, note). When the tip cannot be sampled,tip_thicknessis None and the note says why; the function never raises for a degenerate rib.
- volmdlr_tools.features.measurements.ribs.measure_rib_wall_thickness(aag: AttributedAdjacencyGraph, rib: Rib, maximum_hit: float | None = None, ray_caster: FaceRays | None = None) dict[int, float]#
Measure the thickness of each part wall the rib stands on (the rules’
e).Samples points on each base face next to the rib attachment (pulled laterally away from the root so the ray does not travel through the rib itself), ray-casts along the inward normal through the solid, and takes a trimmed median per face — robust against rays that exit through an opposing rib on the far skin (gross overestimates of the wall).
- Parameters:
aag – The model’s attributed adjacency graph.
rib – The rib whose attached walls are measured.
maximum_hit – Far cutoff for accepted ray hits, in model units; defaults to half the model’s bounding-box diagonal (a wall cannot be thicker than that).
ray_caster – Optional pre-loaded caster over the whole model; pass one when measuring many ribs so the model is loaded once.
- Returns:
Wall thickness per base face, keyed by AAG face index. Faces yielding no usable ray are absent from the dict; the dict is empty when the rib has no
thickness(the sampling offsets and the self-hit cutoff scale with it, and a machine-epsilon cutoff is the documented near-zero-thickness failure mode — seeRIB_THICKNESS_SELF_HIT_FRACTIONinfeatures.constants).
volmdlr_tools.features.measurements.distances module#
Distance measurements between a feature and the rest of the part.
Two relational quantities that design guidelines dimension (ADR 0001: they are measurements, not feature parameters, because each needs geometry the feature does not own):
edge distance: the material ligament from a feature’s boundary to the part’s outer contour — how close a cutout sits to the border of the sheet.
feature distance: the ligament from a feature’s boundary to the boundary of the nearest other cut feature — the web of material between two openings, the “a” of stamping spacing rules.
bend distance: the ligament from a cut feature’s boundary to the nearest bend zone — the “hole to radius” of stamping bend rules.
All three are the 3D minimum distance between two shapes, never center-based
(ADR 0002), and both are measured by volmdlr itself: a
Feature is a
volmdlr.shapes.Shape, so feature.distance_points(other) already
answers this and nothing here re-solves it. On a flat region that distance is
the true ligament; across a bend it cuts through air and understates it, so a
spacing rule reading these can report a false failure on a curved part, never a
false pass. The geodesic upgrade slots in behind these same records.
The bend distance carries that limitation most directly, since a bend is the very thing the straight line cuts across: a hole on one flange measured to a bend on the other answers the chord through the air inside the channel, not the sheet the punch has to travel over. It understates, so a hole-to-bend rule can fail a hole the true ligament would pass — never the reverse.
Pure geometry, like every module in this package: nothing here compares a
measured value against a threshold or produces a verdict. That is the rule
layer’s job (volmdlr_tools.features.rules).
- class volmdlr_tools.features.measurements.distances.BendDistanceMeasurement(distance: float | None, feature_nodes: list[int], bend_nodes: list[int], point_on_feature: Point3D | None = None, point_on_bend: Point3D | None = None, note: str = '', feature: Feature | None = None, bend: Bend | None = None, name: str = '')#
Bases:
DessiaObjectThe measured ligament from one cut feature’s boundary to the nearest bend zone.
The “hole to radius” of stamping bend rules: how far a pierced opening sits from where the sheet starts to fold. Measured to the bend zone — the two coaxial surfaces the sheet wraps around — so the value is the distance to the tangent line where the bend begins, which is how a hole pierced before bending is commonly dimensioned. A slider-pierced hole is often dimensioned to the far side of the radius instead, and this measurement answers less than that, so a rule reading it errs toward reporting a violation rather than missing one.
Bends that no distance can be taken to are not targets: a bend the recognizer described without its radius faces has no zone (see
bend_zones()), and a bend sharing a face with the measured feature is not a separate thing to be far from.Pure measurement record — it carries no verdict. Both sides are identified by their AAG face indices; the live
Featureobjects are in-process conveniences and are not serialized.- Parameters:
distance – The ligament, or None when there is no bend to measure to.
feature_nodes – AAG face indices of the measured feature.
bend_nodes – AAG face indices of the nearest bend, empty when there is none.
point_on_feature – Closest point on the measured feature.
point_on_bend – Closest point on the bend zone.
note – Non-empty when no value could be produced, saying why.
feature – The measured feature (in-process convenience, not serialized).
bend – The nearest bend (in-process convenience, not serialized).
name – Optional name.
- classmethod from_feature(feature: Feature, bends: Iterable[Feature], name: str = '') BendDistanceMeasurement#
Measure one feature’s distance to the nearest bend zone.
- Parameters:
feature – The feature to measure, typically a cut feature.
bends – The features to consider as targets, typically the part’s recognized bends (see
bend_zones()).name – Optional name for the measurement.
- Returns:
The populated measurement; a part with no bend the feature is separate from yields a noted non-value rather than a raise.
- class volmdlr_tools.features.measurements.distances.EdgeDistanceMeasurement(distance: float | None, feature_nodes: list[int], border_nodes: list[int], point_on_feature: Point3D | None = None, point_on_border: Point3D | None = None, note: str = '', feature: Feature | None = None, name: str = '')#
Bases:
DessiaObjectThe measured ligament from one feature’s boundary to the part’s outer contour.
Pure measurement record — it carries no verdict. The measured feature and the border it was measured to are identified by their AAG face indices; the live
Featureis kept only as a convenience for in-process callers and is not serialized, since features are managed by theirFeatureProcessorand do not round-trip on their own.- Parameters:
distance – The ligament, or None when it could not be measured.
feature_nodes – AAG face indices of the measured feature.
border_nodes – AAG face indices of the outer contour measured to.
point_on_feature – Closest point on the feature, for visualization.
point_on_border – Closest point on the border, for visualization.
note – Non-empty when no value could be produced, saying why.
feature – The measured feature (in-process convenience, not serialized).
name – Optional name.
- classmethod from_feature(aag: AttributedAdjacencyGraph, feature: Feature, border_nodes: Sequence[int], name: str = '') EdgeDistanceMeasurement#
Measure one feature’s distance to the part’s outer contour.
- Parameters:
aag – The model’s attributed adjacency graph.
feature – The feature to measure.
border_nodes – The part’s outer contour faces (
processor.outer_contour_nodes); empty on a part with no recognized sheet, which yields a noted non-value rather than a raise.name – Optional name for the measurement.
- Returns:
The populated measurement.
- class volmdlr_tools.features.measurements.distances.FeatureDistanceMeasurement(distance: float | None, feature_nodes: list[int], target_nodes: list[int], point_on_feature: Point3D | None = None, point_on_target: Point3D | None = None, note: str = '', feature: Feature | None = None, target: Feature | None = None, name: str = '')#
Bases:
DessiaObjectThe measured ligament from one feature’s boundary to its nearest other cut feature.
Pure measurement record — it carries no verdict. Both the measured feature and the target it turned out to be nearest to are identified by their AAG face indices; the live
Featureobjects are in-process conveniences and are not serialized.A ligament to an unrecognized cutout is invisible here (ADR 0002): the nearest neighbour is always a recognized feature, so a recognition gap surfaces as an extraction issue, never as a silently shorter distance.
- Parameters:
distance – The ligament, or None when there is no other cut feature.
feature_nodes – AAG face indices of the measured feature.
target_nodes – AAG face indices of the nearest other feature, empty when there is none.
point_on_feature – Closest point on the measured feature.
point_on_target – Closest point on the nearest feature.
note – Non-empty when no value could be produced, saying why.
feature – The measured feature (in-process convenience, not serialized).
target – The nearest feature (in-process convenience, not serialized).
name – Optional name.
- classmethod from_feature(feature: Feature, candidates: Iterable[Feature], name: str = '', connectors: Sequence[Feature] = ()) FeatureDistanceMeasurement#
Measure one feature’s distance to the nearest other cut feature.
Candidates are filtered to cut features, and any candidate on the same opening as feature is dropped: one sharing a face with it (the feature itself, or a relative in the feature hierarchy, so a countersunk hole’s own entry blend can never stand in as its nearest neighbour), and one joined to it through touching boundaries (see
group_openings()) — a fragment of the same cutout is a zero web, or a web measured across the opening through air.Candidates are visited nearest-box-first (see
_nearest_target()), so a part with many cutouts does not pay for a full solve against every one of them.- Parameters:
feature – The feature to measure.
candidates – The features to consider as targets, typically the part’s internal cut features (see
internal_cut_features()).name – Optional name for the measurement.
connectors – Formed rims joining the fragments around them into one opening (see
opening_connectors()).
- Returns:
The populated measurement; a lone feature yields a noted non-value rather than a raise.
- volmdlr_tools.features.measurements.distances.border_shape(aag: AttributedAdjacencyGraph, nodes: Sequence[int]) Compound#
Bundle AAG faces into one shape, so a face-index boundary can be measured to.
The counterpart of a
Feature, which is already a shape. The part’s outer contour is handed around as face indices rather than as an object, and this is what makes it an argumentvolmdlr.shapes.Shape.distance_points()accepts — one compound, so one solve covers every border face.- Parameters:
aag – The model’s attributed adjacency graph.
nodes – Face indices to bundle.
- Returns:
A compound holding those faces.
- volmdlr_tools.features.measurements.distances.closest_approach(shape: Shape, other: Shape) tuple[float, Point3D, Point3D] | None#
Return
volmdlr’s closest approach between two shapes, or None on a degenerate pair.The distance is read off the two points rather than solved a second time, so a record’s value and its points can never disagree.
Only an adapter: the measurement is
volmdlr.shapes.Shape.distance_points(). What it adds is this package’s contract that a boundary OCP cannot solve yields a noted non-value rather than an exception out of the middle of a rulebook run.- Parameters:
shape – One boundary.
other – The other.
- Returns:
(distance, point_on_shape, point_on_other), or None when OCP finds no solution.
- volmdlr_tools.features.measurements.distances.cut_features(features: Iterable[Feature]) list[Feature]#
Select the material-removal features, one entry per distinct face set.
Keyed on
Feature.categoryrather than on classes, so features from any extractor qualify and a class-hierarchy refactor cannot silently drop a family.- Parameters:
features – Recognized features, typically
processor.all_features.- Returns:
The cut features, one representative per face set.
- volmdlr_tools.features.measurements.distances.distinct_features(features: Iterable[Feature]) list[Feature]#
Select one representative per distinct face set, best-typed one winning.
The de-duplication matters: two extractors run over the same part recognize the same round through cutout as both a hole and a round cavity. Left in, each would be listed as the other’s nearest neighbour at zero distance, and every spacing rule would fail on every part.
Which of the two survives is not left to registry order: a representative carrying a real
FeatureTypebeats one still typedUNKNOWN, because rules are keyed on that type and an untyped representative would make them report not applicable on a cutout they do concern. Two equally typed representatives keep the first seen.- Parameters:
features – Recognized features, typically
processor.all_features.- Returns:
One feature per face set, in first-seen order.
- volmdlr_tools.features.measurements.distances.features_on_outer_contour(aag: AttributedAdjacencyGraph, features: Sequence[Feature], border_nodes: Sequence[int], connectors: Sequence[Feature] = ()) list[Feature]#
Select the features that belong to the border rather than sit inside the sheet.
A feature with a face on the outer contour — a notch, a corner, a corner relief — is the border. So is an opening that only touches it: there is no material between the two, which makes it an open cutout, not a hole with a web to the edge. And, as for any opening, a fragment touching such a feature belongs with it (see
group_openings()).- Parameters:
aag – The model’s attributed adjacency graph, to reach the border faces.
features – The features to sort.
border_nodes – The part’s outer contour faces (
processor.outer_contour_nodes); empty puts nothing on the border.connectors – Formed rims joining the fragments around them (see
opening_connectors()).
- Returns:
The features on or touching the outer contour, in input order.
- volmdlr_tools.features.measurements.distances.group_openings(features: Sequence[Shape], connectors: Sequence[Shape] = ()) list[list[Shape]]#
Group features into openings: features whose boundaries touch bound one opening.
Recognition can split one cutout into several features — a lance’s walls come back as one-face fragments meeting at the slit ends. Two features that share a vertex have no material between them, so they are one opening, and the grouping is transitive: two fragments on opposite walls of a lance never touch, but the fragments between them join them, and the distance across them is the opening’s width, through air, not a web.
Some fragments never touch any other cut feature — a lance’s opposite walls meet only the formed tab between them. connectors close that gap: features they touch are joined through them, but they are never openings themselves and appear in no group (see
opening_connectors()). A lance joins only through the walls of its cut, not through the bends and tab skin it also owns.Vertices are compared by topological identity, which holds because every feature is built from the part’s own faces.
- Parameters:
features – The features to group; any shape built from the part’s own faces groups the same way, such as the border’s (
border_shape()).connectors – Shapes that join what they touch without being grouped.
- Returns:
The openings, each a list of features, in first-seen order of their first member.
- volmdlr_tools.features.measurements.distances.internal_cut_features(aag: AttributedAdjacencyGraph, features: Iterable[Feature], border_nodes: Sequence[int], connectors: Sequence[Feature] = ()) list[Feature]#
Select the cut features inside the sheet: the openings a web is measured between.
A cut feature on or touching the outer contour is the border (see
features_on_outer_contour()): a cutout’s distance to it is an edge distance, and its own distance to the border is zero by construction, so it is no feature-spacing target.- Parameters:
aag – The model’s attributed adjacency graph, to reach the border faces.
features – Recognized features, typically
processor.all_features.border_nodes – The part’s outer contour faces (
processor.outer_contour_nodes); empty keeps every cut feature.connectors – Formed rims joining the fragments around them (see
opening_connectors()).
- Returns:
The internal cut features, one per face set.
- volmdlr_tools.features.measurements.distances.opening_connectors(features: Iterable[Feature]) list[Feature]#
Select the formed features whose rim is a cutout: flanged cutouts, extrusion holes, louvres and lances.
Passed to
group_openings()as connectors, they join the cut fragments around one formed rim into one opening, without being openings themselves. A lance joins only through the walls of its cut: what touches its tab skin or its bends is not on its rim.- Parameters:
features – Recognized features, typically
processor.all_features.- Returns:
The connectors, in input order.
- volmdlr_tools.features.measurements.distances.opening_cut_walls(aag: AttributedAdjacencyGraph, features: Iterable[Feature], connectors: Sequence[Feature]) list[Feature]#
Build the cut walls of formed openings as cut features, where no cut feature already holds them.
A flanged cutout found from its formed skin owns the walls of its cut (a louvre its slit, an extrusion hole its pierce), so recognition reports no cavity of its own over them. The opening is no cut feature (its category is not one of
CUT_CATEGORIES), yet its walls still bound the web to the next opening, the border and the nearest bend: these features stand for them. Likeborder_shape(), they are built from the part’s own faces, and their type is read off those faces as a cavity’s is.Each wall is held once. Two readings of one opening, carrying the same walls, give one feature; walls a recognized cut feature already holds give none. A lance owns its cut walls too, but its walls were never read as a cavity, so they are not measured here.
- Parameters:
aag – The model’s attributed adjacency graph, to reach the faces.
features – Recognized features, typically
processor.all_features.connectors – The formed openings (see
opening_connectors()).
- Returns:
One cut feature per opening that has walls no cut feature holds, in connector order.
- volmdlr_tools.features.measurements.distances.with_perforation_holes(features: Iterable[Feature]) list[Feature]#
List the features, each perforation followed by its holes.
A perforation owns the holes of its field, so recognition does not report them as cavities; whatever checks or measures every opening of a part reaches them through this, as
with_held_folds()reaches the bends a jog or a lance owns. The perforation itself is no cut feature: a web is measured from each of its holes, never from the field.- Parameters:
features – Recognized features, typically
processor.all_features.- Returns:
The features and the holes they hold, in first-seen order, each once: applying it twice changes nothing.
volmdlr_tools.features.measurements.flat_pattern module#
The blank a sheet-metal part is cut from, measured for costing and nesting.
Pure measurement: the record says what the blank is, or why there is none; deciding whether that is acceptable belongs to whoever reads it.
- class volmdlr_tools.features.measurements.flat_pattern.BlankMeasurement(area: float | None, nesting_width: float | None, nesting_height: float | None, k_factor: float, reason: Literal['not_sheet_metal', 'non_developable', 'closed_loop', 'overlap', 'placement_mismatch', ''] = '', note: str = '', flagged: int = 0, unplaced_holes: int = 0, name: str = '')#
Bases:
DessiaObjectThe blank’s area and the smallest rectangle of sheet it nests in.
- Parameters:
area – The blank’s area, or None when the part does not unfold.
nesting_width – The nesting rectangle’s longer side, or None.
nesting_height – Its shorter side, or None.
k_factor – The K-factor the blank was developed with.
reason – Why the part does not unfold, or
"".note – The explanation, or
"".flagged – How many formed features’ holes to pierce the blank does not give, such as a collar too tall for its footprint; they are left to the forming tool.
unplaced_holes – How many holes the blank cuts at the developed side’s opening because their other opening could not be laid onto it; such a hole may be cut too wide.
name – Optional name.
- classmethod from_processor(processor: FeatureProcessor, k_factor: float = 0.33, name: str = '') BlankMeasurement#
Unfold the part and measure its blank.
- Parameters:
processor – The part’s feature processor.
k_factor – Where the neutral layer sits, as a fraction of the thickness from the inside face of a bend; 0.33 by default. See
FeatureProcessor.unfold().name – Optional name.
- Returns:
The measurement; a part that does not unfold gives no values and says why.