Interactive 3D Distance Field Computation using Linear ... · et al. 1999; Sigg et al. 2003; ......

9
Interactive 3D Distance Field Computation using Linear Factorization Avneesh Sud Naga Govindaraju Russell Gayle Dinesh Manocha {sud,naga,rgayle,dm}@cs.unc.edu Department of Computer Science University of North Carolina at Chapel Hill http://gamma.cs.unc.edu/gvd/linfac Abstract We present an interactive algorithm to compute discretized 3D Euclidean distance fields. Given a set of piecewise linear geometric primitives, our algorithm computes the distance field for each slice of a uniform spatial grid. We express the non-linear distance function of each primitive as a dot prod- uct of linear factors. The linear terms are efficiently com- puted using texture mapping hardware. We also improve the performance by using culling techniques that reduce the number of distance function evaluations using bounds on Voronoi regions of the primitives. Our algorithm involves no preprocessing and is able to handle complex deforming mod- els at interactive rates. We have implemented our algorithm on a PC with NVIDIA GeForce 7800 GPU and applied it to models composed of thousands of triangles. We demonstrate its application to medial axis approximation and proximity computations between rigid and deformable models. In prac- tice, our algorithm is more accurate and almost one order of magnitude faster as compared to previous distance compu- tation algorithms that use graphics hardware. Keywords: distance field, generalized Voronoi diagram, graphics hardware, texture mapping, collision detection, medial-axis transform 1 Introduction Given a set of geometric primitives, the distance field at a point is the minimum distance from the point to the clos- est primitive. Distance fields are used for shape represen- tation, proximity computations, morphing, boolean opera- tions, path planning, scientific visualization, etc. In this paper, we address the problem of interactive computation of discretized distance field along a uniform grid. The geo- metric primitives may correspond to open or close objects, polygonal models or point primitives. Distance fields are closely related to the concept of Voronoi diagrams. Given a set of primitives, a Voronoi diagram par- titions the space into regions, where each region consists of all points that are closer to one primitive than to any other. Many algorithms have been proposed to compute discretized Voronoi diagrams and distance fields along a grid using graphics rasterization hardware [Woo et al. 1997; Hoff et al. 1999; Sigg et al. 2003; Sud et al. 2004]. These al- gorithms rasterize the distance functions of the geometric primitives and use the depth buffer hardware to compute an approximation of the lower envelope of the distance func- tions. The algorithms for general polygonal primitives ap- proximate the non-linear distance functions using a distance mesh. This can be expensive for complex models and the accuracy of the overall approach is governed by the tessel- lation error. As a result, previous techniques are unable to compute 3D distance fields of complex models at interactive rates. Main Results: In this paper, we present a new algorithm for fast computation of 3D discretized distance fields of a set of convex polygonal primitives using texture mapping hard- ware. Our algorithm computes the distance field on a 2D slice by rasterizing the distance vectors from the points on the slice to the primitives. We present an elegant geometric formulation to represent the distance vectors at any point on a polygon as bilinear interpolation of the distance vectors of the polygon vertices. This linear factorization of distance vectors maps well to the bilinear interpolation capabilities of the texturing hardware. We compute polygons on the 2D slice bounding the Voronoi region for each primitive and express the distance vectors of the polygon vertices using the texture coordinates. We compute the magnitude of the distance vector using a fragment program. We have imple- mented our algorithm on a Pentium IV PC with a NVIDIA GeForce 7800 GTX GPU and use it for medial axis approx- imation and proximity queries between deformable models. We have observed up to one order of magnitude performance improvement over earlier methods. In practice, our algo- rithm is able to compute 3D distance fields of complex mod- els composed of thousands of triangles at interactive rates. Our approach is simple to implement and has many advan- tages: Generality: Our algorithm involves no precomputa- tion and is directly applicable to models undergoing non-rigid motion. Moreover, we do not make any as- sumptions about the shape or mesh topology and our algorithm is applicable to polygon soup models. Accuracy: The linear factorization framework is ro- bust and can compute the distance field up to 32-bit floating point precision on current GPUs. Furthermore, we provide tight bounds on accuracy of the discrete Voronoi diagram. Efficiency: The distance vectors are computed using the bilinear interpolation capabilities of GPUs. As a re- sult, we are able to compute distance fields of complex models consisting of thousands of polygons at interac- tive rates. Organization: The rest of the paper is organized as follows. We describe the related work on distance field computations

Transcript of Interactive 3D Distance Field Computation using Linear ... · et al. 1999; Sigg et al. 2003; ......

Interactive 3D Distance Field Computation using Linear Factorization

Avneesh Sud Naga Govindaraju Russell Gayle Dinesh Manocha

{sud,naga,rgayle,dm}@cs.unc.edu

Department of Computer ScienceUniversity of North Carolina at Chapel Hill

http://gamma.cs.unc.edu/gvd/linfac

Abstract

We present an interactive algorithm to compute discretized3D Euclidean distance fields. Given a set of piecewise lineargeometric primitives, our algorithm computes the distancefield for each slice of a uniform spatial grid. We express thenon-linear distance function of each primitive as a dot prod-uct of linear factors. The linear terms are efficiently com-puted using texture mapping hardware. We also improvethe performance by using culling techniques that reduce thenumber of distance function evaluations using bounds onVoronoi regions of the primitives. Our algorithm involves nopreprocessing and is able to handle complex deforming mod-els at interactive rates. We have implemented our algorithmon a PC with NVIDIA GeForce 7800 GPU and applied it tomodels composed of thousands of triangles. We demonstrateits application to medial axis approximation and proximitycomputations between rigid and deformable models. In prac-tice, our algorithm is more accurate and almost one order ofmagnitude faster as compared to previous distance compu-tation algorithms that use graphics hardware.

Keywords: distance field, generalized Voronoi diagram,graphics hardware, texture mapping, collision detection,medial-axis transform

