<<

Three-Dimensional Halfspace Constructive Solid Tree Construction from Implicit Boundary Representations

Suzanne F. Buchele Richard H. Crawford Southwestern University The University of Texas at Austin Georgetown, Texas Austin, Texas [email protected] [email protected]

ABSTRACT General Terms This paper presents a new method to compute construc- Algorithms, Design tive solid geometry (CSG) tree representations of an object whose faces consist of planar and non-planar surfaces. The Keywords algorithm described accepts as input a valid boundary rep- resentation of an object consisting of piecewise implicit sur- Representation conversion, reverse engineering, geometric faces, and computes a halfspace CSG representation of the and topological representations, product and assembly mod- object. A class of objects that are describable by the sur- eling faces bounding them are valid input for the algorithm of this work, although methods currently exist to compute the 1. INTRODUCTION AND MOTIVATION additional information necessary to process non-describable There are two primary focuses for the conversion of bound- objects as well. This work builds on and comple- ary representations (b-reps) to halfspace Constructive Solid ments the other work in this , in which dominating half- Geometry (CSG) tree representations, namely the represen- spaces are used to simplify the b-rep to CSG conversion pro- tation of 3-D solids in CAD systems, and reverse engineering cess. We include factored faces to enable the factorization of of 3-D solids. dominating halfspaces throughout the algorithm. Thus, an CAD systems typically use a combination of object rep- efficient disjoint decomposition of the solid is obtained as a resentation techniques, including boundary representations matter of course in the algorithm, so that CSG minimization (b-reps), in which objects’ boundaries and other neighbor- is generally not necessary. hood and orientation information is stored, and CSG rep- This work is motivated by reverse engineering of mechan- resentations, in which a tree representation is stored using ical parts, in which a model of a part is recovered from in- solid primitives and Boolean operations [12]. Hybrid CAD formation obtained by some sort of sensing technique (e.g. systems, in which some combination of representations are CAT scanning, laser range finding). The recovery of a valid used in tandem or conjunction with each other in a single CSG-tree description of an object from a boundary repre- CAD system is the norm for current CAD modelers. To sentation of it can provide useful information to an engineer facilitate the most efficient and flexible computations in a in the area of reverse engineering and in other related CAD system, the conversion between representations may to solid modeling as well. The CSG tree also provides a rela- be useful. Algorithms are well-known for the CSG to b-rep tively neutral representation that can enhance form feature conversion process, primarily to facilitate rendering of solid recognition and . models by the CAD systems. The problem of b-rep to CSG conversion has historically been considered too difficult for general purpose implementation, although fundamental re- search and development of a general purpose b-rep to CSG Categories and Subject Descriptors algorithm has been presented [14, 15, 16, 21]. I.3.5 [Computer Graphics]: Computational Geometry Reverse engineering of mechanical parts is the general pro- and Object Modeling—boundary representations; curve, cess of recovering a model of a physical mechanical object , solid, and object representations; J.6 [Computer from information obtained by some sort of sensing tech- Aided Engineering]: [computer-aided design] nique. These sensing techniques include, but are not limited to, CAT and MRI scans, laser rangefinder scans, stereo- scopic sensing, and contact sensing devices. Reverse engi- neering may be needed when parts do not conform to their associated model, or when an original CAD model of the Permission to make digital or hard copies of all or part of this work for part does not exist. Most current advances in reverse en- personal or classroom use is granted without fee provided that copies are gineering of mechanical parts have focused on recovering a not made or distributed for profit or commercial advantage and that copies boundary representation (b-rep) of an object. Recovered bear this notice and the full citation on the first page. To copy otherwise, to boundary representations of these surfaces can vary from republish, to post on servers or to redistribute to lists, requires prior specific a triangulation of points to piecewise parametric surfaces permission and/or a fee. SM'03, June 16–20, 2003, Seattle, Washington, USA. (common representations include parametric spline surfaces Copyright 2003 ACM 1-58113-706-0/03/0006 ...$5.00. and NURBS surfaces) to piecewise algebraic surfaces [5]. For

reverse engineering, a boundary representation may fail to g : 3 → separates 3 into two pieces. Bounded solid sufficiently recover the original geometry of the object due CSG representations operate on a predefined set of canoni- to the varying range of types of surfaces fit, the orientation cal solid primitives which are also regular sets. of surface patches, and inherent limitations in parametric representations. The extraction of a CSG representation of 3. PREVIOUS WORK a solid may be considered a “user friendly” form for the ge- In 2-D, the problem of b-rep to CSG conversion is consid- ometric data in the field of reverse engineering. It is easier ered solved for cases with modest and realistic limitations than a boundary representation of the object for an engineer ([11, 20, 15, 14]). In 3-D, early or limited attempts to obtain to parameterize and manipulate, and could be entered into CSG-type information from b-reps of an object were done CSG, b-rep, and hybrid modeling CAD systems through a by Lin and Chen [9], Woo [22] and Tang and Woo [18, 19], CSG user interface. and Menon and Kim [10] Shapiro and Vossler present a solution to b-rep to half- 2. DEFINITIONS space CSG conversion for 3-D solids [14, 16, 21], in which 3

A halfspace ψ of is a set of the form ψ = {(x, y, z) : they solve the general problem of converting from a bound-

3 g(x, y, z) ≥ 0} for some function g : → . When the ary representation (b-rep) of a solid to a halfspace CSG function g is restricted to be a , then the halfspace ψ as- representation of it, for solids defined as regular subsets of sociated with g is a halfplane. In this work we consider only 3 bounded by quadric surfaces. Central to Shapiro and

halfspaces that are non-empty, regular, pathwise connected Vossler’s work is the idea of a canonical intersection term.

