Model Clipping Triangle Strips and Quad Meshes.

Similar documents
Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

3D vector computer graphics

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

For instance, ; the five basic number-sets are increasingly more n A B & B A A = B (1)

CMPS 10 Introduction to Computer Science Lecture Notes

2D Raster Graphics. Integer grid Sequential (left-right, top-down) scan. Computer Graphics


Scan Conversion & Shading

R s s f. m y s. SPH3UW Unit 7.3 Spherical Concave Mirrors Page 1 of 12. Notes

A Binarization Algorithm specialized on Document Images and Photos

Scan Conversion & Shading

Programming in Fortran 90 : 2017/2018

6.854 Advanced Algorithms Petar Maymounkov Problem Set 11 (November 23, 2005) With: Benjamin Rossman, Oren Weimann, and Pouya Kheradpour

Module Management Tool in Software Development Organizations

Parallelism for Nested Loops with Non-uniform and Flow Dependences

Complex Numbers. Now we also saw that if a and b were both positive then ab = a b. For a second let s forget that restriction and do the following.

Mathematics 256 a course in differential equations for engineering students

Some Tutorial about the Project. Computer Graphics

Interpolation of the Irregular Curve Network of Ship Hull Form Using Subdivision Surfaces

Simplification of 3D Meshes

UNIT 2 : INEQUALITIES AND CONVEX SETS

Line Clipping by Convex and Nonconvex Polyhedra in E 3

High-Boost Mesh Filtering for 3-D Shape Enhancement

Parallel matrix-vector multiplication

RADIX-10 PARALLEL DECIMAL MULTIPLIER

TN348: Openlab Module - Colocalization

Hermite Splines in Lie Groups as Products of Geodesics

Notes on Organizing Java Code: Packages, Visibility, and Scope

SLAM Summer School 2006 Practical 2: SLAM using Monocular Vision

Cluster Analysis of Electrical Behavior

A mathematical programming approach to the analysis, design and scheduling of offshore oilfields

Collision Detection. Overview. Efficient Collision Detection. Collision Detection with Rays: Example. C = nm + (n choose 2)

Array transposition in CUDA shared memory

The Codesign Challenge

VISUAL SELECTION OF SURFACE FEATURES DURING THEIR GEOMETRIC SIMULATION WITH THE HELP OF COMPUTER TECHNOLOGIES

A Fast Content-Based Multimedia Retrieval Technique Using Compressed Data

CE 221 Data Structures and Algorithms

An Optimal Algorithm for Prufer Codes *

Data Representation in Digital Design, a Single Conversion Equation and a Formal Languages Approach

Analysis of Continuous Beams in General

Problem Set 3 Solutions

Lecture 5: Multilayer Perceptrons

Virtual Memory. Background. No. 10. Virtual Memory: concept. Logical Memory Space (review) Demand Paging(1) Virtual Memory

Wishing you all a Total Quality New Year!

Related-Mode Attacks on CTR Encryption Mode

Multiblock method for database generation in finite element programs

Accounting for the Use of Different Length Scale Factors in x, y and z Directions

On Some Entertaining Applications of the Concept of Set in Computer Science Course

Computer Animation and Visualisation. Lecture 4. Rigging / Skinning

ELEC 377 Operating Systems. Week 6 Class 3

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

High level vs Low Level. What is a Computer Program? What does gcc do for you? Program = Instructions + Data. Basic Computer Organization

Range images. Range image registration. Examples of sampling patterns. Range images and range surfaces

An Approach in Coloring Semi-Regular Tilings on the Hyperbolic Plane

Electrical analysis of light-weight, triangular weave reflector antennas

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

Lecture #15 Lecture Notes

Assembler. Building a Modern Computer From First Principles.

Course Introduction. Algorithm 8/31/2017. COSC 320 Advanced Data Structures and Algorithms. COSC 320 Advanced Data Structures and Algorithms

Problem Definitions and Evaluation Criteria for Computational Expensive Optimization

Outline. Discriminative classifiers for image recognition. Where in the World? A nearest neighbor recognition example 4/14/2011. CS 376 Lecture 22 1

Harvard University CS 101 Fall 2005, Shimon Schocken. Assembler. Elements of Computing Systems 1 Assembler (Ch. 6)

Support Vector Machines

Active Contours/Snakes

