Abstract:
In a data processing system for determining intersections between geometric objects, the work is split between a CPU and a stream processor. The intersection determination is controlled by the CPU. Data processing intensive parts of intersection algorithms, such as checking possible overlap of objects, checking overlap of normal fields of objects, approximating the extent of an object, approximating the normal fields of an object, or making conjectures for intersection topology and/or geometry between objects, are run on the stream processor. The results of the algorithmic parts run on the stream processor are used by the part of the algorithms run on the CPU. In cases where conjectures for the computational result are processed on the stream processor, the conjectures are checked for correctness by algorithms run on the CPU. If the correctness check shows that the result found is incomplete or wrong, additional parts of the algorithm are run on the CPU and possibly on the stream processor.

Description:
FIELD OF THE INVENTION 
     The invention relates generally to a computer apparatus and a data processing method and apparatus in which the intersections between two or more geometric objects, as well as self-intersections in one geometric object, are determined. More particularly, the invention relates to a computer apparatus and a data processing method which may be employed with advantage in computer aided design, computer aided manufacturing, rapid prototyping, finite element pre-processing, computer animation and other applications where correct intersections between geometric objects are to be determined rapidly. 
     In this text, the phrase “intersections for geometric objects” is defined as comprising as well “intersections between two or more geometric objects” as “self-intersections in one and the same geometric object”. Further, the phrase “tessellated representation” is defined as comprising both the mathematically defined “tessellated representation” and “triangulation representation”, and the phrase “tessellation” is defined as comprising both the mathematically defined “tesselation” and “general triangulations”. 
     DESCRIPTION OF RELATED ART 
     Within CAD (Computer-Aided Design) and other product development oriented applications it is a common practice in prior art to use only programs executed on the CPU (Central Processor Unit) to calculate intersections between geometric objects. A number of approaches exist that give more or less guarantee of the quality of the intersection calculated. However, for collision culling in graphics applications the use of GPUs (Graphics Processor Unit) is proposed in “ Fast Collision Culling using Graphics Processors , UNC-CH Technical Report, January 2004” by Naga Govindaraju, Ming C. Lin and Dinesh Manocha. 
     Although the innovation is not limited to CAD, we will describe the mathematics behind the innovation in CAD-related terms. In CAD the surfaces can be
         Parametric surfaces. A surface p(s,t), (s,t)εΩ⊂R 2  is described as a mapping from a closed and bounded set ΩεR 2  to R 3 . The surface is piecewise polynomial, i.e. it is built by a patchwork of rational pieces (minimum is one piece) that meet with tangent, curvature or higher order continuity. The standardized representation format for rational piecewise polynomials within CAD is NURBS—NonUniform Rational B-splines.   Low degree algebraic surfaces such as the plane (degree 1), conics (degree 2) and the torus (degree 4). The algebraic surfaces are described by an implicit polynomial equation f (x, y, z)=0, (x, y, z)εR 3 , of total degree 1, 2 or 4.       

     A great challenge within CAD is to make high quality models. In such models, fast high quality intersection calculations are necessary to enable efficient design of high quality CAD-models. While the intersection of two planar surfaces is simple to evaluate, the intersection of two NURBS surfaces p(s,t), (s,t)εΩ 1 . and r(u,v), (u,v)εΩ 2  is a major challenge. 
     As an example, let both surfaces be bi-cubic, e.g. of degree 3 in both parametric variables. The intersection problem p(s,t)=r(u,v) is the problem of solving 3 polynomial equations in four variables, with the polynomial degree in each variable being 3. Let us assume that we find the exact implicit representation q(x,y,z)=0 of a polynomial segment of the surface r(u,v), (u,v)εΩ 2 . When r(u,v) is bicubic, this implicit equation has total degree 18. Combining the parametric representation of one surface with the exact implicit representation of the other surface q(p(s,t),)=0 reduces the number of unknowns to two. However, the resulting problem is now to find the zero set of a polynomial equation in two variables with polynomial degree in both variables being 54. Thus the intersection problem encountered in CAD is in general a very challenging problem. 
     Over the years, many approaches have been followed to calculate intersections between CAD-type surfaces. In general, the more computations you can afford, the higher the quality of the intersection will be. Stream processors offer high computational performance. Graphics cards (GPUs) have a stream processor type architecture. The rapid growth in the computational performance of graphics cards experienced from 2003 opens up the possibility to use these as a computational resource in intersection algorithms. A graphics card used as a stream processor in intersection calculations offers high volume computations with a low cost. Thus, combining one or more CPUs and one or more GPUs in intersection calculations has the potential to significantly increase the available computational power, and thus the quality of intersection calculations. 
     The publication “The Ray Engine”, Graphics Hardware 2002, Sep. 1-2. 2002, Saarbrücken, Germany, The Eurographics Association, 2002, by Nathan A. Carr et al, discloses a computer system for estimating intersections between rays and triangles, to provide information regarding ray intersection points closest to the “camera” from which the rays emanate. A cooperation between GPU and CPU is described, however the GPU provides only such intersection points as just mentioned, and is not able to provide more complex topology information. 
     The simplest approach for the intersection of geometric objects is to approximate both surfaces with triangulations and intersect these triangulations. Another fairly simple approach is lattice evaluation where a lattice of curves is calculated over both surfaces and the lattice of curves from each surface is intersected with the other surface. The points identified can be used for tracing out intersection curves on which the points lie. For both these methods, the intersection calculated is a conjecture of the actual intersection, not a proved calculation. 
     For certain classes of low degree algebraic representations, explicit representations of the intersection topology and geometry exist. However, for the intersection of general algebraic or parametric surfaces, no such explicit representations exist. 
     Homotophy continuation is an approach where a known problem is solved and then the problem is modified gradually to a more complex problem. During the modification the solution is monitored. Intersection algorithms exist based on this approach. 
     Recursive methods use a divide and conquer strategy. If the problem is too complex for determining the topology of the intersection, the problem is split into sub-problems, the idea being that the sub-problems are simpler to solve than the original problem. However, in this approach care must be taken to ensure that the sub-problems are simpler. If care is not taken a problem can become more complex after subdivision. The subdivision approach can ensure that all intersections are found within specified tolerances when run on a normal CPU. However, recursive methods are computationally expensive. 
     Marching methods are used in surface/surface intersections. It is a method where we start from a point on the solution and then search for new points on the intersection close to the current point. When singular points are reached, points where the surface normal vanishes, problems occur when deciding how to continue the search. Marching methods can use start points generated e.g. by lattice evaluation or recursive subdivision. A marching method has no guarantee that the complete intersection configuration is found. 
     Bi-section methods are closely related to marching methods. In the case of a bi-section method two or more points on an intersection curve are given, and new points are calculated in between. The process can be repeated until all curve segments are a satisfactory approximation of the true intersection curves. If two adjacent points do not belong to the same intersection curve branch, the bisection will not converge. Detecting the lack of convergence can be used for detecting when a conjecture or proposed intersection curve is a misinterpretation of a situation with multiple intersection branches. 
     Within Computer Aided Design low quality calculation of intersections results in low quality CAD-models. Lattice evaluation methods are in general faster than recursive methods. However, lattice evaluation can not detect singular intersection points and might miss intersection branches. Recursive methods are slower since they search for a guaranteed solution within specified tolerance. 
     Accordingly there is a need for fast calculations of guaranteed intersection results. 
     SUMMARY OF INVENTION 
     Briefly, and in general terms, the present invention provides improvements in intersection calculations and apparatus whereby data processing speed can be increased substantially and the quality guaranteed within specified tolerances. 
     More particularly, by way of example and not necessarily by way of limitation, the present invention provides an organization of the intersection process to be performed on at least one CPU initiating computational intensive tasks on at least one stream processor. In cases when the calculation results from the at least one stream processor creates a conjecture, the CPUs are used for evaluating the correctness of the calculation. In cases when the stream processors return verified information, the information can be used directly in the part of the intersection process controlled and executed on the CPUs and possibly also for launching new computation intensive tasks to be performed by the stream processors. In other words, the present innovation provides an intersection calculation process that provides the use of at least one CPU and at least one stream processor, using the computational power of the stream processors to perform computer intensive tasks such as generating a conjecture of the topology and geometry of the intersection, and then using this conjecture as a guide through a verification process. In case the conjecture is not valid within the tolerances specified, the information from the conjecture is used to guide the process of improving the conjecture and verifying that the result is valid within the tolerances specified. This improvement process can combine the use of the CPUs and the stream processors, and has possibly multiple repetitions. The approach also opens up the possibility to use the computational power of the stream processors to detect spatial separation of geometric objects or their normal sets, or to make verified approximations to the extent of the normal sets or the spatial extent. 
     Hence, the present invention satisfies a long existing need for enhanced intersection calculations at increased processing speed. The present invention clearly fulfils these needs. 
     Hence, in a first aspect of the present invention there is provided a computer apparatus for determining and finding a geometric representation of intersection topology for geometric objects that are described using any of parametric representation, algebraic representation and tessellated representation, the computer apparatus comprising at least one central processor unit (CPU) operative to perform portions of an intersection algorithm, initialize sub-algorithms thereof, control the sub-algorithms and to process a conjecture for an intersection calculation result, wherein the computer apparatus further comprises at least one stream processor unit (SPU) operative to receive subparts of the intersection algorithm from the at least one CPU and to execute the sub-algorithms of the intersection algorithm, resulting in information necessary to establish the conjecture, and to return the information to the at least one CPU. 
     Preferable and favourable embodiments of the computer apparatus of the present invention appear from the appended dependent claims  2 - 6 . 
     In a second aspect of the present invention there is provided a method for determining and finding, in a computer apparatus comprising at least one central processor unit (CPU), a geometric representation of intersection topology for geometric objects that are described using any of parametric representation, algebraic representation and tessellated representation, the method comprising
         initializing, in the at least one CPU, sub-algorithms of an intersection algorithm,   controlling, in the at least one CPU, the sub-algorithms of the intersection algorithm,   executing, in the at least one CPU, the sub-algorithms of the intersection algorithm, and   processing a conjecture for an intersection calculation result,
 
