Algorithms for accurate rapid prototyping replication ... - IngentaConnect

6 downloads 0 Views 532KB Size Report
Diseases, University of Hull and Hull and East Yorkshire. Hospitals NHS Trust, UK. Keywords. Rapid prototyping, Algorithms, Health, Software. Abstract. A set of ...
Introduction

Algorithms for accurate rapid prototyping replication of cancellous bone voxel maps

Cancellous bone Bone tissue consists of calcium hydroxyapatite mineral absorbed onto a collagen matrix. Throughout life there is a process of remodelling, where old bone is removed by osteoclast cells and new collagen fibres are laid down by osteoblast cells. This is under the control of physical activity and several hormones. There are two types of bone structure, cortical and cancellous. Cortical bone is predominantly solid and makes up the shafts of the long bones in the skeleton. Cancellous bone has a porous structure made up of an array of trabecular bone fibres interspersed with bone marrow, and is found near the joint surfaces of the long bones and within the individual vertebrae making up the spinal column. Bone grows under body forces and the trabecular fibres follow the principal lines of stress, as can be clearly seen, for example, in a cross-section of the hip. The density of a human skeleton increases from birth reaching a maximum between the third and fourth decades, thereafter gradually decreasing with advancing age. Osteoporosis has been defined as “a decrease in bone mass and architectural deterioration of bone tissue, leading to enhanced bone fragility and consequent increase in fracture risk” (Consensus Development Conference, 1991). Osteoporosis results from an imbalance between osteoclast and osteoblast cells, with a net activity of the osteoclasts creating a loss of bone tissue. The predominant factor for osteoporosis is the female menopause, caused by a reduction in oestrogen levels, and hence, the widespread use of hormone replacement therapy (HRT). Additional “secondary” causes of osteoporosis include rheumatoid arthritis,

G. Sisias , R. Phillips C.A. Dobson M.J. Fagan and C.M. Langton The authors G. Sisias is at the Department of Computing, School of Informatics, University of Bradford, UK R. Phillips is at the Department of Computer Science, University of Hull, UK C.A. Dobson and M.J. Fagan are at the School of Engineering, University of Hull, UK C.M. Langton is at the Centre for Metabolic Bone Diseases, University of Hull and Hull and East Yorkshire Hospitals NHS Trust, UK Keywords Rapid prototyping, Algorithms, Health, Software Abstract A set of algorithms has been developed and evaluated for 3D and 21/2D rapid prototyping replication of 3D reconstructions of cancellous bone samples. The algorithms replicate a voxel map without any loss of fidelity, so as to increase the validity of the comparison of mechanical tests on the 3D reconstructed models with those predicted by finite element analyses. The evaluation is both in terms of algorithmic complexity and the resultant data set size. The former determines the feasibility of the conversion process, whereas the latter the potential success of the manufacturing process. The algorithms and their implementation in PC software is presented.

The authors gratefully acknowledge the financial support of the EPSRC, charity OSPREY, Action Research, and the Hull and East Yorkshire Hospitals NHS Trust. The authors would also like to thank Bert van Rietbergen (Eindhoven, The Netherlands) for providing the data for the human bone samples, along with Chris Manners (3D Systems Inc, USA), Colin Blain (3D Systems, UK), and Kris Wouters (Materialise, Belgium) for their technical support. Thanks also go to Richard Bibb (National Centre for Product Design & Development Research, University of Wales Institute, UK) for building the solids.

Electronic access The research register for this journal is available at http://www/emeraldinsight.com./research_registers The current issue and full text archive of this journal is available at http://www/emeraldinsight.com/1355-2546.htm Rapid Prototyping Journal Volume 8 · Number 1 · 2002 · pp. 6 –24 q MCB UP Limited · ISSN 1355-2546 DOI 10.1108/13552540210413266

6

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

renal osteo-dystrophy and steroidal therapy. Osteoporosis occurs predominantly at cancellous bone sites, due to the higher surface area. It is clinically manifested in the form of fractures, predominantly of the wrist, spine and hip, typically occurring in female subjects from the ages of 50, 60 and 70 years, respectively. The current annual cost of osteoporosis to the UK Department of Health has been estimated to be £940 million (Dolan and Torgerson, 1998), and is steadily rising due to the increasing number of elderly subjects in the population. Associated with this, 25 percent of subjects suffering a hip fracture die within 12 months, and 25 percent of those remaining never regain full independent living. In order to further our understanding of osteoporosis and its dependence upon the material and structural properties of cancellous bone, many experimental studies continue to be undertaken on natural tissue samples obtained from human subjects and animals. A significant difficulty however in analysing in vitro bone samples is that the structural parameters have to be elucidated by destructive means, typically in the form of slice histomorphometry. In addition, the human in vitro samples most readily available tend to be from an elderly population and therefore may be of limited structural variation compared to the full population age range. The development of a physical model of cancellous bone whose structure could be controlled would provide significant advantages over the study of in vitro samples and would also enable the relationship between the mechanical integrity and hence fracture risk of cancellous bone and its structural properties to be more exactly defined. Further complementary applications include validation of stochastic simulations of cancellous bone remodelling (Langton et al., 1998a) and validation of ultrasound measurement parameters of velocity and broadband attenuation for the assessment of osteoporosis (Langton and Njeh, 1999).

(Issa et al., 1998). The techniques of serial sectioning (Odgaard et al., 1990) and microcomputed tomography (mCT) (Kinney et al., 1995) reconstruction offers the ability to obtain 3D reconstructions of in vitro samples of natural cancellous bone tissue (Ruegsegger et al., 1996). There is a compromise between reconstruction resolution and sample size, for typical cancellous bone samples of 10 mm dimension, resolutions of the order of 20 mm may be achieved. However, representations of such 3D reconstructions are extremely memory demanding, typically requiring approximately 900 – 1500 MB per sample. For stereolithography replication of the natural tissue samples, it is necessary to convert 3D reconstruction data into a file format suitable for rapid prototyping production. Unfortunately, the size of the resultant file is normally beyond the memory capacity of rapid prototyping systems. To understand the cause of this limitation, it is necessary to explain the basis of the conversion process. Stereolithography data structures There are two types of files that can be used to transfer the geometry of a structure to the stereolithography (SL) manufacturing equipment. By far the most widely used is the STL format, while the other one is the SLC format which is better suited for mCT (computed tomography) data sets. There are two versions of the STL format (3D Systems Inc., 1989), a text-based version, and a binary counterpart. The latter is preferred for passing data to manufacturing equipment because the binary files tend to be less than one quarter of the size of their text equivalents. The STL format is a list of triangles that define the outer shell (surface) of a structure. The information required per triangle is its surface normal and the three vertices of the triangle itself. A requirement of the specification is that all x, y and z co-ordinates of each vertex of each triangle should be positive (not zero), Cartesian, and floating-point. This requirement does not hold for the surface normals. Limitations on the maximum range of co-ordinates are imposed only by the equipment building the structure. When objects are either too large or too small, they must be uniformly scaled accordingly, since the vector nature of the way structures are defined allows scaling to take place without compromising the accuracy

The use of stereolithography in the study of cancellous bone The value of stereolithography to the study of cancellous bone has already been described for the validation of ultrasound assessment (Langton et al., 1997,1998b; Hodgskinson et al., 1996) and the development of phantoms for magnetic resonance imaging 7

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

of definition of objects. The SLC format is a 21/2D description of objects, using contours (3D Systems Inc., 1994). The files are mainly composed of a list of sets of contours for every z layer of the object being described. Each set of contours on the same z level describes the interior and exterior of the object, based on the orientation of every contour. There are two issues to consider when tessellating the surface of a solid. The first is the “vertex-tovertex violation”; the second is the presence of isolated (bone) islands in the voxel map. The vertex-to-vertex violation restriction applies to the triangle-based representation of a solid (STL), and states that a vertex of one triangle must not lie on the edge of another. This situation is flagged from the building machine as an error in the input data set and is automatically rectified, illustrated in Figure 1. The presence of (bone) islands (isolated sections of material floating in a void) in a structure also poses a difficulty in the manufacturing process. Since islands are not supported by other sections of bone around them or by the base platter of the SL equipment they eventually sink in the liquid resin. Such islands need to be identified in the original voxel map and removed before the structures are converted to STL or SLC format and passed to manufacturing.

a tessellated surface. A precalculated table of 256 entries of all possible tessellated configurations of a 2 £ 2 £ 2 elemental voxel array is used to sequentially convert pairs of voxel planes into triangles. The algorithm generates a large number of triangles, whilst “smoothing” the surface of solids. Turk (1992) described a method of creating surface models at several levels of detail from an original polygonal description of a given object. This method shows how a new set of vertices can be distributed over the surface of an object and connected to one another to create a re-tiling of a surface that is faithful to both the geometry and topology of the original surface. This re-tiling method is best suited to models that represent curved-surfaces, but performs poorly with objects that have well defined corners and sharp edges. Schroeder et al. (1992) described an algorithm that makes multiple passes over an existing triangle mesh, using local geometry and topology to remove vertices that pass a distance or angle criterion. The holes left by the vertex removal are then patched using a local triangulation process. Gueziec and Dean (1994) defined a method for surface simplification based purely on geometric criteria. It operates serially by visiting successively each edge of the triangulation. A given triangle edge is replaced by a vertex in a single operation, thus eliminating two triangles three edges and one vertex, whenever this operation minimally perturbs the surface. A feature of this simplification method is that triangles grow at a uniform rate in a given area. Hamann (1994) developed an algorithm that given a surface triangulation, each triangle is weighted according to the

Related work Lorensen and Cline (1987) and Cline et al. (1988) have described the marching cubes algorithm which creates from a voxel map. The source data exists in a volume element (voxel) format, where a large 3D array of voxel elements (voxel map) describes an object with

Figure 1 The left figure shows an example of a violation of the vertex-to-vertex rule, and the right one the correct configuration

8

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

pre-computed principal curvatures at its vertices. A triangle is associated with a surface region with low curvature if the sum of the absolute curvatures at its vertices is low. This measure is used as a weight to determine a triangle’s significance. The triangle with the lowest weight is identified and removed from the triangulation. It is then replaced by a new point that lies on a local surface approximant. The region affected by a triangle’s removal is re-triangulated, and weights are computed for all new triangles introduced. Hinker and Hansen (1993) have shown how coplanar and nearly coplanar polygons can be merged into larger complex polygons that are then re-triangulated into fewer simple polygons than originally required. Given correct polygon traversal order that prevents the creation of loops, bow-tie polygons and similar degeneracies, the algorithm can successfully deal with polygons containing holes. In some respects this is similar to the method introduced in this paper, although here the reduced data set is produced directly with a simple method that automatically avoids degeneracies and produces proper non-intersecting polygons. Hoppe et al. (1993) solve the mesh optimisation problem by minimising an energy function that explicitly models both conciseness of representation and fidelity to the data. The trade-off between geometric fit and compact representation is controlled by a user selectable parameter. A large value of that parameter indicates the preference of a sparse representation over a dense one, usually at the expense of degrading the fit.

Consequently, to avoid configurations the definitions do not apply on, it is important to have a tight bounding box around the structure. This means that there should not be voxel planes on any of the six faces of the overall voxel map that are totally occupied of marrow (void) elements. A degenerate case where the definition could fail is if there are islands of bone elements on all of the six faces of the overall voxel map while the main body of the structure does not extend to cover the entire bounding box. In this case the main structure is removed as if it were an island. The problem, although extremely rare, is solved by adjusting the bounding box to clip those external islands. Although versions of the algorithm operating on the horizontal x- and y-axes are similar, a z-axis (vertical) scan alone is sufficient to remove all islands. In the first stage of the algorithm, all bone elements that are on the top and bottom planes of the structure and are attached to the bounding box are marked (Appendix A1). In the second stage (Appendix A2), all elements that are neighbours (next) to Top-Attached or BottomAttached elements are marked accordingly. In the final stage (Appendix A3), the voxel map is scanned once more and all the bone elements that do not have their Top-Attached and Bottom-Attached flags set are switched to marrow, hence eliminating the islands. It must be noted that although the algorithm is quite demanding in processing time, it is considerably more stable than a recursive seed-filling algorithm. The problems with recursive seed-filling arise from (a) variable and large static or dynamic memory requirements for the recursion; and (b) the need for correct selection of the initial voxel where the recursive process will start from.

Methods—algorithm development Three algorithms have been developed to facilitate stereolithographic replication of cancellous bone structures: island removal; tessellation; and contour extraction.

Tessellation algorithms—STL A very fast non-optimal way to tessellate the surface of a voxel map without violating the vertex-to-vertex rule is to generate two triangles for every visible face of every voxel (Appendix B). The effects of this algorithm can be seen in the example of Figure 2. The advantages of this non-optimal tessellation algorithm are that it is very fast and simple to implement. However, it generates an unnecessarily large number of triangles, this impacting the feasibility of the manufacturing process. The aim of the optimal tessellation algorithm is to generate

Island removal We define that: “an element or a set of elements is part of the main body of a structure when they exhibit connectivity with the bounding box of the structure in all three orthogonal directions”; and that “an element is not an island when it is attached to the main body of a structure or when it is attached to another element that is not an island”. 9

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 2 The diagram on the left shows a three voxel configuration and the diagram on the right the resultant 28 triangle configuration from the above algorithm

the minimum number of triangles needed to represent the surface of the voxel map, whilst still producing STL compatible triangle configurations. This algorithm is split into five stages, as outlined in Figure 3. These stages are repeated for every vertex plane in all six orthogonal scanning directions (i.e. increasing and decreasing x, y, and z ). The algorithm is based on the fact that the least number of triangles are generated from contours that have been defined with the minimum necessary number of vertices. In the first stage the algorithm determines which vertices describing the voxel map are necessary and considers only those. In the second stage the contours that pass from the vertices from the first stage are traced, so that closed shapes are produced. In the third stage the algorithm determines which contours are enclosed by others, hence forming a hierarchy that indicates areas that belong to the object

and therefore should be tessellated, and exclusion areas that should not be tessellated. In the fourth stage the contours are reorientated in clockwise or counterclockwise order and merged accordingly so as to form a single contour for the last stage of the tessellation process. In the final stage the single contour from the previous stage is tessellated. Stage 1: Central vertex generation in a 23 voxel configuration In order not to violate the vertex-to-vertex rule when deciding whether to generate or skip a certain vertex, it is important to consider all six possible orthogonal planes into which that specific vertex belongs to (increasing and decreasing x, y and z ). There are 28 = 256 different combinations in the 23 voxel configuration illustrated in Figure 4, depending on the position of the bone voxels. All 256 combinations are represented by their unique value on a table, along with an indication whether that specific configuration would require the central vertex to be generated. The numbering is done according to the scheme described in Figure 5. All the potential configurations on both the front and back voxel planes, along with the indication whether the corresponding configuration should generate a vertex, are summarised in Table I.

Figure 3 The stages in the optimal tessellation algorithm

Stage 2: Vertex tracing for contour definition After the vertices defining the contours in a vertex plane between two voxel planes are specified, they must be grouped together appropriately so as to form the contours. This process starts by selecting the top-left most vertex and following around the contour to 10

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 4 Central vertex “A” may or may not need to be generated, depending on which of the eight surrounding voxels are bone

(combination of “vertex type” 2 or D and “heading towards” direction of North ). Figure 6 shows an example of four contours. Contours A and D are parent contours (not enclosed, but enclosing), contour B is a sibling of A but a parent of C, and contour C is not a parent of any contour but a sibling of B. All are defined in a clockwise fashion, with only the necessary vertices. The area between contours A and B

which it belongs, until the starting vertex is met again. The direction to follow from each vertex to the next one is selected according to Table II. The starting vertex configuration is always of type 2, which corresponds to a single element at the bottom-right corner of any 2 £ 2 elemental configuration. According to Table II and by the assumption the contours are to be defined in a clockwise fashion, the next vertex to move should be on the right

Figure 5 Voxel numbering scheme. Depending whether each of the eight voxels is bone or not, the corresponding values are added together to form the index in the look-up table to determine if the central vertex (common to all voxels) should be generated

11

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Table I All 256 cases from Figure 4 are summarised. The columns 0 – F (in hexadecimal notation) show all voxel configurations on the near plane and all the rows 0 – F show the corresponding configurations on the far plane. Their combination indicates whether the central vertex “A” should be generated

is to be tessellated, as well as the areas enclosed by contours C and D. The algorithm groups the vertices (A1. . .A4, B1. . .B4, C1. . .C4 and D1. . .D4) into four contours (Appendix C1). Applying the algorithm to the example of Figure 6 will detect the contours in order of A, B, C and lastly D.

Stage 3: Contour enclosure detection To tessellate a set of contours on the same plane properly, it is important to determine their enclosure relationship. That way, areas that should not be tessellated in the direction of tessellation (e.g. increasing z ) are left blank, whereas the remaining are correctly tessellated. Such exclusion areas are a result of

Table II Table defining all the cases of the vertex tracing process

12

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 6 An example of a simple voxel configuration where the area between contour B and contour C is not to be tessellated, and contours A and D share a common vertex (A3 and D1)

two neighbouring voxel planes where one of them is smaller than another and hence their common vertex plane contains areas that are not visible. The enclosure detection algorithm works by firing horizontal rays that span the full width of the vertex plane and calculating intersections with the contours as the rays travel from left to right. When a contour is hit once, a mark is kept that indicates we not travelling inside the newly intersected contour. If the mark is odd when another contour is met, then the second contour is a sibling of the first. If the mark is even, we are outside of the current contour. This odd-even rule is iteratively applied to all horizontal rays, and at the end of the process the parentsibling relationship of all contours in a given vertex plane is defined. Execution profiles of the detection algorithm have shown that this section of the whole tessellation algorithm is responsible for over 98 percent of the overall execution time. The algorithm’s performance is enhanced in several ways. The greatest performance enhancement is achieved by firing only one single full-width ray for every line of voxels

and accumulating all intersections in a buffer. The buffer is then sorted in ascending order, which guarantees that all intersections are placed in the order they would be, had small rays been fired between voxels on the same voxel line. The second performance enhancement comes from the lack of proper line-segment to line-segment intersections. In the enclosure detection algorithm, a line segment is said to be intersected by a ray, when the former’s vertical co-ordinates lie on both sides of the ray. Consequently, expensive tests of planar line intersections are avoided by not requiring the solution of a system of two equations with two unknowns for every potential intersection. The last performance enhancement comes from keeping track of how many of the contours in the contour list passed to the detection algorithm have their parent status defined. The parent status of a contour does not change once defined. Hence, once all contours have their parent status defined, there is no need for further intersection tests. This results in premature termination of the enclosure detection algorithm. Execution profiles on the detection 13

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

stage, however, have shown that time reduction is only in the order of 2 – 5 percent. Despite this, the increase can potentially be far greater on vertex planes sparsely populated by contours. In the example of Figure 7, rays R1, R5 and R6 enter and exit contour A without intersecting another contour while inside A. Rays R2 and R4, while inside A, intersect B, which is marked as enclosed by A. Ray R3 intersects C when it is already inside B, and therefore C is a sibling of B. Ray R7 does not intersect another contour inside D, and therefore D is a parent contour without siblings (as is C). Ray R8 is not fired, since by now the parent status of all four contours has been defined. Note that the rays are fired in the middle of voxels, to guarantee that no ray will overlap with any horizontal segment of any contour. The algorithm that detects the parentsibling relationship of contours on the same plane is described in Appendix C2.

situations where parent contours have more than one sibling, the merging takes place with the first one only to form a combined one, and then the combined is merged with the next sibling, until all immediate siblings have been merged together. In the example shown in Figure 8, A would be merged with B, forming AB. AB would then be merged with C, forming ABC. ABC would be merged with D, forming ABCD. Finally, ABCD would be merged with E, forming the final ABCDE. The selection of vertices where two contours must be merged is important. Any two vertices cannot be selected, because wrong triangle configurations may result. As a rule, a parent contour can be merged with a sibling contour only at a point of minimum distance. As a result, there cannot be another immediate sibling closer to the parent, as that would be the closest in the first place. For instance, (in Figure 6), A1 cannot be merged with B3, as the bridge between them would pass over both B and C. A1 would have to be merged with B1, as there are no other vertices from immediate siblings of A closer to A1 than B1. Care must be taken, though, to invert the orientation of the siblings prior to merging, since they define areas to be excluded. In Figure 6, the orientation of A is maintained (as parent), but of B inverted to {B1,B4,B3,B2}. The final combined contour AB would then become AB = {A1,B1,B4,B3,B2,B1,A1,A2,A3,A4}. Had there been other immediate siblings of A, their distance to AB would be calculated and the closest merged to AB. Given a set of contours K1,K2,K3,. . ., Kn, where n[ [1,1) and contours K2,K3,. . ., Kn are the first level siblings of K1, the total number of vertices in the final merged contour is given by:

Stage 4: Contour merging before tessellation It is possible that the tessellation algorithm (Stage 5) may be faced with the configurations described in Figure 6, where the area between two contours must be tessellated. To tessellate only such areas (avoiding the exclusion areas), such contours must be joined together to form a single contour. The combined tessellated contour will then give the correct triangle configuration that will avoid the exclusion areas. As shown in Figure 6, it is also possible to have contours that enclose others, those further enclosing others, and so on, in an infinite recursive fashion. It is only necessary to merge contours from two consecutive levels. For instance (Figure 6), A must be merged with B, but not B with C. Had there been an exclusion contour inside C (say E), C would have to be merged with E. Consequently, this merging process can be summarised in the following: Top level (without parents) contours are successively merged with their immediate siblings only. The siblings of siblings are then set to be parent contours (i.e. not enclosed by others), and this process is repeated until no more merges can be performed. Therefore, as in Figure 6, A would merge with B to form a single contour (called AB), but C and D would not be merged with others. Then the tessellation process would consider combined contour AB and simple contours C and D. In

V Total ¼ 2ðn 2 1Þ þ

n X

Vi

ð1Þ

i¼1

where: VTotal is the total number of vertices in the merged contour, Vi is the number of vertices for each individual contour. Proof: The total number of vertices after merging K1 with K2 is (V1+V2+2). The merger of the K1K2 contour with K3 totals ((V1+V2+2)+V3+2) vertices, etc. Hence, by rearranging the following sequence: ðððV 1 þ V 2 þ 2Þ þ V 3 þ 2Þ þ V 4 þ 2Þ þ ... þ Vn þ 2 14

ð2Þ

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 7 Application of the contour enclosure detection algorithm on the configuration outlined in Figure 6. Intersections of rays with the contours are shown in circles

as

orientation of a contour is described in Appendix C4.

ðV 1 þ V 2 þ V 3 þ V 4 þ . . . þ V n Þ þ 2ðn 2 1Þ

ð3Þ

Stage 5: Contour tessellation The final stage of the process receives the contours from the merging stage and creates the triangles that cover their entire surface. The actual tessellation algorithm accepts a contour and scans its vertices sequentially in a cyclic fashion, trying to derive triangles from every triad of vertices found. Based on the determinant of every triad of vertices, the algorithm is able to determine if that triangle is inside or outside the contour of reference. Additionally, the algorithm makes certain that potential triangles do not enclose any other vertices. Consequently, a triangle is valid when it is inside the contour and is not enclosing other vertices. Whenever a triangle can be created, from the three points defining it, the middle one is removed from the contour. The algorithm will not fail if co-linear vertices are found, and will stop as soon as there are less than three vertices left.

Equation (1) is derived. The algorithm that will merge a parent contour with all its siblings is described in Appendix C3. The algorithm that inverts the Figure 8 Example of a non-enclosed contour with four siblings, where B, C, D and E define exclusion areas that must not be tessellated

15

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

However, a limitation is that a contour must not be self-intersecting. Such configurations are conveniently avoided by the vertex-tracing algorithm of Stage 2. Although this greedy algorithm is well suited for fast operation, it can be replaced by others that generate better triangle configurations (De Berg et al., 1997; Guibas and Stolfi, 1985). Two versions of the algorithm may be considered. The first one is biased on creating fan-type triangular topologies when possible. After the middle vertex of a valid triangle is decimated, the starting vertex is kept the same, the third one becomes the second, and the next (fourth after the first) becomes the third. Hence, the same starting vertex is kept for as long as valid triangles can be generated. Although this version of the algorithm is faster than the second (fewer cycles around a contour), it tends to generate long and thin triangles. The second algorithm operates mainly on the perimeter of contours, avoiding long and thin triangles. After the decimation of the middle vertex of a valid triangle, the algorithm uses the last vertex of the valid triangle as the starting one, and brings in another two vertices from the remaining contour. Hence the algorithm now no longer keeps the same starting vertex, decreasing the probability of immediately finding another valid triangle. As a drawback, more cycles are needed around a contour, making this version of the algorithm slower. It must be noted that it is perfectly possible for both versions to give exactly the same triangle configurations with the same number of attempts, depending on the starting vertex and topology of vertices. The second variation of the tessellation algorithm is similar to one described by Hinker and Hansen (1993), differing only in the determination of criterion of triangle validity. Figure 9 shows the effects of the optimal tessellation algorithm on the example of Figure 6. The two versions are shown together in Appendix C5, with the difference marked in bold typeface, indicating that the presence of this statement corresponds to the first version of the tessellation algorithm, and the absence to the second.

FileSizeSTL ¼ 84 þ 50F Total

ð4Þ

where FileSizeSTL is the size of the STL file, FTotal is the total number of triangles defining the surface of a voxel map, 84 corresponds to the size of the STL file header and 50 is the number of bytes of storage required per triangle. It is inductively proven that the number of triangles generated from a contour is (De Berg et al., 1997): F Contour ¼ V Contour 2 2

ð5Þ

Consequently, the overall number of triangles generated by tessellating a structure is dependent on the number of contours and the number of vertices of every contour: F Total ¼

t X

V j 2 2t

ð6Þ

j¼1

where Vj is the number of vertices of contour j, t is the total number of contours after the merging process.

Contour extraction algorithm—SLC The algorithm that extracts the contours of every z layer of a voxel map to compose the equivalent SLC compatible structure is similar to the STL algorithm. To describe a simple cube in STL, 12 triangles are needed. The data set for the SLC file for the same structure needs only the four vertices at the bottom of the cube. Consequently, there is no need to consider the voxel plane below the one being processed, as the interactions between any two voxel planes do not matter. For every layer only the necessary vertices must be generated, which are then grouped together to form contours. This stage is similar to the vertex generation stage of the STL algorithm, although much simpler. The contour enclosure is defined exactly the same way as in the STL algorithm, and hence not described again. Finally, the contours are orientated so that the outer most (non-enclosed) are counter-clockwise (CCW), and the internal ones are with interchanging orientation, depending on their enclosure depth. Much like Stage 1 for the STL tessellation algorithm, the vertices that correspond to a voxel plane may or may not be generated based on a look-up table (Table III) with 16 entries.

Tessellated data-set size calculation The final size of the STL file containing all triangles that define the surface of a voxel map is calculated as follows: 16

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 9 Example showing the effects of the optimal tessellation algorithm on the structure of Figure 6. There are totally 12 triangles compared to the 72 of Figure 6 (two for every voxel face)

The software controlling the stereolithography manufacturing equipment can distinguish parts that have to be solidified from the orientation of the contours of every layer. The outer-most are always CCW, the immediately

inner ones clockwise (CW), the next ones CCW, etc. The algorithm to arrange contours that belong to the same layer in the appropriate orientation is based on the enclosure definition of those, and is described in Appendix C6. The size of an SLC file, given the total number of contours (TC ) and total number of vertices (TV ) it contains and the number of z layers (ZL ) in a specific tissue sample, is given by:

Table III All 16 possible voxel combinations of a 2 £ 2 voxel configuration are outlined, along with the indication of whether the corresponding central vertex is generated

FileSizeSLC ¼ 2329 þ 8ðZL þ 2TC þ TV Þ ð7Þ

Human sample data The human bone tissue data were processed after they were converted from a grey-scale format to a binary (segmented) format. The calcaneus sample has 1433 elements at 28 mm resolution, and the remaining 2823 elements at 14 mm resolution. The physical size of all is approximately 4£4 £ 4 mm and their densities are 9– 25 percent.

Results The software was tested on a PC with two Intel Pentium II—300 MHz processors, 17

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

512 MB SDRAM under Microsoft Windows 2000 Professional, using the Borland C++ Builder 5.0 Professional compiler. The compiler was set to maximum code performance optimisations, Pentium II instructions, and 8-byte alignment of data structures. Execution timings were recorded 12 times, and the highest and lowest timings were discarded before the average of the remaining 10 was calculated. The software was forced to run on one processor with realtime priority. The testing criteria also involved the resultant data file sizes apart from the execution times.

resultant solids are intended for mechanical testing, it was essential to replicate the voxel maps into triangle and contour based data without compromising quality. As a consequence, algorithms such as marching cubes for the 3D data and line generalisation or curve fitting for 21/2D data were avoided. The reasoning behind the dual support of STL and SLC type data is based exclusively on the available software and hardware capabilities of the stereolithography manufacturers. The STL format is far more widely used than the SLC, although the latter is better suited for CT type structures. STL files are far larger than their SLC equivalents, as the results show. It was experimentally determined that a PC equipped with 256 MB of main memory and with excessive disk swapping could only handle STL files containing up to approximately 2 million triangles, or about 100 MB of data. Although the human samples were optimised to fall below that limit, larger bone samples of say 5003 voxels, even if optimised, still produce vastly bigger files, exceeding 600 MB (up to 1500 MB for the non-optimised versions). Despite the SLC files being an order of magnitude more compact, they are not widely supported and consequently not always be an option. Table IX shows that the SLC files are roughly 13 – 17 times smaller than their equivalent optimised STL counterparts, and 28 – 33 times smaller than the non-optimised STL versions. When full SLC support is available from the rapid prototyping manufacturers, this is by far the best option; not only due to the low execution time requirements or inversely limited computer requirements, but also due to the small file sizes. Most importantly, though, it is possible to build more than one solid at a time, significantly reducing the cost of manufacture. At present the algorithms presented replicate a voxel map in geometry data very accurately. There is potential for improvement when accuracy is not an issue. STL data can be reduced by the marchingcubes algorithm (Lorensen and Cline, 1987) or a variant of it. SLC data can be postprocessed with a line generalisation algorithm (Visvalingam and Whyatt, 1993) or an adaptation of marching cubes in 2D, which will smoothen the contours, reducing storage requirements.

Island removal Figure 10 shows a sample of bone from the calcaneus before and after island removal. The renderings were obtained from the resultant data set of the optimal tessellation algorithm. The results of the island removal algorithm on the human bone samples are outlined in Table IV. The second column shows the total number of voxels of the samples. The third column shows the density of the samples (bone volume over total volume). The fourth column shows the difference in density after island removal as a percentage. The fifth column shows the execution time in a single thread of the above algorithm in our reference system. Tessellation Table V shows the results of the near real-time tessellation (NRT) algorithm on the human samples after all islands had been removed. Table VI shows the corresponding results from the optimal tessellation algorithm (OPT). Table VII shows the results of the contour extraction algorithm. Tables VIII and IX offer a comparison of the above results, in execution time and data set size. In Table VIII the execution times are normalised to the NRT algorithm (the fastest) and in Table IX the data set sizes are normalised to the contour based data (the smallest).

Discussion The purpose of this work was to define the algorithms that would precisely replicate voxel-based bone tissue data in CAD compatible representations. Since the 18

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Figure 10 The image on the left shows the calcaneus sample with islands and the one on the right without

Table IV Results of the island removal algorithm on five human samples Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

Total number of voxels

BV/TV

DBV/TV (islands) (percent)

Time (s)

22,425,768 20,994,336 22,425,768 22,425,768 2,924,207

0.257361 0.161416 0.087932 0.082654 0.117793

0.0003 0.0060 0.0109 0.0035 0.0280

140.90 121.44 106.41 107.78 16.95

Table V The results of the near real-time tessellation (NRT) algorithm. Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

Triangles

Execution time (s)

Data-set size (MB)

3.02 M 2.38 M 1.56 M 2.03 M 639 K

49.85 43.20 41.28 75.52 7.65

144.20 113.66 74.36 96.72 40.48

Triangles

Execution time (s)

Data-set size (MB)

1.48 M 1.19 M 707 K 1.04 M 325 K

3827.28 2962.96 2031.77 2852.69 214.29

70.69 56.64 33.70 49.57 15.51

Table VI The results of the optimal tessellation (OPT) algorithm Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

Despite the relatively fast operation of the software, there is still potential for improvement. Initially the software was designed to operate on PCs equipped with only 64 MB RAM, including the requirements of the underlying operating system. As a consequence, some algorithms were designed to repeatedly evaluate semiconstant expressions, instead of precomputing and storing them in look-up

tables. If memory is not an issue, or indeed a solution is required that makes better use of available resources, significant gains can be made in performance. Similarly, most algorithms are good candidates for parallel processing. It is relatively easy and straightforward to create a multithreaded version of the current software that will enable it to take advantage of multiple processors when available. It should be possible in such 19

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

Table VII The results of the contour extraction algorithm Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

Z layers

Total contours

Total vertices

Execution time (s)

Data-set size (MB)

282 264 282 282 143

2,763 3,249 3,839 6,110 2,662

600,512 425,082 329,774 408,468 113,910

106.95 90.17 90.75 112.10 14.38

4.63 3.30 2.58 3.21 0.91

Table VIII Comparison of the execution time of the three algorithms, normalised to NRT – STL Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

NRT – STL

OPT – STL

SLC

1.00 1.00 1.00 1.00 1.00

76.78 68.59 49.22 37.77 28.01

2.15 2.09 2.20 1.48 1.88

Table IX Comparison of the data-set size of the three algorithms, normalised to SLC Sample Femoral Head Iliac Crest 4th Lumbar Vertebra 2nd Lumbar Vertebra Calcaneus

NRT – STL

OPT – STL

SLC

31.14 34.44 28.21 30.13 33.49

15.27 17.16 13.06 15.44 17.03

1.00 1.00 1.00 1.00 1.00

Despite the popularity of the triangle based representations, employing the less popular contour representation can be the only option when the data set is especially large.

situations to experience a near linear increase in performance.

Conclusions For the purpose of manufacturing solid models based upon human tissue data, a set of algorithms has been developed that replicate voxel based data in CAD formats suitable for rapid prototyping equipment. The conversion algorithms can represent the source data in a triangle based description of a solid’s surface with the option of either fast processing or minimising processing. The first variation of the triangle based algorithm provides the resultant data in near real-time, whilst the second guarantees the minimum data set without any reduction in quality. However, the optimal algorithm is not well suited if further data reduction is required. A third algorithm was developed that processes the source data in layers and produces a set of contours, to offer an additional option of compatibility. A performance and data set size analysis was performed that evaluated the algorithms.

References Cline, H.E., Lorensen, W.E., Ludke, S., Crawford, C.R. and Teeter, B.C. (1988), “Two algorithms for the threedimensional reconstruction of tomograms”, Medical Physics, Vol. 15 No. 3, pp. 320-7. Consensus Development Conference, (1991), “Prophylaxis and treatment of osteoporosis”, American Journal of Medicine, Vol. 90, pp. 107-10. De Berg, M., Van Kreveld, M., Overmars, M. and Schwarzkopf, O. (1997), Computational Geometry: Algorithms and Applications, Springer-Verlag, Berlin. Dolan, P. and Torgerson, D.J. (1998), “The cost of treating osteoporotic fractures in the United Kingdom female population”, Osteoporosis International, Vol. 8, pp. 611-17. Gueziec, A. and Dean, D. (1994), “The wrapper: a surface optimization algorithm that preserves highly curved areas”, Proceedings of Visualization in Biomedical Computing, Vol. 94, pp. 631-42. Guibas, L. and Stolfi, J. (1985), “Primitives for the manipulation of general subdivisions and the

20

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

computation of Voronoi diagrams”, ACM Transactions on Graphics, Vol. 4 No. 2, pp. 74-123. Hamann, B. (1994), “A data reduction scheme for triangulated surfaces”, Computer Aided Geometric Design, Vol. 11, pp. 197-214. Hinker, P. and Hansen, C. (1993), “Geometric optimization”, Proceedings of Visualization, Vol. 93, pp. 189-95. Hodgskinson, R., Njeh, C.F., Whitehead, M.A. and Langton, C.M. (1996), “The non-linear relationship between BUA and porosity in cancellous bone”, Physics in Medicine and Biology, Vol. 41, pp. 2411-20. Hoppe, H., DeRose, T., Duchamp, T., McDonald, J. and Stuetzle, W. (1993), “Mesh optimization”, Computer Graphics Proceedings, pp. 19-25. Issa, B., Gibbs, P., Hodgskinson, R., Langton, C.M. and Turnbull, L.W. (1998), “Assessment of the pore geometry of stereolithography models by high resolution MRI”, Magnetic Resonance Imaging, Vol. 16 No. 5– 6, pp. 651-3. Kinney, J.H., Lane, N.E. and Haupt, D. (1995), “Three dimensional in vivo microscopy of sequential changes in trabecular architecture following estrogen depletion in female rats”, Journal of Bone and Mineral Research, Vol. 10, pp. 264-70. Langton, C.M. and Njeh, C.F. (1999), “Acoustic and ultrasonic tissue characterisation—assessment of osteoporosis”, Journal of Engineering in Medicine, Vol. 213H, pp. 261-9. Langton, C.M., Whitehead, M.A., Langton, D.K. and Langley, G. (1997), “Development of a cancellous bone structural model by stereolithography for ultrasound characterisation of the calcaneus”, Medical Engineering and Physics, Vol. 19 No. 7, pp. 599-604. Langton, C.M., Haire, T.J., Ganney, P.S., Dobson, C.A. and Fagan, M.J. (1998a), “Dynamic stochastic simulation of cancellous bone resorption”, Bone, Vol. 22 No. 4, pp. 375-80. Langton, C.M., Whitehead, M.A., Haire, T.J. and Hodgskinson, R. (1998b), “Fractal dimension predicts broadband ultrasound attenuation in stereolithography models of cancellous bone”, Physics in Medicine and Biology, Vol. 43, pp. 467-71. Lorensen, W.E. and Cline, H.E. (1987), “Marching cubes: a high resolution 3D surface reconstruction algorithm”, Computer Graphics, Vol. 21 No. 4, pp. 163-9. Odgaard, A., Andersen, K., Melsen, F. and Gundersen, H.J.G. (1990), “A direct method for fast threedimensional serial reconstruction”, Journal of Microscopy, Vol. 159 No. 3, pp. 335-42. Ruegsegger, P., Koller, B. and Muller, R. (1996), “A microtomographic system for the non-destructive evaluation of bone architecture”, Calcified Tissue International, Vol. 58, pp. 24-9. Schroeder, W.J., Zarge, J.A. and Lorensen, W.E. (1992), “Decimation of triangle meshes”, Computer Graphics, Vol. 26 No. 2, pp. 65-70. 3D Systems Inc. (1989), Stereolithography Interface Specification, 3D Systems, CA. 3D Systems Inc. (1994), SLC File Specification, 3D Systems, CA. Turk, G. (1992), “Re-tiling polygonal surfaces”, Computer Graphics, Vol. 26 No. 2, pp. 55-64.

Visvalingam, M. and Whyatt, J.D. (1993), “Line generalisation by repeated elimination of points”, Cartographic Journal, Vol. 30 No. 1, pp. 46-51.

Appendix A. Island removal algorithm (A1) Mark both slices attached to top and bottom planes of bounding box FOR (all voxels on y ) DO FOR (all voxels on x ) DO IF (the element on [x, y, bottom ] is bone) THEN Mark it as Bottom-Attached END IF IF (the element on [x, y, top ] is bone) THEN Mark it as Top-Attached END IF END FOR END FOR

(A2) Mark all elements belonging to main structure DO Set Top-Attached and Bottom-Attached to false // Bottom-top scan FOR (all z elements from Bottom+1 to Top planes) DO Mark all those bone voxels on the z plane that have their bottom bone voxels marked as Bottom-Attached. When that happens, Bottom-Attached to true. Mark all those bone voxels on the z plane that have their top bone voxels marked as Top-Attached. When that happens, set Top-Attached to true. END FOR DO Set Slice-State-Change to false FOR (all bone elements on the z plane) DO IF (they are not marked as BottomAttached but they are next to one that is) THEN Mark them as Bottom-Attached Set both Slice-State-Change and BottomAttached to true END IF IF (they are not marked as Top-Attached but they are next to one that is) THEN Mark them as Top-Attached Set both Slice-State-Change and TopAttached to true 21

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

END IF END FOR WHILE (Slice-State-Change is true) // Top-bottom scan FOR (all z elements from Top2 1 to Bottom planes) DO Mark all those bone voxels on the z plane that have their top bone voxels marked as Top-Attached. When that happens, set Top-Attached to true. Mark all those bone voxels on the z plane that have their bottom bone voxels marked as Bottom-Attached. When that happens, set Bottom-Attached to true. END FOR DO Set Slice-State-Change to false FOR (all bone elements on the z plane) DO IF (they are not marked as Top-Attached but they are next to one that is) THEN Mark them as Top-Attached Set both Slice-State-Change and TopAttached to true END IF IF (they are not marked as BottomAttached but they are next to one that is) THEN Mark them as Bottom-Attached Set both Slice-State-Change and BottomAttached to true END IF END FOR WHILE (Slice-State-Change is true) WHILE (there are elements that were newly marked as Top-Attached or BottomAttached )

FOR (all y voxels) DO FOR (all x voxels) DO IF (the voxel on [x, y, z ] is bone) THEN IF ([x-1, y, z ] is not bone) THEN Generate left triangles Calculate surface normals Output triangles END IF IF ([x+1, y, z ] is not bone) THEN Generate right triangles Calculate surface normals Output triangles END IF IF ([x, y 2 1, z ] is not bone) THEN Generate bottom triangles Calculate surface normals Output triangles END IF IF ([x, y+1, z ] is not bone) THEN Generate top triangles Calculate surface normals Output triangles END IF IF ([x, y, z 2 1] is not bone) THEN Generate near triangles Calculate surface normals Output triangles END IF IF ([x, y, z+1] is not bone) THEN Generate far triangles Calculate surface normals Output triangles END IF END IF END FOR END FOR END FOR

(A3) Delete bone islands FOR (all z voxels) DO FOR (all y voxels) DO FOR (all x voxels) DO IF (the element on (x, y, z ) is bone and either of the Top-Attached or BottomAttached flags are false) THEN Turn that element to marrow END IF END FOR END FOR END FOR

Appendix C. Optimal tessellation (C1) Node tracing for contour definition Let V be the starting top-left vertex in voxel plane Let D be the north direction of heading Let VL be an empty vertex list DO Add V to VL Let VT be the vertex type of V IF (VT is not a shared vertex [i.e. of type 5 or A]) THEN Mark V as used ELSE IF (V is still shared by a contour) THEN Mark V as not shared any more ELSE

Appendix B. Near real-time tessellation algorithm FOR (all z voxels) DO 22

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

LET IMM_PARENT be M ELSE LET IMM_PARENT to be the parent of CL[M] END IF END IF END FOR LET UC be the number of contours without their parenthood status defined (2) Go to next row (y ) END WHILE

Mark V as used END IF END IF Let D be the new direction to travel to DO Travel to the next vertex as indicated by D WHILE ((NOT another vertex is met) AND (NOT starting vertex is met)) WHILE (NOT starting vertex is met) (C2) Contour enclosure detection LET CL be the list of contours with undefined parenthood status (all -2) LET E be an empty set of integers to represent contour IDs. LET INT be an empty set of intersections (pairs of x co-ordinates with contour IDs) LET UC be the number of contours that have not got their parent status defined WHILE (not every row has been processed AND UC . 0) DO LET R be the ray to test for intersections based on the current row to be processed FOR (every contour in CL) DO LET C be the current contour FOR (every vertex in C) DO IF (the vertical co-ordinates (y ) of the current vertex and the next one lie on both sides of R) THEN Add intersection to INT END IF END FOR END FOR SORT the INT set in ascending order with a non-recursive algorithm (insertion sort) Set all E elements to 0 Let IMM_PARENT to be -1 (without parent) FOR (every intersection in INT) DO LET M be the contour ID of the current intersection IF (M . = 0) THEN Increment E[M] IF (the remainder of the division of E[M] with 2 is 1) THEN Let the parent of CL[M] be IMM_PARENT IF (the parent of CL[M] , 0) THEN LET the enclosed state of CL[M] be false ELSE LET the enclosed state of CL[M] be true LET the encloses state of CL[IMM_PARENT] be true END IF

(C3) Contour merging Let Parent be the parent contour Let CL be the list of contours on the current plane Let VL be the final merged vertex list Let TVL1 and TVL2 be two temporary empty vertex lists Let SiblingCounter be the number of siblings of Parent Invert all siblings of Parent Copy the parent to TVL1 WHILE (SiblingCounter . 0) DO Let ClosestDistance be the maximum representable floating-point number Let Sibling be the closest to Parent sibling WHILE (a sibling was found) DO FOR (every vertex i of the sibling) DO FOR (every vertex j of the parent) DO Let d be the distance of vertex i from vertex j IF (d , ClosestDistance) THEN Let BestSibling be Sibling Let ClosestDistance be d Remember both i and j END IF END FOR END FOR Let Sibling be the next closest sibling to Parent END WHILE Mark all the immediate siblings of BestSibling as parent contours Merge TVL1 and BestSibling into TVL2 with best i and best j Clear TVL1 Let TVL1 be TVL2 Clear TVL2 Clear BestSibling Decrement SiblingCounter END WHILE (C4) Contour orientation inversion Let VL be the contour to be inverted 23

Rapid prototyping replication of voxel maps

Rapid Prototyping Journal

G. Sisias et al.

Volume 8 · Number 1 · 2002 · 6–24

END IF Let I2 be the index of the next valid vertex after I1 Let I3 be the index of the next valid vertex after I2 END WHILE

Let Same be the indicator whether to retain the same starting vertex IF (Same is true ) THEN Assume the number of vertices in VL . 2 Let I be 1 ELSE Assume the number of vertices in VL . 1 Let I be 0 END IF Let J be the number of vertices in VL-1 WHILE (I , J) DO Swap VL[I] and VL[J] Increment I Decrement J END WHILE

(C6) Contour re-orientation Let CL be the list of contours of a layer Let C = 0, representing the number of contours with defined orientation Let T be the set of all types of orientation for each contour in CL Let n be the number of contours in CL FOR (I [ [0,n)) DO IF (CL[I] has no parent) THEN Turn CL[I] orientation to CCW Increment C T[I] = CCW ELSE T[I] = UNDEFINED END IF END FOR WHILE (C , n) DO FOR (I [ [0,n)) DO IF (T[I] is UNDEFINED) THEN IF (T[CL[I].Parent] = =CW) THEN Invert CL[I] Increment C T[I] = CCW ELSE-IF (T[CL[I].Parent] = =CCW) THEN Increment C T[I] = CW END IF END IF END FOR END WHILE

(C5) Contour tessellation Let VL be the vertex list to be tessellated Let FL be an empty triangle list Let VC be the number of vertices of VL Let I1 be 0 (the index referring to the first vertex of VL) Let I2 be 1 (the index referring to the second vertex of VL) Let I3 be 2 (the index referring to the third vertex of VL) WHILE (VC . = 3) DO IF ((the facet made of VL[I1], VL[I2], VL[I3] is front-facing) AND (VL[I1],VL[I2], VL[I3] do not enclose any other vertex of VL)) THEN Let F be the facet made of VL[I1],VL[I2] and VL[I3] Add F to FL Remove VL[I2] Decrement VC Let I1 be I3 ELSE Let I1 be I2

24