Difi: Fast Distance Field Computation Using Graphics Hardware
Total Page:16
File Type:pdf, Size:1020Kb
DiFi: Fast Distance Field Computation using Graphics Hardware Avneesh Sud Dinesh Manocha Department of Computer Science Univeristy of North Carolina Chapel Hill, NC 27599-3175 {sud,dm}@cs.unc.edu http://gamma.cs.unc.edu/DiFi Abstract Most practically efficient methods for computing the dis- tance fields in 2− or 3−space compute the distance field We present a novel algorithm for fast computation of dis- on a discrete grid. Essentially the methods fall into 2 cat- cretized distance fields using graphics hardware. Given a egories: methods based on front propagation and methods set of primitives and a distance metric, our algorithm com- based on Voronoi regions. putes the distance field along each slice of a uniform spatial Main Contributions: In this paper we present an ap- grid by rasterizing the distance functions. It uses bounds proach that computes discrete approximations of the 3D dis- on the spatial extent of Voronoi regions of each primitive as tance field and its application to medial axis computation well as spatial coherence between adjacent slices to cull the using the graphics hardware. Our contributions include: primitives. As a result, it can significantly reduce the load on the graphics pipeline. We have applied this technique 1. A novel site culling algorithm that uses Voronoi region to compute the Voronoi regions of large models composed properties to accelerate 3D distance field computation of tens of thousands of primitives. For a given grid size, 2. A technique for reducing the fill per slice using con- the culling efficiency increases with the model complexity. servative bounds on the Voronoi regions To demonstrate this technique, we compute the medial axis transform of a polyhedral model. In practice, we are able 3. Formulation of a distance field application as a SIMD to obtain up to one order of magnitude improvement over process that is efficiently computed on modern graph- earlier algorithms that compute the distance fields using ics hardware. graphics hardware. The algorithm has been implemented and applied to in- put models consisting of tens or hundreds of thousands of Keywords: distance fields, graphics hardware, Voronoi re- triangles. The running time on a 2.5GHz PC with an nVidia gions, proximity computations, fragment programs GeForce FX 5800 Ultra graphics card ranges from a second for small models to tens of seconds for huge models. Our 1 Introduction approach improves on the state-of-art in following ways: Given a set of geometric objects, a distance field is de- • Generality: No assumption is made with regards to in- fined at each point by the smallest distance from the point put set. The input models can be non-orientable, non- to one of the objects. Distance Fields have been used in a manifold surfaces. number of applications including implicit surface represen- • Efficiency: We show our approach is significantly tation, proximity queries, spatial data manipulation, shape faster than previous approaches. The culling tech- analysis, path planning, skeletonization, pattern recognition niques provide us with a 4 − 20 times speedup in dis- and local optimization. The problem of computing a dis- tance field computation over previous approaches that tance field is closely related to the problem of computing a can handle generic models. The GPU based computa- Voronoi diagram. Once the voronoi diagram is computed, tion of the medial axis is 2 − 75 times faster than the the distance field can easily be computed as the distance to CPU based implementation. the respective site. For higher order objects, such as lines and triangles, one needs to compute a generalized voronoi • Scalability: The performance gain increases as the diagram. model size increases. 2 Related Work uses precomputed depth textures, and uses a quadtree to es- timate voronoi region bounds. However, extensions of this The problem of computing a distance field can be approach to higher-order sites and dimensions are not ex- broadly classified by the type of input object representation. plained. The object can be given either as a data on a voxel grid, such Another scan-conversion method to compute 3-D Eu- as a binary image or as an explicit surface representation, clidean distance fields upto a maximum distance d for mani- such as a triangle mesh. fold triangle meshes is the Characteristics/Scan-Conversion (CSC) algorithm presented by Sean Mauch [20]. It uses 2.1 Voxel Data based methods the connectivity of the manifold mesh to compute polyhe- dral bounding volumes for the Voronoi cells. The distance function for each site is then evaluated only for the voxels Methods to compute the distance transform of voxel data lying inside this polyhedral bounding volume. An efficient can be approximate or exact. Approximate methods con- GPU based implementation of the CSC algorithm is pre- sider distance transformations in a local neighborhood of sented in [29]. The number of polygons sent to the graphics each voxel. Danielsson [4] uses a scanning approach in pipeline is reduced by expanding some polyhedral bounding 2D based on the assumption that the nearest object pixels volumes. Also the general purpose computation capability for adjacent pixels are similar. The Fast Marching Method of modern GPUs is used to compute the non-linear distance (FMM)[28] propogates a contour to compute the distance functions using fragment programs. A more detailed com- transformation from the neighbors. This provides an ap- parison with these approaches is presnted in Section 6.2.1. proximate finite difference solution to the Eikonal Equation |∇u| = 1/f. Repeated application of the local masks of the approx- 2.3 Geometric Computations on the GPU imate algorithms till a stable solution is reached provides exact distance transforms. A parallel algorithm for this is proposed in [31]. Efficient implementations of this store Apart from distance fields, graphics hardware has been a propogation front in dynamic lists [7, 25]. Propogation increasingly utilized to accelerate a number of geometric methods can be augmented by storing additional informa- computations, including visualization of constructive solid tion like direction vectors to nearest voxel [22] and clos- geometry models [9, 27], interferences and cross-sections est features [13]. Propogating additional information along [1, 23, 26], Minkowski sums [14, 15], and applications like with the FMM, leads to an exact distance transform algo- cloth animation [30] and virtual surgery [18]. rithm [2]. Another class of exact distance transform algo- In recent years, the performance of graphics hardware rithms are based on computing partial voronoi diagrams and has increased more rapidly than that of CPUs. Moreover, dimensionality reduction. A linear time algorithm for com- graphics hardware has evolved from a fixed-function ren- puting Euclidean distance transform os a 2-D binary image dering pipeline to a pipeline with programmable vertex and is presented in [3]. This is extended to segment lists in [11] fragment stages with support for upto full IEEE single- and k-D images and further distance metrics in [21]. precision floating point. Programmable graphics hardware is optimized for highly-parallel code [17]. Purcell et al. 2.2 Surface Representation based methods [24] argue that current GPUs can be modeled as parallel stream processors highly optimized for some SIMD appli- cations. This has led to considerable research in develop- A family of methods determines the distance field for ing algorithms for efficient general purpose computation us- models represented by polygonal surfaces. The work by ing graphics hardware [10], including 3-D level set solvers scan-converting a number of geometric primitives related to [16]. the polygonal surface and conditionally overwriting com- puted distance value at each voxel. Any polygonal model can be decomposed into a collection of point (vertices), line 3 Overview segments (edges) and triangular (faces) sites. Hoff et al. [12] use graphics hardware to render a polyg- onal approximation of the distance field and compute Gen- In this section, we present the basic concepts important eralized Voronoi Diagrams in two and three dimensions. to our approach. We give a formal definition of distance This approach works on any polygonal input and distance fields, the relation to generalized voronoi diagrams and re- functions. A detailed discussion of this algorithm, and its view graphics hardware based computation of a discrete ap- limitations is provided in section 3.2. An efficient version proximation. We then show how we may accelerate it for of the 2-D algorithm for point sites is presented in [5]. It large input sizes. 3.1 Distance Fields and Generalized Voronoi Dia- also depends on the complexity of the distance func- grams tion and the desired error bound. This computation is CPU limited. Given a set of input sites {S ,S ,...,S } in n dimen- 1 2 k 2. Vertex transfer and transformation. Let the average sional space, for any point p ∈ Rn, let dist(p, S ) denote i number of vertices per site distance mesh is v. Then the distance from the point p to the site S . dist(p, S ) is i i the total cost for N slices is O(vkN). This computa- a scalar function f : n → . The Distance Field is the R R tion is bus bandwidth and vertex processing limited. minima of all distance functions representing the distance from any point P ∈ Rn to the closest site. The dominance 3. Rasterization. Distance functions that have an infinite region of Si over Sj is defined by region of influence (such as the hyperboloid of a point) require computing distance values for each pixel for a Dom(Si,Sj) = {p | dist(p, Si) ≤ dist(p, Sj)} slice. Thus the worst case cost for N slices of N × N pixels, with k distance meshes per slice is O(kN 3). In For a site S , the Voronoi region for S is defined by i i practice this is the real bottleneck on current graphics processors due to large fill generated.