1 Introduction

Given a set of geometric primitives, the distance field at apoint is the minimum distance from the point to the clos-est primitive. Distance fields are used for shape represen-tation, proximity computations, morphing, boolean opera-tions, path planning, scientific visualization, etc. In thispaper, we address the problem of interactive computationof discretized distance field along a uniform grid. The geo-metric primitives may correspond to open or close objects,polygonal models or point primitives.

Distance fields are closely related to the concept of Voronoidiagrams. Given a set of primitives, a Voronoi diagram par-titions the space into regions, where each region consistsof all points that are closer to one primitive than to anyother. Many algorithms have been proposed to computediscretized Voronoi diagrams and distance fields along a gridusing graphics rasterization hardware [Woo et al. 1997; Hoff

et al. 1999; Sigg et al. 2003; Sud et al. 2004]. These al-gorithms rasterize the distance functions of the geometricprimitives and use the depth buffer hardware to compute anapproximation of the lower envelope of the distance func-tions. The algorithms for general polygonal primitives ap-proximate the non-linear distance functions using a distancemesh. This can be expensive for complex models and theaccuracy of the overall approach is governed by the tessel-lation error. As a result, previous techniques are unable tocompute 3D distance fields of complex models at interactiverates.

Main Results: In this paper, we present a new algorithmfor fast computation of 3D discretized distance fields of a setof convex polygonal primitives using texture mapping hard-ware. Our algorithm computes the distance field on a 2Dslice by rasterizing the distance vectors from the points onthe slice to the primitives. We present an elegant geometricformulation to represent the distance vectors at any point ona polygon as bilinear interpolation of the distance vectors ofthe polygon vertices. This linear factorization of distancevectors maps well to the bilinear interpolation capabilitiesof the texturing hardware. We compute polygons on the2D slice bounding the Voronoi region for each primitive andexpress the distance vectors of the polygon vertices usingthe texture coordinates. We compute the magnitude of thedistance vector using a fragment program. We have imple-mented our algorithm on a Pentium IV PC with a NVIDIAGeForce 7800 GTX GPU and use it for medial axis approx-imation and proximity queries between deformable models.We have observed up to one order of magnitude performanceimprovement over earlier methods. In practice, our algo-rithm is able to compute 3D distance fields of complex mod-els composed of thousands of triangles at interactive rates.

Our approach is simple to implement and has many advan-tages:

Generality: Our algorithm involves no precomputa-tion and is directly applicable to models undergoingnon-rigid motion. Moreover, we do not make any as-sumptions about the shape or mesh topology and ouralgorithm is applicable to polygon soup models.

Accuracy: The linear factorization framework is ro-bust and can compute the distance field up to 32-bitfloating point precision on current GPUs. Furthermore,we provide tight bounds on accuracy of the discreteVoronoi diagram.

Efficiency: The distance vectors are computed usingthe bilinear interpolation capabilities of GPUs. As a re-sult, we are able to compute distance fields of complexmodels consisting of thousands of polygons at interac-tive rates.

Organization: The rest of the paper is organized as follows.We describe the related work on distance field computations

in Section 2. Section 3 gives an overview of linear factoriza-tion and distance vector evaluation. We present conserva-tive bounds on the Voronoi regions of primitives in Section4 and describe our GPU based distance field computationalgorithm in Section 5. We describe its implementation andhighlight its performance on medial axis approximation andproximity queries in Section 6. Finally, we analyze our al-gorithm and compare its performance with prior techniquesin Section 7.

2 Related Work

In this section, we briefly survey prior work on distance fieldcomputations and GPU-based algorithms to evaluate non-linear functions.

2.1 Distance Fields

Distance field algorithms can be broadly classified based onthe model representations such as images, volumes or polyg-onal representations. For an overview of these algorithms,refer to the surveys [Cuisenaire 1999; Aurenhammer 1991].

Algorithms for image-based data sets perform exact or ap-proximate computations in a local neighborhood of the vox-els. Danielsson [1980] used a 2D scanning approach basedon the similarity between neighboring pixels. Sethian [1999]proposed the fast marching method to propagate a contourand compute distance transformations. Exact algorithms forhandling 2-D and k-D images in different metrics have alsobeen proposed [Breu et al. 1995; Maurer et al. 2003].

There is extensive work in computing the exact Voronoi dia-gram of a set of points. A good survey of these algorithms isgiven in [Aurenhammer 1991]. For geometric models repre-sented using polygonal or higher order surfaces in 3D, manyalgorithms compute an approximation to the Voronoi dia-gram by computing distance fields on a uniform grid or anadaptive grid. A key issue is the underlying sampling rateused for adaptive subdivision [Vleugels and Overmars 1998;Teichmann and Teller 1997; Etzion and Rappoport 2002].Many adaptive refinement strategies use trilinear interpola-tion or curvature information to generate an octree spatialdecomposition [Shekhar et al. 1996; Frisken et al. 2000; Perryand Frisken 2001; Varadhan et al. 2003].

The computation of a discrete Voronoi diagram on a uniformgrid can be performed efficiently using parallel algorithmsimplemented on graphics hardware. Hoff et al. [1999] ren-dered a polygonal approximation of the distance function ondepth-buffered graphics hardware and computed the gener-alized Voronoi Diagrams in two and three dimensions. Anefficient extension of the 2-D algorithm for point primitives isproposed in [Denny 2003]. Sud et al. [2004; 2005] presentedan approach for efficiently computing k-D Voronoi diagramsof polygonal primitives by culling primitives which do notcontribute to the final Voronoi diagram within each slice.A class of exact distance computation and collision detec-tion algorithms based on external Voronoi diagrams are de-scribed in [Lin 1993]. A scan-conversion method to computethe 3-D Euclidean distance field in a narrow band aroundmanifold triangle meshes (CSC algorithm) was presented byMauch [2003]. The CSC algorithm uses the connectivity ofthe mesh to compute polyhedral bounding volumes for the