wherein
 
the method further comprises
   transmitting at least one of the sub-algorithms of the intersection algorithm to at least one stream processor unit (SPU) comprised by the computer apparatus,   the at least one SPU executing sub-algorithms of the intersection algorithm, resulting in information necessary to establish the conjecture, and   returning the information to the at least one CPU.       

     Preferable and favourable embodiments of the invention appear from the appended dependent claims. 
     These and other objectives and advantages of the invention will become apparent from the following more detailed description, when taken in conjunction with the accompanying drawings of illustrative embodiments. 
    
    
     
       SHORT DESCRIPTION OF THE DRAWINGS 
         FIG. 1  shows a typical architecture of a computer apparatus in accordance with an embodiment of the present invention, 
         FIG. 2  shows an example of occlusion testing for NURBS surfaces, 
         FIG. 3  shows a 2-dimensional simplification of an extension for triangles to volumes, for finding the normal field of NURBS surfaces, and 
         FIG. 4  shows examples of-comparisons of vector angles in self-intersection problems for NURBS surfaces. 
     
    
    
     DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     One typical example of a prior art intersection algorithm is the division of the intersection calculation into a topology phase that detects points on candidate curves e.g. by lattice evaluation followed by a marching or bi-section of candidate curves. 
     Another example is a first step using recursive subdivision to detect the intersection topology, and a subsequent step refining the detected curves by either bi-section or marching. 
     The invention has two main components:
         The structuring in the algorithm for intersection calculation into a process comprised of the steps:
           1. Start the intersection calculation on the one or more CPUs   2. Use the one or more stream processors to calculate conjectures on the intersection curve geometry and/or topology.   3. Verify and correct the intersection conjecture possibly including a reiteration of the second step on a subpart of the original problem.   
           The execution of computation intensive parts of the intersection algorithm on one or more stream processors and the use of the computations from the one or more stream processors in the algorithm controlled and partly performed on one or more CPUs.       

     In the above described apparatus, among sub-processes that can run either on the one or more CPUs or one or more stream processors are:
         Processing of geometric objects to extract information to be used for determining if two or more objects possibly overlap.   Processing of geometric objects to extract information to be used for determining if the normal vector fields of two geometric object possibly overlap.   Processing of geometric objects to calculate an approximation to the extent of an object, an approximation that is guaranteed to contain the extent of the geometric object.   Processing of geometric objects to calculate an approximation to the normal field extent of an object that is guaranteed to contain the normal field of the geometric object   Tessellation of a geometric object   Calculation of partial derivatives of a geometric object, either in points or as a closed expression,   Calculation of normals of a geometric object, object, either in points or as a closed expression.       

     The preferred selection for implementation is a standard PC running e.g. Windows, Linux or other operating systems with one or more stream type processor, preferably GPU(s). However, the invention is aimed at any CPU and stream processor configuration on any operating system. Concerning GPUs, the preferred selection is currently one or more graphics cards with one or more GPUs. However, the idea is not limited to graphics cards. It should be noted that the one or more CPUs and the one or more stream processors can use different floating point precisions. The algorithms in the one or more CPUs will typically be using 64 bit floating point representation, while the algorithms on the one or more GPUs will typically use 32 bit floating point representation. 
     In  FIG. 1  is a simplified view of a relevant architecture, where the one or more CPUs and one or more GPUs are connected to a high-speed bus, e.g. PCI Express. Alternatively, the GPU can be connected to an AGP-bus as is widely used in PC in 2004. 
     Example: Separation of Objects Using One or More GPUs, Example for NURBS surface 
     We assume that two untrimmed NURBS surfaces are to be intersected. An example is the implementation of the intersection on the combination of one or more CPUs and one or more GPUs. The algorithm uses occlusion culling and a number of predefined viewing directions. In the occlusion testing one alternative is to use the convex hull of Bezier subpatches when performing the occlusion testing, another alternative is to use SLEVEs. The mathematics of SLEVEs can be found in “J. Peters,  Mid - structures of Subdividable Linear Efficient Function Enclosures Linking Curved and Linear Geometry ”, in  Proceedings of SIAM conference , Seattle, November 2003, Nashboro Press, 2004. Combinations of these two approaches can be used as well. In  FIG. 2 , left part, we see polygons before occlusion culling based on the first view direction. In the right part of the figure, we see the results of the occlusion culling. 
     Checking for Overlap of Two NURBS Surfaces (Surface_A and Surface_B) 
     
         
         
           
             1. For both Surface_A and Surface_B a knot insertion algorithm is initiated based on the Oslo Algorithm. For both surfaces discrete B-splines for converting the surfaces from a NURBS representation to a Bezier representation are evaluated. 
             2. Either the one or more CPUs or the fragment processors of the GPU combine the input information to convert the NURBS surfaces to grids of Bezier patches. 
             3. The fragment processor subdivide each Bezier patch a predefined number of times in both parameter directions to produce a control net for each surface lying close to the surface. Denote these refined surface nets Ref_A and Ref_B 
             4. All Bezier patches of Ref_A are initiated with tags:=not_treated and Bezier patches of Ref_B are initiated with tag:=not_treated. 
             5. For each predefined viewing direction
           a. For each not_treated Bezier patch Ref_A i  of Ref_A, use occlusion queries on the GPU to determine which not_treated Bezier patch Ref_B j  of Ref_B obscures the back faces of Ref_A i . If the back faces of Ref_A i  are not obscured, Ref_A i  is marked as treated.   b. Any Bezier patch Ref_B j  in Ref_B that do not obscure any back faces of any untreated subpatch of Ref_A is marked as treated.   c. For each not_treated Bezier patch Ref_B j  of Ref_B use occlusion queries on the GPU to determine which not_treated Bezier patch Ref_A i  of Ref_A obscures the back faces of Ref_B j . If the back faces of Ref_B j  are not obscured Ref_B j  is marked as treated.   d. Any not treated Bezier patch Ref_A i  in Ref_A that do not obscure any back faces of any untreated subpatch of Ref_B is marked as treated.   e. If all subatches of both Ref_A and Ref_B are treated, the surfaces A and B do not overlap.   
         
             6. Remember which subpatches of Ref_A overlap which subpatches of Ref_B
 
