Algorithm Search⌘K

Techniqueresearch

Constrained fitting in reverse engineering

Also called GlobFit, constrained reverse engineering.

Fits several primitives at once subject to relations such as parallel axes, orthogonal faces and equal radii, so the model keeps the design intent.

Constrained fitting fits several primitives of a scanned part at the same time, so that the fitted surfaces satisfy geometric relations that the designer intended: faces that are parallel or orthogonal, holes that are coaxial or of equal radius, a fillet that is tangent to its two faces. If each region of a segmented scan is fitted alone, as on the geometric primitive fitting page, the noise makes two faces that should be orthogonal meet at 89.789.7 degrees, and the model is useless for redesign. The technique has three parts: find candidate relations among the separate fits, choose a subset that is consistent and not redundant, and refit all primitives together, minimizing the total fitting error subject to the chosen relations as equality constraints. The constrained problem is solved by sharing parameters, by Lagrange multipliers, or by a penalty or augmented Lagrangian method. Benkő, Kós, Várady, Andor and Martin (2002) set out this approach for reverse engineering. GlobFit, by Li, Wu, Chrysanthou, Sharf, Cohen-Or and Mitra (2011), is one method of this kind: it discovers the relations among primitives found by RANSAC and enforces them in three stages.

In plain words

When a part is scanned and each face is fitted on its own, the result is close but not exact. Two walls that were drawn at a right angle come out at almost a right angle. Two holes that were drawn with the same radius come out with slightly different radii. An engineer who reads the model cannot tell an intended small angle from a scanning error.

Constrained fitting looks for such near coincidences, decides which of them the designer most likely meant, and then fits all the faces again together, so that the right angle is exactly a right angle and the radii are exactly equal. The fit gets a little worse in the strict sense of distance to the points, but the model now says what the part is.

When it applies

  • A scan has been segmented into regions, and each region has been fitted with a primitive: plane, sphere, cylinder, cone or torus.
  • The object is a manufactured part, so its design is full of exact relations: parallel, orthogonal, coplanar, coaxial, concentric, equal radii, tangent, symmetric.
  • The separate fits are close to satisfying these relations, within the noise. A relation that is clearly violated by the data is not a relation of the part.
  • The result is used as a CAD model, for redesign, for machining, or as the nominal of an inspection, where the intent matters more than the last micrometer of fit.

The template