Voronoi cells. The distance function for each site is evalu-ated only for the voxels lying inside this polyhedral boundingvolume. Sigg et al. [2003] described an efficient GPU basedimplementation of the CSC algorithm.

2.2 GPU-Based Non-linear Computations

Many algorithms have been proposed to exploit the pro-grammability features of GPUs to evaluate and render higherorder functions or surfaces. Bolz and Schroder [?] used frag-ment programs to evaluate the Catmull-Clark subdivisionsurfaces. Their approach represented the control points intexture memory and used a fragment program to computebicubic B-spline surfaces. Purcell et al. [2003] presented ray-tracing algorithms by using fragment programs to evaluateray-primitive intersections. Kanai and Yashui [2004] pre-sented an improved algorithm to compute per-pixel normalson subdivision surfaces. Elegant algorithms to directly ren-der curves and parametric surfaces such as NURBS and T-spline surfaces have also been proposed [Guthe et al. 2005;Loop and Blinn 2005; Shiue et al. 2005]. In contrast withthese approaches, our algorithm explicitly decomposes thedistance functions into linear factors and uses bilinear in-terpolation capabilities of the texture mapping hardware toevaluate these functions on a planar domain.

3 Distance Fields

In this section, we give an overview of our approach to com-pute distance fields using texture mapping hardware. Givena collection of convex polygonal primitives, our algorithmcomputes the minimum distance along a 3D grid to thesegeometric primitives. The geometric primitives are classifiedinto points, lines, or triangles and are known as sites. In or-der to compute the distance fields, we define the Euclideandistance functions of these sites. More specifically, the dis-tance function computes the minimum distance of points toa given site. Formally, given a point p and a site oi, thedistance function d(p, oi) = minq∈oi

d(p,q). The distancebetween the points is computed using the Euclidean metric.Given a set of sites P = {o1, o2, . . . , on}, the 3D distancefield at a point p is given by D(p,P) = minoi∈P d(p, oi).

We compute distance fields on a 3D grid of points. The3D distance field is computed by sweeping along the Z axis.For each plane perpendicular to the Z axis, the distancefield is computed using the distance from the sites to theplane [Hoff et al. 1999; Sigg et al. 2003; Sud et al. 2004].The underlying distance function is a degree two function(i.e. a quadric surface in 3D). For example, the Euclideandistance function of a point site to a plane is one sheet of thehyperboloid, and of a line to a plane is an elliptical cone [Hoffet al. 1999].

Given a complex model with tens of thousands of sites, eval-uating the non-linear distance function for each site can beexpensive. Hoff et al. [1999] computed a piece-wise linear ap-proximation of the distance function using a polygonal dis-tance mesh. However, the linear approximation introducestessellation error. Moreover, the overhead of computing thepolygonal approximation can be high for interactive applica-tions. Sigg et al. [2003] used the programmable capabilitiesof GPUs to evaluate the non-linear distance function at eachpoint (or pixel) on the plane. They briefly mention use of

bilinear interpolation, and present an approach which usesseveral instructions per fragment to compute the distancefunction. Detailed comparisons with their approach is pre-sented in Section 7.

Our Approach: In contrast to earlier approaches, we com-pute the distance function for each site by evaluating thedistance vector field on the GPU. A distance vector fieldconsists of vectors from the 3D points to the closest pointon the site. The magnitude of the distance vector providesthe value of the distance function of the site at a grid point.We first present a formulation to compute the distance vec-tor at any point on a planar polygon by using the distancevectors of the polygon vertices to the site. Next, we presenttechniques to compute these planar polygons which bound asite’s Voronoi region on a slice. Finally, we map the problemof distance vector computation to texture mapping hardwareon the GPU.

3.1 Linear Factorization

Figure 1: Distance vector computation: This figure illus-trates the distance vector computation at any point on aplane. The distance vector at an interior point is a bilin-ear interpolant of the distance vectors at the vertices.

We use linear factorization of distance vectors to evaluatethe distance functions. Formally speaking, the linear fac-torization expresses the distance vector at each point insidethe polygon in terms of bilinear interpolation of the distancevectors of the polygon vertices. Given a convex polygon Pwith vertices (v1, . . . , vk), the linear factorization expressesthe distance vector at any interior point p of the polygon as

~d(p, oi) =

kX

i=1

αi~d(vi, oi),

where

p =k

X

i=

αivi, 0 ≤ αi ≤ 1 andk

X

i=1

αi = 1.

We present three key properties of distance vector computa-tion at a point on a plane to point sites, line segment sites,and triangular sites. These properties are used to evaluatethe distance functions efficiently. We first highlight the prop-erty to perform linear factorization of the distance vector ofa point on a line to a point site.

Property 1. Given two points a and b on a plane and a

point site p. Let ~da and ~db denote the distance vectors of a

and b to p respectively. Then, the distance vector ~dx of anypoint x = αa+(1−α)b,0 ≤ α ≤ 1 is the linear combination

of distance vectors of a and b, and ~dx = α ~da + (1− α) ~db.

Property 1 indicates that given the distance vectors of thevertices of any planar primitive to a point site, the distancevector of any interior point can be computed using a bilinearinterpolation of the distance vectors of vertices.

The distance vector of a point x that projects orthogonallyto the interior of a line segment is a vector perpendicularto the line. We use the following property to perform linearfactorization of the distance vector of a point that projectsonto a line segment.Property 2. Given two points a and b on a plane and a

line segment l with end points e and f . Let ~da = e− a and~db = f − b denote the distance vectors of a and b to the

site l respectively. Then, the distance vector ~dx of any pointx = αa + (1 − α)b,0 ≤ α ≤ 1 is the linear combination of

distance vectors of a and b, and ~dx = α ~da + (1− α) ~db.

We use property 2 to compute the distance vector of anypoint that projects onto l. This property indicates that giventhe vertices of a convex polygon whose projection lies withinl, the distance vector of any interior point in the convexpolygon is the bilinear interpolation of the distance vectorsof the convex polygon vertices to l.

We extend Property 1 and Property 2 to compute the dis-tance vector of a point x that projects interior to a triangu-lar site. It can be seen that the distance vector of x is thenormal to the triangle.

Property 3. Given three points a, b and c on a plane and

a triangular site t with vertices e, f and g. Let ~da = e− a,~db = f−b and ~dc = g−c denote the distance vectors of a, b

and c to the site t respectively. Then, the distance vector ~dx

of any point x = α1a+α2b+(1−α1−α2)b,0 ≤ α1, α2 ≤ 1is the linear combination of distance vectors of a,b, and c

and ~dx = α1~da + α2

~db + (1− α1 − α2) ~dc.

Property 3 indicates that given the vertices of a convex poly-gon projecting onto t, the distance vector of any interiorpoint is the bilinear interpolation of the distance vectors ofthe polygon vertices. Furthermore, the distance vectors ofthe polygon vertices are normal to the triangular site.Lemma 1. There exists a linear factorization to computethe distance vector of any point to a planar site.

Proof. Trivial. Based on properties 1, 2, and 3.

4 Domain Computation

In the previous section we showed that the distance vectorfrom a point in the interior of a convex polygon to a sitecan be expressed as a bilinear interpolant of the distancevectors at the polygon vertices. In this section, we define theconvex domain on a slice for which the distance function ofa site is computed. We also present an approach to computeconservative bounds on the domain.

The region where the distance function of a site contributesto the distance field is exactly its Voronoi region. However,it is non-trivial to compute the exact Voronoi regions forhigher order sites (i.e. lines, polygons) [Culver et al. 1998].Moreover, the Voronoi regions are not necessarily convex.Instead of computing the exact Voronoi region, we compute aconvex polygonal domain Qi,k on the slice sk, which boundsthe intersection of the Voronoi region of site oi with slice sk.

We present separate algorithms for manifold and non-manifold sites. We first present an algorithm to compute theQi,k for non-manifold sites. Later, we present an improvedalgorithm for manifold sites that exploits the connectivity tocompute tighter convex polygonal domain.

Non-Manifold Sites We present the algorithm for a trian-gle and it can be easily extended to a convex polygon. For atriangle tj with vertices p1, p2, p3 and unit normal nt, con-sider the three (open) half-spaces given by planes throughthe three edges and perpendicular to the plane of the trian-gle. The half-spaces are given as Hi = (x− pi) · ni ≥ 0, i ∈{1, 2, 3}, where ni satisfies (pi − pi+1) · ni = 0,nt · ni = 0.Any point in the intersection of these halfspaces is closer tothe interior of the triangle, and any point not contained inthe intersection H1 ∩H2 ∩H3 is closer to one of the sites onthe boundary of the triangle. The convex polygonal domainQj,k is the intersection of the three half-spaces with slice sk.

Given a line segment ej with end points p1 and p2, considerthe two (open) halfspaces defined by planes perpendicular tothe line through the end points, H1 = (p2−p1)·(x−p1) > 0and H2 = (p1 − p2) · (x − p2) > 0. Any point x in theintersection of the two half spaces is closer to the interior ofthe line segment e, and a point not in the intersection will becloser to one of the end points. Thus, the convex polygonaldomain Qj,k is the intersection of the two half spaces H1, H2

with the slice sk.

Finally, given a point pj, the domain Qj,k is the entire slicesk.

Manifold Sites For a manifold site, we exploit the neigh-borhood information to compute a convex polytope Gi whichbounds the Voronoi region of a site oi [Culver 2000; Mauch2003; Sigg et al. 2003]. For a particular slice sk, the domainof computation of a site oi is given by the intersection of thepolytope with the slice, Qi,k = Gi ∩ sk. For a triangle site,the bounding polytope is given by a triangular prism definedby intersection of three half spaces (as described above).

For an edge e incident on two triangles with normals n1,n2, the convex polytope is a wedge obtained by the inter-section of four half-spaces. Two of the half-spaces are de-fined by parallel planes through the end vertices of the edgeas shown above. The other two half-spaces are defined byplanes containing the edge e and have normals n1 and n2.

For a point site p, with n incident edges e1, . . . , en, the poly-tope Gp is given by intersection of half-spaces correspondingto planes through the point q and orthogonal to each inci-dent edge ei, i.e. Gp =

T

1≤i≤nHi, Hi = (x−p) ·ei ≥ 0. In-

stead of exactly computing the half-space intersection, withtime complexity O(n log n), we present a simple algorithmto compute a conservative approximation of the boundingpolytope Gp for a point site p in O(n) time.

A point site is defined as convex iff all edges incident on thepoint have an internal dihedral angle less than π. Let p bea convex point, with incident edges ei, 1 ≤ i ≤ n in order.

Then edges of the convex polytope Gp are given by p+λni,where ni = ei×ei+1 (modulo n) and ni is the normal of thetriangle ti containing edges ei and ei+1.

This construction does not work for hyperbolic points [Peik-ert and Sigg 2005]. Previous approaches expand the bound-ing polytopes of adjacent triangles to handle hyperbolicpoints, however this results in a complex fragment programto compute the distance functions [Sigg et al. 2003]. Wepresent an efficient algorithm to compute a bounding poly-tope Gp for a hyperbolic point p (see figure 2(a)). Let na bethe average of the normals of all incident triangles. Let nj

be the normal which maximizes θ(i) = na×ni

|na×ni|, i = 1, . . . , n.

We consider the case when θ(i) < π/2. Let C be a rightcircular cone with axis na and opening angle 2θ(j). We nowprove that the bounding polytope Gp is a subset of cone C.

