Skip to main content

Module network

Module network 

Source
Expand description

A network of B-spline patches fitted to a scan at once.

The caller lays out the network: four-sided patches, each bounded by curves drawn on the scan (a polyline, or a curve), a curve between two patches shared by both. fit_network fits every patch to the points in one least-squares system, in which:

  • a shared curve is one set of poles. Both patches’ boundary rows are the same unknowns, and the corners where curves meet are one unknown each, so the patches meet exactly, with no gap to report but rounding.
  • a curve that is not a crease is held tangent, pole by pole. Each pole of the curve and the poles beside it in the two patches are held on one line, at a ratio fixed along the curve: B − L = λ (R − B). The cross derivatives of the two patches along the curve are then parallel everywhere, the same tangent plane on either side. The ratio is read off a fit without the constraints, as the ratio of the pole spacings either side, and is shared by every curve that runs straight on through a corner of four patches, which is what lets the constraints of the curves crossing there agree.
  • a corner of other than four patches is held tangent where it can be. The triples hold the parameter lines that cross a curve to one direction on both sides of it. At a corner of three patches (or five, or six, or the point a three-sided patch’s missing side shrinks to) the lines crossing a curve there lean one way on one side and the other way on the other, and no triple holds; tangency there needs the cross derivatives to differ by a multiple of the curve’s own tangent, D₁ + λ D₂ + γ T = 0. At the corner that puts the curves’ first poles in one plane, at ratios read off the fit without the constraints. A corner of an odd number of patches whose curves all run on to the network’s border is first held with λ constant and γ linear along each whole curve: a cubic spline on the curve’s knots, nought where it is nought at as many points as it has coefficients, an exact linear condition though not a pole-by-pole one. It binds each curve to a single cubic where γ is not nought at its knots. Otherwise, or where that misses the points, a corner is held by its spans: the knot past each curve’s span next to the corner is doubled, that span is a quadratic, and γ is a quadratic over it with a double root at its far end and nought past it. Past that span the curve is held by the pole triples at its corner’s ratio, so its far end may be on the border, a corner of four patches (an edge’s fillet attached to a rounded box corner) or a junction, and spans raised there shrink the quadratic span. A junction pins the curve to its patch’s knot spacings; the line through the junction is then held at the corner’s ratio instead, tangent but not C¹. A curve may also run on to another corner held by its spans, which pins it to a second ratio: the first poles round a corner may be scaled to give its curves other ratios, so both corners are scaled to the geometric mean of the two, moved as little as closes every cycle of a corner’s scales all of whose curves are asked a ratio. Where neither way meets the points, a corner of an odd number of patches, or an even number above four, whose curves each run on to the border or to another such corner has its gluing spread along its curves: λ constant and γ linear along each whole curve, from the corner’s g to a value read off the fit at the border or to the other corner’s, every knot inside the curve’s strip doubled and the curves along it held C² across each. The curve is then as free to refine as any, its patches only C¹ across those knots. At an even corner the twists round it close in a cycle that is always singular, which leaves one condition on the curves’ second poles, held with the rest. This is the gluing a Coons patch’s parameters carry, γ falling along the whole curve, which the points at their seed’s parameters admit where γ nought past one span does not. So a corner of three patches or more, other than four, whose curves each run on to the border, a corner of four patches, a junction or another such corner is held, every curve into it tangent to rounding, as long as the fit still comes within the tolerance: the one ratio along each curve these conditions allow is a restriction the points at their seed’s parameters need not admit. Where no way of holding it does, and at any other corner of other than four patches (an apex, or a junction), a curve with such a corner at an end is fitted without the triples: near tangent as the points are smooth, its angle measured into Network::worst_tangent. Every such corner’s widest angle between the patches’ normals is reported in Network::corners.
  • a fan is held tangent where it can be. At a point every patch there shrinks its missing side to, both patches beside each curve into it shrink, so the parameter lines crossing the curve turn neither way and its pole triples hold it from end to end. Each patch’s normal at the point is the limit S_d × S_dw, d across its missing side and w along it: from the point to the row of poles one in from that side, crossed with the row’s own derivative. The patches share one tangent plane there where every patch’s such row lies in one plane through the point; the rows are held to the layout they take in the fit without the constraints, projected on a plane through the point, its orientation, scale and shear left free. A fit holding a fan is kept only where every patch’s normal at the point is defined all along its missing side and points one way, which the Bernstein coefficients of (R − V) × R' bound, R the row and V the point. Each way of holding the corners is first tried with the fans held, and only where none of them comes within the tolerance are the fans left near tangent. A point where a three-sided patch meets four-sided ones is left near tangent, its angle measured into Network::worst_tangent: exact tangency is not offered there. The three-sided patch’s cross derivative vanishes at the point and the other’s does not, so no ratio fixed along the curve serves, and the gluing that does, a D₃ + b D₄ + c T = 0 with polynomial a, b, c, is not the one the seed’s parameters give the points: fitted to the fit without the constraints, the best such gluing misses its cross derivatives by 2 to 4.5 per cent, however fine the spans. Held to it, the patches shear off the points’ parameters and stand further off the shape than the fit near tangent does (on a ball’s cap of four wedges, two three-sided, clean at 0.001: near tangent at 1.2e-3 rad, 2.3e-4 off the ball).
  • a side may be a chain of curves. A curve may end on the middle of a patch’s side (a T-junction), the side then a chain of curves meeting there (ChainedPatch). The patch takes a knot of multiplicity three at the junction, so its boundary row is the chain’s poles, shared exactly, and the side opposite crosses the same junction: it is split alike, or is one curve whose knots carry the junction too. The patch is held C¹ across the parameter line between the two, pole by pole, at the ratio of the knot spacings either side, or tangent at a corner’s ratio where a curve from a corner held by its spans ends there. That line runs straight on from the curve ending at the junction, so that curve is held tangent at that same ratio, and the chain’s curves either side of the junction share theirs, as at a corner of four patches.
  • spans are raised per strip. The curves opposite each other in a patch share knots, and so do all the curves of a strip of patches joined through their opposite sides. Where a patch misses the points by more than the tolerance its strips gain spans, the way fit_surface_scattered_over refines a single patch.
  • points may be reparameterised. Once refinement ends, fit_network_chained can move every point’s parameters to its nearest point on its patch and fit the patches again, a fit kept only where it comes nearer the points. Where every way of holding the corners misses, and so does the fit near tangent, each held fit that missed is finished that way from its spans before the near-tangent one is kept: a point whose nearest point lies on a side its patch shares is taken by the patch across that side where that one is nearer, as the seeds take each point by the nearest. A step is kept only while it holds the corners, takes off more of the squared distances than twice the noise’s variance, read once off the fit at the seed’s parameters, and leaves neither the worst miss that is not a stray nor the worst of all no worse; after each, the fit is refined on with that variance held, every patch a point misses, strays and all, tried at more spans, for at most eight steps. The first that comes within the tolerance is the network.

The constraints are solved for exactly, by elimination, before the least squares: what is held tangent is tangent to rounding.

Structs§

ChainedPatch
A patch of the network whose sides may each be a chain of curves.
IrregularCorner
A corner inside the network where other than four patches meet, every curve at it smooth (a patch whose side runs straight through it counts twice): held tangent to rounding, or near tangent, as the module documentation describes.
LoopSide
One side of a loop fit_loop_quads fills: its curve over a range, and how the fill leaves it.
Network
What fit_network produced.
NetworkOptions
How fit_network fits.
PatchDef
A patch of the network: its four sides, walked round it.
PatchFit
How one patch fits its points.
PatchSide
One side of a patch: the curve along it and which way it runs.

Enums§

Across
How a patch leaves a held border curve: the direction every step from a pole of the curve to the pole one row in may take.
CurveDef
A curve of the network, as the caller draws it on the scan.

Functions§

fit_loop_quads
Fill a closed loop of sides with one four-sided patch per corner of the loop, every side held exactly and held across as it says.
fit_network
Fit a network of patches to a scan’s points, all at once.
fit_network_chained
fit_network over patches whose sides may be chains of curves, a curve ending on the middle of another’s side at a T-junction, with parameter correction.