









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Lecture 20: Solid Modeling ... a cubit on the one side, and a cubit on the other side Exodus 26:
1. Solids A solid is a 3-dimensional shape with two well-defined sides: an inside and an outside. Thus, for any point in space it is possible, at least in principle, to determine whether the point lies on the inside, or on the outside, or on the boundary of a solid. Solid modeling allows us to represent more complicated shapes than surface modeling. With solid models, we can compute mass properties such as volume and moments of inertia; we can check for interference and detect collisions; we can also apply finite element analysis to calculate stress and strain for solid models. Three types of solid modeling techniques are common in Computer Graphics: constructive solid geometry (CSG), boundary representations (B-Rep), and octrees. Constructive solid geometry relies heavily on ray tracing both for rendering and for analysis, so constructive solid geometry is closest to methods with which we are already familiar from surface modeling. Boundary representations often rely on parametric patches such as Bezier patches or B-splines, freeform surfaces which we shall study later in this course. In contrast, octrees are an efficient spatial enumeration technique, a method for approximating smooth 3-dimensional shapes with a simple, compact collection of rectangular boxes. In this lecture we shall give a brief survey of each of these solid modeling methods, and we shall compare and contrast the advantages and disadvantages of each approach. 2. Constructive Solid Geometry (CSG) In constructive solid geometry, we begin with a small collection of simple primitive solids -- boxes, spheres, cylinders, cones, and tori (see Figure 1) -- and we build up more complicated solids by applying boolean operations -- union, intersection and difference (see Figures 2 and 3) -- to these primitive solids. For example, if we want to drill some holes in a block, then we can model this solid by subtracting a few cylinders from a box (see Figure 3). Figure 1: Primitives for a solid modeling system: a box, a sphere, a cylinder, a cone, and a torus.
Solids are stored in binary trees called CSG trees. The leaves of a CSG tree store primitive solids; the interior nodes store either boolean operations or nonsingular transformations. Nodes storing boolean operations have two children; nodes storing transformations have only one child. Boolean operations allow us to build up more complicated solids from primitive solids. Transformations allow us to reposition the solid from a canonical location to an arbitrary location or to rescale the solid from a symmetric shape to a more general shape. Each node of a CSG tree defines a solid. The solid defined by a leaf node is the primitive solid stored in the leaf. The solids at interior nodes are defined recursively. If the interior node stores a transformation, then the solid corresponding to the node is the solid generated by applying the transformation in the node to the solid stored by the node’s child. If the interior node stores a boolean operation, then the solid corresponding to the node is the solid generated by applying the boolean operation in the node to the solids stored in the node’s two children. The solid corresponding to the root of the tree is the solid represented by the CSG tree (see Figures 2 and 3). €
€ sphere € cylinder € cylinder €
rotation Figure 2: A spherical tank with two cylindrical pipes (left), modeled by a CSG tree consisting of the union of a sphere and two cylinders (right). € − € − € − € box € cylinder € 1 cylinder 2 € cylinder 3 Figure 3: A solid block with three cylindrical holes (left), modeled by a CSG tree that subtracts three cylinders from a box (right).
each interval € Ik inside the solid by € Δ A and add the results, then we get a good approximation to the volume of the solid. Thus € Volume ≈ ∑ (^) kLength ( Ik )Δ A. Alternatively, we can apply Monte Carlo methods to compute the volume of a solid represented by a CSG tree. Monte Carlo methods are stochastic methods based on probabilistic techniques. Enclose the solid inside a rectangular box. If we select points at random, uniformly distributed inside the box, then some of the points will fall inside the solid and some of the points will fall outside the solid. The probability of a point falling inside the solid is equal to the ratio of the volume of the solid to the volume of the box. Thus € _# Points inside Solid
Volume ( Solid ) Volume ( Box ) so € Volume ( Solid ) ≈ _# Points inside Solid
× Volume ( Box ). Therefore to find the volume of a solid, all we need is a test for determining if a point lies inside or outside the solid. There are two ways to perform this inside-outside test: by ray casting or by analyzing the CSG tree recursively. To apply ray casting, observe that a point lies inside a solid if and only if an arbitrary ray emanating from the point intersects the solid an odd number of times; otherwise the point lies outside the solid. Now the same interval analysis we applied in the ray casting algorithm for rendering solids represented by CSG trees can be applied to determine the number of times a ray intersects a solid and hence too whether a point lies inside or outside a solid. However, for CSG trees built from simple primitives, it is easier to determine whether a point lies inside or outside a solid by analyzing the CSG tree recursively. To begin, one can easily determine whether a point lies inside or outside simple primitives like boxes, spheres, cylinders, and cones by using the appropriate distance formulas (see Exercises 1-3). For example, a point P lies inside a sphere if and only if the distance from the point P to the center C of the sphere is less than the radius R of the sphere -- that is, if and only if €
2 < R 2
. For a solid such as a torus defined by an implicit equation € F ( x , y , z ) = 0 , if the gradient € ∇ F = (^) (∂ F / ∂ x ,∂ F / ∂ y ,∂ F / ∂ z ) represents the outward pointing normal, then a point P lies inside the solid if and only if €
if the gradient € ∇ F represents the inward pointing normal, then a point P lies inside the solid if and only if € F ( P ) > 0 (see Exercise 4). Once we have an inside-outside test for each of the primitives, we can generate an inside- outside test for each CSG tree recursively in the following fashion. If the root stores a
transformation T , then a point P lies inside the corresponding solid if and only if the point €
− 1 ( P ) lies inside the solid represented by the root’s child. If the root stores a boolean operation, then to determine if a point P lies inside the corresponding solid, first perform tests to determine if the point P lies inside the solids represented by each of the root’s two children and then apply the boolean operation at the root to the outcome of these two tests. Pseudocode for this inside-outside test on a CSG tree is presented below. Algorithm for Determining if a Point P Lies Inside or Outside a Solid Represented by a CSG Tree If the solid is a primitive: Use the appropriate distance formula or the implicit equation associated with the primitive to determine whether the point P lies on the inside or the outside of the primitive. Otherwise if the solid is a CSG tree: If the root stores a transformation T, Recursively determine if the point €
− 1 ( P ) lies inside or outside the root’s child. Otherwise if the root stores a boolean operation: Recursively determine if the point lies inside or outside the root’s two children. There are three cases to consider: Union If P lies inside the child at either node, then P lies inside the solid_._ Intersection If P lies inside the children at both nodes, then P lies inside the solid. Difference ( €
If P lies inside the child at the left node (A) and outside the child at the right node (B), then P lies inside the solid. Otherwise P lies outside the solid. Constructive solid geometry based on CSG trees has many advantages, The representation is compact, the data structure is robust, and the user interface based on boolean operations is simple and natural. Transformation nodes in the CSG tree permit parameterized objects based on canonical positions or canonical shapes. The analysis of CSG trees is also straightforward: ray casting can be used for rendering, calculating volume, and testing whether points lie inside or outside a solid. Nevertheless, constructive solid geometry also has certain disadvantages. There is no adjacency information in a CSG tree. That is, there is no information about which surfaces are next to a given surface. But adjacency information is crucial in manufacturing, especially for NC machining. Also, in a CSG model there is no direct access to the vertices and edges of the solid. Thus, it is difficult for a designer to select specific parts of an object as referents, nor can a designer
€ V € E € F Figure 4: The nine potential sets of pointers for a topological data structure. The winged-edge data structure is a standard representation for topology, which makes a reasonable compromise between time and space. Most of the pointers in a winged-edge data structure are stored with the edges. For solids bounded by 2-dimensional manifolds, each edge lies on two faces, and each edge typically connects two vertices. In the winged-edge data structure, edges are oriented and each edge points to: 2 Vertices -- Previous ( P ) and Next ( N ) (orientation), 2 Faces -- Left ( L ) and Right ( R ), 4 Edges -- € PR , NR and €
In addition, each vertex points to one edge that contains the vertex, and each face points to one edge that lies on the face (see Figure 5).
P N L − Face (^) E R − Face PR
Figure 5: The winged-edge data structure. With the winged-edge topology, we can answer all questions of the form: Is A on or adjacent to B. Typical queries are: Find all the edges surrounding a face. Find all the faces adjacent to a face. Find all the vertices lying on a face. Find all the edges passing through a vertex. We leave it as a straightforward exercise to the readers to convince themselves that these queries can
all be answered quickly and easily from the data stored in the winged-edge topology (see Exercise 9). The main advantages of the winged-edge topology are that in addition to supporting fast retrieval of topological information, the winged-edge data structure is of moderate size and is relatively easy to maintain during boolean operations. One problem with the winged-edge topology is that this data structure does not support faces with holes -- that is, faces defined by one exterior loop and one or more interior loops. To solve this problem auxiliary edges are typically added to the model in order to connect the inner loops to the outer loop. These auxiliary edges have the same face on both sides (see Figure 6)!
Face
Auxiliary Edge Figure 6 : A face with a hole. The face is surrounded by two loops (left). An auxiliary edge connects the two loops (right). Notice that the auxiliary edge has the same face on both sides. Boundary file representations are more complicated than CSG trees, so it is easy to make a mistake in the topology when updating a model during a boolean operation. One way to check the consistency of the topology in the boundary file is to verify Euler’s formula. Euler’s formula for solids bounded by 2-dimensional manifolds asserts that €
where V = # vertices, E = # edges, F = # faces, H = # holes in faces, C = # connected components, and G = # holes in the solid (genus). For example, for a cube, V = 8, E = 12, F = 6, H = 0, C = 1, and G = 0. Therefore, €
If Euler’s formula is not satisfied, then there is a error in the model. Moreover, it is unlikely (though possible) that an invalid model will actually satisfy Euler’s formula. Therefore Euler’s formula provides a robust check for the consistency of the topological model. Topology plays no essential role in rendering. Therefore, ray tracing for solids represented by boundary files is essentially the same as ray tracing for surface models: simply intersect each ray with each surface on the boundary of the solid and display the closest intersection point.
Algorithm Intersect each surface (face) of A with each surface (face) of B to form new curves (edges) on A and B. {Difficult Computations} Intersect each new curve with existing edges on the old faces to form new vertices and edges on A and B. Insert the new faces, edges, and vertices into the topology of A and B. {Update Topological Data Structures} Combine the boundary topologies based on the particular boolean operation: € ∂( A ∪ B ) = (∂ A − ∂ AinB )∪ (∂ B − ∂ BinA ) € ∂( A ∩ B ) = ∂ AinB ∪ ∂ BinA € ∂( A − B ) = (∂ A − ∂ AinB )∪ ∂ BinA € ∂( B − A ) = (∂ AinB )∪ (∂ B − ∂ BinA ) While this pseudocode may seem straightforward, the actual computations can be quite difficult. Computing accurate surface-surface intersections is hard; maintaining correct boundary files is time consuming as well as susceptible to numerical errors because to speed up the computations the intersections are typically calculated using floating point arithmetic. Many man years are generally required to code robust boolean operations on boundary file representations. The main advantage of boundary file representations is that adjacency information is readily available. This adjacency information is important for manufacturing operations such as NC machining. Adjacency information also permits the designer to modify the model by tweaking vertices and edges, and to extract important features for manufacturing such as holes and slots. Moreover, unlike CSG representations, the boundary file representation is unique. Thus it is possible to decide whether two solids are identical by comparing their boundary file representations. Finally, we can verify the correctness of the topological model by checking Euler’s formula. The main disadvantage of the boundary file representation is that maintaining the topology requires maintaining a large and complicated data structure. Therefore boolean operations on boundary file representations are slow and cumbersome to compute. Moreover, floating point inaccuracies can cause disagreements between geometry and topology; tangencies are particularly hard to handle. Hence, it is difficult to maintain robust boundary file representations for solids bounded by curved surfaces. Thus even though boundary file representations facilitate the solution of several important problems in design and manufacturing, boundary files also introduce additional problems of their own. Therefore, next we shall investigate yet another, much simpler type of representation for solids that has some advantages over boundary file representations.
4. Octrees Octrees are an efficient spatial enumeration technique. In naive spatial enumeration, space is subdivided into a large collection of small disjoint cubes all of the same size and orientation -- usually with faces parallel to the coordinate planes -- and each solid is defined by a list of those cubes lying inside or on the boundary of the solid. The accuracy of spatial enumeration for solids bounded by curved surfaces depends on the size of the cubes used in the spatial enumeration, so there are tradeoffs between the accuracy of the model and the space necessary to store the model. To save on storage, octrees vary the size of the cubes so that lots of small cubes get coalesced into larger cubes. Large cubes are used to model the interior of the solid, while small cubes are used to model the boundary of the solid. The cubes in an octree are called voxels. In an octree representation of a solid the number of voxels is typically proportional to the surface area; most of the subdivision of large cubes occurs to capture the boundary of the solid. Octrees to model solids are generated by the following divide and conquer algorithm. Figure 7 illustrates a 2-dimensional analogue of an octree, a quadtree for the area enclosed by a planar curve. Octree Algorithm Start with a large cube containing the solid. The faces of the large cube should be oriented parallel to the coordinate planes. Divide this large cube into 8 octants. Label the cube in each octant as either E = empty, F = full, or P = partially full, depending on whether the octant is outside, inside, or overlaps the boundary of the solid. Recursively subdivide the P nodes until their descendents are labeled either E, or F , or a lowest level of resolution (cutoff depth) is reached. Figure 7: A quadtree model for the area enclosed by a planar curve. Notice that most of the subdivision of the large squares into smaller squares occurs along the bounding curve.
5. Summary There are three standard techniques in Computer Graphics for modeling solids: CSG trees, boundary files (B-Rep), and octrees. Each of these representations have certain advantages and disadvantages. For easy reference, in Table 1 we compare and contrast six of the main properties of these three representations for solids, including ( i ) the accuracy of the model, ( ii ) the size of the domain of the solids that are readily represented by the model, ( iii ) the uniqueness of the model, ( iv ) the ease of verifying the validity of the model, ( v ) whether or not the model is closed under boolean operations, and finally ( vi ) the compactness of the model. CSG B–REP Octree Accuracy Good Good Mediocre Domain Large Small Large Uniqueness No Yes Yes Validity Easy Hard Easy Closure Yes No Yes Compactness Good Bad Mediocre Table 1: Comparison of different solid modeling methods. Exercises:
€ c
Figure 8: A box with a corner corner at Q , edges parallel to the unit vectors € a , b , c , with length, width, and height given by the scalars € l , w , h. 13
Interpret these formulas geometrically. € A € €^ Q^ • H €
Figure 9: A bounded cylinder of radius R and height H with an axis line L determined by a base point Q and a unit direction vector A.
Interpret these formulas geometrically.
€
Figure 10: A bounded cone with vertex V , cone angle € α and height H , with an axis line parallel to the unit direction vector A.
∑ (^) k ( Qk • Nk ) Area ( Sk ).