Theorem 1. Let p be a manifold point, and C be a coneconstructed as above. Then the convex polytope Gp boundingthe Voronoi region of p is a subset of C.

Proof. If Gp = ∅, then the result trivially holds. It is suffi-cient to show that Gp ∩ πk ⊆ C ∩ πk for any plane πk. Con-sider a plane π orthogonal to na, and let Q be the convexpolygon obtained by intersection of Gp with π, Q = Gp ∩π.Let xi be the intersection of the ray from p along directionni. Gp ∩ π is the convex region given by the intersection of2D half spaces, each half space is given by the line throughxi and xi+1 (modulo n) (see figure 2(b)). For any pointy ∈ π, let r = maxi=1,...,n d(xi,y). By construction, a circlec with center y and radius r will contain Q. Taking y = xa,we get c = C ∩ π and Gp ⊆ C.

Figure 2: Bounding polytope computation for a hyperbolicpoint: p is hyperbolic point with 5 incident edges ei, i =1, . . . , 5. (a) The polytope Gp bounds the Voronoi region ofp. Gp is bounded by a cone C. (b) Intersection of Gp withplane π, showing construction of C.

Theorem 1 implies that any convex polytope containing thecone C will bound the bounding polytope Gp of a hyper-bolic point p. We use a square pyramid to approximate thebounding polytope as shown in figure. If θ(i) ≥ π/2, thenwe treat the hyperbolic point as non-manifold.

5 Distance Field Computation using GPUs

In this section, we present our algorithm for distance com-putation on the GPU using linear factorization. Given asite and a slice, the convex domain is computed as described

in Section 4. The distance vector to the site is computedat each vertex of the convex polygon. The distance vectoris encoded as a 3D texture coordinate, and the polygon israsterized on the GPU.

Graphics processors (GPUs) have many specialized hard-ware units to perform bilinear interpolation on the attributesof vertices of polygons. These vertex attributes consistof the color, position, normal, or texture co-ordinates ofthe vertices. These attributes are 4-D vectors of the form(vx, vy, vz, vw) and transformations are applied to the at-tributes in the vertex processing unit. The transformed ver-tices are bilinearly interpolated by the rasterization hard-ware and the interpolated vectors at each fragment are usedfor lighting computations using Gouraud or Phong shading,or environment mapping applications. In order to achievehigher performance, the rasterization hardware consists ofmultiple vector units to compute the interpolated vectors.

We use the fast bilinear interpolation capabilities of GPUsfor distance vector computation. Based on the linear fac-torization formulation, we map the distance vector compu-tation to the GPUs using vertex attributes of the polygons.We use orthographic transformations and perform a one-to-one mapping between the points on the plane and thepixels on the screen. The bilinear interpolation of the vertexattributes is used for distance vector computation at eachpoint on the plane.

The interpolation units in current GPUs can perform compu-tations on different vector representations. For example, thevectors can be represented using 8-bit, 16-bit or 32-bit float-ing point values and the vector components may be signed orunsigned. Since the components of the distance vectors aresigned and represented in 32-bit floating point precision, weuse the 3D texture co-ordinates of the vertices to representthe distance vectors of vertices. The interpolated texture co-ordinates are used in a single instruction fragment programto compute the magnitude of the distance vector. The dis-tance field is updated to compute the minimum either usingthe MIN instruction in the fragment program or by usingthe depth test functionality.

We now present the expressions for computing the distancevectors from a convex polygon vertex to a point, an edgeand a triangle. These are:

Point: Given a point site p and a vertex v, the distance

vector from v to p is ~d(p,v) = p− v.

Edge: For an edge e with end points p1 and p2, the

distance vector from a vertex v to e is ~d(e,v) = (p1−

v) + λ (p2−p1)|p2−p1|

, where λ = (v−p1)·(p2−p1)|p2−p1|

.

Triangle: Given a triangle t with a unit normal n,the distance vector from a vertex v to t is given as~d(t,v) = [(pi − v) · n] n, where pi is one of the threevertices of the t.

The pseudocode for computing the distance field for aslice sk is presented in Algorithm 1. The functionComputePolygon(oi,sk) computes the convex polygonal do-main bounding the Voronoi region of site oi on slice sk.

The algorithm for computing the distance field in the en-tire domain M is presented in Algorithm 2. The functionSetOrthoProjection(M) sets up the projection matrix to bethe bounds of the (axis-aligned) domain of computation M .NormProgram() is a single instruction fragment program

Input: slice sk, site set POutput: distance field D(sk,P)

foreach site oi ∈ P doQi,k ← ComputePolygon(oi, sk)foreach vertex v ∈ Qi,k do

Compute distance vector ~d(oi,v)Assign texture coordinates of v,

(r, s, t)← ~d(oi,v)endDraw textured polygon Qi,k at depth z = 0

end

Algorithm 1: ComputeSlice(sk, P): This algorithmcomputes the distance field for sk for a set of primi-tives P

that computes the Euclidean norm of the 3D texture co-ordinate at a pixel and writes it out the value to the depthbuffer. The functions StartSlice(sk) and EndSlice(sk) setupthe rendering state at the beginning and end of computationof a given slice sk. The state setup involves enabling a float-ing point rendering buffer, clearing the buffer and reading itback to the CPU after computation.

Input: site set P, domain M , number of slices mOutput: distance field D(M,P)

Enable depth testSet depth test function to less thanSetOrthoProjection (M)Enable fragment program NormProgramforeach slice sk, k = 1, . . . , m do

StartSlice (sk)ComputeSlice (sk,P)EndSlice (sk)

endDisable fragment program NormProgram

Algorithm 2: Compute3D(P, M , m): Computesthe 3D discretized distance field on a uniform gridM with m slices.

6 Implementation and Applications

In this section, we describe our implementation and highlightits application to medial axis approximation and proximityqueries between deformable models.