3 sets in , such that the regularized complement halfspace In 3 (or d for d ≥ 1), a collection of n sets (or, specifi-

∗ ψ , is also a non-empty pathwise connected set (and is reg- cally, halfspaces) partition 3 into 2n subsets (some possibly ular by definition). We refer to the surface associated with empty). We can represent these 2n subsets, or, cells, as in- a halfspace ψ = {(x, y, z) : g(x, y, z) ≥ 0} defined by some tersections of the n halfspaces and their complements. function g, as Sψ = bd(ψ) = {(x, y, z) : g(x, y, z) = 0}, and Also central to Shapiro and Vossler’s work is their De- 3 we call the set Sψ the surface of ψ. We say the surface scribability Theorem ([15, 14, 16, 21]). A set Γ ⊆ is Sψ = {(x, y, z) : g(x, y, z) = 0} defined by the function g describable by halfspaces Ψ = {ψ1, . . . , ψN } if there exists a induces the two halfspaces ψ = {(x, y, z) : g(x, y, z) ≥ 0} (halfspace) CSG expression for Γ containing only halfspaces ∗ and ψ = {(x, y, z) : g(x, y, z) ≤ 0}. Buchele [6] points out in Ψ. Shapiro and Vossler’s Describibility Theorem is as fol- that non-degenerate quadric surfaces of a single sheet (ellip- lows: given a set Ψ = {ψ1, ..., ψN } of halfspaces such that ∗ ∗ soids, of one sheet, , hyperbolic and ellip- bd(Γ) ⊂ Sψ1 ∪ · · · ∪ SψN , solid Γ is (halfspace) describable tic , and elliptic, hyperbolic, and parabolic cylin- by Ψ iff for each canonical intersection term, all points in the ders) induce two non-empty regular, pathwise connected canonical intersection term have the same membership sets. classification with respect to Γ. Shapiro and Vossler also use We define a solid to be a regular subset of 3 . The bound- the concept of separating halfspaces. A separating halfspace ary of the solid Γ is denoted bd(Γ). We define the natural is defined as a halfspace that is necessary in the (halfspace)

surfaces of a solid Γ to be the minimal set of surfaces ¡ such CSG representation of a solid but is not a natural halfspace

that bd(Γ) ⊆ ¡ . A F of a solid Γ is a subset of a natural of it. Not all solids can be represented as a halfspace CSG surface S of the solid such that F is a maximally connected tree in which leaves consist only of natural halfspaces of the

component of bd(Γ). If we denote ¢ to be the set of all faces solid. Shapiro and Vossler [16, 21] present an algorithm to of a solid Γ, then we can define the boundary representation, compute any necessary separating halfspaces to represent

or b-rep, of Γ as the union of all faces of the solid Γ, that is, the solid when the solid is not describable by its natural ¢ bd(Γ) = £ F for faces F ∈ . halfspaces alone The surfaces used in the definition of the boundary, faces, Shapiro and Vossler point out that dominating halfspaces and b-rep of a solid are typically defined either paramet- can simplify the CSG representation of a solid if factored out rically or implicitly. An implicit (or algebraic) surface of at the beginning of the algorithm. A dominating halfspace 3

is a set of the form S = {(x, y, z) : g(x, y, z) = 0}, for ψi of a solid Γ is a halfspace such that ψi ⊆ Γ. Similarly, a

3 g dominating halfspace ψj of the regularized complement of a some algebraic function : → [17]. We use an implicit ∗ ∗ surface representation in our work, since we use the fact solid Γ, Γ , is a halfspace such that ψj ⊆ Γ . that the implicit definition induces two regular halfspaces in The basic b-rep to CSG approach of Shapiro and Vossler a convenient notational form. Surfaces represented implic- is to first factor any dominating halfspaces of the solid or the itly also have advantages in the solid modeling environment, complement of the solid, deriving a resultant solid after each such as the ease of point membership classification and the pass. When no more dominating halfspaces can be factored simplicity of extracting geometric information directly from from the original or a subsequent resultant solid, they com- the surface equation [5, 7]. Implicit surfaces have recently pute all canonical intersection terms induced by the remain- gained attention in the fields of computer graphics, solid ing halfspaces. If any canonical cell contains points that are modeling, and reverse engineering (eg., [1, 4, 3]). both interior and exterior to the solid, separating halfspaces A CSG-tree is a singly-rooted binary tree in which the are computed and the canonical cells are re-evaluated. Once ∗ internal nodes are the regularized set operations union (∪ ), a set Ψ of sufficient and necessary halfspaces is determined ∗ ∗ intersection (∩ ), and set difference (− ), or rigid-body and the canonical CSG representation of the solid or resul- transformations, and the leaves are regular sets. In 3 there tant solid is determined, Shapiro and Vossler then attempt are two types of CSG-tree representations, halfspace and to minimize this halfspace CSG representation using prime bounded solid CSG representations. Halfspace CSG repre- implicants. [14, 2] sentations operate on regular sets that are halfspaces, com- Our b-rep to CSG development builds on and comple- monly algebraic halfspaces in which an algebraic function ments Shapiro and Vossler’s theory in a number of ways. Buchele [6] introduces a new method for b-rep to halfspace and Out factored faces are identified whenever a non-planar CSG conversion to allow for BSP and bounded solid CSG halfspace is factored. conversion from a b-rep of an object as well as halfspace We identify dominating halfspaces using the bounding CSG conversion. The BB family of algorithms convert from structure and factored faces in the following manner. A half- a b-rep to a BSP (Binary Space Partitioning) tree repre- space ψ is a dominating halfspace of a current solid Γcurrent sentation of the solid (the BB algorithm) and then converts if there are no original faces of the solid, or In/Out or Out from the BSP tree to a halfspace CSG tree representation as factored faces of the solid, on the interior of the halfspace well (the BBHC algorithm). We consolidate Buchele’s BB (int(ψ)). Similarly, a halfspace ψ is a dominating halfspace ∗ and BBHC algorithms here, bypassing the BSP to halfspace of the regularized complement of the solid, Γcurrent, if there CSG conversion. are no original faces of the solid, or Out/In or In factored faces of the solid, on int(ψ). Whenever we factor a halfspace, we remove any original 4. B-REP TO HALFSPACE CSG CONVER- faces completely contained in the halfspace surface from the SION current bounding structure of the current region λ, and add the factored faces to the bounding structure. If the halfspace ψ is factored as a dominating halfspace of the solid, one of the resulting regions will be identified as an “in” or “out” 4.1 Overview of BHC Algorithm ∗ region; λ ∩ ψ if ψ is a dominating halfspace of the solid, We present a new algorithm based on Buchele’s BB and ∗ ∗ BBHC algorithms [6] to directly convert from a b-rep of a or λ ∩ ψ if ψ is a dominating halfspace of the regularized 3-D solid to a CSG tree representation of it. We call this complement of the solid. In this case the entire bounding consolidated algorithm BHC, for B-rep to Halfspace CSG structure associated with that region, including any factored conversion. Like Shapiro and Vossler’s algorithm, we take faces just identified on that region, will be discarded. advantage of dominating halfspaces and factor them from Because the BHC algorithm checks for dominating half- the representation at the start of the algorithm. Because spaces on each pass through each region the object is par- of our addition of factored faces, we do not fully compute a titioned into, the resulting halfspace CSG tree is of small resultant solid after each pass of dominating halfspace fac- size overall. If only dominating halfspaces are factored, the torization, and we are able to factor dominating halfspaces halfspace CSG tree will be of minimal size (the number of throughout the algorithm. Thus, a simplified factorization leaves in the tree will equal the number of halfspaces in the is generally possible as a matter of course in the algorithm. boundary representation). Each time we partition, we du- A stack of regions to be processed (initially one region, all plicate at least one halfspace in the CSG tree (the one we of 3 ) is maintained. Only one region is the current region partitioned on), and split the solid region into two. Because at any time. Regions are popped from the stack as they we choose a halfspace to partition by choosing the one that are processed, and any resulting regions to be processed in splits a minimal number of faces, halfspaces that must be the future are pushed onto the stack. Along with the re- duplicated on each of the two resulting regions after a par- gion is stored the bounding structure, which gives enough tition are minimized, at least in a greedy fashion. information about the current solid on that region, so that computing a complete boundary representation of the cur- 4.2 Discussion of BHC Algorithm rent (partially factored) solid is not necessary. The bound- We illustrate the BHC algorithm given in Figure 1 us-