Accessibility Analysis for the Automatic Contact and Non-contact Inspection on Coordinate Measuring Machines

F Geometric Mean Graphs

LS-TaSC Version 2.1. Willem Roux Livermore Software Technology Corporation, Livermore, CA, USA. Abstract

VRT012 User s guide V0.1. Address: Žirmūnų g. 27, Vilnius LT-09105, Phone: (370-5) , Fax: (370-5) ,

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

The Shortest Path of Touring Lines given in the Plane

Conditional Speculative Decimal Addition*

Intro. Iterators. 1. Access

APPLICATION OF AN AUGMENTED REALITY SYSTEM FOR DISASTER RELIEF

Private Information Retrieval (PIR)

Intra-Parametric Analysis of a Fuzzy MOLP

ETAtouch RESTful Webservices

Chapter 4. Non-Uniform Offsetting and Hollowing by Using Biarcs Fitting for Rapid Prototyping Processes

A MOVING MESH APPROACH FOR SIMULATION BUDGET ALLOCATION ON CONTINUOUS DOMAINS

The stream cipher MICKEY-128 (version 1) Algorithm specification issue 1.0

Image Alignment CSC 767

Reducing Frame Rate for Object Tracking

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

Today Using Fourier-Motzkin elimination for code generation Using Fourier-Motzkin elimination for determining schedule constraints

BITPLANE AG IMARISCOLOC. Operating Instructions. Manual Version 1.0 January the image revolution starts here.

Explicit Formulas and Efficient Algorithm for Moment Computation of Coupled RC Trees with Lumped and Distributed Elements

Proper Choice of Data Used for the Estimation of Datum Transformation Parameters

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

Parallel Numerics. 1 Preconditioning & Iterative Solvers (From 2016)

Meta-heuristics for Multidimensional Knapsack Problems

Cell Count Method on a Network with SANET

THE PULL-PUSH ALGORITHM REVISITED

News. Recap: While Loop Example. Reading. Recap: Do Loop Example. Recap: For Loop Example

Quality Improvement Algorithm for Tetrahedral Mesh Based on Optimal Delaunay Triangulation

APPLICATION OF MULTIVARIATE LOSS FUNCTION FOR ASSESSMENT OF THE QUALITY OF TECHNOLOGICAL PROCESS MANAGEMENT

Support Vector Machines. CS534 - Machine Learning

Barycentric Coordinates. From: Mean Value Coordinates for Closed Triangular Meshes by Ju et al.

An Accurate Evaluation of Integrals in Convex and Non convex Polygonal Domain by Twelve Node Quadrilateral Finite Element Method

An Iterative Solution Approach to Process Plant Layout using Mixed Integer Optimisation

CHAPTER 2 DECOMPOSITION OF GRAPHS

Transcription:

Model Clppng Trangle Strps and Quad Meshes. Patrc-Glles Mallot Sun Mcrosystems, Inc. 2550 Garca Avenue, Mountan Vew, CA 94043 Abstract Ths paper descrbes an orgnal software mplementaton of 3D homogeneous Model Clppng for Trangle Strps and Quadrlateral Meshes. After a defnton of these graphcs enttes, and a study of ther geometrcal characterstcs, the dfferent possble stuatons when clppng trangles s presented. The detaled descrpton of the ernel of the algorthm, optmzed for clppng trangle strps s made, followed by the specfc cases that can be found when dealng wth quadrlateral meshes. Precsons are gven concernng memory usage of the proposed method, and a complete mplementaton of the algorthm for trangle strps n the C language follows. The concluson ncludes some performance numbers that can be expected from the gven algorthm. CR categores and Subect Descrptors: I.3.3 [Computer Graphcs]: Pcture/Image Generaton, Dsplay algorthms, Vewng algorthms; Addtonal Key Words and Phrases: 3D Polygon Clppng, Trangle Strps, Quadrlateral Meshes.