6.1 Implementation

We have implemented our algorithm on a PC with a 3.2GHz Pentium IV CPU with 2 GB memorywith an NVIDIAGeForce 7800 GPU connected via 16x PCI Express bus andrunning Windows XP operating system. We used OpenGLas the graphics API and used ARB fragment program forimplementing the fragment program. The fragment programis used to compute the magnitude of the distance vector.We computed the distance field using a tiled render texturewith 32-bit floating point precision. Our run-time algorithmcomputed the distance vectors for the vertices of the con-vex polygon associated with each site. The polygons arerasterized onto the rendertexture. We incorporated the op-timizations to improve the performance of our algorithm on

Model Polygon Distance Field HAVOC Lin.Fac.

Count Resolution Time (in sec) Time (in sec)

Triceratops 5.6K 256× 112× 84 3.87 0.768Head 22K 78× 105× 128 17.47 0.846

Gargoyle 11K 256× 103× 91 10.2 0.625Bunny 1.5K 256× 252× 196 4.8 0.772

Shell Charge 4.5K 126× 128× 126 2.8 0.276

Table 1: This table highlights the performance of our algorithm (Lin.Fac.) andHAVOC [Hoff et al. 1999] on different polygonal models. We observe 5 − 10times speedup times on a Pentium IV PC with NVIDIA GeForce 7800 GPU.

Figure 3: Separation Distance Computationbetween deforming bunnies: Average querytime=120ms, grid resolution= 2563.

manifold objects. There are no precomputations and the al-gorithm is directly applicable to deforming models and dy-namic environments. The performance of our system variesas a function of model complexity and grid resolution.

Our approach takes a fraction of a second to compute thedistance field of a model with thousands of polygons on a256 × 256 × 256 grid. The performance of our algorithmto compute the global distance field for various models ishighlighted in Table 1. We analyzed our implementation us-ing Intel’s vTune benchmarking software. The time spenton computation of the bounding convex polygons was ap-proximately 12% of the total time. The observed maximumnumber of triangles sent to GPU was 3MTris/s; maximumnumber of pixels rendered was 1.6Gpixels/s and estimatedmemory bandwidth achieved was 26GB/s.

6.2 Proximity Computation

We have applied our algorithm to compute proximity in-formation among deformable models. These include differ-ent proximity queries including collision detection, separa-tion distance and penetration depth estimation, and contactnormals computation. The penetration distance is definedas the minimum translation distance required to separatetwo overlapping objects. We first compute the distance fieldin the localized region of overlap between two oriented ob-jects, O1 and O2. Next, we use the stencil test to computethe points on O1 interior to O2. These computations areperformed on each slice of the distance field, and the maxi-mum stored value at these interior points on the slices of thedistance field is used to approximate the penetration depth.This test is repeated by swapping O1 and O2. The separa-tion distance between two objects is the minimum Euclideandistance from the points on one object to the other object.Given two objects, we first compute the closest point P1 onO1 using the distance field of O2, and the closest point P2

on O2 by using the distance field of O1. Our algorithm com-putes the separation distance as the distance between P1 andP2.

Our overall proximity computation algorithm is based onPIVOT [Hoff et al. 2001] that uses a combination of objectspace location and distance field computation along a grid.We compute the collision response between the overlappingobjects based on a constraint-based approach.

We used our algorithm for interactive proximity query on asequence of deforming bunnies as shown in Figure C.1 (colorplate). Each bunny consists of 2K triangles and undergoesdeformation based on a mass-spring system. At each frame,we perform proximity queries using a grid resolution of 2563.The distance computation is only performed on the localized

regions computed using bounding box of each bunny. Theaverage time to perform each proximity query is 120ms. Ascompared to HAVOC and PIVOT [Hoff et al. 2001], our newdistance computation algorithm results in a speedup of 7−12times (as shown in Figure 4).

6.3 Medial Axis Approximation

We use discretized distance fields to compute an approxi-mate medial axis. Given the polygonal boundary of a solidmodel, we compute the distance field and its gradient, anduse them to extract the simplified medial axis [Foskey et al.2003]. Our algorithm computes a neighbor direction field ofthe object and applies a user-specified separation angle cri-terion. The separation angle criterion acts like a low-passfilter and is used to eliminate noisy features in the medialaxis. Our algorithm traverses through the voxels and usesthe neighbor direction field to decide which voxels lie on themedial axis. The selection operation is also performed us-ing a fragment program and the gradient field is stored inthe texture memory. In Figure C.2 (color plate), we demon-strate an application of our algorithm to compute the ap-proximate medial axis of the Gargoyle model with 11K tri-angles on a 256 × 103 × 91 grid. Moreover, we observed 16times speedup over HAVOC-based medial axis approxima-tion algorithm [Foskey et al. 2003].

7 Comparison and Limitations

We have used our algorithm to compute distance fields ofcomplex models consisting of thousands of polygons. Ouralgorithm is able to compute 3D discretized fields at inter-active rates (i.e. 3− 12 frames per second) for 2563 grid oncomplex models. Our initial benchmarks indicate that ouralgorithm is almost one order of magnitude faster as com-pared to earlier algorithms including HAVOC [Hoff et al.1999], DiFi [Sud et al. 2004] We present qualitative compar-isons with HAVOC and DiFi, and and GPU-based imple-mentation of CSC algorithm [Sigg et al. 2003].

HAVOC and DiFi: These approaches compute a polyg-onal approximation of the non-linear distance function ofeach site. For large models, the distance mesh approxima-tion step becomes a bottleneck. Furthermore, all the trian-gles are sent from the CPU to the GPU during each framefor rasterization. In contrast, our algorithm only computesthe distance vector at the vertices of the convex polygonsand uses the bilinear interpolation capabilities of the tex-ture mapping hardware. Our distance computation algo-rithm has much lower CPU-GPU bandwidth requirementsas we only transmit the distance vectors at the vertices of