ing structure for a region consists of all original faces that ing the 2-D example shown in Figure 2 as a running ex-

intersect the interior of the region ( ¢ O), all factored faces ample. In this case, the original solid Γ is shown as the 2 that have been associated with the region ( ¢ F ), and all half- shaded region, the original current region λcurrent is , spaces that may be used to factor the current region (Ψ). and Ψ = {ψ1, ψ2, . . . , ψ8}. We begin the procedure by de- Halfspaces are factored one at a time in the algorithm. termining the set ΨIncl to be the set of all halfspaces whose

At each iteration, we check to see if a dominating halfspace surface contains original faces ( ¢ O) that lie on the interior, can be factored from the current representation of the cur- as opposed to the boundary, of λcurrent. In the initial case, rent solid. If a dominating halfspace cannot be factored, we ΨIncl = Ψ ( 2). choose a partitioning halfspace, and split the solid and re- If ΨIncl 6= ∅, that is, if there are original faces on λcurrent gion into two pieces. Each piece is then treated as a solid that have not yet been factored, then we construct the set∗ in a recursive call, and dominating halfspaces are factored ΨDom to be the set of all dominating halfspaces of Γ and Γ on λcurrent (Line 4). A halfspace ψ is a dominating halfspace

from each piece if possible. ∗ ¢ Factored faces are subsets of surfaces of halfspaces that of the current solid Γcurrent if ψ or ψ ∈ Ψ, ¡ face F ∈ O

∗ ¢ have been factored from the solid. They are used to as- such that F ∩ int(ψ) 6= ∅, and ¡ face Ff ∈ F , Ff an In/Out ∗ sure the overall correctness of the algorithm. The purpose or Out factored face, such that Ff ∩ int(ψ) 6= ∅. Similarly, ψ

of factored faces is to identify regions of space that are in- halfspace is a dominating∗ halfspace∗ of the complement of ¢ side or outside the current solid. We identify four types of the current solid Γcurrent if ψ or ψ ∈ Ψ, ¡ face F ∈ O such

∗ ¢ factored faces, called In, In/Out, Out, and Out/In factored that F ∩ int(ψ) 6= ∅, and ¡ face Ff ∈ F , Ff an Out/In or ∗ faces. Specifically, In and Out/In factored faces alert us to In factored face, such that Ff ∩ int(ψ) 6= ∅. In our example, ψ1, ψ2, ψ3 regions of space that must be correctly identified as “in” the we find∗that and are dominating∗ halfspaces of Γ, resulting solid, while Out and In/Out factored faces alert is and ψ5 , is a dominating halfspace of Γ . to regions of space that must be correctly classified as “out” Since ΨDom 6= ∅ then we can factor each of these dom- of the resulting solid. In/Out and Out/In factored faces inating halfspaces from the solid Γ (Line 6). Pseudo code are identified whenever a halfspace is factored whose sur- of FactorDomHalfspaces is given in Figure 3. We may face contains an original face of the solid. In addition, In choose the first dominating halfspace to factor arbitrarily Algorithm BHC 3

Input: Nil CSG tree, λcurrent = ,

¡ ¢ = { ¢ O = {F1, . . . , Fk}, F = ∅, Ψ = {ψ1, . . . , ψN }}

1. While λcurrent 6= ∅ £ £ ∗