Each primitive jj has parameters θj\theta_j and a fitting error Ej(θj)=∑x∈Rjd(x,S(θj))2E_j(\theta_j) = \sum_{x \in R_j} d(x, S(\theta_j))^2 over its region RjR_j. A relation is an equation g(θ)=0g(\theta) = 0 in the parameters of a few primitives, such as n1⋅n2=0n_1 \cdot n_2 = 0 for orthogonal planes or r1−r2=0r_1 - r_2 = 0 for equal radii.

  1. CONSTRAINED-FIT(regions R_1..R_k, tolerance τ, budget β)
  2. 1for j ← 1 to k do θ_j ← geometric fit of the primitive of R_j alone
  3. 2C ← candidate relations g with |g(θ)| ≤ τ for the separate fits
  4. 3A ← ∅
  5. 4for each stage s in (orientation, placement, equality) do
  6. 5for each candidate g of stage s in C, the most nearly satisfied first do
  7. 6if A ∪ {g} is consistent and g is not implied by A then
  8. 7θ' ← argmin Σ_j E_j(θ_j) subject to h(θ) = 0 for every h in A ∪ {g}
  9. 8if Σ_j E_j(θ'_j) − Σ_j E_j(θ_j) ≤ β then A ← A ∪ {g}; θ ← θ'
  10. 9return θ and the accepted relations A

The holes are the list of relation types and their tolerances τ\tau, the order in which candidates are tried, the test for consistency and redundancy, the solver of line L7, and the error budget β\beta.

Line L2, candidates. Orientation relations compare directions: the normals of planes and the axes of cylinders, cones and tori. Two directions within a few degrees are candidates for parallel, within a few degrees of 9090 for orthogonal. Placement relations compare positions: coplanar planes, coaxial cylinders, concentric spheres. Equality relations compare sizes: equal radii, equal distances between parallel planes. The tolerance comes from the noise of the scanner and the size of the regions.

Lines L4 and L5, the order. Orientations come first, because a placement such as coaxial only makes sense once the axes are parallel, and a size equality only once the placement is fixed. This is the order of the three stages of GlobFit. Within a stage, trying the most nearly satisfied candidate first is a greedy choice; it gives a consistent answer but not necessarily the set of relations that a designer would choose.

Line L6, consistency and redundancy. Candidates can conflict: if n1∥n2n_1 \parallel n_2, n2∥n3n_2 \parallel n_3 and n1⊥n3n_1 \perp n_3 are all accepted, the system has no solution. They can also be redundant: n1∥n3n_1 \parallel n_3 follows from the first two. A redundant constraint makes the Jacobian of the constraints rank deficient, so the Lagrange system of line L7 is singular even when the constrained problem itself is fine. Both are detected by checking whether the new constraint gradient is a combination of the others at the current solution, or, for orientation relations, by grouping the directions into classes of parallel directions first and relating classes, not pairs.

Line L7, the solver. Three common ways:

  • Shared parameters. Write the constrained family directly: parallel planes share one unit normal, coaxial cylinders share an axis, equal radii share rr. The problem becomes an unconstrained fit with fewer parameters, solved by Gauss-Newton or Levenberg-Marquardt. This is exact and well conditioned when the relations have such a form.
  • Lagrange multipliers. Solve ∇E(θ)+∑hλh∇h(θ)=0\nabla E(\theta) + \sum_h \lambda_h \nabla h(\theta) = 0, h(θ)=0h(\theta) = 0 by Newton steps on this system. Exact at convergence, but it needs independent constraints.
  • Penalties. Minimize E(θ)+w∑hh(θ)2E(\theta) + w \sum_h h(\theta)^2 for growing ww, or use an augmented Lagrangian. Simple, but a pure penalty meets the constraints only in the limit and gets badly conditioned as ww grows.

Line L8, the budget. A relation that raises the error by much more than the noise explains is rejected: the data say that the part does not have it.

Why the parallel case is exact. For two planar regions AA and BB with one shared unit normal nn and offsets dAd_A, dBd_B, the error is ∑x∈A(n⋅x−dA)2+∑x∈B(n⋅x−dB)2\sum_{x \in A} (n \cdot x - d_A)^2 + \sum_{x \in B} (n \cdot x - d_B)^2. For fixed nn, setting the derivatives in dAd_A and dBd_B to zero gives dA=n⋅xˉAd_A = n \cdot \bar x_A and dB=n⋅xˉBd_B = n \cdot \bar x_B for the centroids. What remains is nT(SA+SB)nn^{\mathsf T} (S_A + S_B) n with the scatter matrices SA=∑x∈A(x−xˉA)(x−xˉA)TS_A = \sum_{x \in A} (x - \bar x_A)(x - \bar x_A)^{\mathsf T} and SBS_B alike, so nn is the eigenvector of the smallest eigenvalue of SA+SBS_A + S_B, by the Rayleigh quotient argument of principal component analysis. The separate fits have the errors λmin⁡(SA)\lambda_{\min}(S_A) and λmin⁡(SB)\lambda_{\min}(S_B), and the increase λmin⁡(SA+SB)−λmin⁡(SA)−λmin⁡(SB)\lambda_{\min}(S_A + S_B) - \lambda_{\min}(S_A) - \lambda_{\min}(S_B) is never negative, since nTSAn≥λmin⁡(SA)n^{\mathsf T} S_A n \ge \lambda_{\min}(S_A) and nTSBn≥λmin⁡(SB)n^{\mathsf T} S_B n \ge \lambda_{\min}(S_B) for every unit nn. The same pooling works for any number of parallel planes.

Classic examples

  • Two parallel lines. Region AA has the points (0,0)(0, 0), (1,0.1)(1, 0.1), (2,−0.1)(2, -0.1), (3,0.1)(3, 0.1), (4,0)(4, 0) and region BB the points (0,2)(0, 2), (1,2.1)(1, 2.1), (2,1.9)(2, 1.9), (3,2)(3, 2), (4,1.9)(4, 1.9). The separate orthogonal fits give a horizontal line for AA, with error 0.02800.0280, and a line for BB tilted by 1.721.72 degrees, with error 0.01900.0190. The joint fit with a shared normal, from the pooled scatter matrix, tilts both lines by 0.860.86 degrees, with total error 0.05150.0515 against 0.04700.0470 for the separate fits, and puts them 1.9601.960 apart. The increase of 0.00450.0045 is the price of the relation.
  • The faces of a box. Six planes in three parallel pairs with mutually orthogonal normals. The constrained fit makes the normals an orthonormal frame, which is what the B-rep reconstruction of a prismatic part needs to produce exact right angles and straight edges.
  • Holes and shafts. Cylinders of a flange that share an axis, or a bolt circle of holes with equal radii and parallel axes, fitted with shared axis and radius parameters by the geometric fit.
  • Fillets. A blend cylinder tangent to two planes, as in a rolling ball blend, has its axis parallel to the line where the planes meet and its axis at distance rr from both; Benkő and his coauthors treat such tangency relations.
  • GlobFit. Primitives from efficient RANSAC shape detection are compared in orientation, placement and equality, relations are chosen greedily stage by stage, and the primitives are refitted after each stage under the accepted relations.

Variations

  • Relations given by the user. In interactive reverse engineering the user picks the relations, and only lines L7 and L8 run.
  • Global search of relations. Instead of a greedy pass, the choice of relations is a combinatorial problem: maximize the number or weight of relations subject to an error budget. Exact search is exponential; greedy order, clustering of directions and of sizes, and voting are the usual heuristics.
  • Soft constraints. Keep every candidate with a weight, as a penalty term, and let the fit decide. This avoids hard choices but does not produce exact relations.
  • Constraints among curves. The same scheme applies to 2D profiles and sketches: lines and arcs with tangency, parallelism and equal lengths, which is how a profile for extrusion is rebuilt.
  • Template fitting. Fit a whole parametric model, such as a standard part from a catalog, whose parameters already encode all relations.

Pitfalls

  • Conflicting relations. Three planes pairwise within tolerance of parallel and orthogonal give an infeasible system. Check consistency before solving, as in line L6.
  • Redundant relations. They make the Lagrange or Newton system singular. Work with classes of parallel directions, or test the rank of the constraint Jacobian.
  • Tolerance too large. Relations that the designer did not intend get enforced, and real small angles of drafts disappear. A draft angle of one or two degrees on a molded part looks like a near parallel.
  • Tolerance too small. Intended relations are missed when a region is small or noisy, because its fitted direction is uncertain. The tolerance should depend on the uncertainty of each fit, not be one number for all.
  • Order dependence. A greedy pass can accept a weak relation early that blocks a stronger one later. Sorting by how nearly each candidate holds reduces this but does not remove it.
  • Bad segmentation. A relation is only as good as the regions it relates; points from a fillet left in a plane region tilt the plane and can hide a true orthogonality.

Exercises

  1. Show that for qq planar regions with one shared normal, the best normal is the smallest eigenvector of ∑jSj\sum_j S_j, and that the error increase over the separate fits is λmin⁡(∑jSj)−∑jλmin⁡(Sj)≥0\lambda_{\min}(\sum_j S_j) - \sum_j \lambda_{\min}(S_j) \ge 0.
  2. Give three relations among three plane normals that are pairwise consistent but jointly infeasible, and three that are jointly consistent but redundant. Answer: n1∥n2n_1 \parallel n_2, n2∥n3n_2 \parallel n_3, n1⊥n3n_1 \perp n_3; and n1∥n2n_1 \parallel n_2, n2∥n3n_2 \parallel n_3, n1∥n3n_1 \parallel n_3.
  3. Two coaxial cylinders share an axis but have different radii. Write the shared-parameter form of their joint fit and count its parameters. Answer: one axis (4 parameters) and two radii, 6 in total, against 10 for two separate cylinders.

References

  1. Pál Benkő, Géza Kós, Tamás Várady, László Andor and Ralph Martin, Constrained fitting in reverse engineering, Computer Aided Geometric Design 19(3), 2002, 173 to 205, the simultaneous fit of several curves and surfaces under constraints between their parameters, the section on numerical methods for constrained fitting, and the 2D and 3D examples
  2. Yangyan Li, Xiaokun Wu, Yiorgos Chrysanthou, Andrei Sharf, Daniel Cohen-Or and Niloy J. Mitra, GlobFit, consistently fitting primitives by discovering global relations, ACM Transactions on Graphics 30(4) (SIGGRAPH 2011), article 52, the detection of global relations among RANSAC primitives and the three stages of constrained refitting (orientation, placement, equality)
  3. Naoufel Werghi, Robert Fisher, Craig Robertson and Anthony Ashbrook, Object reconstruction by incorporating geometric constraints in reverse engineering, Computer-Aided Design 31(6), 1999, 363 to 399, the global improvement of a reconstructed shape from feature positions and the geometric relations between features, posed as constrained least squares

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises