Optimized Spatial Hashing For Collision Detection
Optimized Spatial Hashing For Collision Detection
Optimized Spatial Hashing For Collision Detection
net/publication/2909661
CITATIONS READS
346 3,994
5 authors, including:
All content following this page was uploaded by Matthias Teschner on 04 January 2015.
Matthias Teschner Bruno Heidelberger Matthias Müller Danat Pomeranets Markus Gross
Abstract 1 Introduction
We propose a new approach to collision and self– Physically–based simulations and animations of de-
collision detection of dynamically deforming ob- formable objects play an important role in vari-
jects that consist of tetrahedrons. Tetrahedral ous research areas, such as cloth modeling, games,
meshes are commonly used to represent volumet- and computational surgery. In order to realistically
ric deformable models and the presented algorithm process the interaction between deformable objects,
is integrated in a physically–based environment, very efficient collision detection algorithms are re-
which can be used in game engines and surgical quired. Further, the information provided by the
simulators. The proposed algorithm employs a hash collision detection approach should allow for an ef-
function for compressing a potentially infinite reg- ficient and physically–correct collision response.
ular spatial grid. Although the hash function does This paper describes a new algorithm for the
not always provide a unique mapping of grid cells, detection of collisions and self–collisions of de-
it can be generated very efficiently and does not re- formable objects based on spatial hashing. The al-
quire complex data structures, such as octrees or gorithm classifies all object primitives, i. e. vertices
BSPs. We have investigated and optimized the pa- and tetrahedrons, with respect to small axis–aligned
rameters of the collision detection algorithm, such bounding boxes AABB. Therefore, a hash function
as hash function, hash table size and spatial cell maps the 3D boxes (cells) to a 1D hash table index.
size. The algorithm can detect collisions and self– As a result, each hash table index contains a small
collisions in environments of up to 20k tetrahedrons number of object primitives, that have to be checked
in real–time. Although the algorithm works with against each other for intersection. Since a hash ta-
tetrahedral meshes, it can be easily adapted to other ble index can contain more than one primitive from
object primitives, such as triangles. the same object as well as primitives from differ-
ent objects, self–collisions and collisions of differ-
ent objects can be detected. The actual collision de-
tection test computes barycentric coordinates of a
vertex with respect to a penetrated tetrahedron. This
information can be employed to estimate the pen-
etration depth for a pair of colliding tetrahedrons.
The penetration depth can be used for further pro-
cessing, such as collision response.
Using a hash function for spatial subdivision is
very efficient. While spatial subdivision usually
requires one pre–processing pass through all ob-
ject primitives to estimate the global bounding box
and the cell size, this pass can be omitted in our
approach. On the other hand, the hash mecha-
nism does not always provide a unique mapping
of grid cells to hash table entries. If different 3D
Figure 1: Environment with dynamically deforming grid cells are mapped to the same index, the per-
objects, that consist of tetrahedrons. formance of the proposed algorithm decreases. In
666
tetrahedron. The actual intersection test computes
barycentric coordinates of a vertex with respect to
a tetrahedron in order to estimate, whether a vertex
penetrates a tetrahedron.
The consistent processing of all object primi-
tives enables the detection of collisions and self–
collisions. If a vertex penetrates a tetrahedron, a
collision is detected. If the vertex and the tetrahe-
dron belong to the same object, a self–collision is
detected. If a vertex is part of a tetrahedron, the in- Figure 2: Hash values are computed for all grid cells
tersection test is omitted. covered by the AABB of a tetrahedron. The tetra-
Spatial Hashing of Vertices: In the first pass, the hedron is checked for intersection with all vertices
positions of all vertices are discretized with respect found at these hash indices.
to a user–defined cell size. Therefore, the coor-
dinates of the vertex position (x, y, z) are divided AABB of t, the second step actually tests, whether
by the given grid cell size l and rounded down to p is inside t. This test computes barycentric coordi-
the next integer (i, j, k): i = x/l, j = y/l, nates of p with respect to a vertex of t. Details are
k = z/l. given in Sec. 4.4.
The hash function hash maps the discretized 3D
position (i, j, k) to a 1D index h and the vertex and
object information is stored in a hash table at this 4 Parameters
index h: h = hash(i, j, k).
Refer to Sec. 4.1 for details on the hash function. In this section, we investigate the parameters of the
Sec. 4.2 and Sec. 4.3 describe how to find the opti- presented algorithm. The characteristics of the hash
mal hash table size and cell size, respectively. function, the size of the hash table, the size of a
In addition to generating a hash value for each 3D cell for spatial subdivision, and the actual inter-
vertex, this first pass also computes the AABBs section test influence the performance of the algo-
of all tetrahedrons based on their current deformed rithm. We have optimized all these aspects of the
state. algorithm.
Spatial Hashing of Tetrahedrons: While the first
pass has considered all vertices to build the hash ta-
4.1 Hash Function
ble and to update the AABBs of the tetrahedrons,
the second pass of the algorithm traverses all tetra- In the first pass of the algorithm, hash values are
hedrons. computed for all discretized vertex positions. These
First, the minimum and maximum values de- hash values should be uniformly distributed to guar-
scribing the AABB of a tetrahedron, are discretized. antee an adequate performance of the algorithm.
Again, these values are divided by the user–defined The hash function has to work with vertices of the
cell size and rounded down to the next integer. Sec- same object, that are close to each other, and with
ond, hash values are computed for all cells affected vertices of different objects, that are farther away.
by the AABB of a tetrahedron. Therefore, all cells We have tested several hash functions in our
are traversed from the discretized minimum to the implementation, basically variants of additive and
discretized maximum of the AABB (see Fig. 2). All rotating hash functions. However, we have not
vertices found at the according hash table index are systematically investigated the characteristics of
tested for intersection. hash functions. It gets three values, describing a
Intersection Test: If a vertex p and a tetrahedron vertex position (x, y, z), and returns a hash value:
t are mapped to the same hash index and p is not
part of t, a penetration test has to be performed. hash(x,y,z) = ( x p1 xor y p2 xor z p3) mod n
The actual intersection test consists of two steps. where p1, p2, p3 are large prime numbers, in
First, p is checked against the AABB of t, which our case 73856093, 19349663, 83492791, respec-
has been updated in the first pass. If p penetrates the tively. The value n is the hash table size.
666
The function can be evaluated very efficiently 8
and produces a comparatively small number of hash
7
collisions for small hash tables. As described in
666
200 10
180
160 8
Collision detection [ms]
Figure 5: Performance of the collision detection al- Figure 6: Performance of the collision detection al-
gorithm for two deformable vessels (see Fig. 9) with gorithm for 100 deformable objects (see Fig. 8) with
an overall number of 5898 vertices and 20514 tetra- an overall number of 1200 vertices and 1000 tetra-
hedrons with varying grid cell size. Hash table size hedrons with varying grid cell size. Hash table size
is 9973. is 4999.
666
6 Results
We have performed experiments with various
setups of deformable objects (see Tab. 1 and
Tab. 2). Setups A, B and D are illustrated in Fig. 7,
8, 9, respectively. Fig. 10 illustrates the tetrahedral
meshes of the patient–individual models of two
vessels used in setup D. Setup C and E use the
same deformable objects like B.
666
8 Ongoing Work
Efficient collision detection is an essential compo-
nent in real–time simulation environments for de-
formable objects. However, a realistic interaction
between dynamically deforming objects also re-
quires a correct collision response. Since our algo-
rithm provides the exact position of a vertex inside
a penetrated tetrahedron, we can employ this infor-
mation for collision response. If we assume, that a
face or a vertex of the penetrated tetrahedron is part
of the object surface, we can easily derive the pen-
etration depth, which allows for a correct collision
response.
Further, we are about to accomplish a mod-
ular framework for real–time simulation of de-
Figure 9: Test setup D. formable objects, which can be used in game en-
gines or surgical simulators. We have integrated ef-
ficient deformable models based on linear finite ele-
ments [23] and the proposed collision detection ap-
proach. Completed with the above mentioned colli-
sion response, the framework will handle interact-
ing deformable models of up to several thousand
tetrahedrons in real–time.
9 Conclusion
We have introduced a method for detecting colli-
sions and self–collisions of dynamically deforming
objects. Instead of computing the global bounding
box of all objects and explicitly performing a spa-
Figure 10: Tetrahedral mesh of test setup D.
tial subdivision, we propose to use a hash function
that maps 3D cells to a hash table, thus realizing a
While vertex positions are mapped to the hash ta- very efficient, implicit spatial subdivision. The ac-
ble exactly once, tetrahedrons are usually mapped tual vertex-in-tetrahedron test is based on barycen-
to several hash indices, which leads to a larger num- tric coordinates. It provides information, that can be
ber of elements in the hash table, thus decreasing used for physically–based collision response. We
the performance of the algorithm. have investigated and optimized the parameters of
The comparison of the performance with other our approach. Experiments, performed with vari-
existing collision detection approaches is difficult. ous test scenarios, show that environment of up to
There exist numerous public domain libraries, such 20k tetrahedrons can be processed in real–time, in-
as RAPID [9], PQP [18], and SWIFT [7]. However, dependent from the number of objects.
these approaches are not optimized for deformable
objects. They work with data structures, that can 10 Acknowledgement
be pre–computed for rigid bodies, but have to be
updated in case of deformable objects. This research is supported by the Swiss National
Our approach has been implemented based on Science Foundation. The project is part of the
tetrahedrons. However, it is not restricted to tetra- Swiss National Center of Competence in Research
hedrons and could handle other object primitives as on Computer Aided and Image Guided Medical In-
well by simply replacing the intersection test. terventions (NCCR Co–Me).
666
References [15] Y. Kim, M. Otaduy, M. Lin, D. Manocha, “Fast pen-
etration depth computation for physically–based an-
[1] G. Baciu, W. Wong, H. Sun, “RECODE: an image– imation,” Proceedings of ACM SIGGRAPH Sympo-
based collision detection algorithm,” The Journal of sium on Computer Animation ’02, pp. 23–31, 2002.
Visualization and Computer Animation, vol. 10, pp. [16] Y. Kim, K. Hoff, M. Lin, D. Manocha, “Closest
181–192, 1999. point query among the union of convex polytopes
[2] D. Baraff, “Collision and contact,” SIGGRAPH ’01 using rasterization hardware,” Journal of Graphics
Course Notes, 2001. Tools, 2003, to appear.
[3] G. van den Bergen, “Efficient collision detection [17] J. Klosowski, M. Held, J. Mitchell, H. Sowizral, K.
of complex deformable models using AABB trees,” Zikan, “Efficient collision detection using bound-
Journal of Graphics Tools, vol. 2, no. 4, pp. 1–13, ing volume hierarchies of k–DOPs,” Proceedings of
1997. SIGGRAPH ’96, pp. 171–180, 1996.
[18] E. Larsen, S. Gottschalk, M. Lin, D. Manocha, “Fast
[4] R. Bridson, R. Fedkiw, J. Anderson, “Robust treat-
proximity queries with swept sphere volumes,” Tech-
ment of collisions, contact and friction for cloth an-
nical Report TR99-018, University of North Car-
imation,” Proceedings of SIGGRAPH ’02, pp. 594–
olina at Chapel Hill, 1999.
603, 2002.
[19] T. Larsson, T. Akenine–Moeller, “Collision detec-
[5] T. Cormen, C. Leiserson, R. Rivest, “Introduction to tion for continuously deforming bodies,” Proceed-
Algorithms,” ISBN 0-262-03141-8, The MIT Press, ings of Eurographics ’01, pp. 325–333, 2001.
Cambridge, Massachusetts, 1990.
[20] J. Lombardo, M.-P. Cani, F. Neyret, “Real–time col-
[6] G. Debunne, M. Desbrun, M.-P. Cani, A. Barr, “Dy- lision detection for virtual surgery,” Proceedings of
namic real–time deformations using space & time Computer Animation ’99, pp. 33–39, 1999.
adaptive sampling,” Proceedings of SIGGRAPH ’01,
[21] S. Melax, “Dynamic plane shifting BSP traversal,”
pp. 31–36, 2001.
Proceedings of Graphics Interface ’00, pp. 213–220,
[7] S. Ehmann, M. Lin, “SWIFT: Accelerated prox- 2000.
imity queries between convex polyhedra by multi– [22] B. Mirtich, “Efficient algorithms for two–phase col-
level voronoi marching,” Technical Report TR00- lision detection,” Technical Report TR-97-23, Mit-
026, Univ. of North Carolina at Chapel Hill, 2000. subishi Electric Research Laboratory, 1997.
[8] F. Ganovelli, J. Dingliana, C. O’Sullivan, “Buck- [23] M. Müller, J. Dorsey, L. McMillan, R. Jagnow, B.
etTree: Improving collision detection between de- Cutler, “Stable Real–Time Deformations,” Proceed-
formable objects,” Proceedings Spring Conference ings of ACM SIGGRAPH Symposium on Computer
on Computer Graphics SCCG ’00, Budmerice Cas- Animation SCA ’02, pp. 49–54, 2002.
tle, Bratislava, 2000. [24] X. Provot, “Collision and self–collision handling in
[9] S. Gottschalk, M. Lin, D. Manocha, “OBB–tree: A cloth model dedicated to design garment,” Proceed-
hierarchrical structure for rapid interference detec- ings of Graphics Interface ’97, pp. 177–189, 1997.
tion,” Proceedings of SIGGRAPH ’96, pp. 171–180, [25] S. Quinlan, “Efficient distance computation between
1996. non–convex objects,” Proceedings of IEEE Int. Conf.
[10] T. He, A. Kaufman, “Collision detection for volu- on Robotics and Automation, pp. 3324-3329, 1994.
metric objects,” Proceedings of IEEE Visualization [26] G. Bradshaw, C. O’Sullivan, “Sphere–tree construc-
’97, pp. 27–34, 1997. tion using medial–axis approximation,” Proceedings
[11] G. Hirota, S. Fisher, M. Lin, “Simulation of non– of the ACM SIGGRAPH Symposium on Computer
penetrating elastic bodies using distance fields,” Animation SCA ’02, pp. 33–40, 2002.
Technical Report TR00-018, University of North [27] G. Turk, “Interactive collision detection for molecu-
Carolina at Chapel Hill, 2000. lar graphics,” Technical Report TR90-014, Univer-
sity of North Carolina at Chapel Hill, 1990.
[12] K. Hoff, A. Zaferakis, M. Lin, D. Manocha, “Fast
and simple 2D geometric proximity queries using [28] P. Volino, M. Courchesne, N. Magnenat–Thalmann,
graphics hardware,” Proceedings of Symposium on “Versatile and efficient techniques for simulating
Interactive 3D Graphics ’01, pp. 145–148, 2001. cloth and other deformable objects,” Proceedings of
SIGGRAPH ’95, pp. 137–144, 1995.
[13] P. Hubbard, “Interactive collision detection,” Pro-
[29] G. Zachmann, “Minimal hierarchical collision de-
ceedings of IEEE Symposium on Research Frontiers
tection,” Proceedings of ACM Symposium on Virtual
in Virtual Reality ’93, pp. 24–31, 1993.
Reality Software and Technology VRST ’02, pp. 121–
[14] M. Hughes, C. DiMattia, M. Lin, D. Manocha, “Ef- 128, 2002.
ficient and accurate interference detection for poly- [30] D. Zhang, M. Yuen, “Collision detection for clothed
nomial deformation and soft object animation,” Pro- human animation,” Proceedings of Pacific Graphics
ceedings of Computer Animation ’96, pp. 155–166, ’00, pp. 328–337, 2000.
1996.
666