volmdlr_tools.reverse_engineering package#
Reading how a part was built: the part’s PartReading,
and the techniques that each read one way of building a part off it. The user guide walks through each one,
starting at Part Reading.
Technique domains#
Split a part into technique domains: regions each built by one modelling technique, in a tree.
A mixed part is seldom one extrusion or one revolution. A profiled plate carries a turned hub, a turned shaft has a milled keyway, a moulded tube carries bosses, lugs and lettering. Each region is explained by one technique, and a recogniser for that technique can rebuild it once it is told which faces are its own. This module finds those regions, the domains, and how they hang together; each domain is then rebuilt by its own recogniser and the results are composed back into one solid.
The split is made in layers, cheapest and most certain first:
Topology. A feature cut off from the rest of the part along one closed loop of edges, a boss along a concave loop or a pocket along a convex one, sharp or blended, is set apart first. The loops are read from the adjacency graph alone, and each piece is split on its own, so one hard problem becomes several small ones. A piece’s loop is its boundary against its parent. A lone flat face cut off by a loop is a cap, not a feature; features of one sign turned about one axis under one parent whose loops face each other, such as the two ends of a tab through a wall, are one.
Fits. Each face is tested against the hypotheses the part’s faces vote for (see
technique_fits): which extrusion directions, which revolution axes and which sweep planes it fits, as a wall or as a cap.Growth. Within a piece, a candidate region is a connected set of faces fitting one hypothesis; caps and blends link faces, and a blend fitting the hypothesis is a wall of it. A region is founded by a curved wall that is not a blend, or by two flat ones: a fillet turning about its own axis founds no revolution, and one flat face is no profile. An extrusion is grown slab by slab: the walls of one slab reach caps at the same two levels and stay between them; a wall ending on a chain of blends reaches the cap at its far end. The candidate explaining the largest area is taken, a flat face counting only in the share of its outline the candidate bounds, since a flat face fits many hypotheses at once; its faces are withdrawn from the others, and so on until no candidate is left. On a tie the more specific technique wins: an extrusion before a revolution before a sweep, unless the extrusion needs several drafts, as a turned profile of cones would; and between two extrusions, the one with the larger caps.
What is left. A blend that no hypothesis explains belongs to the domain it lies inside, when every face around it is in that domain, and is a junction blend between domains otherwise; it is re-applied as a fillet once the domains are composed. A small patch of other faces lying inside one domain, such as a chamfer, is held by it as well; the rest become free-form domains. A domain lists what it holds this way apart from what its technique explains.
Caps and merges. A flat face may close several domains, such as the top of a plate a hub stands on. It goes to the domain it shares the longest boundary with. Domains of one hypothesis that meet are then one domain: the slabs of a moulded body drafted along one pull direction are stacked in it. A domain whose walls bound a void and open through its caps alone stays apart from one whose walls bound material: the hollow of a cover cut from below is no slab of the plate it opens in, while a notch reaching the plate’s outline is read with the plate. A closed feature that one extrusion or revolution builds together with the domain it stands on, as the step of a turned shaft behind its shoulder, is folded back into it and the piece split again.
Tree. Within a piece, the domain standing on the other at their interface is the child: a hub stands on the plate because the plate’s face there is a cap of the hub’s revolution. Such an interface is not a closed loop on one face: it is a virtual split along that carrier face. The largest domain standing on no other, and no such hollow cut into another, is the piece’s root, larger domains are attached first, and the root of a piece hangs from the domain of its parent it stands on, along the piece’s closed loop.
Whether a child adds material or removes it is read from its interface: a concave corner, or a concave blend, stands a boss on its parent, and a convex one sinks a pocket into it. A child whose walls lean towards their own middle bounds removed material whatever its corners say: the walls of a passage meet each other in concave corners, and a hole whose end is the floor of a pocket meets the pocket’s walls concavely.
- class volmdlr_tools.reverse_engineering.techniques.domains.DomainInterface(child: int, parent: int, kind: Literal['closed_loop', 'virtual_split'], sign: Literal['add', 'remove'] | None, edge_ids: tuple[int, ...], junction_blend_face_ids: frozenset[int], carrier_face_ids: frozenset[int], carrier: Frame3D | None, closed: bool, length: float, extension: float, extension_direction: Vector3D | None)#
Bases:
objectWhere a domain meets its parent, and how to compose them.
- Parameters:
child – Index of the child domain.
parent – Index of the parent domain.
kind –
"closed_loop"when the child is cut off along one closed loop,"virtual_split"when the two meet along a face of the parent that the child’s technique would cap.sign –
"add"when the child stands on the parent,"remove"when it sinks into it,Nonewhen the interface does not tell: no corner or blend along it is concave or convex, as at a tangent foot, or the child does not touch the parent it was hung from.edge_ids – The edges along which the two meet, or meet the junction blends between them.
junction_blend_face_ids – The blends between the two, re-applied as fillets after composition.
carrier_face_ids – The faces of the parent the child meets: its base faces across a closed loop, the faces it would cap across a virtual split.
carrier – The plane of the carrier when it is flat, its
waxis the outward normal of the parent.closed – Whether the edges close into loops.
length – The length of the interface.
extension – How far to extend the child across the carrier, so that composing it never meets the parent along a coincident face.
extension_direction – The way to extend it when the carrier is flat and the sign known: into the parent’s material for an added child, out of it for a removed one;
Noneotherwise.
- class volmdlr_tools.reverse_engineering.techniques.domains.DomainTree(domains: tuple[TechniqueDomain, ...], interfaces: tuple[DomainInterface, ...], features: tuple[ClosedFeature, ...], face_count: int, notes: tuple[str, ...] = ())#
Bases:
objectThe technique domains of a part, the root first, each child after its parent.
- Parameters:
domains – The domains, numbered by their position.
interfaces – One interface per domain that has a parent.
features – The closed features the part was split along first.
face_count – The number of faces of the part.
notes – What the split could not settle, in words.
- children(index: int) tuple[TechniqueDomain, ...]#
Return the domains whose parent is the domain at index.
- domain_of(face_id: int) TechniqueDomain | None#
Return the domain owning a face,
Nonefor a junction blend.
- interface(child: int) DomainInterface | None#
Return the interface of a domain with its parent,
Nonefor the root.
- property junction_blend_face_ids: frozenset[int]#
Every junction blend between two domains.
- property root: TechniqueDomain#
The domain at the root of the tree.
- route() Literal['extrusion', 'drafted_extrusion', 'revolution', 'sweep', 'free_form'] | None#
Return the technique the part’s body is built by when one domain is the whole body, else
None.Features hanging from the body along closed loops, such as holes, pockets and bosses, do not stop a part from being routed: the flow of the body’s technique recognises them as it does today. A body in several domains, split virtually, is a mixed part and goes to composition.
- exception volmdlr_tools.reverse_engineering.techniques.domains.NoBodyFacesError#
Bases:
ValueErrorEvery face of the part lies in its closed features, so no domain outside them can be the body.
- class volmdlr_tools.reverse_engineering.techniques.domains.TechniqueDomain(index: int, kind: Literal['extrusion', 'drafted_extrusion', 'revolution', 'sweep', 'free_form'], hypothesis: TechniqueHypothesis | None, wall_face_ids: frozenset[int], cap_face_ids: frozenset[int], absorbed_face_ids: frozenset[int], role: Literal['base', 'add', 'remove'] | None, parent: int | None, piece: int | None, area: float, span: tuple[float, float] | None, draft_angle: float | None, bounding_box: BoundingBox, levels: tuple[float, ...] = ())#
Bases:
objectA region of a part built by one technique.
- Parameters:
index – Position of the domain in its tree.
kind – The technique:
"extrusion","drafted_extrusion","revolution","sweep", or"free_form"for faces no hypothesis explains.hypothesis – The hypothesis the domain’s walls fit,
Nonefor a free-form domain.wall_face_ids – The faces the technique shapes.
cap_face_ids – The flat faces square to its direction that close it.
absorbed_face_ids – The faces it holds that the technique does not explain: blends, and small patches tangent inside it, re-applied or recognised on the rebuilt domain.
role –
"base"for the root of the tree,"add"for material standing on the parent,"remove"for material taken out of it,Nonewhen its interface does not tell (seeDomainInterface.sign).parent – Index of the parent domain,
Nonefor the root.piece – Index of the closed feature the domain lies in,
Nonefor the body of the part.area – The area of all its faces.
span – Its extent along the hypothesis direction, as positions from the hypothesis origin.
draft_angle – For a drafted extrusion, the area-weighted median angle by which its drafted walls lean, radians; walls that stand straight do not count. Zero for a straight extrusion,
Nonefor the other kinds, where a draft does not apply.bounding_box – The box holding its faces.
levels – For an extrusion, the positions along its direction of the caps its slabs reach, ascending; a domain stacking several slabs has more than two.
- property face_ids: frozenset[int]#
Every face the domain owns.
- volmdlr_tools.reverse_engineering.techniques.domains.technique_domains(reading: PartReading, *, features: Iterable[ClosedFeature] | None = None, tol: float | None = None, fits: TechniqueFits | None = None) DomainTree#
Split a part into technique domains and read how they hang together.
- Parameters:
reading – The part.
features – The features cut off along closed loops, split first; found from the loops bounding the part’s depressions and protrusions when omitted. Pass an empty tuple to split by technique alone.
tol – Lengths below this count as equal; defaults to a small share of the part’s bounding box diagonal. Not to be given with fits, which carries its own.
fits – How the part’s faces fit each hypothesis, when already read; read from the part when omitted.
- Returns:
The domain tree, root first.
- Raises:
NoBodyFacesError – If every face of the part lies in the closed features.
ValueError – If tol is not positive, or both tol and fits are given.
Technique fits#
Read, face by face, which modelling techniques could have made a part, and with which parameters.
Every technique leaves a mark on each face it makes, and the mark can be read on the face alone:
an extrusion along a direction
d, straight or drafted, makes side walls whose normal keeps one angle todall over the face (a right angle for a straight extrusion, a little less for a drafted one) and flat caps whose normal isditself;a revolution about a line makes faces whose normal lines all meet that line, and flat faces square to it: planes, and cylinders, cones, tori and spheres coaxial with it, or any surface of revolution;
a sweep of a profile round a path lying in a plane square to
dcarries the profile without twisting it, so along the directiond x nin which the profile travels, the angle between the normalnandddoes not change. Extrusions alongdand revolutions about a line parallel todare sweeps too: a sweep hypothesis matters only where it explains faces that no more specific one does.
The parameters are read from the part as a whole, so that faces vote for shared hypotheses instead of each proposing its own: the directions come from the clusters of axes and plane normals of the part’s analytic faces, and the lines from the axes its rotational faces turn about. Each face is then tested against every hypothesis on points sampled inside it, and every test is local and cheap.
A face fits a hypothesis as a wall, a face the technique shapes, or as a cap, a flat face square to its direction, which closes an extrusion at one level or is a shoulder of a turned profile. A cap fits many hypotheses at once, so it is weak evidence: it joins a region but does not found one.
- class volmdlr_tools.reverse_engineering.techniques.technique_fits.FaceNormals(reading: PartReading)#
Bases:
objectThe outward normals at points inside the faces of a part, each face read once, when first asked about.
- Parameters:
reading – The part; its faces are numbered as its adjacency graph numbers them.
- leans_within(face_id: int, direction: Sequence[float], max_draft: float) bool#
Tell whether every point read of a face leans off direction by at most max_draft, or the face is a cap.
Unlike a wall of an extrusion fit, the lean may change over the face: a round on a drafted wall passes.
- Parameters:
face_id – The face to read.
direction – The direction of the extrusion; need not be a unit vector, and names a line, not an arrow.
max_draft – The largest angle, in radians, by which a wall may lean off the direction.
- Raises:
ValueError – If direction is the null vector.
- class volmdlr_tools.reverse_engineering.techniques.technique_fits.FacesRead(faces: frozenset[int], walls: frozenset[int], caps: frozenset[int], area_share: float)#
Bases:
objectThe faces read for one hypothesis, and which of them fit it as walls and as caps.
- Parameters:
faces – The faces read.
walls – The faces read that fit the hypothesis as walls.
caps – The faces read that fit the hypothesis as caps.
area_share – The share of the part’s area that the faces read hold, whether or not they fit.
- class volmdlr_tools.reverse_engineering.techniques.technique_fits.TechniqueFits(hypotheses: tuple[TechniqueHypothesis, ...], fits: dict[int, dict[int, FaceFit]], areas: tuple[float, ...], planar: tuple[bool, ...], tolerance: float, unsampled: frozenset[int] = frozenset({}))#
Bases:
objectThe hypotheses a part’s faces vote for, and how each face fits each one.
- Parameters:
hypotheses – The hypotheses, numbered by their position.
fits – For each face id, the hypotheses it fits, by their number.
areas – The area of each face, indexed by face id.
planar – Whether each face is flat, indexed by face id.
tolerance – Lengths below this count as equal.
unsampled – The faces no sample landed on, such as a thin sliver: they fit no hypothesis for want of a reading, which says nothing of whether they would.
- faces_fitting(hypothesis: int) dict[int, FaceFit]#
Return the faces fitting a hypothesis, with how each fits.
- fit(face_id: int, hypothesis: int) FaceFit | None#
Return how a face fits a hypothesis,
Nonewhen it does not.
- roles(number: int, kind: Literal['extrusion', 'revolution', 'sweep'], faces: Iterable[int] | None = None) FacesRead#
Return the faces read for a hypothesis, which of them fit it as walls and as caps, and the area they hold.
- Parameters:
number – The number of the hypothesis.
kind – The kind the hypothesis must be.
faces – The faces to read; the faces fitting the hypothesis by default. A face handed in that does not fit the hypothesis is read all the same, and is neither a wall nor a cap of it.
- Raises:
ValueError – When the hypothesis is not of the kind asked for.
- walls_of(face_id: int) tuple[int, ...]#
Return the hypotheses a face fits as a wall.
- class volmdlr_tools.reverse_engineering.techniques.technique_fits.TechniqueHypothesis(kind: Literal['extrusion', 'revolution', 'sweep'], direction: Vector3D, origin: Point3D | None = None)#
Bases:
objectA way a region of a part may have been built, with the parameters that fix it.
- Parameters:
kind –
"extrusion"for an extrusion along direction, straight or drafted;"revolution"for a revolution about the line through origin along direction;"sweep"for a profile swept round a path lying in a plane square to direction.direction – Unit direction; it names a line, not an arrow.
origin – A point of the axis of a revolution,
Nonefor the other kinds.
- axis() ndarray#
Return the unit direction as an array.
- point() ndarray#
Return the axis point of a revolution as an array, the origin of space for the other kinds.
- volmdlr_tools.reverse_engineering.techniques.technique_fits.technique_fits(reading: PartReading, *, tol: float | None = None) TechniqueFits#
Read which hypotheses each face of a part fits.
- Parameters:
reading – The part; its faces are numbered as its adjacency graph numbers them.
tol – Lengths below this count as equal; defaults to a small share of the part’s bounding box diagonal.
- Returns:
The hypotheses the part’s faces vote for and how each face fits each of them.
- Raises:
ValueError – If tol is not positive.
Straight prisms#
Recognising the straight prisms a part is made of, from the walls they leave on its surface.
A part built from extrusions along several directions has no section that is one prism’s: a
plane cutting across a prism along d also cuts through the other prisms that stand on it
or run through it. What a prism leaves of itself is its walls: the faces that run along
d, planes that contain it and cylinders about it. Each wall is a piece of the prism’s
profile that stands over a range of levels along d, and the pieces that stand over the
same range, taken so that the material is on the left of each, chain into the profile.
A wall face can be wider than the prism it belongs to: a face of one plane may be a prism’s wall and, beyond a corner, the end of another prism. Only the part of a wall that is as tall as the face itself is the prism’s; it is found by asking, between the vertices of the face, whether the face reaches both ends of its range.
A rim rounded after the prism was made wears its wall away short of the prism’s end: the wall stops where the round begins, and the prism ends at the cap the round turns onto. Such a wall is read on through the round.
Two prisms stacked on one another may share a side: one face runs on unbroken over both their ranges of levels. A stretch of such a taller face that runs from where one of a prism’s walls stops to where another begins is that prism’s wall too, round or flat.
A profile that does not close is a prism whose other walls stand inside the part. Its ends are joined by a straight chord, which must lie between material on its left, and a lone arc of half a turn or more is also offered completed to the circle it was cut from.
A part made by intersecting prisms along several directions has no prism of its own along any of them: each prism is larger than the part, and the part is what they share. Such a prism is the part’s envelope along its direction: its profile is the outline the part casts along it, drawn from the walls that lie on that outline, and it runs over the part’s whole length.
- class volmdlr_tools.reverse_engineering.techniques.straight_prisms.Prism(direction: ndarray, frame: Frame3D, start: float, end: float, closures: tuple[Loop2D, ...], face_ids: tuple[int, ...], chords: int, carried: bool = False, against: bool = False)#
Bases:
objectA straight extrusion read from the walls of a part.
frameis the sketch plane atstart, with its third axis the direction of the extrusion, andclosuresthe profile in that frame: the first is the best guess, and the others close the same walls another way. A profile that runs counter-clockwise encloses material, a clockwise one a void.face_idsare the wall faces, standing over the whole range, that the first closure runs along, andchordshow many straight joints it draws where no wall is.carriedis whether its walls were carried across a flat chamfer on to a cap, through the corners a cone about the direction turned off them, or on hidden inside the part past where their faces stop: the same walls are then read as they stand too, as another prism.againstis whether its walls were read apart from the walls they share a stretch of the profile with, as a body standing against another, like a gusset: it is added on to that body, never built first.- property additive: bool#
Return whether the prism is material, as opposed to a void cut from the part.
- property height: float#
Return the length of the extrusion.
- volmdlr_tools.reverse_engineering.techniques.straight_prisms.recognise_envelope(reading: PartReading, fits: TechniqueFits, number: int) tuple[Prism | None, str]#
Read the prism the part’s outline along an extrusion of it makes over the part’s whole length.
The part lies inside it, so it is a body to intersect with another, not one to build the part from alone. Its profile is the outline of the part’s shadow along the direction, drawn from the stretches of the walls along it that lie on that outline, and from straight chords that lie on it where no wall does, as the edge of a face that leans across the direction. Only the outer outline is read: holes through the shadow are the part’s voids.
- Parameters:
reading – The part.
fits – How the faces of the part fit each hypothesis.
number – The number of the extrusion hypothesis, in fits, whose direction the envelope is read along.
- Returns:
The envelope, or
Nonewith the reason it could not be read.- Raises:
ValueError – When number is not that of an extrusion hypothesis of the part’s fits.
- volmdlr_tools.reverse_engineering.techniques.straight_prisms.recognise_prisms(reading: PartReading, fits: TechniqueFits, number: int, *, mask: Iterable[int] | None = None) tuple[tuple[Prism, ...], tuple[str, ...]]#
Read the straight prisms along an extrusion of the part from the walls the part has along it.
- Parameters:
reading – The part.
fits – How the faces of the part fit each hypothesis.
number – The number of the extrusion hypothesis, in fits, whose direction the prisms are read along.
mask – Faces to leave out — the faces of the features proposed on the part — which are no prism’s walls nor rounds; the part itself is still the material the walls are read against.
Nonereads every face.
- Returns:
The prisms, the material ones and the voids, and the reasons for the wall chains that were left out.
- Raises:
ValueError – When the mask names a face the part does not have, or number is not that of an extrusion hypothesis of the part’s fits.
Bosses#
Recognise cylindrical bosses among the faces a primary technique leaves unexplained.
A moulded tab is a short cylinder standing on the body. Its two end circles are usually
rounded before it is fused, so each end shows up as a coaxial torus, and the place where it
meets the body is often blended again, which leaves a ring of small cylinders, tori and free
form patches around its foot. recognise_bosses() groups such faces and reads the
cylinder, its two end planes and the two blend radii from them.
Assumptions:
A boss is the largest group of coaxial, equal-radius, convex cylindrical faces of a connected set of residual faces, plus any further group that has a free end of its own. A cylinder split into several faces counts as one group.
An end is closed when a coaxial torus whose major and minor radii add up to the boss radius, or a plane perpendicular to the axis, sits at that end of the lateral face. The plane of the end is read from the torus (centre plane pushed out by the minor radius), so it may lie buried inside the body. An end that is neither is open and must stand against a plane perpendicular to the axis among the faces next to the component, or be buried in a round bar next to it whose axis crosses the boss’s: the boss is then drawn from that axis.
A boss needs at least one closed end, and its two closed ends must agree on the blend radius. Anything else, a lone edge fillet for instance, is left unexplained.
A cylinder that runs on smoothly into a plane along every straight edge it has is the rounded corner of a prism, not a boss, and is left unexplained.
A face of the component that is not lateral, an end torus or a cap belongs to the junction blend of the nearest boss when it is curved like a blend: its radius, read from the surface or from its curvature, is under half the boss radius, and it touches the boss or another face of the junction. Planes and larger faces, a rib fused to the boss for instance, stay unexplained.
- class volmdlr_tools.reverse_engineering.techniques.bosses.CylindricalBoss(face_ids: frozenset[int], base_center: tuple[float, float, float], direction: tuple[float, float, float], radius: float, height: float, end_blend_radius: float | None, junction_blend_radius: float | None, junction_face_ids: frozenset[int])#
Bases:
objectA cylinder standing on the body, with the blends recognised around it.
- Parameters:
face_ids – Every face of the boss, its end blends and its junction blend, numbered as the faces of the part’s adjacency graph are.
base_center – Centre of the base end plane, on the axis; the end with the lower coordinate along
direction. The plane may lie inside the body.direction – Unit axis direction, from base to top, whose largest component is positive.
radius – Radius of the cylinder.
height – Distance between the two end planes along the axis.
end_blend_radius – Fillet radius on both end circles,
Nonewhen the ends are sharp.junction_blend_radius – Radius of the blend joining the boss to the body,
Nonewhen sharp.junction_face_ids – The faces of that junction blend.
Bosses compare and hash by value.
- volmdlr_tools.reverse_engineering.techniques.bosses.recognise_bosses(reading: PartReading, face_ids: Iterable[int], *, tol: float | None = None) tuple[tuple[CylindricalBoss, ...], frozenset[int]]#
Recognise the cylindrical bosses among some faces of a part.
The faces are split into connected components. In each, the largest group of coaxial convex cylinders is the boss, and the coaxial tori and planes at its ends give the end planes and the fillet radius of its ends. The remaining faces of the component that are curved like a blend and reach the boss through one another are the junction blend, whose radius is read from analytic blend faces or, for free form ones, from their curvature. Bosses of different components that share axis, radius and end planes are one boss: a tab straddling a wall shows up on both sides of it.
- Parameters:
reading – The part the faces belong to.
face_ids – The faces to examine, numbered as the faces of the part’s adjacency graph are.
tol – Length under which two values count as equal; defaults to a fixed fraction of the part’s size.
- Returns:
The bosses, ordered by their lowest face id, and the ids of the faces no boss explains.
- Raises:
ValueError – If tol is not positive.
Local features#
Recognising local features of revolution: bosses, holes and pockets turned about their own axis.
A moulded part carries many small features that are each a profile turned about a line of their
own: a bolt ear, a drafted boss with a rounded top, a drilled hole with a ball end, a counterbore.
They stand on or sink into a body that is itself built another way, so the faces they leave behind
are the ones a primary technique cannot explain. recognise_local_features() reads such faces.
The faces of a feature share an axis: cylinders, cones and tori turn about it, spheres are centred on it, and flat faces standing square to it close the ends or form the shoulders. Faces that share an axis and touch each other, or lie on one surface, make one feature. Cutting them by a half plane through the axis gives the meridian: the feature’s radius against its position along the axis, a chain of lines and arcs in which drafts, end blends and root blends appear as a slanted line or an arc tangent to its neighbours, exactly as they do in a revolved sketch.
Whether the feature is added or removed follows from which side of its faces the material lies on; a boss with a bore is read as the boss and the bore, two features on one axis. A feature is reported only when its faces turn far enough about the axis; by default that is a whole turn, so a groove cut through a wall or a pad with rounded corners is not one, and a feature that other geometry interrupts is reported when a lower share is accepted.
Conventions. The meridian lies in the axes (t, r): t is the position along axis_direction
from axis_origin and r the distance from the axis. The axis points from the root of the
feature, where it meets the body, to its tip: the end that reaches the axis or closes the feature
with a flat face, or, for a feature open at both ends such as a through hole, the narrower end. t
is zero at the root.
- class volmdlr_tools.reverse_engineering.techniques.local_features.LocalRevolvedFeature(axis_origin: tuple[float, float, float], axis_direction: tuple[float, float, float], mode: Literal['add', 'remove'], profile: tuple[Primitive2D, ...], height: float, end_kind: Literal['flat', 'conical', 'spherical', 'rounded', 'open'], radius: float, draft_angle: float | None, end_blend_radius: float | None, root_blend_radius: float | None, face_ids: frozenset[int], root_face_ids: frozenset[int], turn_share: float, area: float, deviation: float)#
Bases:
objectA boss, hole or pocket turned about its own axis.
axis_originis the point of the axis at the feature’s root andaxis_directionthe unit axis from root to tip.profileis the meridian, in the axes(t, r), as a chain from the root to the tip.modetells whether the feature is material added to the body ("add") or material taken from it ("remove").heightis the axial distance from root to tip: the depth of a hole.end_kindnames the tip:"flat","conical","spherical"(a ball end),"rounded", or"open"when the feature passes through.radiusis the radius of the longest wall at its root end, anddraft_anglethe angle in radians between that wall and the axis, positive when the feature narrows towards its tip. A wall is a line that runs further along the axis than across it; a feature with none, such as a shallow cone or an all-arc dome, gives its widest radius andNonefor the draft.end_blend_radiusandroot_blend_radiusare the radii of the arcs at the tip and at the root,Nonewhen those are sharp.face_idsnumber, as the faces of the part’s adjacency graph are, the faces the meridian explains;root_face_idsare further faces of the given piece, blends of the root on a body that is not flat, that belong to the feature without being faces of revolution.turn_shareis the share of a whole turn about the axis that the faces cover (1 when they close up, less when other geometry interrupts them),areathe area offace_idsanddeviationthe largest distance from a sample of one of those faces to the meridian turned about the axis.- closed_profile() Loop2D#
Return the region swept by the feature as a closed outline in the axes
(t, r).The meridian is closed along the axis: from each end of the chain straight to the axis, and along the axis between the two. A boss with a bore is the filled boss, from which the bore is then removed.
- property depth: float#
Return the depth of a hole or pocket: the same length as
height.
- profile_edge_tuples() list[tuple[str, dict]]#
Return the meridian as sketch edges in the axes
(t, r).
- volmdlr_tools.reverse_engineering.techniques.local_features.recognise_local_feature(reading: PartReading, face_ids: Iterable[int], *, tol: float | None = None, min_turn: float = 1.0) LocalRevolvedFeature | None#
Recognise the one feature of revolution that the faces of an isolated piece make, or
None.For a piece cut off a part on its own, a boss or pocket with its end and root blends. When the piece holds several features the one with the largest area is returned;
Nonesays the piece is not of revolution.- Parameters:
reading – the part the faces belong to.
face_ids – the faces of the piece, numbered as the faces of the part’s adjacency graph are.
tol – as for
recognise_local_features().min_turn – as for
recognise_local_features().
- Raises:
ValueError – as for
recognise_local_features().SectionError – as for
recognise_local_features().
- volmdlr_tools.reverse_engineering.techniques.local_features.recognise_local_features(reading: PartReading, face_ids: Iterable[int] | None = None, *, tol: float | None = None, min_turn: float = 1.0) tuple[LocalRevolvedFeature, ...]#
Recognise the bosses, holes and pockets of revolution among some faces of a part.
The faces are split into connected components. In each, the faces that turn about one line, and the flat faces square to it that are bounded by circles about it, are grouped, and the group is split into sets with the material on one side of their faces, joining the faces that lie on one surface. Each set whose faces turn far enough about the line is a feature when its meridian is one chain of lines and arcs. The faces of a component that no feature explains, the blend of a boss’s root on a body that is not flat for instance, are attached to the nearest feature when the faces are given.
Nothing is reported for faces that are cut through, such as a slot open on one side, or for a body of revolution whose both ends reach the axis. A face whose material side cannot be told belongs to no feature, and a set whose faces add as much material as they remove is not one.
- Parameters:
reading – the part the faces belong to.
face_ids – the faces to examine, numbered as the faces of the part’s adjacency graph are; all faces by default. Given the faces of a single isolated piece, at most the features of that piece come back, and none if the piece is not of revolution.
tol – length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
min_turn – least share of a whole turn about its axis that a feature’s faces must cover. The default asks for a whole turn; a feature that a neighbouring junction interrupts needs less, and then a quarter-turn fillet along an edge needs more than 0.25 to stay out.
- Returns:
the features, ordered by their lowest face id.
- Raises:
ValueError – if tol is not positive or min_turn is not in
(0, 1].SectionError – if a face cannot be cut by a half plane through the axis it turns about.
Local pads#
Split the pads, pockets and bosses that stand on or sink into a part, and read the pads as sketches.
Lettering, plaques, spot faces, shallow pockets and moulded tabs share one topology: a set of
faces, all the faces the feature owns, hangs from the rest of the part along a single closed loop
of edges and from nowhere else. Cutting the graph of faces along such a loop cuts the feature off.
split_local_features() finds every loop of the two kinds and cuts the part along all of them
at once, so a glyph on a plaque on a neck comes back as a tree: the glyph is a piece whose parent is
the plaque’s piece, whose parent is the neck’s. The part itself is never taken apart; only the
adjacency between its faces is read. The cutting is done by
ShapeIsolatedBossSplitter; this module reads what it cuts off.
Two kinds of loop cut a feature off:
a boss is cut off along a concave loop, either sharp, where the walls meet the base at an edge, or blended, where a ring of concave blends leaves the base (see
volmdlr_tools.features.extractors.blend_roots);a pocket is cut off along a convex loop: its rim, sharp or blended.
The piece must turn over, which keeps a lone face or a corner blend from passing for a feature. When the loop is a hole in a face, the piece is the side without that face, however large it is; the loop’s base side may also be several faces joined tangentially, which the loop is a hole in none of, and the piece is then the side of the smaller area, at most half that of the rest.
A piece is then read as a pad or a pocket, a LocalPad, when the faces across its loop lie on
one plane or cylinder, its top is an offset of that base at one height, and its side walls lean by
less than 30 degrees. Its outline is the section of the side walls by the surface midway between the
base and the top, carried back to the base along the walls’ draft, in a chart of the base: its own
plane, or for a cylinder the unrolled surface. A piece that is not a pad, because it stands on a curved
base of another kind, is taller than it is wide, has several levels or no walls, is returned as an
IsolatedPiece with the reason, so that another recogniser can take it up.
Assumptions:
a feature touches the rest of the part only along its loop: a boss running off the edge of its base has no closed loop and is not split;
the base side of a pad is one plane or one coaxial cylinder, and a pad on a cylinder does not wrap half way round it;
the side walls lean outward by no more than 30 degrees from the base normal.
- class volmdlr_tools.reverse_engineering.techniques.local_pads.IsolatedPiece(face_ids: frozenset[int], parent: int | None, kind: Literal['boss', 'pocket'], base_face_ids: frozenset[int], root_blend_face_ids: frozenset[int], reason: str)#
Bases:
objectA set of faces cut off from the rest of a part along one closed loop, that is not read as a pad.
- Parameters:
face_ids – The faces the piece owns, numbered as the faces of the part’s adjacency graph are; the faces of the pieces it contains are not among them.
parent – Index, in the result, of the piece that contains this one,
Nonewhen it stands on the rest of the part.kind –
"boss"when a concave loop cuts it off,"pocket"when a convex one does.base_face_ids – The faces of its parent, or of the rest of the part, that it hangs from.
root_blend_face_ids – The blend faces where it leaves its base, empty when the loop is sharp.
reason – Why the piece is not a pad or a pocket.
- class volmdlr_tools.reverse_engineering.techniques.local_pads.LocalPad(base_face_id: int, base_kind: ~typing.Literal['plane', 'cylinder'], frame: ~volmdlr_tools.reverse_engineering.techniques.local_pads.PadFrame, mode: ~typing.Literal['add', 'remove'], height: float, draft_angle: float, outlines: tuple[~volmdlr_tools.parametrics.curves2d.Loop2D, ...], top_blend_radius: float | None, root_blend_radius: float | None, face_ids: frozenset[int], deviation: float, parent: int | None, island_face_ids: frozenset[int] = <factory>, root_blend_face_ids: frozenset[int] = <factory>, top_blend_face_ids: frozenset[int] = <factory>, axisymmetric: bool = False, top_plane: tuple[tuple[float, float, float], tuple[float, float, float]] | None = None)#
Bases:
objectA pad raised off a base surface, or a pocket sunk into it.
- Parameters:
base_face_id – The largest face the pad stands on.
base_kind – Kind of the base surface.
frame – Sketch frame of the pad on its base.
mode –
"add"for a pad and"remove"for a pocket.height – Distance between the base surface and the top, or the floor of a pocket.
draft_angle – Angle in radians by which the walls lean, positive when the pad, or the hollow of a pocket, narrows away from the base, as a taper that eases release from a mould does.
outlines – The closed outlines of the pad’s section at the base, in the chart of frame, counter- clockwise, boundaries before the holes they enclose; a glyph with a counter has a boundary and a hole.
top_blend_radius – Radius of the rounding of the top edges,
Nonewhen they are sharp.root_blend_radius – Radius of the blend where the pad meets its base,
Nonewhen it is sharp; the mean of the radii when they differ. Both are read as a feature’s blends are, byblend_radius().face_ids – The faces the pad owns, numbered as the faces of the part’s adjacency graph are: top, walls and blends, without the faces of the pieces it contains.
deviation – Largest distance between a wall face of the pad and the drafted extrusion of its outlines.
parent – Index, in the result, of the piece the pad stands on,
Nonewhen it stands on the rest of the part.island_face_ids – Faces of the base surface the pad encloses, such as the inside of an O; they are part of the base, not of the pad.
root_blend_face_ids – The faces of the root blend.
top_blend_face_ids – The faces of the rounding of the top edges.
axisymmetric – Whether the outlines are one circle or concentric circles, a pad that axis recognisers read as a boss, hole or spot face as well.
top_plane – For a pad whose top is a plane leaning from its base, a point of that plane and its normal out of the material; height is then how high the walls reach, under the highest point of the top.
Nonefor a top parallel to the base.
- class volmdlr_tools.reverse_engineering.techniques.local_pads.PadFrame(kind: Literal['plane', 'cylinder'], origin: tuple[float, float, float], x_axis: tuple[float, float, float], y_axis: tuple[float, float, float], normal: tuple[float, float, float], radius: float | None = None, material_inside: bool = True)#
Bases:
objectThe sketch frame of a pad on its base.
Sketch points are read in a chart of the base. On a plane the chart is the plane itself: a point is
((p - origin) . x_axis, (p - origin) . y_axis), andnormalis the outward normal of the base, equal tox_axis x y_axis, and the axes are those ofsection_frame()along the normal, so pads on parallel planes share their axes. On a cylinderoriginlies on the axis,y_axisis the axis,normalpoints from the axis through the pad’s centre,x_axisisy_axis x normal, and a point is(radius * angle, (p - origin) . y_axis)whereangleturns fromnormaltowardx_axisabouty_axis. A frame compares and hashes by value.- Parameters:
kind –
"plane"or"cylinder".origin – Origin of the chart, on the base surface or on the cylinder’s axis.
x_axis – Unit direction of the first chart coordinate at the origin.
y_axis – Unit direction of the second chart coordinate; the axis of a cylinder.
normal – Unit direction
x_axis x y_axis; outward on a plane, radial on a cylinder.radius – Radius of the base cylinder,
Noneon a plane.material_inside –
Truewhen the base cylinder’s material lies inside it, as on a shaft;Falsefor a bore. AlwaysTrueon a plane, where it has no meaning.
- to_chart(points: ndarray) ndarray#
Return the chart coordinates of 3D points as an
(n, 2)array.
- class volmdlr_tools.reverse_engineering.techniques.local_pads.PadGroup(pad_indices: tuple[int, ...], base_face_ids: frozenset[int], mode: Literal['add', 'remove'], height: float, draft_angle: float)#
Bases:
objectPads that stand on one base at one height with one draft: the letters of a marking, say.
- Parameters:
pad_indices – Indices, in the result, of the pads.
base_face_ids – The base faces of the pads.
mode –
"add"or"remove".height – Mean height of the pads.
draft_angle – Mean draft angle of the pads in radians.
- volmdlr_tools.reverse_engineering.techniques.local_pads.group_local_pads(pads: Iterable[LocalPad], *, tol: float | None = None) tuple[PadGroup, ...]#
Group pads that stand on one base at one height with one draft, such as the letters of a marking.
Pads group when they share a parent and a mode, stand on the same plane or cylinder, and agree on height to 2% of the taller and on draft to half a degree. Every pad of a group agrees so with every other, and the groups do not depend on the order the pads come in.
- Parameters:
pads – Pads as returned by
recognise_local_pads().tol – Distance within which two bases are one plane or one cylinder. Omitted, it is a small fraction of the extent of the pads: the spread of their origins and their greatest height.
- Returns:
The groups, each with the indices of its pads among pads, ordered by their first pad.
- volmdlr_tools.reverse_engineering.techniques.local_pads.read_local_pad(aag: AttributedAdjacencyGraph, face_ids: Iterable[int], *, base_face_ids: Iterable[int], kind: Literal['boss', 'pocket'], root_blend_face_ids: Iterable[int] = (), tol: float | None = None, max_height_ratio: float = inf) LocalPad | IsolatedPiece#
Read a set of faces already known to be a boss or a pocket as a pad.
The faces are taken as given instead of being cut off the part by the splitter: a caller that has recognised a feature by other means asks what pad its faces make.
- Parameters:
aag – The part’s adjacency graph, with its angles calculated.
face_ids – The faces the feature owns, numbered as the faces of aag are.
base_face_ids – The faces the feature stands on or sinks into.
kind –
"boss"for material standing on the base,"pocket"for material taken from it.root_blend_face_ids – The blends between the feature’s walls and its base.
tol – Length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
max_height_ratio – Tallest the pad may be, as a fraction of the largest side of its footprint; unbounded by default.
- Returns:
The pad, or an
IsolatedPiecesaying why the faces are not one.- Raises:
ValueError – If tol or max_height_ratio is not positive.
- volmdlr_tools.reverse_engineering.techniques.local_pads.recognise_local_pads(reading: PartReading, face_ids: Iterable[int] | None = None, *, tol: float | None = None, max_height_ratio: float = 0.5) tuple[LocalPad, ...]#
Recognise the pads and pockets raised off or sunk into the surfaces of a part.
This is
split_local_features()keeping the pads: the pieces that are not one are dropped, and a pad inside one takes the nearest pad above it as its parent, numbered in the result.- Parameters:
reading – The part.
face_ids – Restrict the result to pads whose faces are all among these, numbered as the faces of the part’s adjacency graph are.
tol – Length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
max_height_ratio – Tallest a pad may be, as a fraction of the largest side of its footprint.
- Returns:
The pads, parents first.
- Raises:
ValueError – If tol or max_height_ratio is not positive.
- volmdlr_tools.reverse_engineering.techniques.local_pads.section_outlines(aag: AttributedAdjacencyGraph, face_ids: Iterable[int], frame: PadFrame, level: float, *, tol: float | None = None, opens_through: Iterable[int] = ()) tuple[Loop2D, ...]#
Cut faces by the plane parallel to a base at a height and read the cut as closed outlines.
A cut that runs out of the part leaves its walls’ section open where it leaves. Given the faces it opens through, the two ends on each plane the cut opens through are joined by a line, where the face the section stops on crosses the cutting plane. Beyond it lies either the outside of the part or another feature the cut runs into, whose own record holds that volume.
- Parameters:
aag – The part’s adjacency graph.
face_ids – The faces to cut, such as the walls of a cut running through the part.
frame – Chart of a plane base; the cut lies level along its normal from its origin.
level – Signed distance of the cutting plane from the chart’s origin, along its normal.
tol – Length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
opens_through – The faces the cut may leave the part through, none of them its own faces.
- Returns:
The outlines in the chart, counter-clockwise, boundaries before the holes they enclose.
- Raises:
SectionError – If the faces cannot be cut, or the cut does not close and its open ends do not meet two by two on flat faces the cut opens through.
ValueError – If the frame is not that of a plane.
- volmdlr_tools.reverse_engineering.techniques.local_pads.split_local_features(reading: PartReading, face_ids: Iterable[int] | None = None, *, tol: float | None = None, max_height_ratio: float = 0.5) tuple[LocalPad | IsolatedPiece, ...]#
Split the bosses and pockets off a part by the topology of its faces, and read pads among them.
Every closed loop of concave edges, every ring of concave blends that leaves a base and their convex counterparts for pockets are cut, and what each cuts off is a piece, nested in the piece it lies in. Pieces come parents first. A piece whose base is one plane or cylinder, whose top is an offset of that base and whose walls are steep enough is a
LocalPad; any other is anIsolatedPiece.- Parameters:
reading – The part.
face_ids – Restrict the result to pieces whose faces are all among these, numbered as the faces of the part’s adjacency graph are; by default every piece is returned. A piece inside a dropped one has its parent moved up to the nearest piece kept.
tol – Length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
max_height_ratio – Tallest a pad may be, as a fraction of the largest side of its footprint; a taller piece is left as an isolated piece for a boss recogniser.
- Returns:
The pieces, with their
parentgiving the index of the piece that contains them.- Raises:
ValueError – If tol or max_height_ratio is not positive.
Drafted slabs#
Recognising a stack of drafted slabs: a part built as extrusions, each with its own draft.
A moulded part is often several slabs stacked along one direction d. Inside a slab every
section by a plane normal to d is the same set of outlines, each carrier of which moves
sideways by (h - h0) * tan(draft): lines translate, arcs change radius about a fixed
centre. A draft of zero is a straight extrusion. Where a slab ends the sections stop
following that law, either because another slab with another draft starts, or because a
blend rounds the rim and the offset drifts; the slab’s clean range stops there.
Conventions. Levels are signed distances of the cutting plane along d from the origin, as
in sections.section_frame(), and the 2D axes of every section are that frame’s. Outlines
run counter-clockwise, so a carrier grows with h when it moves outward of the region its
outline encloses; for a hole that means the hole widens, which is material receding. The
draft angle is the arctangent of that growth per unit of height.
The law is followed piece by piece, not outline by outline: faces of one outline may carry different drafts, and a rolling-ball blend leaves an arc whose centre moves instead of staying put. Pieces that cannot be followed from one level to the next, or that leave the law where most of their outline keeps it, are dropped from the slab and reported as an unpaired share instead of splitting the slab. A loop’s draft is the length-weighted median of the drafts of the pieces that were followed.
A feature fused across a slab, such as a rib, replaces the outline over its own thickness, and for that stretch too little of the outline can be followed. Where the outline comes back on the law the slab already had (the same drafts, offsets carried on from the first stretch) the two stretches are one slab, and the stretch between them is reported as an interruption with the pieces that were lost in it. An outline that returns with another draft, or with other loops, is another slab.
- class volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.DraftedSlab(direction: tuple[float, float, float], frame: Frame3D, start: float, end: float, loops: tuple[Loop2D, ...], draft_angles: tuple[float, ...], draft_spread: tuple[float, ...], deviation: float, unpaired_share: float, untracked_loops: int, levels_checked: int, interruptions: tuple[SlabInterruption, ...] = (), piece_drafts: tuple[tuple[float, ...], ...] = ())#
Bases:
objectA range along a direction over which the section keeps following one law.
startandendare the ends of the clean range, as signed distances alongdirectionof the cutting plane;directionis a unit vector.loopsis the section atstartin the axes offrame, boundaries first and holes after, restricted to the loops that were followed.draft_anglesholds one angle in radians per loop, positive when the loop grows with the height (a hole growing widens): the length-weighted median over the loop’s pieces.draft_spreadis, per loop, the widest difference between two pieces’ drafts.deviationis the largest distance between a piece’s measured offset and the fitted one over every level checked,unpaired_sharethe share of the outline’s length, at its worst level, that was not followed,untracked_loopshow many loops of the reference section, the level the slab was first read at, were not followed at all, andlevels_checkedhow many levels were compared.interruptionslists the stretches insidestarttoendwhere the outline could not be followed and then came back on the same law, in order of height.piece_draftsholds, per loop, one angle per piece of the loop in order: the draft its own wall leans by, or the loop’s draft for a piece that was not followed. An outline whose walls lean differently, as when only some of them are drafted, shows it there. Slabs compare and hash by value.- piece_angles(k: int) tuple[float, ...]#
Return the draft of every piece of loop k, in order: its own where known, else the loop’s.
- property thickness: float#
Return the length of the clean range.
- uniform(k: int, angle_tolerance: float = 0.008726646259971648) bool#
Whether every piece of loop k leans by the loop’s draft, to within angle_tolerance.
- class volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.FaceSamples(reading: PartReading)#
Bases:
objectPoints inside every face of a part, read once for every slab of the part.
- Parameters:
reading – The part’s reading.
- class volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.SlabFaces(walls: frozenset[int], caps: frozenset[int], refusals: tuple[FaceRefusal, ...] = (), levels: tuple[float | None, float | None] = (None, None))#
Bases:
objectThe faces of a part that a drafted slab accounts for.
- Parameters:
walls – The faces lying on the slab’s walls: each outline of its section carried up and down by its draft.
caps – The flat faces square to the slab that close it at either end, within its section there.
refusals – The faces that could not be told to lie on the slab or not, because an outline of its section cannot be carried by its draft to their height, and why.
levels – The position along the slab’s direction of the plane of the caps at its low end and at its high end, as measured on the caps;
Noneat an end where the slab has no cap, as where it meets another slab.
- property faces: frozenset[int]#
Return the walls and the caps.
- class volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.SlabInterruption(start: float, end: float, lost: tuple[Primitive2D, ...], lost_share: float)#
Bases:
objectA stretch inside a slab over which too little of its outline could be followed.
startandendare signed distances along the slab’s direction: the last level before the stretch and the first after it at which the law held.lostholds the pieces of the slab’s reference outline, in the axes of the slab’s frame at the reference level, that were not found at some level inside the stretch, andlost_sharethe share of the reference outline’s length they make up.
- volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.holds_slabs_for(fits: TechniqueFits, number: int, among: Collection[int], normals: FaceNormals) bool#
Tell whether the part may hold slabs along an extrusion hypothesis that account for one of the faces among.
A slab is made of walls, which keep one angle to its direction all over the face, and of flat caps square to it. No slab can be read, and none is worth looking for, when no face of the part is such a wall, or when none of the faces among is a wall, a cap, or a face leaning off the direction by no more than the draft a wall may have: a round on a drafted wall leans by a little more or less from one point to the next, and is the slab’s all the same. This is read from the faces the hypothesis fits and a handful of points of each face among, where reading the slabs cuts the part again and again.
- Parameters:
fits – How the faces of the part fit each hypothesis.
number – The number of the extrusion hypothesis, in fits, the slabs would be read along.
among – The faces the slabs are wanted for.
normals – The faces’ normals, read once for the part.
- Raises:
ValueError – When the hypothesis is not an extrusion.
- volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.parting_runs(slabs: Sequence[DraftedSlab], holes: Sequence[Sequence[bool]]) list[tuple[Literal['up', 'down'], tuple[int, ...]]]#
Return the runs of neighbouring slabs that come out of the mould the same way, each with that way.
Slabs stacked along one direction and pulled out the same way were drafted from one plane: the lowest end of an upward run, or the highest end of a downward one, where the walls part from the other half of the mould.
- Parameters:
slabs – The slabs, in order along their direction.
holes – For each slab, which of its outlines are holes.
- Returns:
Each run’s way and the positions of its slabs, the lone slabs included.
- volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.recognise_drafted_slabs(reading: PartReading, direction: Sequence[float], *, tol: float | None = None, levels: int | Sequence[float] | None = None, angle_tolerance: float = 0.0017453292519943296, resolution: float | None = None, deadline: float = inf) Readings#
Find the drafted slabs stacked along direction in the part, as many as there is time for.
The part is cut at a coarse set of levels, then more finely where a steady stretch gives way to something else. A slab is a maximal run of levels over which most of the section’s outline moves, piece by piece, by a constant amount per unit height; the run’s ends are then located by bisection between the last level that follows the law and the first that does not, so a slab stops where a blend or another slab begins. Slabs are returned in order of increasing height, with whether the time ran out before the scan was read through (
timed_out). A part that is not an extrusion along direction gives none.- Parameters:
reading – the part to read.
direction – the extrusion direction; need not be a unit vector.
tol – fitting tolerance of the sections. Defaults to a fixed fraction of the shape’s diagonal. Offsets are compared to a multiple of it.
levels – the coarse scan, as a number of evenly spread levels (default 40) or as explicit signed distances along direction.
angle_tolerance – draft difference, in radians, below which two halves of a slab count as one slope, when deciding whether its growth is a line rather than a curve.
resolution – how closely a slab’s ends are located, as a distance. Defaults to a fixed fraction of the shape’s extent along direction.
deadline – the moment, on the performance counter, after which the scan is refined no further and no further slab is grown: the slabs found by then are returned, marked as cut short.
- Raises:
ValueError – when direction is null or fewer than three levels are asked for.
- volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.release_of(slab: DraftedSlab, holes: Sequence[bool]) Literal['up', 'down'] | None#
Return the way a slab comes out of the mould, from the way each of its walls leans.
A boundary that shrinks as it rises and a hole that widens both let the material out towards higher levels. Walls that stand straight say nothing; what counts as straight is
mould_release()’s to say, the one rule for every profile.- Parameters:
holes – For each outline of the slab, whether it is a hole.
- Returns:
Nonewhen no wall leans, or when walls lean both ways, as a slab with no single pull has.
- volmdlr_tools.reverse_engineering.techniques.drafted_extrusion.slab_faces(reading: PartReading, slab: DraftedSlab, extrusion: ExtrusionReading, tol: float | None = None, *, samples: FaceSamples | None = None) SlabFaces#
Return the faces of the part that slab accounts for: those on its walls, and the caps closing it.
A wall is a face reaching into the slab’s range whose samples mostly lie on its outlines, each carried by its draft to the sample’s height: a wall that goes on past the range, up to where a blend rounds the rim, is still the slab’s. A slab is read from sections, so its range stops short of such a rim; at each end, its cap is at the nearest level, at or beyond that end, of the flat faces square to the slab that lie inside its section and touch one of its walls, directly or through a blend rounding its rim. A face at that level that also does is a cap.
A face that is neither, at a height an outline of the section cannot be carried to by its draft, is refused: the slab cannot say whether it holds it.
- Parameters:
reading – The part’s reading.
slab – A slab read from the part along one direction.
extrusion – The extrusion of the part along that direction; its caps are the flat faces square to the slab.
tol – The tolerance of the slab’s sections. Defaults to the one the slab was read with by default.
samples – The samples of the part’s faces, when several slabs of the part are read; sampled here when omitted.
- Raises:
ValueError – When the extrusion is not along the slab’s direction.
Offset shells#
Recognise a wall of constant thickness as the offset of its inner skin.
A moulded, cast or drawn part is often a cavity wrapped in a wall: the outer skin is the inner
skin pushed out by one distance. Its faces need not agree one to one. Blends and free form
patches of the two skins are cut differently, so an outer face may cover several inner ones and
the other way round. recognise_offset_shells() therefore pairs points, not faces: from a
point of a face it looks into the material along the normal and measures the distance to the far
skin. Where the far skin is an offset, that distance is the same at every point, the far normal
is opposite to the near one, and the hit lies on the normal line.
Assumptions:
A wall is found where the distances measured over a share of the part’s surface follow one law within the tolerance: a constant thickness, or a thickness that changes linearly with the position along a pull direction, as it does when the two skins are drafted differently. The pull direction is tried among the part’s dominant axes. Each distinct law explains one set of samples, and a face may be explained by several laws.
A face belongs to a wall when at least
min_face_shareof its area is paired according to the law. A wall is one connected group of such faces, so two walls sharing a law but not touching are two shells. The two skins are told apart by which faces are paired across the wall.A wall is thin: its thickness is at most
max_relative_thicknesstimes the side of a square with the area of its smaller skin. Two opposite faces of a block are as far apart as the block is thick, and are not a wall.The inner skin is the one facing the void the wall encloses: more of the lines leaving it away from the material meet the part again than those leaving the outer skin. A flat plate encloses nothing, and its two skins are then told apart by area and face number only.
An opening is a group of faces, joining the skins, that is next to both the inner and the outer skin: the rim of a cup’s mouth. Faces next to only one skin are attachments and are not reported.
A wall is read in a region only where its two skins face each other inside one connected piece of the region; faces next to the piece help measure it but are not part of it.
- class volmdlr_tools.reverse_engineering.techniques.offset_shell.OffsetShell(inner_face_ids: frozenset[int], outer_face_ids: frozenset[int], thickness: float, coverage_inner: float, coverage_outer: float, deviation: float, enclosure_inner: float, enclosure_outer: float, opening_face_ids: frozenset[int], opening_edge_ids: frozenset[int], thickness_gradient: float | None = None, pull_direction: tuple[float, float, float] | None = None, thickness_station: float | None = None, unread_face_ids: frozenset[int] = frozenset({}))#
Bases:
objectA wall whose outer skin is the inner skin offset by a distance that is constant or changes linearly.
- Parameters:
inner_face_ids – Faces of the skin facing the void the wall encloses, numbered as the faces of the part’s adjacency graph are.
outer_face_ids – Faces of the other skin.
thickness – Distance between the skins, along the normal; with a gradient, its value at
thickness_station, the mean position of the paired points along the pull direction.coverage_inner – Share of the inner skin’s area paired with the outer skin at the thickness.
coverage_outer – Share of the outer skin’s area paired with the inner skin at the thickness.
deviation – Largest difference between the thickness law and a measured distance, over the paired points.
enclosure_inner – Share of the lines leaving the inner skin away from the material that meet the part again.
enclosure_outer – The same for the outer skin; the inner skin is the one with the higher share.
opening_face_ids – Faces of the rims where the wall is open, each group joining the two skins.
opening_edge_ids – Edges where the skins meet those rims, numbered as the edges of the part’s adjacency graph are.
thickness_gradient – Change of thickness per unit of position along
pull_direction,Nonewhen the thickness is constant.pull_direction – Unit direction the thickness changes along, whose largest component is positive;
Nonewhen the thickness is constant.thickness_station – Position along
pull_directionat which the thickness isthickness;Nonewhen the thickness is constant.unread_face_ids – Faces of the reading’s scope that could not be read, so that no distance was measured from them or to them: the whole part, or for a region the region and the faces next to it. It is not a claim on them; when there are any, a thickness across them may be that of a farther skin.
- thickness_at(points: ndarray) float#
Return the wall’s thickness at the mean position of some points along the pull direction.
The points should lie on either skin, in one section square to the pull direction: one thickness is returned for all of them, read where their mean lies along that direction. A wall of constant thickness returns
thicknesswherever the points are.- Parameters:
points – Points of the wall’s skin, as an
(n, 3)array.- Returns:
The thickness there.
- Raises:
ValueError – When no point is given.
- thickness_slope_along(direction: Sequence[float] | ndarray) float#
Return how much the wall’s thickness changes per unit of length along direction.
A wall whose thickness follows a linear law along its pull direction changes along any other direction by the law’s gradient times the cosine between the two, so not at all square to the pull. A wall of constant thickness has a slope of zero.
- Parameters:
direction – A direction; only its sense counts, not its length.
- Returns:
The change of thickness per unit of length.
- Raises:
ValueError – When direction has no length.
- volmdlr_tools.reverse_engineering.techniques.offset_shell.recognise_offset_shells(reading: PartReading, *, region: Iterable[int] | None = None, tol: float | None = None, min_area_share: float = 0.01, min_face_share: float = 0.5, max_relative_thickness: float = 0.3, samples_per_face: int = 9, angle_sine: float = 0.05, deadline: float = inf) Readings#
Recognise the walls of a part whose outer skin is its inner skin offset by a constant or linearly changing distance.
Points of every face are looked along the inward normal to the skin on the far side of the material. The distances that many points agree on, as a constant or as a linear function of the position along a dominant axis, are the thickness laws; the faces paired according to one law over most of their area, connected to each other, form a wall.
- Parameters:
reading – The part to examine.
region – Faces of the part to read, numbered as the adjacency graph numbers them; the whole part when
None. A wall returned holds only these faces; their neighbours may help measure it. The share of the part’s surface a wall must cover (min_area_share) is that of the wall as held in the region. Both skins of a wall must lie in one connected piece of the region: a wall whose skins the region holds apart, joined only through faces outside it, is read by the whole part alone.tol – Length under which two thicknesses count as equal; defaults to 1e-4 of the bounding box diagonal.
min_area_share – Smallest share of the part’s surface that a wall’s two skins together must cover.
min_face_share – Smallest share of a face’s area that must be paired at the thickness for it to join a wall.
max_relative_thickness – Largest ratio of the thickness to the side of a square with the area of the smaller skin; a block’s opposite faces are not a wall.
samples_per_face – Number of points examined on every face.
angle_sine – Largest sine of the angle between the normal and the line to the far point, and between the far normal and the opposite of the near one, for two points to be paired.
deadline – The moment, on the performance counter, after which no further thickness is read into walls: the walls built by then are returned, marked as cut short.
- Returns:
The walls, thickest first then by lowest face id, empty when the part has none, with whether the time ran out before every thickness was read (
timed_out).- Raises:
ValueError – If a numeric argument is not positive or a share is not in ]0, 1], if region holds no face, or if no face to read can be triangulated, so that there is nothing to read.
IndexError – If a face of region is no face of the part.
Sweeps#
Recognising a sweep: a profile carried along a path, from one planar cap to another.
A swept body is a profile moved along a path, standing square to it. Its two ends are planar faces, the caps, whose normals are the path’s direction where it leaves and where it arrives. Its lateral faces may be anything: cylinders and planes where the path is a chain of lines and arcs, free-form patches where it is a curve.
Assumptions:
A cap is a planar face with a single outline, and the sweep leaves it along its inward normal. The centre of the cap is a point of the path.
Cut by a plane that stands square to the path, the part gives one closed outline without holes, the profile at that station. The path is followed from station to station, each at the area centre of the profile, until it lands on a second cap.
A profile that stays the same all along the path is a constant sweep. One that changes is drawn through sections: it stays the same between two of them, so the stretches where it does not change tell where the sections stand.
A path that does not turn and a profile that does not change are an extrusion, and a path that does not turn under a changing profile is a loft; neither is read here.
The path is read as a chain of lines and arcs when it lies in a plane and such a chain holds to the stations within tolerance, and as a smooth curve through the stations otherwise.
- class volmdlr_tools.reverse_engineering.techniques.sweep.PlanarPath(frame: Frame3D, primitives: tuple[Primitive2D, ...])#
Bases:
objectA path made of lines and arcs in one plane, each piece starting tangent to the one before it.
- Parameters:
frame – The plane: its origin is the path’s start, its first axis the path’s direction there, and its third axis the normal the path turns about, counter-clockwise, where it first turns.
primitives – The pieces in the axes of the frame, the first starting at the origin.
- class volmdlr_tools.reverse_engineering.techniques.sweep.SplinePath(points: tuple[tuple[float, float, float], ...], start_tangent: tuple[float, float, float], end_tangent: tuple[float, float, float], deviation: float, scalars: tuple[float, float] | None = None)#
Bases:
objectA smooth path drawn through points, leaving along a given direction and arriving along another.
- Parameters:
points – Where the path passes, from its start to its end.
start_tangent – Unit direction at the start.
end_tangent – Unit direction at the end.
deviation – Largest distance of a station of the sweep from the path.
scalars – Factors of the tangents’ lengths at the two ends;
Nonewhen the curve chooses them.
- class volmdlr_tools.reverse_engineering.techniques.sweep.Station(arc_length: float, point: tuple[float, float, float], tangent: tuple[float, float, float], area: float, perimeter: float)#
Bases:
objectThe profile at one point of the path.
- Parameters:
arc_length – Distance along the path from its start.
point – The area centre of the profile.
tangent – Unit direction of the path.
area – Area of the profile.
perimeter – Length of the profile’s outline.
- class volmdlr_tools.reverse_engineering.techniques.sweep.Sweep(faces: frozenset[int], caps: tuple[int, int], stations: tuple[Station, ...], section_lengths: tuple[float, ...], tolerance: float, size: float)#
Bases:
objectA profile swept along a path between two planar caps.
- Parameters:
faces – The part’s faces the sweep accounts for: the caps and the lateral faces its profile cuts.
caps – The part’s two planar faces the sweep starts and ends on, in that order.
stations – The profile along the path, first to last, where the march measured it.
section_lengths – Arc lengths at which the profile is drawn: the two ends, and where it comes to rest in between. A single length,
0.0, when the profile never changes.tolerance – How far the stations may stray from the path the sweep is read as.
size – Diagonal of the part’s bounding box.
- property constant: bool#
Whether the profile is the same all along the path.
- property length: float#
Length of the path.
- property points: ndarray#
The area centres of the stations, as an
(n, 3)array.
- property tangents: ndarray#
The path’s direction at the stations, as an
(n, 3)array.
- class volmdlr_tools.reverse_engineering.techniques.sweep.SweepRefusal(reason: str, face: int, straight: bool = False)#
Bases:
FaceRefusalA pair of caps, or one cap, that was not read as the ends of a sweep, and why.
- Parameters:
reason – Why the part is not a sweep from there.
face – The cap the path was followed from.
straight – Whether the path does not turn, so the body is an extrusion or a loft and not a sweep.
- volmdlr_tools.reverse_engineering.techniques.sweep.cap_outline(reading: PartReading, face: int, x_dir: Sequence[float], tol: float | None = None) Loop2D#
Read the outline of a planar cap as lines and arcs, in the axes standing on its centre.
- Parameters:
reading – The part.
face – Index of the cap among the part’s faces.
x_dir – First axis of the 2D coordinates; the second is the cap’s inward normal crossed with it.
tol – Fitting tolerance. Defaults to a fraction of the part’s size.
- Returns:
The outline, counter-clockwise seen from the cap’s inward side.
- Raises:
SectionError – When the cap has no centre or normal, or its outline is not made of lines and arcs.
- volmdlr_tools.reverse_engineering.techniques.sweep.fit_planar_path(sweep: Sweep) PlanarPath | None#
Read the path as a chain of lines and arcs in a plane, each starting tangent to the one before.
- Parameters:
sweep – The sweep.
- Returns:
The chain, or
Nonewhen the path does not lie in a plane or no short chain holds to its stations.
- volmdlr_tools.reverse_engineering.techniques.sweep.fit_spline_path(sweep: Sweep) SplinePath | None#
Read the path as a smooth curve through a few points, leaving and arriving along the caps’ normals.
The fewest points are used with which every station lies within the tolerance of the curve, the points themselves and the length of the tangents being fitted to the stations.
- Parameters:
sweep – The sweep.
- Returns:
The curve, or
Nonewhen no curve through a few points follows the stations.
- volmdlr_tools.reverse_engineering.techniques.sweep.recognise_sweeps(reading: PartReading, max_cuts: int = 2000, *, region: Iterable[int] | None = None, deadline: float = inf) tuple[list[Sweep], list[SweepRefusal]]#
Read the part’s pairs of planar caps joined by a path as sweeps, as many as there is time for.
- Parameters:
reading – The part.
max_cuts – How many cuts the paths followed from every cap may take in all; the caps left once they are spent are refused, so the same part always gives the same reading.
region – Faces of the part to read, numbered as the adjacency graph numbers them; the whole part when
None. A sweep is read when every face it is carried along lies in the region; its caps may lie next to it. The part is cut by planes only where it is made of the region and the faces next to it, so that a profile is read from those faces alone; a sweep that reaches past the region is refused.deadline – The moment, on the performance counter, after which no path is followed further. The caps left are refused as out of time.
- Returns:
The sweeps, and the caps that were tried as the start of one and not read as such, with the reason; for a region, the caps of the region only.
- Raises:
ValueError – If region holds no face.
IndexError – If a face of region is no face of the part.
- volmdlr_tools.reverse_engineering.techniques.sweep.section_at(reading: PartReading, origin: Sequence[float], tangent: Sequence[float], x_dir: Sequence[float], tol: float | None = None) Loop2D#
Cut the part by the plane standing on a path and return the profile there.
- Parameters:
reading – The part.
origin – A point of the path, in the plane.
tangent – Direction of the path: the plane’s normal.
x_dir – First axis of the 2D coordinates of the outline; the second is
tangent x x_dir.tol – Fitting tolerance of the outline. Defaults to a fraction of the part’s size.
- Returns:
The outline of the cut nearest origin, counter-clockwise, as lines and arcs.
- Raises:
SectionError – When the plane cuts no outline, or the one it cuts is not made of lines and arcs.
Planar sweeps#
Recognising a closed planar sweep: a constant profile carried once round a planar loop.
A gasket, a seal or a ring is a profile swept along a closed path that lies in one plane. Cut such a part by that plane and its section is an annulus: an outer and an inner outline that are offsets of each other. The path is the outline midway between them, and the profile is the section of the part by a plane standing on the path.
Blends need no special care. A fillet of the profile is an arc of the profile’s own section, and a fillet of the path is an arc of the path. What interrupts the sweep, a boss on the wall for instance, appears as outline with no partner on the other side of the wall; it is reported as an interruption and the profile is read where none is nearby.
Conventions. The path lies in the plane frame, whose w axis is the sweep normal n
and whose 2D axes are the frame’s u and v; the path runs counter-clockwise seen
from +n. The profile lies in a station frame: w is the path tangent, u points
to the left of the path (n x w, seen from +n) and v is n. The profile’s 2D
origin is therefore on the path, at the height of the plane frame.
- class volmdlr_tools.reverse_engineering.techniques.planar_sweep.PlanarSweep(plane_frame: Frame3D, path: Loop2D, profile: Loop2D, station_frame: Frame3D, station_parameter: float, wall_offset: float, interruptions: tuple[Primitive2D, ...], invariance_deviation: float, stations_checked: int, path_tangency: TangencyFit)#
Bases:
objectA profile swept along a closed planar path.
plane_frameis the frame of the cutting plane, assection_frame()gives it for the sweep normal.pathis in its 2D axes;profileis in the 2D axes ofstation_frame, whose origin is the point of the pathstation_parameter(an arc length from the path start) along. By invariance the same 2D profile holds in the frame of any other station, in particularpath_start_frame().interruptionsare the outline primitives (plane-frame coordinates) that have no partner across the wall.path_tangencyreports how the path’s tangent junctions were made exact.- path_edge_tuples() list[tuple[str, dict]]#
Return the path as sketch edges in the 2D axes of
plane_frame.
- property path_length: float#
Return the length of the path.
- path_start_frame() Frame3D#
Return the frame standing on the start of the path,
walong the path tangent.Its axes follow the station convention:
uto the left of the path,vthe sweep normal.
- property profile_area: float#
Return the area enclosed by the profile.
- profile_edge_tuples() list[tuple[str, dict]]#
Return the profile as sketch edges in the 2D axes of a station frame.
- volmdlr_tools.reverse_engineering.techniques.planar_sweep.recognise_planar_sweep(reading: PartReading, tol: float | None = None) PlanarSweep | None#
Return the closed planar sweep that the part is, or
Nonewhen it is not one.The part’s dominant axes are tried as the sweep normal, strongest first. At the middle of the part’s extent along each, the section must be an annulus: an outline and a hole that are offsets of each other over most of their length. The path is the outline midway between them. The profile is read from a plane standing on the path where the wall is free of interruptions, and must agree, to within a few section tolerances, with the profile read at every other free stretch of the path, and at four stations at least: where too few stretches are free, at the points of the path farthest from the interruptions.
A tube read this way is a sweep of a rectangle along a circle, and a torus a sweep of a circle along a circle; a revolution recogniser would claim both as well.
- Parameters:
reading – the solid to read.
tol – fitting tolerance of the sections. Defaults to a fraction of the part’s size.
- Returns:
the sweep, or
Nonewhen the part is not a closed planar sweep.
Channels#
Recognising a channel: a profile removed once round a closed planar path.
A seal groove or a cooling channel is the subtractive twin of a gasket. Cut the part by a plane across the channel and the section has two outlines that bound a void between them: an outer wall, and inside it an island of material. Seen from the void the two are offsets of each other, so the channel’s path is the outline midway between them, exactly as for a solid ring.
The profile is the void itself. A plane standing on the path cuts a notch in the part’s outline: walls and a floor, joined by blends, that open onto the surrounding land. The notch is read between the two flat stretches of land that bound it, and the same notch must be found at every other stretch of the path that is free of interruptions, a slot through a wall for instance, and at four stations at least.
Conventions. The path lies in the plane frame, whose w axis points out of the open side of
the channel and whose 2D axes are the frame’s u and v; the path runs counter-clockwise
seen from +w. The profile lies in a station frame: w is the path tangent, v is the
plane frame’s w (so the channel opens towards +v) and u points to the left of the path
seen from the open side. The profile’s 2D origin is on the path, at the height of the plane
frame; its floor is below the origin and its mouth above.
- class volmdlr_tools.reverse_engineering.techniques.channel_sweep.ChannelSweep(plane_frame: Frame3D, path: Loop2D, profile: Loop2D, mouth_index: int, station_frame: Frame3D, station_parameter: float, width: float, floor_height: float, mouth_height: float, interruptions: tuple[Primitive2D, ...], deviation: float, stations_checked: int, face_ids: tuple[int, ...], path_tangency: TangencyFit)#
Bases:
objectA profile removed along a closed planar path.
pathis in the 2D axes ofplane_frameandprofileis the closed void outline, counter- clockwise, in the 2D axes ofstation_frame, whose origin is the point of the pathstation_parameter(an arc length from the path start) along. The primitivemouth_indexof the profile closes it across the open side; the others are the walls, blends and floor. By invariance the same profile holds at every other station.widthis the distance between the two walls halfway between floor and land,floor_heightandmouth_heightare the heights of the floor and of the land alongplane_frame.wfrom that frame’s origin, anddepthis their difference.interruptionsare the outline primitives (plane-frame coordinates) without a partner across the channel;face_idsnumber, as the faces of the part’s adjacency graph are, the faces that bound the channel.- property depth: float#
Return the distance from the floor to the land.
- path_edge_tuples() list[tuple[str, dict]]#
Return the path as sketch edges in the 2D axes of
plane_frame.
- property path_length: float#
Return the length of the path.
- property profile_area: float#
Return the area of the channel’s cross section.
- profile_edge_tuples() list[tuple[str, dict]]#
Return the profile as sketch edges in the 2D axes of a station frame.
- property walls: tuple[Primitive2D, ...]#
Return the profile without its mouth: the walls, blends and floor, as one chain.
- volmdlr_tools.reverse_engineering.techniques.channel_sweep.recognise_channels(reading: PartReading, direction: tuple[float, float, float], *, tol: float | None = None, levels: list[float] | None = None) tuple[ChannelSweep, ...]#
Return the closed channels the part has, read along direction.
The part is cut by planes normal to direction. At a level where a channel runs, the section has a wall and an island inside it that are offsets of each other over most of their length. The path is the outline midway between them; the profile is the notch a plane standing on the path cuts, read where the channel is free of interruptions, and it must agree, to within a few section tolerances, with the notch read at every other free stretch of the path, and at four stations at least: where too few stretches are free, at the points farthest from the interruptions. Sealed voids, which a plane standing on the path cuts as a hole and not as a notch, are not channels, and neither is a raised ring, whose outlines are not a void.
Every channel a level crosses is read, two grooves side by side or one inside the other included, and a channel is reported once however many levels cross it.
- Parameters:
reading – the part to read.
direction – the direction the channels are cut along, for instance the part’s strongest axis; its sign does not matter, each channel reports the side it opens on.
tol – fitting tolerance of the sections. Defaults to a fraction of the part’s size.
levels – distances along direction, from the origin, of the cutting planes. By default one plane in each band between the heights at which flat faces cut the part.
- Returns:
the channels, in the order of the level that first showed them, and at one level from the widest wall in.
- Raises:
ValueError – if direction is zero.
Helical sweeps#
Recognising a helical sweep: a profile carried along a helix, from one planar cap to another.
A profile swept along a helix, standing square to it as the wire of a coil spring does, makes a body that a screw motion carries onto itself: a turn about the helix’s axis together with an advance along it, in proportion. The motion slides each lateral face along itself, so at every point of a lateral face the velocity of the motion lies in the face’s tangent plane. That condition is linear in the six numbers of the motion, so the motion is read from points and normals of the faces, without cutting the part. A plane across a coil meets every turn of it, which makes following the path by cuts slow, and the helix is no chain of lines and arcs and no short spline.
Assumptions:
The lateral faces are faces of the part that are not planar and are joined to one another. They meet the rest of the part at exactly two planar faces with a single outline each, the caps.
One screw motion, and no other, carries every lateral face onto itself. A turned or an extruded body is carried onto itself by more than one motion and is not read here, and neither is a body turned about an axis without advancing along it.
The helix runs on a cylinder, passes through the centre of each cap and stands square to both.
- class volmdlr_tools.reverse_engineering.techniques.helical_sweep.HelicalSweep(faces: frozenset[int], caps: tuple[int, int], axis_origin: tuple[float, float, float], axis: tuple[float, float, float], start: tuple[float, float, float], end: tuple[float, float, float], radius: float, pitch: float, height: float, lefthand: bool, slide: float)#
Bases:
objectA profile swept along a cylindrical helix, between two planar caps.
- Parameters:
faces – The part’s faces the sweep accounts for: the caps and the lateral faces.
caps – The part’s two caps, the one the helix starts on first.
axis_origin – The point of the helix’s axis level with its start.
axis – Unit direction of the axis, the way the helix advances from its start to its end.
start – Where the helix starts: the centre of the first cap.
end – Where the helix ends: the centre of the second cap.
radius – Distance of the helix from its axis.
pitch – Advance along the axis in one turn.
height – Advance along the axis from the start to the end.
lefthand – Whether the helix turns clockwise about its axis, seen with the axis pointing at the viewer.
slide – Largest sine of the angle by which the motion leaves a lateral face.
- property turns: float#
Number of turns the helix makes about its axis.
- volmdlr_tools.reverse_engineering.techniques.helical_sweep.recognise_helical_sweeps(reading: PartReading) tuple[list[HelicalSweep], list[FaceRefusal]]#
Read the part’s bands of faces carried onto themselves by a screw motion, between two caps, as helical sweeps.
- Parameters:
reading – The part.
- Returns:
The helical sweeps, and the bands between two caps that were not read as one, with the reason.
Lofts#
Recognising a loft: a band of free-form faces skinned through closed planar sections.
A lofted solid is a surface drawn through outlines that lie on parallel planes, joined end to end by planar faces or by the faces of the body the loft was grown on. Its lateral faces are free-form patches, and the outlines are the edges the band of patches ends on.
Assumptions:
A lateral face is a B-spline or Bezier surface. Faces that share an edge belong to one band. The seam of a surface that closes on itself is not an end of the band.
The band ends on closed loops of edges, each lying in one plane, and every one of those planes has the same normal. The loops are the sections, ordered by their distance along that normal.
A section is read as lines and arcs, merged where neighbouring pieces share a carrier, so a circle that the part stores as several arcs is one circle and a straight side that it stores in two pieces is one line. A section no lines and arcs follow is refused.
The sections are the ends of the band’s surfaces along the parameter that runs from one section to the next, not only the edges of the part: a loft grown on or cut by another body keeps its whole surface, and its first section may lie inside the body. Where a surface cannot be read that way, the edges the faces end on are used.
A band that is ruled between two sections has a degree-one direction on every face. A smooth band is drawn through more sections than its ends:
resampled()cuts it at evenly spread levels, for the count its poles across the sections suggest.A wall of constant thickness grown on a loft shows as a face that is an offset of the band (
recognise_loft_wall()), open at each end that no face of the part covers.
- class volmdlr_tools.reverse_engineering.techniques.loft.Loft(direction: tuple[float, float, float], faces: frozenset[int], sections: tuple[LoftSection, ...], ruled: bool, caps: frozenset[int] = frozenset({}), section_count: int = 2, void: bool = False)#
Bases:
objectA band of free-form faces skinned through planar sections.
- Parameters:
direction – Unit normal of the sections’ planes, pointing from the first section to the last.
faces – The part’s faces of the band.
sections – The sections, first to last along
direction.ruled – Whether the band is straight between neighbouring sections.
caps – Planar 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 pocket do, and not a body, with the material inside.
section_count – How many sections the surface was most likely drawn through: the poles it has across the sections for a smooth band, two for a ruled one.
- class volmdlr_tools.reverse_engineering.techniques.loft.LoftRefusal(reason: str, faces: frozenset[int])#
Bases:
FaceRefusalA band of free-form faces that was not read as a loft, and why.
- class volmdlr_tools.reverse_engineering.techniques.loft.LoftSection(level: float, loop: Loop2D)#
Bases:
objectOne outline the loft passes through.
- Parameters:
level – Signed distance of the section’s plane from the origin along the loft’s direction.
loop – The outline, counter-clockwise, in the axes of
section_frame(direction, level).
- class volmdlr_tools.reverse_engineering.techniques.loft.LoftWall(thickness: float, faces: frozenset[int], open_ends: tuple[bool, bool])#
Bases:
objectA wall of constant thickness grown on the outside of a loft, as the offset of its band.
- Parameters:
thickness – Distance between the band and the offset surface.
faces – The part’s faces of the wall: the offset surface and the planar faces that join it to the band.
open_ends – Whether the wall is open at the loft’s first and last sections, in that order.
- volmdlr_tools.reverse_engineering.techniques.loft.chain_curves(pool: dict[int, ndarray], join: float) list[list[tuple[int, ndarray]]] | None#
Chain the sampled curves end to end into closed loops, each curve in the direction it is travelled.
- Parameters:
pool – The samples of each curve, from its start to its end, by the curve’s key.
join – How far apart the end of one curve and the start of the next may be.
- Returns:
The loops, each a list of
(key, samples);Nonewhen the curves do not close.
- volmdlr_tools.reverse_engineering.techniques.loft.loop_of_chain(chain: list[tuple[int, ndarray]], frame_axes: tuple[ndarray, ndarray, ndarray], tol: float) Loop2D#
Fit a chain of sampled edges with lines and arcs, one edge at a time, and merge what shares a carrier.
- Parameters:
chain – The loop’s curves end to end, as
chain_curves()gives them.frame_axes – The origin and the two axes of the plane the loop is read in.
tol – The distance within which a line or an arc stands for the samples.
- Returns:
The loop in that plane, counter-clockwise about its normal.
- Raises:
ValueError – When an edge is not made of lines and arcs.
- volmdlr_tools.reverse_engineering.techniques.loft.recognise_loft_wall(reading: PartReading, loft: Loft) LoftWall | None#
Read the part as the loft’s wall: its band is the inside skin and an offset of it is the outside one.
An end of the wall is open when no face of the part covers the loft’s section there. A section whose interior holds a face of the part is closed by it, whatever else touches it.
- Parameters:
reading – The part the loft was read from.
loft – The loft.
- Returns:
The wall, or
Nonewhen no face of the part is an offset of the loft’s band.
- volmdlr_tools.reverse_engineering.techniques.loft.recognise_lofts(reading: PartReading, *, region: Iterable[int] | None = None, deadline: float = inf) tuple[list[Loft], list[LoftRefusal]]#
Read the bands of free-form faces of a part as lofts, as many as there is time for.
- Parameters:
reading – The part.
region – Faces of the part to read, numbered as the adjacency graph numbers them; the whole part when
None. A loft is read when its whole band lies in the region; the planar faces that close it are looked for among the faces next to the region. A band that reaches past the region is refused, over the faces of it in the region. Only the region and the faces next to it are looked at.deadline – The moment, on the performance counter, after which no further band is read; the bands left are refused as out of time.
- Returns:
The lofts, and the bands that were not read as one with the reason each was not.
- Raises:
ValueError – If region holds no face.
IndexError – If a face of region is no face of the part.
- volmdlr_tools.reverse_engineering.techniques.loft.resampled(reading: PartReading, loft: Loft, count: int) Loft#
Return the loft with count sections spread evenly between its ends, cut from its faces.
A smooth band does not show the sections it was drawn through as edges. When they were evenly spread, the right count gives sections that the band passes through exactly.
- Parameters:
reading – The part the loft was read from.
loft – The loft, whose two ends are kept as they are.
count – Number of sections, at least two.
- Raises:
ValueError – When a section the band makes is not made of lines and arcs, or count is below two.
Ribs#
Recognise ribs: thin plates standing on a body, with the drafts and blends moulding leaves on them.
A rib, fin or gusset is a plate grown from the body it stands on. It has two opposite side faces that
face away from each other with material between them, a small thickness next to its height and
length, a free top, and usually a blend where each side meets the body. Moulded ribs taper: the two
sides lean towards each other by the same draft angle, so they are two planes that are not quite
parallel. recognise_ribs() reads such pairs of faces and describes each as a RibPlate, in the
terms a designer would rebuild it with: a profile drawn on the rib’s mid plane, a thickness at the root, a
draft, a top that is flat or rounded, and a root blend.
Assumptions:
The two sides are planar, or free form surfaces that are flat to within the tolerance. A side split into several faces is not joined, so it is read as a rib only if one of its pieces pairs with the other side well enough.
A pair is a rib when the sides face away from each other with material between them, lean at most the largest draft from being parallel, overlap when projected on each other, are closer than the thickness ratio allows next to the extent of their overlap, and each meets the rest of the part along a concave edge or a concave blend (the root). A plate with no root, such as the two faces of a plain block, is not a rib; a block as thick as it is tall is not one either. The blends rounding a rib’s root and top trim its flat sides, so the extent counts them back in: the largest radius of the concave blends meeting the sides tangentially, at the root, and of the convex ones, at the top.
The sides must also meet a free top: a convex edge or a convex blend. A wall closed off by the body on every side is a web between two bodies, not a rib.
The mid plane is the bisector of the two side planes, so it is the plane of symmetry of a symmetrically drafted rib. The profile is the part of the mid-plane section that lies on the rib’s own top and end faces, closed along the faces the rib stands on. The part of the section inside the body is never part of it. A rib flush with the edge of its body shares a face with it, so its section runs on along the body’s outline; it is cut where it first crosses a face the rib stands on. A straight end of the top that lands on a root blend is carried on along itself to the first face the rib stands on, where the root met it before it was rounded. When the ends of the top do not land on faces the mid plane cuts in straight lines (planes, and cylinders or cones whose axis lies in it) the profile is closed by a straight chord, and the result says so.
A round ending the top that lands on a turned face (nearly) tangentially, as a moulded rib’s blend into a hub or a shell does, is slid along the top towards that face by a hundredth of its radius, so that it crosses the face at an angle instead of touching it along a line: a solid with such a touching cannot have the top’s edges rounded. The profile then departs from the input by at most that slide.
The thickness is measured at the root, where the profile is closed, not at the tangent edge of the root blend.
A plate whose top runs all the way round it is its own outline, and that outline holds nothing but material: a loop of the mid-plane section lying inside it bounds a void, a hole through the plate where a hollow body passes through it, which a rib drawn from the outline would fill. Such a plate, as the disk of a flange round a bored hub, has no profile, and the result says why.
- class volmdlr_tools.reverse_engineering.techniques.ribs.RibPlate(face_ids: frozenset[int], side_face_ids: tuple[int, int], base_face_ids: frozenset[int], frame: Frame3D, profile: Loop2D | None, profile_error: str | None, profile_closure: Literal['base', 'chord'] | None, thickness: float, draft_angle: float, lateral_taper: float, height: float | None, length: float | None, top_kind: Literal['flat', 'round'], top_radius: float | None, root_radius: float | None, deviation: float, root_pieces: int = 0, top_room: tuple[float, float] = (inf, inf), landing_slide: tuple[float, float] = (0.0, 0.0), tolerance: float = 1e-06)#
Bases:
objectA thin plate standing on a body, described the way it would be rebuilt: a profile on its mid plane.
The feature-level
Ribnames the same faces by role:side_face_idsare its end faces, the tops amongface_idsits shell faces, the top and root blends its fillet faces andbase_face_idsits base faces. Both tell the roles of the faces around a side from the convexity the adjacency graph gives their edges. This record adds what a rebuild needs: the mid-plane frame and profile, the thickness at the root, the draft and the radii of the top and root blends.- Parameters:
face_ids – Every face of the rib: its two sides, its top and end faces, its top blends and its root blends, numbered as the faces of the part’s adjacency graph are.
side_face_ids – The two side faces, the first having the lower id.
base_face_ids – The faces the rib stands on, reached through sharp roots or through root blends.
frame – A frame on the mid plane, whose
waxis is the plane’s normal, pointing from the second side to the first.vpoints from the root towards the top andualong the rib.profile – The outline of the rib in the axes
uandvofframe, counter-clockwise: the mid-plane section of the rib’s own top and end faces, closed along the faces the rib stands on.Nonewhen the section could not be read;profile_errorthen says why.profile_error – Why
profileis missing,Nonewhen it is there.profile_closure –
"base"when the profile is closed along faces the rib stands on that the mid plane cuts in straight lines,"chord"when its ends land elsewhere and a straight chord stands in for the root,Nonewhen there is no profile.thickness – Thickness of the rib at its root, measured across the two sides.
draft_angle – Half the angle between the sides’ normals and the opposite of each other, in radians, counted along
v: positive when the rib gets thinner towards its top.lateral_taper – The same angle counted along
u, nonzero for a rib that tapers along its length.height – Extent of the profile along
v,Nonewhen there is no profile.length – Extent of the profile along
u,Nonewhen there is no profile.top_kind –
"round"when one blend joins the two sides over the top,"flat"otherwise.top_radius – Radius of the blends that round the top,
Nonewhen it is sharp.root_radius – Radius of the blends between the sides and the body,
Nonewhen the roots are sharp.deviation – Largest distance of a side face from the plane it is read as, zero for true planes.
root_pieces – How many of the profile’s last pieces close it: the straight pieces along the faces the rib stands on, or the chord standing in for them. Zero when the profile could not be read.
top_room – How far each straight end of the top, the one it starts at and the one it ends at, can be carried on along itself and stay inside the body: none where the top ends on an edge of the body.
landing_slide – How far the round ending the top at its start and the one ending it at its end were slid along the top, towards the turned face each lands on almost along it, so that it crosses that face: the profile departs from the part by that much there. Zero where nothing was slid.
tolerance – Length under which two points of the profile are one, as the rib was read with.
kind –
"rib": what the parameters are of, as every parameters a record gives say.
- reaching(depth: float) Loop2D#
Return the profile with its root carried depth into the body the rib stands on.
Each piece that closes the profile is moved that far away from the rib, and the straight ends of the top are carried on along themselves to meet them, so the rib’s top passes through the faces it stands on rather than ending on them: a rib that ends exactly on a face leaves slivers where the two are a hair apart. An end of the top that is no straight piece, or that would leave the body before it met the moved root, is joined to the moved root across it.
- Parameters:
depth – How far to carry the root, not negative; zero returns the profile as it is.
- Raises:
ValueError – When the profile could not be read, or depth is negative.
- volmdlr_tools.reverse_engineering.techniques.ribs.recognise_ribs(reading: PartReading, *, tol: float | None = None, max_thickness_ratio: float = 0.5, max_draft: float = 0.2617993877991494, deadline: float = inf) Readings#
Recognise the ribs standing on a part, as many as there is time for.
Pairs of flat faces that face away from each other with material between them, that lean at most max_draft from being parallel and overlap when projected on each other, are the candidate sides of a rib. A pair is kept when it is thin next to the extent of its overlap and both sides meet the rest of the part at a root and a free top. Each face takes part in at most one rib: the thinnest pairs are taken first. The rib is then read from the mid plane between the sides.
- Parameters:
reading – The part to examine.
tol – Length under which two values count as equal; defaults to 1e-4 of the bounding box diagonal.
max_thickness_ratio – Largest thickness of a rib over the smaller extent of its sides.
max_draft – Largest draft angle, in radians, of one side from the rib’s mid plane.
deadline – The moment, on the performance counter, after which no further pair of sides is read as a rib: the ribs read by then are returned, marked as cut short.
- Returns:
The ribs, ordered by the lowest id of their side faces, with whether the time ran out before every pair of sides was read (
timed_out).- Raises:
ValueError – If tol, max_thickness_ratio or max_draft is not positive.
Pipes and flanges#
Recognising a pipe: a round tube bent along a planar path, read from the faces that wall it.
This is how SweptShapeRecognizer reads a pipe that carries
parts of its own; that class is the entry point, and callers ask it for pipes, flanges() and
flange_face() rather than calling the readers here.
A pipe is one spine, a chain of straight legs joined by circular bends, and a round section carried along it. Its outside is a chain of cylinders and tori, each tangent to the next; when it is hollow its bore is the same chain at a smaller radius. The faces say so without any cutting:
A bend is a torus whose tube radius is also the radius of a cylinder at each end of it, the axis of that cylinder being the tangent of the torus’s central circle where the two meet. Tori that share their central circle are one bend seen at several radii: the largest is the skin and the next the bore.
Two bends may also follow one another with no leg between them, the second turning on where the first stops: a torus meets a torus of its own tube radius whose central circle touches its own, in one plane. The point where the two circles touch is a joint of the spine, shared by the two bends as a leg would be.
The bends are chained through the legs and the joints they share. A leg is one cylinder, however many faces it is parted into: a boss across it, or a plane that flattens the tube, parts its wall without making it two legs. A leg that no other bend takes up is a terminal leg; it runs out to the planar face that closes the bore (through a chamfer’s cone, if one is cut there), or the skin when the pipe is solid.
Assumptions:
The spine lies in one plane: every bend turns about the same direction and every leg is square to it.
The legs are straight and the bends are circular arcs; a pipe bent along a spline is not read here.
The section is a circle. Flanges, bosses and chamfers standing on the pipe are not part of it, and the faces that make them are left for other techniques.
- class volmdlr_tools.reverse_engineering.techniques.pipe.Pipe(start: tuple[float, float, float], end: tuple[float, float, float], bends: tuple[PipeBend, ...], skin_radius: float, bore_radius: float | None, skin_faces: frozenset[int], bore_faces: frozenset[int], caps: tuple[int, int])#
Bases:
objectA round tube along a planar spine of legs and bends.
- Parameters:
start – Where the spine begins, at the planar face that closes the first leg.
end – Where the spine ends, at the planar face that closes the last leg.
bends – The bends from the start to the end; the legs run between them and out to the two ends.
skin_radius – Radius of the outside of the tube.
bore_radius – Radius of the bore, or
Nonefor a solid tube.skin_faces – The faces of the part that wall the outside of the tube.
bore_faces – The faces of the part that wall the bore.
caps – The planar faces the two terminal legs run out to, at the start and at the end.
- property faces: frozenset[int]#
The faces of the part the tube accounts for.
- class volmdlr_tools.reverse_engineering.techniques.pipe.PipeBend(centre: tuple[float, float, float], axis: tuple[float, float, float], radius: float, start: tuple[float, float, float], mid: tuple[float, float, float], end: tuple[float, float, float])#
Bases:
objectOne circular bend of the spine.
- Parameters:
centre – Centre of the arc.
axis – Unit direction the arc turns about.
radius – Radius of the arc, the bend radius of the centreline.
start – Where the arc leaves the leg before it.
mid – A point of the arc half way along.
end – Where the arc joins the leg after it.
- class volmdlr_tools.reverse_engineering.techniques.pipe.PipeFlange(cap: int, underside: int, normal: tuple[float, float, float], thickness: float, centre: tuple[float, float, float], walls: frozenset[int], hole_walls: frozenset[int])#
Bases:
objectA plate standing across the end of a pipe, read from the face it closes the pipe with.
- Parameters:
cap – The planar face the pipe’s leg runs out to; the plate’s outer face.
underside – The planar face on the other side of the plate, parallel to the cap.
normal – Unit direction out of the material at the cap, along the leg and away from the bend.
thickness – Distance between the cap and the underside.
centre – Where the pipe’s spine meets the cap.
walls – The faces that stand round the plate between the cap and the underside.
hole_walls – The faces that bound the holes through the plate, other than the pipe’s own bore.
- property faces: frozenset[int]#
The faces of the part the plate accounts for.
- class volmdlr_tools.reverse_engineering.techniques.pipe.PipeRefusal(reason: str, faces: frozenset[int])#
Bases:
FaceRefusalA bend of the part that is not read as part of a pipe, and why.
- Parameters:
reason – What made it unreadable.
faces – The faces of the part the refusal is about.
- volmdlr_tools.reverse_engineering.techniques.pipe.flange_profile(reading: PartReading, flange: PipeFlange) shapes.Face#
Return the face a plate is drawn on: its cap, less the opening the pipe’s bore makes in it.
The outline and the holes of the plate remain; the opening on the pipe’s axis, where the bore and the cone of a chamfer come out, does not, since the pipe is what makes it.
- Parameters:
reading – The part the plate was read from.
flange – The plate.
- volmdlr_tools.reverse_engineering.techniques.pipe.recognise_flanges(reading: PartReading, pipe: Pipe) tuple[list[PipeFlange], list[PipeRefusal]]#
Read the plate across each end of a pipe: its walls, its underside and how thick it is.
The plate is what lies between the cap the pipe’s leg runs out to and a second plane parallel to it, that its walls, the faces round the outline of the cap, run to. The holes in the cap other than the pipe’s bore are the plate’s holes.
- Parameters:
reading – The part the pipe was read from.
pipe – The pipe.
- Returns:
One plate for each end that has one, and the ends whose cap does not stand on one, with the reason.
- volmdlr_tools.reverse_engineering.techniques.pipe.recognise_pipes(reading: PartReading, *, region: Iterable[int] | None = None) tuple[list[Pipe], list[PipeRefusal]]#
Read the pipes a part shows: each spine, its two radii and the caps its legs run out to.
- Parameters:
reading – The part.
region – Faces of the part to read, numbered as the adjacency graph numbers them; the whole part when
None. A pipe is read when every bend of it lies in the region; its legs and its caps are looked for in the region and the faces next to it, and a pipe whose legs or caps lie further off is refused. Only those faces are looked at.
- Returns:
The pipes read, and what could not be read as one, with the reason.
- Raises:
ValueError – If region holds no face.
IndexError – If a face of region is no face of the part.
Revolutions#
Recognising a region built by revolution: one meridian turned about an axis.
Cut a revolved solid by any plane through its axis and each half of the section is the same
curve once it is written in axial position t and distance from the axis r: the
meridian. Blends of the revolved profile are arcs of the meridian, so they stay in the
profile as tangent arcs instead of being removed from the part.
A part rarely is revolved everywhere. A neck may be revolved over a range of the axis only, and holes, ribs or a handle may be cut into or added to the revolved body. Cutting the part at several azimuths tells which portions of the outline every azimuth agrees on, the revolved profile, and which only some azimuths show. The latter are interruptions; they are reported, and they do not spoil the recognition as long as the revolved portions make up a sufficient share of the outline.
Conventions. The axis is the line through axis_origin along the unit axis_direction;
its sign is chosen so that the direction’s largest component is positive. axis_origin is
the point of the axis level with the part’s lowest point along the axis, so t starts at
zero. The profile lies in the half plane r >= 0; a profile that reaches the axis is
closed along it, as a revolve sketch is drawn.
- volmdlr_tools.reverse_engineering.techniques.revolution.InsideTest#
Whether each of some points lies in the material of a part: it takes world points as an
(n, 3)array and returnsnbooleans.SolidContainment(solid, tolerance).contains_pointsis one, prepared once per part.alias of
Callable[[ndarray],ndarray]
- class volmdlr_tools.reverse_engineering.techniques.revolution.MeridianChain(primitives: tuple[Primitive2D, ...], closed: bool)#
Bases:
objectOne connected piece of the revolved profile, in the axes
(t, r).A
closedchain returns to where it starts, along the axis when the solid reaches it.
- class volmdlr_tools.reverse_engineering.techniques.revolution.MeridianInterruption(azimuth: float, axial_range: tuple[float, float], radial_range: tuple[float, float], length: float)#
Bases:
objectA piece of outline that some azimuths show and the revolved profile does not.
azimuthis the angle, in radians in[0, 2 pi), of the half plane that shows it, measured from the frame given byazimuth_frame().axial_rangebounds the piece along the axis (t) andradial_rangeits distance from the axis (r);lengthis its length in the meridian.
- class volmdlr_tools.reverse_engineering.techniques.revolution.Revolution(axis_origin: tuple[float, float, float], axis_direction: tuple[float, float, float], chains: tuple[MeridianChain, ...], axial_range: tuple[float, float], meridians_checked: int, deviation: float, revolved_share: float, interruptions: tuple[MeridianInterruption, ...], unexplained_faces: tuple[int, ...], explained_area_share: float, turn: tuple[float, float] = (0.0, 6.283185307179586))#
Bases:
objectA region of a part that is the revolution of one meridian about an axis.
chainsare the revolved profile in the axes(t, r),tmeasured alongaxis_directionfromaxis_origin.axial_rangeis the axial extent of the revolved portions.meridians_checkedhalf planes were compared;deviationis the largest distance between a revolved point and its counterpart in the half planes that agree, andrevolved_sharethe share of the reference outline’s length that is revolved.Cutting at a few azimuths cannot see a feature narrower than the gap between them, so the faces themselves are checked as well:
unexplained_facesnumbers (as the faces of the part’s adjacency graph are) the faces that do not lie on the revolved profile, andexplained_area_shareis the share of the part’s surface area that does.turnis how far the profile is turned: the azimuth it starts at, in the frameazimuth_frame()gives, and the angle it sweeps from there the way the right-hand rule turns aboutaxis_direction, both in radians. A whole turn by default. Revolutions compare and hash by value.- meridian_frame() Frame3D#
Return the frame whose
(u, v)axes are the(t, r)of the profile,vwhere the turn starts.Its origin is on the axis and its
uaxis is the unit direction of the axis.
- property profile: tuple[Primitive2D, ...]#
Return the primitives of all chains, chain after chain.
- profile_edge_tuples() list[tuple[str, dict]]#
Return the profile as sketch edges in the axes
(t, r).
- volmdlr_tools.reverse_engineering.techniques.revolution.azimuth_frame(direction: ndarray) tuple[ndarray, ndarray]#
Return the two unit vectors
(e1, e2)that, with direction, make a right-handed frame.Azimuth
thetanames the half plane through the axis alongcos(theta) e1 + sin(theta) e2. The vectors are the in-plane axes ofsection_frame()for direction.
- volmdlr_tools.reverse_engineering.techniques.revolution.cut_meridians(shape: Shape, origin: ndarray, direction: ndarray, azimuths: list[float], spacing: float, *, min_points: int = 2) list[tuple[float, list[ndarray]]]#
Cut a shape by the planes through an axis and return what each half plane shows of it.
The axis passes through origin along the unit direction; each plane holds the axis and the direction at one of the azimuths (see
azimuth_frame()). Each piece is a polyline of(t, r)points,r >= 0, sampled about spacing apart with at least min_points points. The result has two entries per azimuth: the half plane at that azimuth and the one opposite.- Raises:
SectionError – when a plane could not cut the shape.
- volmdlr_tools.reverse_engineering.techniques.revolution.join_pieces(pieces: list[ndarray], join: float) list[ndarray]#
Join polyline pieces whose ends lie within join of each other into one polyline per chain.
- volmdlr_tools.reverse_engineering.techniques.revolution.material_on_left(revolution: Revolution, chain: MeridianChain, inside: Callable[[ndarray], ndarray], tolerance: float) bool | None#
Tell whether the material lies to the left of a chain of a revolution as it is travelled.
Points 50 tolerances off the wall the chain sweeps, on both sides of its three longest pieces, are looked up at three azimuths spread over the revolution’s turn; the side found inside the material more often wins. A revolved wall may be interrupted at some azimuths, so no single azimuth is trusted, and a probe that would cross the axis is not taken. Left is the side a quarter turn counter-clockwise from the direction of travel in the axes
(t, r): material on the left of a chain running towards largertlies farther from the axis, as round a bore.radial_material_side()reads the same thing from one face’s normals, as a sign.- Parameters:
revolution – The revolution the chain belongs to.
chain – The chain whose wall is probed.
inside – Whether each of some world points lies in the material of the part.
tolerance – The fitting tolerance the revolution was read with.
- Returns:
Truewhen the material is on the left,Falsewhen it is on the right, andNonewhen the probes cannot tell.- Raises:
ValueError – When the chain has no piece or the tolerance is not positive.
- volmdlr_tools.reverse_engineering.techniques.revolution.radial_material_side(points: ndarray, normals: ndarray, origin: ndarray, direction: ndarray, weights: ndarray | None = None) float | None#
Return which side of a face, or of several, turning about an axis their material lies on.
The reading is the mean, over the sample points off the axis, of the outward normals there against the unit direction from the axis to the point. It is positive when the material lies inside the face, as on a shaft, and negative when it lies outside, as round a bore.
- Parameters:
points – Points on the faces, as rows.
normals – The unit normal of the faces at each point, pointing out of the material.
origin – A point of the axis.
direction – The unit direction of the axis.
weights – The weight of each point in the mean, as the share of its face’s area it stands for;
Noneweighs every point alike.
- Returns:
The mean, between -1 and 1, or
Nonewhen no sample tells: there is none, each lies on the axis or weighs nothing, or the normals face along the axis so that the mean is exactly zero.
- volmdlr_tools.reverse_engineering.techniques.revolution.recognise_revolution(reading: PartReading, axis: AxisCandidate | tuple[np.ndarray, np.ndarray] | None = None, *, tol: float | None = None, azimuths: int = 6, min_share: float = 0.2, max_axes: int = 5, fits: TechniqueFits | None = None) Revolution | None#
Read the part, or a region of it, as one meridian revolved about an axis.
The part is cut by azimuths planes through the axis, giving twice as many half plane outlines. A point of an outline is revolved when more than half of the other outlines pass within a small distance of it. The outline that agrees best with the others is fitted with lines and arcs wherever it is revolved; whatever it or the others show that the majority does not is reported as an interruption.
Without axis the first
max_axesturns of the part’s technique fits, the one turning the most wall first, are tried and the one with the longest revolved outline wins; a line the part cannot be cut about is passed over. The turns only name the lines: which faces lie on the revolved profile is still decided by sampling them, a stricter question than whether a face fits the turn.- Parameters:
reading – the part to read.
axis – a candidate, or a
(point, direction)pair, to revolve about.tol – fitting tolerance; defaults to a fixed fraction of the bounding-box diagonal.
azimuths – number of cutting planes, spread over half a turn.
min_share – least share of the reference outline’s length that must be revolved.
max_axes – how many turns to try when axis is not given.
fits – how the faces of the part fit each way it may have been built, from which the turns are taken when axis is not given; read from reading when omitted.
- Returns:
the revolution, or
Nonewhen the part has no axis or too little of it is revolved.- Raises:
ValueError – when fewer than two azimuths are asked for.
SectionError – when the part cannot be cut by a plane through the given axis.