{λcurrent Γ and λcurrent Γ } ¡ 2. ΨIncl = GetOriginalHalfspaces(λcurrent, )

3. If ΨIncl 6= ∅ ¡ 4. ΨDom = ComputeDomHalfspaces(λcurrent , )

5. If ΨDom 6= ∅ ¡ 6. λnew = FactorDomHalfspaces(ΨDom, λcurrent , ) 7. Else

8. Choose Partitioning Halfspace ψpart ∈ ΨIncl ¡ 9. PartitionAndPushRegions(ψpart,λcurrent, ) 10. λnew = PopPendingRegion 11. End If 12. Else

{ ¤ original face on int(λcurrent ), and ∃ both In or Out/In and Out or In/Out factored faces on λcurrent} 13. Choose Partitioning Halfspace ψpart ∈ Ψincl Figure 2: Solid Γ. 14. If ψpart = nil 15. Abort with Not Describable Error

17. Else ¡

18. PartitionAndPushRegions(ψpart,λcurrent, ) ψ2, ψ3, and ψ5 from ¢ O and from Ψ, we add each of the

19. λnew = PopPendingRegion faces on ψ1, ψ2, and ψ3, to ¢ F as a factored face of type 20. End If 20. End If In/Out (since each halfspace is a dominating halfspace of

λ λ Γcurrent), we add the face of ψ5 to ¢ F as factored face of 21. current = new ∗ 22. While CheckInOutSolid(λ ) current type Out/In, (since it is a dominating halfspace of Γcurrent), 23. TerminateCSGBranch(λcurrent ) and we create complement faces on ψ1, ψ2, and ψ3, and add 24. λcurrent = PopPendingRegion

25. End While these complement faces to ¢ F as factored faces of type In. 26. End While Lastly, we update the CSG tree. If ψD is a dominating 27. Exit halfspace of Γcurrent, we add a union node as the next node in the CSG tree (Line 23, Figure 3), and we add ψD as the node’s left child (Line 24). If ψD is a dominating halfspace ∗ Figure 1: BHC Algorithm for the B-rep to Halfspace of Γcurrent, we add an intersection node as the next node CSG Tree Conversion Process in the CSG tree (Line 26), and add ψD as the node’s left child (Line 27). In either case, the node’s right child be- ∗ ∗ comes λcurrent ∩ ψD, the next current region (Line 29). (Line 1, Figure 3). In practice, we first factor dominating Once all dominating halfspaces in ΨD have been factored, we return with the new region λcurrent being the one that re- halfspaces∗ of Γcurrent, and then factor dominating halfspaces of Γcurrent. Buchele [6] proved that the order of dominat- sulted from factoring the last dominating halfspace in ΨDom. ing halfspace factorization does not affect the validity of the Figure 4a shows the CSG tree after the initial dominating previously detected dominating halfspaces. halfspace factorizations of our example. After the factoring ∗ ∗ ∗ ∗ ∗ For each dominating halfspace ψD that we factor, we re- process, we have Γ = ψ1 ∪ ψ2 ∪ ψ3∪ (ψ5 ∩ (λnew ∩ Γ)) move any portions of any factored faces that lie on the in- for λnew pictured in Figure 4b. Figure 4b also shows the terior of the dominating halfspaces from the factored faces bounding structure of λnew, containing the original faces of

(Lines 3-7, Figure 3). Since ¢ F = ∅ initially, no removal is Γ remaining on λnew , with arrows indicating surface nor- required. We then remove each original face of the dominat- mals, as well as the factored faces added as a result of our ing halfspace from the set of original faces in the bounding procedure.

structure for this region, ¢ O (Line 10). In addition, for Before continuing another pass of the algorithm, we first λ each dominating halfspace we create a factored face of type chec∗ k if the new current is wholly contained in Γcurrent or In/Out or Out/In (depending on if the halfspace is a domi- Γcurrent (Line 22, Figure 1). We can accomplish this by ∗ nating halfspace of Γcurrent or Γcurrent (Lines 9,11) and add checking if the region contains no original faces of the solid, this factored face (corresponding to the original face) to the and contains either only In or Out/In faces, or, only Out set of factored faces in the bounding structure for this re- or In/Out faces. In this case, λnew is not wholly contained λnew gion ¢ F (Line 12). If the surface of the face is non-planar, inside or outside the solid, so we continue processing as it is for dominating halfspaces ψ1, ψ2, and ψ3, we also at Figure 1, Line 2.∗ Since we know that the region is not create a factored face corresponding to the complement of contained in Γ or Γ , the assertion preceding Line 2 holds. the original face on λcurrent (Lines 13, 14, 15). Because of We continue with with the current region λcurrent (in our the data structure used to store faces, the CreateComple- example, λcurrent is the previous λnew shown in Figure 4b), and Ψ = {ψ4, ψ6, ψ7, ψ8}. Again, ΨIncl = Ψ. On the new mentFace procedure is simply a reversal of the rep- ∗ resentation on the surface for each face. If the complement λcurrent there are no dominating halfspaces of Γ or Γ , so face intersects the current region, as it does in our example, we must choose a partitioning halfspace (Line 8, Figure 1). then it is also added to the bounding structure of the cur- Note that without the In factored faces resulting from fac- toring ψ1, ψ2, and ψ3, we might mistakenly identify ψ4 as a rent region as an In or Out factored face (Lines 16-19). We ∗ then remove the halfspace we have factored (or its comple- dominating halfspace of Γ , or, have to compute the closure ment) from the set of halfspaces in the bounding structure of the resultant solid on λcurrent. for this region (Line 21). So, in our example we remove ψ1, We evaluate each ψ ∈ ΨIncl as to its goodness as a parti-

¡ ¢ FactorDomHalfspaces(ΨDom,λcurrent, = { ¢ O, F , Ψ})

1. ψD = GetFirstDominatingHalfspace(ΨDom ) 2. While ψD 6= nil

3. For every face F ∈ ¢ F ∗ 4. If (F ∩ int(ψ ) 6= ∅) D ∗

5. Replace F with F ∩ ψD in ¢ F 6. End If 7. End For

8. F = GetHalfspaceFaces(ψ , ¢ ) D O a) 9. Ff = F