0 100 200 300 400 5000

500

1000

1500

2000

Frame

Tim

e (

ms

)HAVOC

FeLine

Figure 4: This graph compares the performance of ouralgorithm (Lin.Fac.) with HAVOC [Hoff et al. 1999] forproximity computation. We observe a speedup of 7-12times on the deforming bunny simulation.

101

102

103

104

10−2

10−1

100

101

102

log(Resolution)

log

(tim

e)

Figure 5: This log-log graph demonstrates the perfor-mance of our distance computation algorithm as a func-tion of grid resolution. As the grid resolution increases,the running time is nearly a linear function.

Figure 6: Improved accuracy of our algorithm: This figurehighlights the error in computing the distance field and dis-crete Voronoi diagram using (a) HAVOC and (b) our algo-rithm. The exact Voronoi boundary is indicated by the dottedblue line. HAVOC introduces tessellation error due to poly-gonization of distance functions.

the convex polygon of each site. Our bounds on the con-vex polygonal domain also reduce the fill overhead duringrasterization.

GPU-based CSC algorithm: Sigg et al. [2003] also men-tioned the idea of using bilinear interpolation and dot prod-ucts. However, they do not provide any details on theirderivation or implementation. Instead they present an ap-proach which reduces the number of polyhedra that are scanconverted. The fragment program used by [Sigg et al. 2003]is more complex and increases the load on the fragmentprocessor. Moreover, Sigg et al.’s algorithm is restrictedto inputs that are closed manifolds. Further, it does notprovide the complete generalized Voronoi diagram. Overall,their approach is useful for very highly tessellated modelsand distance field computations with low-grid resolutionsand narrow band sizes. In these cases, each polyhedron canbecome smaller than a few voxels. The polygon transformcan become a bottleneck, and reducing number of polyhedrascan-converted provides speedups.

In contrast, we provide a formal presentation of the linearfactorization and the necessary details to implement it. Ouralgorithm is applicable to general polygonal models. Fur-thermore, our approach computes a pixel accurate discretegeneralized Voronoi diagram (as demonstrated in Figure 6).Our fragment program is much simpler. For large grid reso-lutions and global computations, the distance computation

on the fragment processor becomes the bottleneck and ourapproach is more efficient that [Sigg et al. 2003]. This hasbeen verified by our benchmarks. The cost of slicing thepolyhedra is small and the observed triangle transfer ratesare significantly less than the theoretical peak. Further, ourapproach makes efficient use of the fragment processor.

Limitations: Our approach has some limitations. Firstly,the accuracy of the algorithm is governed by that of thegraphics hardware. For example, the current hardware pro-vides support for 32-bit floating point representation and it isnot fully compatible with the IEEE floating-point standard.Secondly, our algorithm involves a readback from the GPUback to the CPU, which can have additional overhead forhigh resolution distance fields. Our algorithm is only usefulfor computing discretized distance fields and the resulting al-gorithms for proximity queries and medial-axis computationonly perform approximate computations (up to grid reso-lution). For narrow bands, and highly tessellated models,polygon transformation can become a bottleneck.

8 Conclusions and Future Work

We present a new algorithm to compute discretized 3D dis-tance fields for polygonal models. Our algorithm decom-poses the distance function of each primitive into linear fac-tors and evaluates the linear terms using bilinear interpo-lation capabilities of texture mapping hardware. We alsopresent techniques to bound the Voronoi region of each prim-itive and evaluate the distance field within the bounded re-gion. The accuracy of our algorithm is governed by thatof the bilinear interpolation hardware, i.e. 32-bit floatingpoint on current GPUs. In practice, our algorithm is ableto compute distance fields of models composed of thousandsof polygons at 3 − 10 frames a second on a 2563 grid. Wehave used distance field computation for collision and pen-etration depth computation and medial axis approximationof deforming models.

There are many avenues for future work. Our current workis limited to Euclidean distance functions and it would beuseful to extend it to other distance metrics, (e.g. Lk norm).We would like to incorporate other culling techniques that

utilize spatial coherence between successive slices to computethe bounding regions for each site. The linear factorizationbased formulation could also be extended to higher orderprimitives including splines or algebraic surfaces. More-over, we would like to perform distance field computationon adaptive grids and use our algorithm for other applica-tions including morphing, motion planning and navigation,and simulation.

Acknowledgments

This research is supported in part by ARO Contract DAAD19-02-1-0390, and W911NF-04-1-0088, NSF Awards0400134, 0118743, DARPA and RDECOM ContractN61339-04-C-0043 and Intel Corporation. We thank theUNC GAMMA group for many useful discussions andsupport. We are also grateful to the reviewers for theirfeedback.

References

Aurenhammer, F. 1991. Voronoi diagrams: A survey of a fundamental

geometric data structure. ACM Comput. Surv. 23, 3 (Sept.), 345–

405.

Bolz, J., Farmer, I., Grinspun, E., and Schroder, P. 2003. Sparse ma-

trix solvers on the gpu: Conjugate gradients and multigrid. ACM

Trans. on Graphics (Proc. of ACM SIGGRAPH) 22, 3.

Breu, H., Gil, J., Kirkpatrick, D., and Werman, M. 1995. Lin-

ear time Euclidean distance transform and Voronoi diagram algo-

rithms. IEEE Trans. Pattern Anal. Mach. Intell. 17 , 529–533.

Cuisenaire, O. 1999. Distance Transformations: Fast Algorithms

and Applications to Medical Image Processing. PhD thesis, Uni-

versite Catholique de Louvain.

Culver, T., Keyser, J., and Manocha, D. 1998. Accurate compu-

tation of the medial axis of a polyhedron. Tech. Rep. TR98-034,

Department of Computer Science, University of North Carolina.

Appeared in Proceedings of ACM Solid Modeling 99.

