Algorithm Search⌘K

Problemresearch

B-rep to CSG conversion

Also called boundary to CSG conversion.

Find a CSG tree for a solid given by its boundary. Shapiro and Vossler solved it for curved solids by separating halfspaces and a Boolean construction.

B-rep to CSG conversion asks for a CSG formula, a Boolean combination of half-spaces or primitives, whose regularized value is a solid given by its boundary. It is the reverse of boundary evaluation. For polyhedra the half-spaces of the faces are always enough. For curved solids they may not be, because a region with one sign pattern can have parts inside and outside the solid, and extra separating half-spaces are needed. Shapiro and Vossler gave the theory and the construction for curved solids, and the size of a shortest formula is a separate optimization problem.

In plain words

A CSG model says how to build a shape from simple pieces: take this block, cut away that cylinder, add this other block. A boundary model only lists the outer faces. This problem goes from the faces back to a recipe of pieces.

Each face lies on a surface, such as a plane or a cylinder, and the surface splits space into an inside and an outside. The idea is to build the shape from these sides with "and", "or" and "not".

For flat faces this always works. For curved faces it can fail: two places can be on the same side of every surface, while only one of them is in the shape. Then the recipe needs an extra surface that is not a face, only to tell the two places apart.

Definition

Input. A solid S⊂E3S \subset E^3, an r-set, given as a B-rep whose faces lie on surfaces {fi=0}\{f_i = 0\}, i=1,…,ki = 1, \ldots, k. Each surface gives a half-space hi={fi≤0}h_i = \{f_i \le 0\}, oriented so that SS is locally on the side fi≤0f_i \le 0 of each face on it. The hih_i are the face half-spaces.

Output. A Boolean formula Φ\Phi whose leaves are half-spaces, and whose inner nodes are ∪∗\cup^*, ∩∗\cap^* and −∗-^*, with value exactly SS. The leaves are the face half-spaces and, if needed, further half-spaces g1,…,grg_1, \ldots, g_r of a fixed family, such as planes or quadrics.

Objective. In the decision form, does SS have a formula over the face half-spaces alone? In the construction form, find a formula, with extra half-spaces when the face half-spaces are not enough. In the optimization form, find a formula with the fewest leaf occurrences.

Notation. For a point pp that lies on no surface {fi=0}\{f_i = 0\}, its sign vector is σ(p)∈{−,+}k\sigma(p) \in \{-, +\}^k, the signs of f1(p),…,fk(p)f_1(p), \ldots, f_k(p). A cell is a connected component of the set of points with one sign vector.

Variants

  • Polygons and polyhedra. All surfaces are lines or planes. The face half-spaces are always enough, by the lemma below.
  • Each half-space once. For a simple polygon, a formula in which each edge half-plane appears exactly once always exists, and Dobkin, Guibas, Hershberger and Snoeyink compute it in O(nlog⁡n)O(n \log n) time for nn edges.
  • Curved solids. Faces on quadrics, tori and general algebraic surfaces. Separating half-spaces may be needed, and Shapiro and Vossler give methods to find them.
  • Primitives instead of half-spaces. The leaves must be bounded primitives such as blocks and cylinders. This is close to feature recognition, which looks for holes, slots and pockets in a B-rep.
  • Minimum formula. Among the formulas for SS, find a shortest one. This is a form of Boolean function minimization, as in Quine-McCluskey, over the sign vectors that occur.
  • Approximate input. The input is a mesh or a point cloud, and the output is a formula whose solid is close to it.

Examples

An L-shaped polygon. S=[0,2]2−(1,2]2S = [0, 2]^2 - (1, 2]^2 has six edges on the lines x=0x = 0, y=0y = 0, x=2x = 2, y=2y = 2, x=1x = 1, y=1y = 1. A formula over the six edge half-planes, with each one used once, is

S={x≥0}∩{y≥0}∩{x≤2}∩{y≤2}∩({x≤1}∪{y≤1}).S = \{x \ge 0\} \cap \{y \ge 0\} \cap \{x \le 2\} \cap \{y \le 2\} \cap \big(\{x \le 1\} \cup \{y \le 1\}\big).

The point (1.5,1.5)(1.5, 1.5) fails both x≤1x \le 1 and y≤1y \le 1, so it is outside, and every point of the L satisfies one of them.

Face half-spaces that are not enough. In the plane, let S={(x,y):0≤y≤1, 1+y≤x≤3}S = \{(x, y) : 0 \le y \le 1,\ \sqrt{1 + y} \le x \le 3\}, the region right of the parabola branch x=1+yx = \sqrt{1 + y}, below y=1y = 1, above y=0y = 0 and left of x=3x = 3. Its boundary lies on the four curves y=0y = 0, y=1y = 1, x=3x = 3 and y=x2−1y = x^2 - 1, so these give the face half-planes. The points p=(2,0.5)p = (2, 0.5) and q=(−2,0.5)q = (-2, 0.5) both satisfy all four inequalities strictly: 0<0.5<10 < 0.5 < 1, 0.5<30.5 < 3, 2<32 < 3 and −2<3-2 < 3. So σ(p)=σ(q)\sigma(p) = \sigma(q), but p∈Sp \in S and q∉Sq \notin S. By the lemma below, no formula over the four face half-planes has the value SS. The separating half-plane x≥0x \ge 0 fixes it:

S={y≥0}∩{y≤1}∩{x≤3}∩{y≤x2−1}∩{x≥0}.S = \{y \ge 0\} \cap \{y \le 1\} \cap \{x \le 3\} \cap \{y \le x^2 - 1\} \cap \{x \ge 0\}.