10. Remove Face(s) F from ¢ O 11. Set Face Type of Ff to In/Out or Out/In

12. Add Face Ff to ¢ F 13. If SψD a Non-Planar Surface 14. FC = CreateComplementFace(Ff ) 15. FC = FC ∩ λcurrent 16. If FC 6= nil 17. Set Face Type of FC to In or Out

18. Add Face FC to ¢ S 19. End If 20. End If ∗ 21. Remove Halfspace ψD or ψD from Ψ 22. If ψD dominating halfspace of Ψ ∗ 23. AddCSGInternalNode(∪ , λcurrent) 24. AddCSGChildNode(ψD, left, λcurrent) 25. Else ∗ 26. AddCSGInternalNode(∩ , λcurrent) 27. AddCSGChildNode(ψD, left, λcurrent) 28. End If 29. λcurrent = GetChildNode(right, λcurrent) 30. ψD = GetNextDominatingHalfspace(ΨDom ) b) 31. End While 32. Return λ current Figure 4: a) The CSG tree after initial dominating halfspaces are factored. b) Resulting λnew . Figure 3: Algorithm to factor dominating half- spaces.

then split the bounding structure associated with λcurrent

¢ ¢

into two bounding structures, 1 = { O1 , F1 , Ψ1} and 2 ¢ = { ¢ O2 , F2, Ψ2} associated with each resulting region λ1 tioning halfspace, noting that at this point in the algorithm and λ2. All halfspaces remaining in Ψ (all halfspaces associ-

if ψ is a halfspace in ΨIncl, Sψ contains at least a portion ated with λcurrent except ψ6) are included in each of Ψ1 and ¢

of an original face on λcurrent. For our purposes, we choose Ψ2. Only faces of ¢ O, F that intersect the region λ1 are

¢ ¢ ¢

a halfspace that minimizes the number of original, In/Out, included in ¢ O1 , F1 . Similarly, only faces of O, S that ¢ Out/In, In, and Out faces that must be split in order to intersect the region λ2 are included in ¢ O2 , F2 (Lines 27- perform the partitioning, although another criteria may be 30). Finally, the two resulting regions λ1 and λ2 are pushed used if desired. If some number of halfspaces of ΨIncl split as pending regions to be processed in the future (Line 33). the same number of faces, we prefer halfspaces that split the The bounding structure information for each region is stored fewest number of original faces. If more than one halfspace with the region pushed on the stack. fits this criteria, we prefer planar to non-planar halfspaces We continue processing (Line 10, Figure 1) by popping for partitioning. Otherwise, we choose a partitioning half- one of the pushed regions, say, λ1 shown in Figure 6a. λ1 space randomly from the set of halfspaces meeting these is not an “in” or “out” cell (Lines 21-26, Figure 1), so we criteria. We choose ψ6 as the partitioning halfspace (since continue processing it as our next λcurrent. it splits no faces) and partition (Figure 1, Lines 8,9). At this point, ΨIncl = {ψ4}, and ΨDom = ψ4 since ψ4 is a Pseudo code of PartitionAndPushRegions is given in dominating halfspace of Γ on λcurrent (Lines 2-4, Figure 1). Figure 5. The overall algorithm is similar to a single pass We factor ψ4 (Line 6), resulting in the CSG tree depicted through the main loop of FactorDomHalfspaces, except in Figure 6b and the resulting region λnew shown in Figure two resulting sub-regions are generated instead of one. We 6c. The resulting region λnew is not wholly contained in the first insert a union node and two child intersection nodes into solid, so we continue processing with λcurrent = λnew (Lines the CSG tree (Lines 1-5, Figure 5). The right child of the 21-26). left intersection node is the partitioning halfspace ψ6, while In this case, Ψ = {ψ7, ψ8} and ΨIncl = ∅, so we pro- the left child of the right intersection∗ node is the comple- ceed to Line 13 in Figure 1. Since ΨIncl = ∅, then we have ment of the partitioning halfspace, ψ6. The two resulting a current region that contains no original faces (if it did, ∗ ∗ ∗ regions are λ1 = λcurrent ∩ ψ6, and λ2 = λcurrent ∩ ψ6 ΨIncl would not be empty) and contains inconsistent fac- (Lines 6, 7). Since in this case we know ψ6 ∈ ΨIncl (Fig- tored faces (Out/In or In, and, In/Out or Out). We know

ure 1 Line 8), we know that Sψ6 contains a face from ¢ O that the region contains inconsistent factored faces, because and so in Figure 5, Lines 8 and 9, F will not be nil. We if it did not, the region would have been classified as wholly include the original face as a factored face in both the re- inside or outside the current solid. Thus, the assertion be- sulting regions λ1 and λ2 (Lines 11-13). In this case, Sψ6 is fore Line 13 holds. We choose a partitioning halfspace (Line a planar, surface, so we next remove the face of ψ6, F , from 13) ψpart from Ψ such that the surface of ψpart at least par-

¢ O (Line 24), and the halfspace ψ6 from Ψ (Line 25). We tially partitions In/Out and Out factored faces from Out/In

¡ ¢ PartitionAndPushRegions(ψpart, λcurrent, = { ¢ O, F , Ψ})

∗ 1. AddCSGInternalNode(∪ , λcurrent) ∗ 2. AddCSGInternalNode(∩ , λcurrent.Left) 3. AddCSGChildNode(ψpart, right, λcurrent.Left) ∗ 4. AddCSGInternalNode(∩ , λcurrent.Right) ∗ 5. AddCSGChildNode(ψ , left, λcurrent.Right) ∗ part 6. λ1 = λcurrent ∩ ψpart ∗ ∗ 7. λ2 = λcurrent ∩ ψpart)