Culver, T. 2000. Accurate Computation of the Medial Axis of a

Polyhedron. PhD thesis, Department of Computer Science, Uni-

versity of North Carolina at Chapel Hill.

Danielsson, P. E. 1980. Euclidean distance mapping. Computer

Graphics and Image Processing 14 , 227–248.

Denny, M. 2003. Solving geometric optimization problems using

graphics hardware. Computer Graphics Forum 22, 3.

Etzion, M., and Rappoport, A. 2002. Computing Voronoi skeletons of

a 3-d polyhedron by space subdivision. Computational Geometry:

Theory and Applications 21, 3 (March), 87–120.

Foskey, M., Lin, M., and Manocha, D. 2003. Efficient computation of

a simplified medial axis. Proc. of ACM Solid Modeling, 96–107.

Frisken, S., Perry, R., Rockwood, A., and Jones, R. 2000. Adap-

tively sampled distance fields: A general representation of shapes

for computer graphics. In Proc. of ACM SIGGRAPH, 249–254.

Guthe, M., Balazs, A., and Klein, R. 2005. Gpu-based trimming and

tessellation of nurbs and t-spline surfaces. ACM Trans. Graph.

24, 3, 1016–1023.

Hoff, III, K. E., Culver, T., Keyser, J., Lin, M., and Manocha, D.

1999. Fast computation of generalized Voronoi diagrams using

graphics hardware. In Computer Graphics Annual Conference

Series (SIGGRAPH ’99), 277–286.

Hoff, K., Zaferakis, A., Lin, M., and Manocha, D. 2001. Fast and

simple 2d geometric proximity queries using graphics hardware.

Proc. of ACM Symposium on Interactive 3D Graphics, 145–148.

Kanai, T., and Yasui, Y. 2004. Per-pixel evaluation of parametric

surfaces on gpu. ACM Workshop on General Purpose Computing

on Graphics Processors.

Lin, M. 1993. Efficient Collision Detection for Animation and

Robotics. PhD thesis, Department of Electrical Engineering and

Computer Science, University of California, Berkeley.

Loop, C., and Blinn, J. 2005. Resolution independent curve rendering

using programmable graphics hardware. ACM Trans. Graph. 24,

3, 1000–1009.

Mauch, S. 2003. Efficient Algorithms for Solving Static Hamilton-

Jacobi Equations. PhD thesis, Californa Institute of Technology.

Maurer, C., Qi, R., and Raghavan, V. 2003. A linear time algorithm

for computing exact euclidean distance transforms of binary images

in arbitary dimensions. IEEE Transactions on Pattern Analysis

and Machine Intelligence 25, 2 (February), 265–270.

Peikert, R., and Sigg, C. 2005. Optimized bounding polyhedra for

gpu-based distance transform. In Proceedings of Dagstuhl Seminar

os Scientific Visualization.

Perry, R., and Frisken, S. 2001. Kizamu: A system for sculpting

digital characters. In Proc. of ACM SIGGRAPH, 47–56.

Purcell, T., Donner, C., Cammarano, M., Jensen, H., and Hanra-

han, P. 2003. Photon mapping on programmable graphics hard-

ware. ACM SIGGRAPH/Eurographics Conference on Graphics

Hardware, 41–50.

Sethian, J. A. 1999. Level set methods and fast marching methods.

Cambridge.

Shekhar, R., Fayyad, E., Yagel, R., and Cornhill, F. 1996. Octree-

based decimation of marching cubes surfaces. Proc. of IEEE Vi-

sualization, 335–342.

Shiue, L.-J., Jones, I., and Peters, J. 2005. A realtime gpu subdivision

kernel. ACM Trans. Graph. 24, 3, 1010–1015.

Sigg, C., Peikert, R., and Gross, M. 2003. Signed distance transform

using graphics hardware. In Proceedings of IEEE Visualization.

Sud, A., Otaduy, M. A., and Manocha, D. 2004. DiFi: Fast 3D

distance field computation using graphics hardware. Computer

Graphics Forum (Proc. Eurographics) 23, 3, 557–566.

Sud, A., Govindaraju, N., and Manocha, D. 2005. Interactive compu-

tation of discrete generalized voronoi diagrams using range culling.

In Proc. International Symposium on Voronoi Diagrams in Sci-

ence and Engineering.

Teichmann, M., and Teller, S. 1997. Polygonal approximation of

Voronoi diagrams of a set of triangles in three dimensions. Tech.

Rep. 766, Laboratory of Computer Science, MIT.

Varadhan, G., Krishnan, S., Kim, Y., and Manocha, D. 2003. Feature-

sensitive subdivision and isosurface reconstruction. Proc. of IEEE

Visualization.

Vleugels, J., and Overmars, M. H. 1998. Approximating Voronoi

diagrams of convex sites in any dimension. International Journal

of Computational Geometry and Applications 8 , 201–222.

Woo, M., Neider, J., and Davis, T. 1997. OpenGL Programming

Guide, Second Edition. Addison Wesley.

Figure C.1: Proximity Computations on Deforming Models: We use our interactive distance field computation for separationand penetration distance for dynamic simulation of deforming bunnies. Each bunny consists of 2K triangles and we computelocalized distance fields on a 2563 grid for the simulation shown in this sequence. The average distance field and proximityquery takes 120ms on a 3.2 GHz Pentium IV PC with NVIDIA GeForce 7800 GPU.

Figure C.2: Medial Axis Approximation: The left image shows the11K Gargoyle model. The right image shows its simplified medial axisusing our distance field algorithm. We use a grid of size 256×103×91and the distance field computation takes around 625 ms on a 3.2 GHzPentium IV PC with an NVIDIA GeForce 7800 GPU.

Figure C.3: Contact Normal Computation for de-forming bunnies: The average query takes 120mson a 3.2GHz Pentium IV PC with NVIDIAGeForce 7800 GPU.