The same happens in space with faces on a cylinder or a torus.

Known algorithms

There are no algorithm pages for this problem yet. The known methods are these.

  • Canonical union of cells (Shapiro and Vossler 1991). Compute the cells of the arrangement of the face surfaces, classify one point of each cell against SS with set membership classification, and take the union of the cells inside SS, each written as the intersection of the kk half-spaces or their complements. The result is correct whenever the face half-spaces are enough, and its size is the number of inside cells times kk. A second phase reduces the formula by Boolean minimization.
  • Separation (Shapiro and Vossler 1993). When two cells with one sign vector have different classifications, add half-spaces that split them, then run the canonical construction on the larger set.
  • Single-occurrence formulas for simple polygons (Dobkin, Guibas, Hershberger and Snoeyink). A formula in which each edge half-plane appears once, built in O(nlog⁡n)O(n \log n) time for nn edges.

Bounds

Lemma (describability). SS has a formula over half-spaces H={h1,…,hk}H = \{h_1, \ldots, h_k\} if and only if every two points p,qp, q that lie on none of the surfaces and have σ(p)=σ(q)\sigma(p) = \sigma(q) are both in SS or both outside SS.

Proof. (Only if.) Let Φ\Phi be a formula and pp a point on none of the surfaces. Near pp each fif_i keeps its sign, so the plain Boolean value of Φ\Phi is the same at all points of a ball around pp, and it depends only on σ(p)\sigma(p). Regularization does not change the value at a point of an open set where the plain value is constant. So the value of Φ\Phi at pp is a function of σ(p)\sigma(p), and two points with the same sign vector are both in or both out. (If.) Let Σ\Sigma be the set of sign vectors of points of int⁡S\operatorname{int} S off the surfaces, and let Φ=⋃σ∈Σ∗⋂i∗hiσi\Phi = \bigcup^*_{\sigma \in \Sigma} \bigcap^*_i h_i^{\sigma_i}, where hi−h_i^- is hih_i and hi+h_i^+ is its closed complement. By the condition, a point off the surfaces is in Φ\Phi exactly when it is in SS. The surfaces have no interior, and both Φ\Phi and SS are regular closed, so they are the closures of the same open set, and Φ=S\Phi = S. ■\blacksquare

Polyhedra. For planes, each set of points with one sign vector is an intersection of open half-spaces, which is convex and so connected. A connected set that does not meet ∂S\partial S lies in int⁡S\operatorname{int} S or outside SS. So the condition of the lemma holds, and every polyhedron has a formula over its face half-spaces. The arrangement of kk planes has O(k3)O(k^3) cells, so the canonical formula has O(k4)O(k^4) leaf occurrences. In the plane, kk lines give O(k2)O(k^2) cells and O(k3)O(k^3) occurrences. Each half-plane once is enough for simple polygons.

Curved solids. The parabola example shows that the condition can fail for curved faces, so separating half-spaces are needed in general. Shapiro and Vossler show how to find them for the surfaces of common solids. A bound on how many are needed in the worst case is not given in the sources here.

Minimum size. Finding a shortest formula is a minimization over Boolean formulas. Shapiro and Vossler reduce the canonical formula by methods of Boolean minimization, and their results on the size are measured on examples. The complexity of computing a minimum formula for a solid is not settled in the sources here.

Reductions

  • To set membership classification. The canonical construction needs one in or out answer per cell, which is a point classification against the B-rep.
  • To arrangements. The cells are those of the arrangement of the face surfaces. For polygons this is the line arrangement of the edge lines.
  • To Boolean minimization. Once the inside and outside sign vectors are known, a shortest formula over the given half-spaces is a shortest Boolean formula for a partial function on {−,+}k\{-, +\}^k, where the sign vectors that occur in no cell are don't-cares.
  • Inverse of boundary evaluation. Boundary evaluation of the output formula must return the input solid, which gives a check of any conversion.

Applications

  • Editing. A CSG tree can be edited by changing a parameter of a primitive, so a conversion makes imported B-rep models editable.
  • Ray casting and classification. CSG ray casting and point classification work directly on the formula.
  • Model exchange and compression. A short formula can be a compact description of a solid.
  • Reverse engineering. A CSG description of a scanned part, built from the fitted surfaces, gives a model with design intent.

References

  1. Vadim Shapiro and Donald L. Vossler, Construction and optimization of CSG representations, Computer-Aided Design 23(1), 4 to 20, 1991, the whole paper (the canonical union of cells built from the half-spaces of the faces, and the reduction of its size)
  2. Vadim Shapiro and Donald L. Vossler, Separation for boundary to CSG conversion, ACM Transactions on Graphics 12(1), 35 to 55, 1993, the whole paper (why the face half-spaces of a curved solid may not be enough, and how separating half-spaces are found)
  3. David Dobkin, Leonidas Guibas, John Hershberger and Jack Snoeyink, An efficient algorithm for finding the CSG representation of a simple polygon, Computer Graphics 22(4), Proceedings of SIGGRAPH 1988, the whole paper (a formula for a simple polygon in which each edge half-plane appears once)
  4. David Dobkin, Leonidas Guibas, John Hershberger and Jack Snoeyink, An efficient algorithm for finding the CSG representation of a simple polygon, Algorithmica 10(1), 1 to 23, 1993, the journal version, with the O(n log n) construction of the formula
  5. Aristides A. G. Requicha, Representations for rigid solids, theory, methods, and systems, ACM Computing Surveys 12(4), 437 to 464, 1980, the discussion of conversion between representations

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)
WritingW2 basic
  • a known algorithm
  • a contract.yaml