8. F = GetHalfspaceFace(ψpart , ¢ O) 9. If F 6= nil 10. For i = 1, 2 11. Ffi = F ∩ λi 12. Set Face Type of Ffi to In/Out or Out/In

13. AddFace Ffi to ¢ Fi 14. End If 15. If Sψpart a Non-Planar Surface 16. FC = CreateComplementFace(F ) a)

17. If FC 6= nil SplitFaceIntoComponents(FC , ¢ O) 18. For each component FC (j) 19. For i = 1, 2 20. FCi (j) = FC (j) ∩ λi 21. Set Face Type of FCi (j) to In or Out

22. Add Face FCi (j) to ¢ Fi 23. End If

24. Remove Face F from ¢ O 25. Remove Halfspace ψpart from Ψ

26. Ψ1 = Ψ; Ψ2 = Ψ ¢ 27. For every face F ∈ ¢ O or F

28. If (F ∩ int(ψpart) 6= ∅) ¢ 29. Add Face F ∩ ψpart to ¢ O or F ∗ 1 1 30. If (F ∩ int(ψ ) 6= ∅)

part ∗ b) ¢ 30. Add Face F ∩ ψpart to ¢ O2 or F2 31. PushPendingRegions(λ1, λ2) 32. Return

Figure 5: Algorithm to partition. and In factored faces. Of the possible partitioning halfspaces that partially partition factored faces, we choose the half- space that minimizes the number of factored faces that must be split at partitioning. If some number of halfspaces split the same number of factored faces, we prefer planar to non- planar halfspaces. Otherwise, we choose a partitioning half- space randomly from the set of halfspaces meeting these c) criteria. If no partitioning halfspace can be found (that is, no halfspaces of Ψ partially split the In/Out and Out faces Figure 6: a) λ1 after ψ6 is partitioned. b) CSG tree from the Out/In and In faces), then we have detected a re- after ψ4 is factored. c) The resulting λnew after ψ4 is gion that is not describable by the halfspaces of Ψ and we factored. abort processing (Line 15). At this point in the algorithm the computation of separating halfspaces might be added to the algorithm, as in Vossler and Shapiro’s method [21], in order to make the solid describable. In this case, ψ7 par- titions the In/Out faces from the In faces, so we partition gions onto the pending regions stack (Line 31) and continue using ψ7. by popping one of the recently pushed regions in Figure 1 at Returning to PartitionandPushRegions (Figure 5), we Line 19. Both of the regions we just pushed are inside and first update the CSG tree (Lines 1-5) and compute the new outside the solid (one contains only In/Out faces, the other contains only In faces), so we consolidate the CSG tree by λ1 and λ2. The partitioning surface Sψ7 contains no faces replacing the (internal) parent node of the CSG tree with on λcurrent, so F = nil in this case (Line 9), and FC = Sψ7 (Line 16). Since the partitioning surface is non-planar (Line its left child (Line 23). Since this consolidation is done for both of the recently pushed regions, we obtain the resulting 15), we split Sψpart ∩λcurrent into connected surface compo- nents (Line 17), and examine each surface component sep- CSG tree shown in Figure 7a. arately. The connected surface components, (determined We continue withLine 2, Figure 1) with the region λcurrent by SplitFaceIntoComponents) are connected surface re- = λ2 shown in Figure 7b. This was the second resulting region after ψ6 was partitioned. We have ΨIncl = {ψ7, ψ8}, gions in λcurrent partitioned by original faces in ¢ O. In this ∗ ∗ ∗ and ΨD = {ψ8} since ψ8 is a dominating halfspace of Γ on case, Sψpart ∩λcurrent = ∅, so no factored faces are added to ∗ both of the next regions (Lines 19-22). We remove ψ7 from λcurrent. We factor ψ8, resulting in the CSG tree depicted Ψ (line 25), and put each of the special faces into either the in Figure 7c. The resulting region λnew is shown in Figure new λ1 or λ2 (Lines 27-30). We push the two resulting re- 7d. λnew is not an “in” or “out” cell, so we continue (Line a) Figure 8: The final CSG tree, after ψ7 is factored.

1, Figure 1) with the new region λcurrent = λnew shown in Figure 7d. ΨIncl = {ψ7}, and ΨD = {ψ7} since ψ7 is a dominating halfspace of Γ on λcurrent. We factor ψ7 (Figure 1, Line 6). ∗ We note that the resulting region is wholly contained in Γ (Line 22), so we consolidate the CSG tree, and since there are no more pending regions we exit. The final resulting CSG tree for the original object shown in Figure 2 is shown in Figure 8. Buchele [6] gives a thorough discussion of the proof of correctness of the BB and BBHC methods for b-rep to BSP (BB algorithm) and BSP to halfspace CSG (BBHC algo- rithm). This algorithm is an encapsulation of the two, in which the straightforward BSP to halfspace CSG conver- b) sion is incorporated into the b-rep partitioning algorithm. Therefore, an almost identical proof of correctness follows for this algorithm as well. 4.3 Complexity of BHC Algorithm The BHC algorithm is typically an O(n3) algorithm, where n is the number of halfspaces (natural and separating) of the solid. This assumes that the number of disjoint faces imbedded in the surface of each halfspace is constant (O(1)), and that each face is bounded by an O(1) number of other faces. There will typically be O(n) passes through the al- gorithm, each pass either factoring a number of dominating c) halfspaces, or, partitioning the solid into two solids. In each pass, ComputeDomHalfspaces is O(n2), since each po- tential halfspace must be compared against every original and factored face. Factoring dominating halfspaces is O(n) (assuming we factor O(1) dominating halfspaces each time we factor). If we partition, determining the best partition- ing halfspace is O(n2) and performing the partitioning is also O(n2). Whenever we partition, we split the solid into two regions, and so exponential growth in the number of required passes is possible. However, because of the ability to factor domi- nating halfspaces frequently in the algorithm, on real objects we have seen less than n total passes through the algorithm, despite needing to partition the objects occasionally. d) 4.4 Implementation of BHC Algorithm