Example Separation of Normal Fields of Two Surfaces on GPU, Example for NURBS Surfaces
 
           
         
       
    
     In this example we make the normal fields for both surfaces and represent these as rational Bezier patches. These Bezier patches can be subdivided to a required level of detail. For each such sub patch we will have control points that are projected to 3D and that can be displayed as a grid of points. Now given one such normal field Bezier sub patch Sub A from Surf_A, and similarly Sub_B from Surf_B. We want to compare all combinations of three control points from Sub_A with all combinations of three controls from Sub_B. It is not sufficient to just compare the triangles, thus we choose to extend the triangles to volumes.  FIG. 3  shows a 2D simplification of the extension that is described in the following (only two unit vectors A 1 , A 2 ). 
     In 3D the extension is as follows:
         Given 3 unit vectors A 1 , A 2 , and A 3      Make C as the outward normal vector to the plane spanned by A 1 , A 2 , and A 3      Assume that A 1 , A 2 , and A 3  are in order counter clockwise around C.   Make new vertices A 1 ′, A 2 ′, and A 3 ′ by
           A 1 ′=A 1 /(cos φ 1 )=A 1 /(C·A 1 )   A 2 ′=A 2 /(cos φ 2 )=A 2 /(C·A 2 )   A 3 ′=A 3 /(cos φ 3 )=A 3 /(C·A 3 )   Note if the dot product is zero then the triangle spans an angle equal to π, and overlap must take place.   
           Draw the triangles:
           A 1 , A 3 , and A 2     A 1 ′, A 2 ′, and A 3 ′   
           The planar four sided regions defined by
           A 1 , A 2 , A 2 ′ and A 1 ′   A 2 , A 3 , A 3 ′ and A 2 ′   A 3 , A 1 , A 1 ′ and A 3 ′   
           As we do not control the orientation of the normals of the surfaces we must also draw the volume mirrored around the origin   Draw the triangles:
           −A 1 , −A 2 , and −A 3      −A 1 ′, −A 3 ′, and −A 2 ′   
           The planar four sided regions defined by
           −A 1 , −A 1 ′, −A 2 ′ and −A 2      −A 2 , −A 2 ′, −A 3 ′ and −A 3      −A 3 , −A 3 ′, −A 1 ′ and −A 1     
               

     The original volume and the mirrored version we call the mirrored extended triangles. 
     We assume that two untrimmed NURBS surfaces are to be tested for overlap of normals. An example of the implementation of the algorithm on the combination of at least one CPU and a GPU: 
     Checking for Overlap of Normal Fields Two B-Splines Surfaces (Surface_A and Surface_B) 
     
         
         
           
             1. For both Surface_A and Surface_B a knot insertion algorithm is initiated based on the Oslo Algorithm. For both surfaces discrete B-splines for converting the surfaces from a NURBS representation to a Bezier representation are evaluated. 
             2. The CPU or the fragment processor on the GPU combines the input information to convert the NURBS surface to a grid of (rational) Bezier patches. 
             3. The GPU makes the exact normal fields of each (rational) Bezier patch of both surfaces. The continued processing is performed on the Bezier patches representing the normal fields. 
             4. The GPU subdivided each normal field rational Bezier patch a predefined number of times in both parameter directions to produce a control net for each surface normal field lying close to the surface. Denote these refined normal fields surface nets Ref_A and Ref_B 
             5. All Bezier patches of Ref_A are initiated with tags:=not treated and Bezier patches of Ref_B are initiated with tag:=not treated. 
             6. For each predefined viewing directions
           a. For each not treated Bezier patch Ref_A i  of Ref_A, use occlusion queries on the GPU to determine which not treated Bezier patch Ref_B j  of Ref_B has mirrored extended triangles that obscures the back faces of the mirrored extended triangles of Ref_A i . If the back faces of the mirrored extended triangles of Ref_A i  are not obscured, Ref_A i  is marked as treated.   b. Any Bezier patch Ref_B j  in Ref— B  with the mirrored extended triangles that do not obscure the mirrored extended triangles of any back faces of any untreated subpatch of Ref_A is marked as treated.   c. For each not treated Bezier patch Ref_B j  of Ref_B use occlusion queries on the GPU to determine which not treated Bezier patch Ref_A i  of Ref_A has mirrored extended triangles that obscure the back faces the mirrored extended triangles of Ref_B j . If the back faces of Ref_B j  are not obscured, Ref_B j  is marked as treated.   d. Any Bezier patch Ref_A i  in Ref_A with the mirrored extended triangles that do not obscure the mirrored extended triangles of any back faces of any untreated subpatch of Ref_B is marked as treated.   e. If all subpatches of both Ref_A and Ref_B are treated, the normal fields surfaces A and B do not overlap.   
         
             7. Remember which subpatches of Ref_A overlap which subpatches of Ref_B.
 