Model Clppng Trangle Strps and Quad Meshes. Introducton. One can easly fnd n the lterature 1, 2, 4 some nformaton on how to perform clppng of general 3D graphcs prmtves, such as lnes and polygons. Wth the graphcs system archtectures currently avalable, the term polygon often refers to trangles or quads paced together n more complex structures such as trangle strps and quad meshes. It s generally when usng these prmtves that the best drawng performance can be acheved on most of the advanced graphcs systems 5, 6. One of the most expensve operaton n graphcs s to perform clppng. Dstncton can be made between Model Clppng, where the clppng planes can be arbtrarly orented, and Vew Clppng, where the number of clppng planes, as well as ther orentaton, s fxed. Ths artcle proposes a soluton that taes nto account the specfc organzaton of Trangles Strps and Quad Meshes prmtves n order to acheve effcent Model Clppng. Some of the prncples dscussed here can be appled to other, smpler, graphc structures such as mult-bounded polygons, n order to mprove the effcency of standard clppng methods. The general soluton proposed for the clppng equatons can also be smplfed n order to perform Vew Clppng of the same prmtves 7. Data Study. An easy way of optmzng a graphcs ppelne operatons s not to modfy the structure of the prmtve all along the graphcs ppelne. Unfortunately, some operatons of the ppelne can modfy, or brea, the logcal structure of the ntal prmtve. Ths s typcally the case of clppng, where a trangle of a trangle strp can be changed (clpped) nto a n-sded polygon, after beng clpped by (n-3) planes, breang the structure of the ntal trangle strp. Ths paper proposes a general approach to the clppng of trangle strps n the case of 3D homogeneous coordnates and arbtrary orented clppng planes. The partculartes of the extenson to the clppng of quad meshes are also detaled. The proposed method accepts a sngle trangle strp structure at the nput of the clppng process, and returns a sngle trangle strp structure at the output. In the case of quad meshes, the quads are clpped row by row, and the clppng process can return multple rows of quads for a sngle row of quad at the nput. Whle descrbed by a lst of ponts, trangle strps do have a logcal organzaton that should be consdered durng the clppng step. A trangle strp conssts of an ordered lst of n vertces {v 0, v 1,..., v n-1 that defne a sequence of n-2 trangles. The trangles n the strp share common edges. Thus, the th trangle s formed of vertces, +1, +2. On

the other hand, a quad mesh conssts of a matrx of m rows and n columns (m, n > 1) of vertces stored as an ordered lst of (mn) vertces {v 00, v 01,..., v 0(n-1), v 10,..., v (m-1)0, v (m-1)1,..., v (m-1)(n-1).a quad mesh, as descrbed here, defnes (m-1)(n-1) quads q, (=0, (m-1)(n-1) -1) formed from each square of adacent vertces v, v (+1),v (+1), v (+1)(+1), where = m, and = mod (n). The quads are drawn n the order q, (=0, (m-1)(n-1) -1). Fgure 1 gves a pctoral examples of a sngle trangle strp and a quad mesh. 0 2 1 3 10 00 01 02 03 4 5 20 8 6 7 30 40 50 60 10 9 Fgure 1: A sngle trangle strp and a smple quad mesh Algorthm Study. We propose to clp the prmtves usng a method derved from the Sutherland-Hodgman algorthm 1. Ths means that the clppng calculatons wll be lmted to determnng ntersectons wth one clppng plane at a tme, separatng the prmtve nto two regons: the nsde and the outsde. These calculatons wll be repeated as many tmes as needed to scan all the enabled clppng planes. The Sutherland-Hodgman method nvolves a lot of computatons as well as memory operatons. However, snce we defne our Model space as a 3D homogeneous space, and the vertces can have both normal and color nformaton, t seems to be the most effcent. Each ntersecton (computed only when needed) s based on the parametrc equaton of the edge from one vertex to another: R = λq + ( 1 λ)p, λ [ 0,0, 1,0 ]

The value of λ s used to compute the ntersecton vertex coordnates (R), and can also be used to lnearly nterpolate per vertex color and/or normal data f needed. The ntersecton, n the case of a lne segment such as P Q, has to be evaluated only when the end ponts of that lne le n opposte regons. If a bt s assgned to each pont, wth a 1 meanng les outsde and a 0 meanng les nsde, then the ntersecton wll be computed only when (bt[p] exclusve-or bt[q]) s set, meanng that one pont les outsde and the other one les nsde the clppng regon. If both bts are set, that means the entre lne segment s outsde the clppng regon. The entre lne segment s nsde the clppng regon when both bts are equal to 0. Ths approach, presented n 3, offers the advantage of usng fast operatons to chec for trval cases, and provdes a way to eep ntermedate results avalable for the next pont. In the case of a trangle, we can tae advantage of three ponts at a tme and for quads, four ponts can be consdered two by two. A Model Clppng plane s defned by a 3D pont and a normal vector, both expressed n the Model Space. Some graphcs pacages specfy the clppng planes n World Coordnates 8, 9, but t s always possble to transform the clppng planes so that they are defned n Model Space Coordnates, thus smplfyng the graphcs ppelne to be the followng: Prmtve n Model coordnates Model Clppng Transformaton to NPC Vew Clppng Dvson by W Transformaton to DC Renderng Let C be a model clppng plane, C: { S R 4, N R 4, S = ( S x, S y, S z, 1),a pont of C n 3D Model Space, and N = ( N x, N y, N z, 0), a unt vector normal to C.

In fact, a sngle vector can be used to fully defne the clppng plane, as shown n 10, let E be that vector: E R 4, and E = ( N x, N y, N z, ( S x N x + S y N y + S z N z )). Then P: P R 4, P = ( x, y, z, w) s nsde the half-space defned by C f E T P 0. There wll be clppng of the segment P Q f sgn( E T P) sgn( E T Q), that s f P and Q are on opposte sdes of C. Fgure 2 graphcally presents dfferent possble stuatons for both P and Q n respect to C. A pont exactly on the clppng plane s consdered nsde the half-space. P P N S N S Q N S C C C Q P & Q on opposte sdes of C P & Q on dentcal sdes of C P Q Fgure 2: Possble stuatons of P & Q n respect to C. When there s ntersecton, P and Q are on opposte sdes of C. The ntersecton pont R must satsfy two equatons: R must belong to the lne segment P Q: R = λq + ( 1 λ)p, and R must belong to the plane C: E T R = 0. The case of trangle strps. A trangle strp s (obvously) composed of trangles. Each trangle can be consdered separately for the ntersecton calculatons. However, the mplementaton of the clppng algorthm should provde a way to avod multple equvalent calculatons by tang advantage of the logcal organzaton of the vertces. Because a trangle s composed of three ponts, and each pont can be ether nsde, or outsde a gven half-space, there are 8 dfferent stuatons when computng the clpped result of a trangle wth a sngle clppng plane. Each case generates a partcular sequence of

ponts at the output of the clppng process. Ths process wll be repeated as many tmes as Model Clppng planes to clp aganst. Fgure 3 shows the dfferent cases and the resultng output that has to be generated by the Model Clppng n order to mantan the ntal organzaton of the trangle strp. Clp codes [,, ] output sequence of ponts 000,, 001 a c a,, c,, 110 a c, a, c, c * 010 a b, a,, b, 101 a b a,, b 100 b,,,, b 011 b c c, c, b, * (* see text) 111 Fgure 3: trangle stuatons, the gray areas represent the reectng half-space. In order to mantan the trangle strp structure, the trangle strp Model Clppng algorthm can generate some trangles wth an area of zero. By dong ths, the trangle strp structure can be mantaned even when a trangle degenerates nto a quad after clppng wth a clp-plane. There are specal cases, when clppng a trangle wth clppng codes

equal to 011 or 110 (Fgure 3, cases mared *). The code 110 ndcates that the current trangle has ts two last ponts outsde the current half-space, and the frst pont of the trangle s nsde the current half-space, so the trangle strp s leavng the vsble half-space. The code 011 ndcates the opposte stuaton, the trangle strp enters agan, or for the frst tme, the vsble half-space. In ths partcular case, a new trangle strp should be ssued. Even n the case of a sngle trangle strp nput, t s possble to generate more than one trangle strp after the clppng operaton. Fgure 4 gves further detal, explanng such a stuaton. There s a way, however, to avod generatng multple trangle strps at the model clppng output n order to stll be able to tae advantage of an accelerated renderer. The soluton proposed n the case presented n Fgure 4, s to duplcate ponts Q and R so that three degenerate trangles (e.g. trangles wth an area of 0) are ssued to eep the logc of the orgnal trangle strp. In that partcular case, these trangles would be (P, Q, Q), (Q, Q, R), (Q, R, R). The mplementaton presented later n ths paper taes advantage of ths method. It should be noted that ths can be appled only when the renderng stage, further down n the graphcs ppelne, nows how to deal wth degenerate trangles. c P Q R S a b m...,, : clppng code 110, generates, P, Q,, m: clppng code 111, culled, m, a: clppng code 111, culled m, a, b: clppng code 111, culled a, b, c: clppng code 011, generates R, S, c... A new trangle should be ssued when clppng a, b, c Fgure 4: Multple trangle strps created by the clppng operaton. The case of quad meshes. The same prncple that has been presented for trangle strp can be appled to quad meshes 11. In the quad mesh case,

however, a sngle quad can generate 16 dfferent cases dependng on the stuaton of the four ponts of the quad n respect to a model clppng plane. Also, a sngle row of quads wll generate one or several rows of quads and the clppng of quad meshes can only generate a subset, or specal case of the quad mesh prmtve. Fgure 5 shows some examples of quads stuaton where the clppng operaton has to generate several rows of quads at the output. Quad meshes are generally organzed such that t s easy to solate a complete row; but the order n whch the ponts appear for a gven row can mpact the effcency of the clppng operaton. Ths because the mplementaton presented here s based on the same prncple than n the case of trangle strps, and expects to be able to shft the nformaton concernng the last two ponts of the current quad n order for them to become the frst two ponts of the next quad. P Q R S ntal quad P a c b d S 1001, generate: a, P, a, c, new row, b, d, S, d Q a c b R d 0110, generates: Q, a, d, a, new row, d, c, d, R a Q b 1110, generates: Q, a, b, a, new row Fgure 5: New row generaton cases. P Q c b 1100, generates: Q, P, b, c, new row Memory consderatons. The standard clppng algorthm proposed by Sutherland-Hodgman mples a lot of memory or stac operatons. A detaled ntroducton to the prncple of the algorthm s presented n 2, showng the dfferent steps used to clp a polygon, n 2D, or 3D. Although t s mentoned that the reentrant characterstc of the orgnal algorthm avods the need for ntermedate storage, the cost mpled n stac operatons and recursve calls s probably not well suted n the case of a software mplementaton wth large data structures. Whle eepng the same general ntersecton prncples, ths artcle proposes a dfferent approach, necesstatng ntermedate storage, but lmtng the number of nner loops of the clppng algorthm to the number of actve clppng

planes. The algorthm frst bulds a lst of ponters to the orgnal ponts, provded by the caller. It then only propagates ponters to ponts, and not the ponts themselves, from one stage of the clpper to the next stage, thus avodng expensve memory copy operatons. When the generaton of new ponts s made necessary because of an actual ntersecton wth a clppng plane, the algorthm saves the ntersecton pont n a pont stac and eeps the ponter to that pont for use n the next clppng stages. Fnally, when all the clppng planes have been scanned, an output lst of ponts s buld from the current lst of ponters. Implementaton. The algorthm proposed here supports the case where the W components of the vertces of the trangle strp are postve. Model Clppng for negatve w s requres to change the clppng equaton n the mplementaton proposed below (ths exercse s left to the reader), and supportng lnes wth end vertces havng both postve and negatve w s requre two passes by the clppng algorthm n order to render both postve and negatve sectons, one for each clppng equaton. Fgure 6 shows the result of clppng a sngle trangle wth coordnates beng (1,0,0,1), (0,1,0,1), and (0,0,1,1) compared to a trangle wth coordnates beng (1,0,0,1), (0,1,0,-1), and (0,0,1,-1). It has been shown 12 that under certan crcumstances, the coordnate system n whch clppng s perform may nfluence the number of passes that have to be done n order to consder both postve and negatve w s. In fact ths s true only n the case vertces n the negatve space are generated because of the specal nature of the proecton transform. It s stll necessary to perform two dstnct passes when the data ntally contans both postve and negatve w components. 0,0,1,1 0,0,1,-1 z z x y 1,0,0,1 0,1,0,1 x y 1,0,0,1 0,1,0,-1 a) All w components are postve. b) w components are postve and negatve Fgure 6: Effect of Postve and Negatve w components.

The followng s an example of mplementaton of the model clppng for trangle strps, based on the prncples presented n ths artcle. For smplfcaton purposes, the vertex structures contan only coordnates data. They can easly be modfy to tae nto account color and/or normal nformaton, n whch case, the ntersecton macros should also be modfed. The structure H_pont s used to store the pont coordnates, H_lst represents a lst of ponts. The model clppng planes are represented by a structure of type H_plane, contanng the 4 sgnfcant elements of a model clppng plane. Clp_ctx represents the context state nformaton used by the algorthm. It contans storage for defnng a lst of clppng planes, and arrays of ponts or ponters to ponts. These arrays should be ntalzed to null ponters and the correspondng number of elements should be set to 0. #defne MEM_INCREMENT 64 * 3D pont structure typedef struct { float coords[4]; H_pont; typedef struct { nt num_hponts; H_pont *hponts; H_lst; typedef struct { float normal[3]; float cst; H_plane; typedef struct { H_plane *Mclp_planes; nt num_planes; H_pont **ponters_bucet_0; nt ponters_bucet_0_max; H_pont **ponters_bucet_1; nt ponters_bucet_1_max; H_pont *hponts_bucet; nt hponts_bucet_max; nt hponts_bucet_ndex; Clp_ctx; * * Space codng nformaton: * * Ths 3D clppng functon s based on the ntersecton of * lnes usng a lne segment parametrc equaton: * * Let P a pont on the lne segment, then f A and B are the * extremes ponts of the lne segment, we can wrte: * P = l * B + (1 - l) * A, wth l = [0..1] * A 0 bt means nteror, whle * a 1 bt means exteror. * * Intersecton macros

#defne COMPUTE_INTER_3D(P, P_plan, S) \ P = pre_stage[n]; \ P_plan = P->coords[0] * plane->normal[0] + \ P->coords[1] * plane->normal[1] + \ P->coords[2] * plane->normal[2] - \ P->coords[3] * plane->cst; \ clp_code = ((P_plan < 0.) << S); #defne POINT_INTER_3D(P, P_plan, Q, Q_plan) \ f (clp_ctx->hponts_bucet_ndex >= clp_ctx->hponts_bucet_max) { \ f (clp_ctx->hponts_bucet) { \ C = (H_pont *)realloc(clp_ctx->hponts_bucet, \ (clp_ctx->hponts_bucet_max + MEM_INCREMENT) * szeof(h_pont)); \ else { \ C = (H_pont *)malloc((clp_ctx->hponts_bucet_max + MEM_INCREMENT) \ * szeof(h_pont)); \ \ f (C) { \ clp_ctx->hponts_bucet_max += MEM_INCREMENT; \ clp_ctx->hponts_bucet = C; \ else { \ out->num_hponts = 0; \ return; \ \ \ lambda = P_plan / (P_plan - Q_plan); \ C->coords[0] = P->coords[0] + lambda * (Q->coords[0] - P->coords[0]); \ C->coords[1] = P->coords[1] + lambda * (Q->coords[1] - P->coords[1]); \ C->coords[2] = P->coords[2] + lambda * (Q->coords[2] - P->coords[2]); \ C->coords[3] = P->coords[3] + lambda * (Q->coords[3] - P->coords[3]); \ cur_stage[n_cur_s] = C; \ n_cur_s += 1; \ clp_ctx->hponts_bucet_ndex += 1; \ C += 1; #defne POINT_COPY(P) \ cur_stage[n_cur_s] = P; \ n_cur_s += 1; * h3d_strp_clp: * 3D trangle strp clpper. A trangle strp s made of * vertces logocally organzed n trangles (...). The frst * trangle s composed of the vertces 0, 1, and 2. The second * trangle s represented by the vertces 1, 2, and 3, and so * on untl the last vertex. * As presented n the algorthm, a trangle strp outputs only * one trangle strp. Ths s possble f degenerate trangles * are acceptable. * * Notes: * Ths s bascally a Sutherland-Hodgman algorthm. But a non-recursve * verson. h3d_strp_clp(clp_ctx, n, out) regster Clp_ctx *clp_ctx; regster H_lst *n; regster H_lst *out;

{ regster H_pont **pre_stage, **cur_stage, **tmp_stage; regster H_pont *P, *Q, *R, *C; regster H_plane *plane; regster nt n_pre_s, n_cur_s, n_cur_max; regster nt, n; regster unsgned char clp_code; double lambda; float P_plan, Q_plan, R_plan; * At nt, set the prevous stage pont to the nput ponts values. n_cur_s = n->num_hponts; f (clp_ctx->ponters_bucet_0_max < (n_cur_s + MEM_INCREMENT)) { f (pre_stage = (H_pont **)malloc((n_cur_s + MEM_INCREMENT) * szeof(h_pont *))) { f (clp_ctx->ponters_bucet_0) free(clp_ctx->ponters_bucet_0); clp_ctx->ponters_bucet_0 = pre_stage; clp_ctx->ponters_bucet_0_max = n_cur_s + MEM_INCREMENT; else { out->num_hponts = 0; return; f (clp_ctx->ponters_bucet_1_max < (n_cur_s + MEM_INCREMENT)) { f (pre_stage = (H_pont **)malloc((n_cur_s + MEM_INCREMENT) * szeof(h_pont *))) { f (clp_ctx->ponters_bucet_1) free(clp_ctx->ponters_bucet_1); clp_ctx->ponters_bucet_1 = pre_stage; clp_ctx->ponters_bucet_1_max = n_cur_s + MEM_INCREMENT; else { out->num_hponts = 0; return; cur_stage = clp_ctx->ponters_bucet_0; for ( = 0; < n_cur_s; ++) cur_stage[] = &(n->hponts[]); C = clp_ctx->hponts_bucet; clp_ctx->hponts_bucet_ndex = 0; * For each of the clppng plane, clp (f necessary). plane = clp_ctx->mclp_planes; for ( = 0; ( < clp_ctx->num_planes && n_cur_s > 2); ++, plane++) { * swtch memory between current and prevous. pre_stage = cur_stage; n_pre_s = n_cur_s; f (cur_stage == clp_ctx->ponters_bucet_0) { cur_stage = clp_ctx->ponters_bucet_1; n_cur_max = clp_ctx->ponters_bucet_1_max; else { cur_stage = clp_ctx->ponters_bucet_0; n_cur_max = clp_ctx->ponters_bucet_0_max; n_cur_s = 0;

* Start clppng of the prevous stage, for the th clp plane. * Output ponts go n the current_stage memory. * Start clppng of the trangle strp from the prevous stage * nto the current stage, for the th clp plane. * * Process the frst pont of the trangle strp. * clp_code = 0; n = 0; COMPUTE_INTER_3D(Q, Q_plan, 1) * Now, process the second pont of the trangle strp. n = 1; COMPUTE_INTER_3D(R, R_plan, 2) * (Q, R) represents the frst lne segment of the frst trangle of * the trangle strp. We need to clp t as a lne * to ensure the frst two ponts of the trangle. n = clp_code >> 1; swtch (n) { case 0: Q and R nsde POINT_COPY(Q) POINT_COPY(R) case 1: Q outsde, R nsde POINT_INTER_3D(Q, Q_plan, R, R_plan) POINT_COPY(R) case 2: Q nsde, R outsde POINT_COPY(Q) POINT_INTER_3D(Q, Q_plan, R, R_plan) case 3: Q and R outsde default: * Process each subsequent pont of the trangle strp. * P, Q, R form the (n-2)th trangle of the strp. for (n = 2; n < n_pre_s; n++) { clp_code >>= 1; P = Q; Q = R; P_plan = Q_plan; Q_plan = R_plan;

COMPUTE_INTER_3D(R, R_plan, 2) * We need to ensure that enough memory s avalable. f (n_cur_max < n_cur_s + 3) { tmp_stage = (H_pont **)realloc(cur_stage, (n_cur_max + MEM_INCREMENT) * szeof (H_pont *)); f (tmp_stage) { f (cur_stage == clp_ctx->ponters_bucet_0) { clp_ctx->ponters_bucet_0_max += MEM_INCREMENT; else { clp_ctx->ponters_bucet_1_max += MEM_INCREMENT; else { out->num_hponts = 0; return; cur_stage = tmp_stage; n_cur_max += MEM_INCREMENT; * clp_code has now 3 bts that represent the stuaton of the trangle * n respect to the clp boundary. 8 dfferent cases can occur. swtch (clp_code) { case 0: all nsde POINT_COPY(R) case 1: P outsde, Q and R nsde POINT_INTER_3D(R, R_plan, P, P_plan) POINT_COPY(Q) POINT_COPY(R) case 2: P nsde, Q outsde and R nsde POINT_COPY(R) POINT_INTER_3D(Q, Q_plan, R, R_plan) POINT_COPY(R) case 3: P and Q outsde, R nsde POINT_INTER_3D(R, R_plan, P, P_plan) memcpy((char *)(cur_stage + n_cur_s), (char *)(cur_stage + n_cur_s - 1), szeof(h_pont)); n_cur_s += 1; POINT_INTER_3D(Q, Q_plan, R, R_plan) POINT_COPY(R) case 4: P and Q nsde, R outsde POINT_INTER_3D(R, R_plan, P, P_plan) POINT_COPY(Q) POINT_INTER_3D(Q, Q_plan, R, R_plan) case 5: P outsde, Q nsde, R outsde POINT_INTER_3D(Q, Q_plan, R, R_plan)

case 6: P nsde, Q and R outsde POINT_INTER_3D(R, R_plan, P, P_plan) memcpy((char *)(cur_stage + n_cur_s), (char *)(cur_stage + n_cur_s - 1), szeof(h_pont)); n_cur_s += 1; case 7: P, Q and R outsde default: * The trangle strp has been clpped aganst all (enabled) clppng * planes. * Copy the result to the output. f (n_cur_s > 2) { for ( = 0; < n_cur_s; ++) out->hponts[] = *(cur_stage[]); out->num_hponts = n_cur_s; else { out->num_hponts = 0; return; Concluson. Ths artcle has presented a dfferent approach to 3D homogeneous clppng of complex prmtves. Most of the partculartes presented here: re-organzaton of the Sutherland-Hodgman algorthm, ntersecton computatons, nonunform clppng volume, etc. can be used n any 3D homogeneous polygon clppng. The performance of the proposed algorthm s better that 89,000 trangles per second for trval acceptance and better than 114,000 trangles per second for trval reect on a Sun-Sparc staton 330, wth the C program gven n the prevous paragraph, for one model clppng plane and trangle strps of 10 or more trangles. The effcency of the clppng algorthm vares wth the number of planes and the number of trangles per trangle-strp. The worst case of the algorthm -one trangle per trangle strp- stll clps at an honorable speed of 32,000+ trangles per second. The specfc case of sngle trangles should be optmzed separately. An mplementaton optmzed for Vew

Clppng 7, 11 and lmted to the clppng aganst unform volumes (boundares have fxed values, -1.0, 0.0, or +1.0) gves also better performances. The method presented here has also been appled n the case of quadrlateral meshes. The clppng operaton s performed one quad-mesh row at a tme, and can generate several quad-mesh rows at the output of the clppng algorthm 11. Because quads are composed of four ponts, the algorthm taes two ponts at a tme, and the core of the clppng process necesstates 16 dfferent cases.

Bblography: 1 Sutherland, I. E, and Hodgman, G. W., 1974. Reentrant Polygon Clppng, CACM, 17 (1), 32-42. 2 Foley, vandam, Fener, Huges, 1990, Computer Graphcs, Prncples and Practce, Addson Welsey 12110. 3 Mallot, P. G., 1986, Contrbuton à l étude des systèmes graphques: archtectures logcelle et matérelle, Ph.D. Thess, Unversty Claude Bernard, Lyon I, Lyon, France. 4 Newman, W.M., and Sproull, R.F., 1979, Prncples of Interactve Computer Graphcs, McGraw Hll. 5 Deerng & al, 1988. The Trangle Processor and Normal Vector Shader, CACM, 22 (4), 21-30. 6 Aeley, K., and Jermolu, T., 1988. Hgh Performance Polygon Renderng, CACM, 22 (4), 239-246. 7 Arvo, J., 1991. More Graphcs Gems, Academc Press. 8 PHIGS standard, 1988, Functonal Descrpton, Internatonal Standard ISO 9592. 9 XGL 2.0, 1991, Reference Manual and Programmers gude, Sun Mcrosystems, Inc. 10 Hübl, J. and Herman, I., 1990. Modellng Clp: Some More Results, Computer Graphcs Forum 9, North Holland, 101-107. 11 Mallot, P.G., 1989. Three Dmensonal Homogeneous Clppng of Trangle Strps and Quadrlateral Meshes, Sun Mcrosystems, Inc. nternal document. 12 Ab-Ezz, S., and Wozny, M.J., 1190. Factorng a Homogeneous Transformaton Ppelne for a more Effcent Graphcs Ppelne, Computer Graphcs Forum 9, North Holland, 245-255.