Figure 7: a) CSG tree after ψ7 is partitioned. b) The theory presented has been used to develop an ex- Pending λ2, the right child region when ψ6 was par- perimental implementation of the BHC algorithm. The im- titioned. c) CSG tree after ψ8 is factored. d) Re- plementation is written in C and runs in conjunction with sulting region after ψ8 is factored. Mathematica 4.0. The implementation is not currently op- timized for speed. The BHC implementation takes as input a quadric bound- ary representation of an object, and computes a valid CSG Figure 9: First test object Figure 10: Second test object

representation of the object defined by the input b-rep, us- ing the BHC algorithm. This experimental implementation is designed to work for objects bounded by quadric surfaces of a single sheet, although implementations for more general surfaces (implicit surfaces that induce two non-empty, reg- ular, pathwise-connected halfspaces) may also be developed using the BHC algorithm. The output is a text-formatted CSG tree listed in a pre-order traversal order, in which in- ternal nodes are the operators regularized union and regu- Figure 11: a) 2-D cross section in neighborhood of larized intersection, and leaf nodes are halfspaces. An ex- rounded edge of cavity. b) Same edge with separat- tension to the BHC algorithm was implemented, in that if ing halfspace added. separating surfaces are added to the input b-rep and the ob- ject is describable using its natural halfspaces plus the sep- arating halfspaces induced by these separating surfaces, the separating halfspaces are used with the natural halfspaces can be thought of as being formed by a cylindrical surface to compute the CSG tree representation of the object. intersecting the neighboring planes in tangent lines. A 2-D view looking down on a forming a rounded edge is shown in Figure 11a. Point p shown is inside the solid Γ (the 5. TEST RESULTS shaded region shown), while point q is outside the solid Γ. The experimental implementation of the BHC algorithm However, points p and q lie in the same canonical cell, and was tested on several objects. Three objects were chosen so, the solid is not describable. The BHC implementation that tested several aspects of the algorithm, including the applied to the b-rep of this object correctly determined that detection of non-describable objects. Two objects were cho- the object is not describable. sen that were not describable by their natural halfspaces. We can easily determine a set of separating halfspaces that In both cases, separating halfspaces were easily determined would make the second test object describable, however. An (by hand) and added to the b-rep for each object. With the example of a halfspace added, ψnew , is shown in Figure 11b. addition of the separating halfspace information, a correct Because of the unique geometry of this object, two of the halfspace CSG tree representation of the object was then six separating halfspaces actually coincide. We augmented computed by the BHC implementation. the original b-rep to include these separating halfspaces, so The first test object used is shown in Figure 9. This object that the new augmented b-rep of the object consists of the was taken from a paper on feature-based design and recog- original 32 halfspaces, 33 faces, 76 edges, and 56 vertices of nition [8]. The b-rep of the object consists of 21 halfspaces, the object, plus the 4 unique separating halfspaces. Using 45 faces, 114 edges, and 78 vertices. Using the BHC imple- the BHC implementation on this augmented b-rep, a half- mentation, a halfspace CSG tree was computed consisting of space CSG tree was computed consisting of 35 levels, 38 in- 22 levels, 27 internal nodes (regularized union/intersection ternal nodes (regularized union/intersection operators), and operators) and 28 leaves (halfspaces). Although seven of 39 leaf nodes (halfspaces). Here, three of the halfspaces are the halfspaces are duplicated in the resulting halfspace CSG duplicated in the resulting halfspace CSG tree, resulting in tree, the tree is of minimal total size for this object. a nearly minimal total tree size for this object. The second test object used is shown in Figure 10. This The third test object used is shown in Figure 12. This ob- object was taken from a paper on recognizing features ject was taken from the same paper on feature-based design in solid models [13]. The b-rep of the object consists of 32 and recognition as the first test object [8]. The b-rep of the halfspaces, 33 faces, 76 edges, and 56 vertices. This object object consists of 37 halfspaces, 48 faces, 123 edges, and 85 is not describable by its natural halfspaces. To see this, vertices. This object is not describable by its natural half- consider the round edges at the corners of the pocket at the spaces, due to the rounded edges in the inner cavities and top of the object. These rounded edges are blends, that along the outside of the object. The BHC implementation bounding surfaces induce two non-empty, regular halfspaces. The BHC algorithm is implemented for solids bounded by non-degenerate quadric surfaces of a single sheet. Many me- chanical objects, particularly those manufactured by turn- ing or simple machining operations, consist of such planar and quadric surfaces. Solids whose bounding surfaces are higher degree polynomial surfaces, or non-polynomial sur- faces, would work in theory using this method, although the implemetation of surface-surface intersection methods for more complex surfaces may limit its usefulness in practice. Because of the direct, halfspace by halfspace factorization process of the algorithm, no post-processing to minimize the resultant CSG tree is necessary. The BHC algorithm naturally produces an efficient CSG representation from the input b-rep. The current BHC implementation accepts a b-rep of a Figure 12: Front and rear view of the third test solid that is describable by its natural halfspaces. Alter- object. natively, a solid that is not describable by its natural half- spaces, but whose b-rep has been appended with separating halfspaces is also acceptable by this algorithm. The compu- applied to the b-rep of this object correctly determined that tation of separating halfspaces for a quadric solid has been the object is not describable. solved by Shapiro and Vossler [16]. The solution to the prob- Once again, we can easily determine a set of separating lem is most completely given in the patented work of Vossler halfspaces that would make the third test object describable, and Shapiro [21]. Thus, the Shapiro and Vossler/Vossler and however. Three planar halfspaces are needed. Two planar Shapiro separating halfspace algorithm might be integrated halfspaces separate the rounded edges along the outside of with the BHC algorithm to compute necessary separating the object, while one additional planar halfspace separates halfspaces as non-describable regions of the object are de- the rounded edges at the upper side of the inner cavities. tected. The rounded edges at the lower side of the inner cavities are already separated by the plane defining the upper of the object. We augmented the original b-rep to include 7. REFERENCES these separating halfspaces, so that the new augmented b- [1] F. Bernardini, C. L. Bajaj, J. Chen, and S. D. R. rep of the object consists of the original 37 halfspaces, 48 Automatic Reconstruction of 3D CAD Models from faces, 123 edges, and 85 vertices of the object, plus the 3 Digital Scans. International Journal of Computational separating halfspaces. Using the BHC implementation on Geometry & Applications, 9(4 & 5):327–369, 1999. this augmented b-rep, a halfspace CSG tree was computed [2] G. Birkhoff and T. C. Bartree. Modern Applied consisting of 24 levels, 55 internal nodes, and 56 leaf nodes. Algebra. McGraw-Hill, 1970. Sixteen of the halfspaces are duplicated in the resulting half- [3] J. Bloomenthal, editor. Introduction to Implicit space CSG tree. Six of these duplicates occur because six Surfaces. Morgan Kaufman, 1997. partitions are needed for this object. The other ten half- [4] J. Bloomenthal and B. Byvill, editors. Implicit spaces are due to multiple faces on the same halfspace oc- Surfaces. Morgan Kaufman, 1996. curring in different regions after partitioning. The resulting [5] P. Brunet and A. Vinacua. Modeling Closed Surfaces: tree size is not minimal, but of small total tree size overall. A Comparison of Existing Methods. In Mathematical Compared to Buchele’s BB and BBHC algorithms, the Methods in Computer Aided Geometric Design II. consolidated BHC algorithm runs in approximately the same Academic Press, 1992. time. The BHC algorithm is slightly faster, due to the elim- [6] S. F. Buchele. Three-Dimensional Binary Space ination of the BSP to halfspace CSG conversion step. Partitioning Tree and Constructive Solid Geometry Tree Construction from Algebraic Boundary 6. CONCLUSIONS Representations. PhD thesis, The University of Texas This research complements the work of Shapiro and at Austin, 1999. Vossler [15, 14, 16, 21] in solving the problem of computing [7] I. D. Faux and M. J. Pratt. Computational Geometry a halfspace CSG tree representation of a three-dimensional for Design and Manufacture. John Wiley & Sons, object bounded by quadric surfaces. This work is motivated 1979. by the representation of 3-D solids and by the problem of [8] J. Han and A. A. G. Requicha. Integration of Feature reverse engineering of 3-D solids. The algorithm presented Based Design and Feature Recognition. Computer here is an encapsulation of Buchele’s BB and BBHC algo- Aided Design, 29(5):393–403, 1997. rithms [6] which compute a binary space partitioning (BSP) [9] W. Lin and T. Chen. CSG-Based Object Recognition tree representation from a b-rep of a solid object, and con- using Range Images. In Proceedings of the 9th vert the BSP tree to a halfspace CSG tree representation. International Conference on Pattern Recognition, Conversion to a bounded solid CSG tree representation of pages 99–103, November 1988. the solid may also be possible, as in Buchele’s BBC algo- [10] S. Menon and Y. S. Kim. Handling Blending Features rithm[6]. in Form Feature Recognition using Convex The theory of this work is applicable to any solid whose Decomposition. In Proceedings 14th Annual ASME International Computers in Engineering Conference [18] K. Tang and T. Woo. Algorithmic Aspects of and Exhibition, 1, pages 79–92, 1994. Alternating Sum of : Part 1: Data Structure [11] D. P. Peterson. Boundary to Constructive Solid and Difference Operation. Computer Aided Design, Geometry Mappings: A Focus on 2D Issues. Computer 23(5):357–366, June 1991. Aided Design, 18(1):3–14, 1986. [19] K. Tang and T. Woo. Algorithmic Aspects of [12] A. A. G. Requicha and J. R. Rossignac. Solid Alternating Sum of Volumes: Part 2: Nonconvergence Modeling and Beyond. IEEE Computer Graphics and and its Remedy. Computer Aided Design, Applications, pages 31–44, September 1992. 23(6):435–443, July 1991. [13] H. Sakurai and D. C. Gossard. Recognizing Shape [20] D. L. Vossler. Sweep-to-CSG Conversion using Features in Solid Models. IEEE Computer Graphics Pattern Recognition Techniques. IEEE Computer and Applications, pages 22–32, September 1990. Graphics and Applications, 5(8):61–68, August 1985. [14] V. Shapiro and D. L. Vossler. Construction and [21] D. L. Vossler and V. Shapiro. System and Method for Optimization of CSG Representations. Computer Converting Boundary Representations to Constructive Aided Design, 23(1):4–20, 1991. Solid Geometry Representations for [15] V. Shapiro and D. L. Vossler. Efficient CSG Three-Dimensional Solid Object Modeling. Technical Representations of Two-Dimensional Solids. report, United States Patent No. 5,537,519, July 1996. Transactions of the ASME, 113:292–305, September [22] T. C. Woo. Feature Extraction by Volume 1991. Decomposition. In Proceedings on CAD/CAM [16] V. Shapiro and D. L. Vossler. Separation for Technology in Mechanical Engineering, pages 76–94, Boundary to CSG Conversion. ACM Transactions on 1982. Graphics, 12(1):25–55, January 1993. [17] D. M. Y. Sommerville. Analytical Geometry of Three . Cambridge University Press, 1939.