Example of Self-intersection for NURBS Surfaces
 
           
         
       
    
     The normal field of a tangent continuous surface has to span an angle larger than π for the surface to be able to turn back on itself and thus possibly self-intersect. The self-intersection can be of two types:
         Self-intersection with vanishing normal vector. In these cases the self-intersection can be a closed loop within the surface. The two traces of the self-intersection curve meet in a point where the normal vanishes.   Self-intersection with non-vanishing normal. The two traces do not meet and will touch the boundary of the surface. In the case of non-vanishing normal, points on all self-intersection curves can be identified by finding the intersection of the surface boundary with the surface.       

     By dividing the NURBS surface into small subsurfaces and analyze the surface normal behaviour of the separate sub-surfaces and the normal behaviour of adjacent sub-surfaces, it is possible to identify cases with non-vanishing surface normals. For a NURBS-surface p(u,v) a closed description can be generated for the surface normal by making the cross product n(u,v)=p u (u,v)×p v (u,v) of the two first order partial derivatives. It is straight forward to describe n(u,v) as a NURBS surface. For n(u,v) to vanish, either one of the vertices of n(u,v) has to vanish or the vertices has to span an angle greater than or equal to π. 
     To compare if a set of at least three normalized vectors span an angle less than π, we can check if all possible sums of any selection of two vectors from the set span less than π/2. In  FIG. 4  we illustrate this for 3 vectors in the plane. In the left part of  FIG. 4  the three vectors span an angle less than π, and we see that the sum of any selection of two of these vectors span less than π/2. In the right part the 3 vectors span angle greater than π, and we see that the sum of any selection of two of these vectors span more than π/2. 
     To establish non-vanishing normal within a subpatch, the vertices of the normal field should span an angle less than π. To perform this test we:
         First test if any vertex of the normal field has vanished   We normalize all non-vanishing vertices of the normal field surfaces.   We then check if the vertices of the normal field span an angle less than π/2, by making the scalar product of all selections of normalized vertices of the normal field, and check if all the scalar products are positive.   In the cases when the above scalar products are non-positive we check if they span less than π. Thus, first we make a set of vectors denotated A, consisting of all possible sums of the two vectors from the normalized set of vertices of the normal field. If the scalar product of all selections of two vectors from the set A is positive, then the normal field spans an angle less than π, and the normal field of the subpatch is non-vanishing.       

     To establish that normals of adjacent tangent continuous subpatches that are joined with continuous tangent plane span less than π, we use the fact that if both patches span less than π/2, then the composition of the two patches must span less than π. In the above test we identify patches that will span less than π/2. 
     Test for Possibility of Vanishing Normal in NURBS Surface 
     
         
         
           
             1. The Surface is initiated based on the Oslo Algorithm. The discrete B-splines for converting the surface from a NURBS representation to a Bezier representation is evaluated. 
             2. The CPUs or fragment processor of the GPU combine the input information to convert the NURBS surface to a grid of (rational) Bezier patches. 
             3. The fragment processor of the GPU makes the exact normal fields of each (rational) Bezier patch of both surfaces. The continued processing is performed on the Bezier patches representing the normal fields. 
             4. The fragment processor of the GPU subdivided the normal field rational Bezier patch a predefined number of times in both parameter directions to produce a control net for each surface normal field lying close to the surface. Denote this refined normal surface Ref_A. 
             5. Initiate a texture, Flag, similar in size to the number of Bezier patches in Ref_A. One pixel is allocated to each Bezier subpatch. 
             6. On the GPU for each subpatch Ref_A i  of Ref_A
           Initiate the pixel in Flag corresponding to Ref_A i  to 0.   If any coefficient vector of Ref_A i  vanish set Flag to 2, and go to next subpatch. Normalize the coefficient vector lengths to 1.   For all selections of two coefficients vectors C and D from Ref_A i , make the scalar product of C and D. If the scalar product is no positive set pixel in Flag to 1.   If the Flag value is zero then the patch normals span less than π/2 and self-intersect of subpatch is impossible, continue to next subpatch.   For all selections of two coefficients vectors C and D from Ref_A i , make a vector equal to C+D and store in a texture for vectors Vect.   Make the scalar product of all selections of two Vectors from Vect, if the scalar product is none positive then a vanishing normal is possible, set pixel in Flag to 2 and continue with next subpatch.   
         
             7. For each subpatch we will have after the completion of this
           If Flag=0 then the normals of the subpatch span less than π/2. If two adjacent subpatches both have Flag=0 then they can only intersect along a shared boundary or a shared corner.   If Flag=1 then the normals of the subpatch span less than π but more than π/2. The subpatch might intersect an adjacent patch outside of the shared boundary, or a shared corner.   If Flag=2 then the normals of the subpatch span more or equal to π, vanishing normal. Self-intersection within subpatch possible.   
         
             8. Remember which subpatches might have a vanishing normal and which adjacent sub-patches might intersect outside of the shared boundary.
 
Intersection of Boundary with Subpatch Strip Along the Boundary
 
           
         
       
    
     In the case where no possibilities of vanishing normals have been identified all self-intersections must touch a surface boundary. Thus the self-intersections can be traced by analyzing the interaction between the surface boundary and the surface. One challenge in this setting is that when a boundary element is intersected with the patch itself we will get coincidence if care is not taken. To take care of this one approach is to split the problem into two problems:
         Intersection of the boundary with the patch with a subpatch strip along the boundary removed from the patch. The subpatch strip should correspond to the subpatch strip used when determining the possibility of vanishing normal at the start of this example.   Intersection of the boundary with the subpatch strip. The Flag values of each subpatch strip along the boundary can guide us to the proper handling of the boundary intersection.   We use the same subdivision of the boundary as for the subpatch strip (given when making the Flag)   For all sub elements on the boundary
           For all subpatches along the boundary
               If subpatch same as sub boundary indicate intersection only if Flag=2   If subpatch adjacent to sub patch the sub boundary belongs to indicate intersection Only if sum of Flags&gt;0.   If not subpatch and sub boundary not adjacent indicate indicate intersection only if boxes overlap.