Organ Modeling and Simulation using Graphical Processing Units

3 downloads 153 Views 2MB Size Report
a spring characterized by a rest length and an elastic coefficient and a damper with a ... much faster than drawing dire
Organ Modeling and Simulation using Graphical Processing Units Marco Altomonte, Davide Zerbato, Stefano Galvan, Paolo Fiorini Department of Computer Science, University of Verona

Interactive, physics-based simulations and animations are a growing research area with possible applications in several fields. An increasing interest is towards medical applications, since the simulation of tissues and human organs for training and computer aided surgery relies on these techniques for realistic rendering. It is not difficult to mimic the behavior of a soft tissue in simulation. However, when the computation of deformable object dynamic is required at high rates, even high end computers have inadequate performance. To be stable and realistic the rendering of forces needs a framerate of, at least, 1 kHz. Our method is based on mass spring models and computes a realistic force each millisecond that can be used to provide force feedback to the user. We exploit the graphical processing units computational power to obtain the required framerate. To take advantage of such hardware data structures and algorithms used in the computation have to be completely redesigned. The results will prove the utility of this approach and the possibility to obtain a very high framerate without the necessity to perform extrapolation or to introduce artificial delay in the rendered force.

To represent all data needed during the integration it is necessary to memorize informations about points, tetrahedra and springs. All the data have to be stored in matrices, or textures. To store information about points we use: a matrix with their positions at time t; a matrix with their positions at time t − 1;

Figure 3: Texture construction from the valence values; in orange: wasted memory

Volume conservation force can be easily computed scrolling through all tetrahedron and evaluating:

a matrix with their mass;

F = (Vr − V )nt

a matrix with the force that acts on them. Each point whose position in the texture is (u, v) has an implicitly assigned index that is v ∗ width + u. To improve the overall performance spring are memorized on a stack of textures of constant size width × height, this is necessary to tackle some hardware limitations. The number of texture allocated is equal to the maximum valence of the model (i.e. the maximum number of spring that acts on a point). In the four field of a spring at position (u, v) there are:

where Vr and V are the rest and current volume of the thetrahedron and nt is the normal of the face opposite to the considered point. Recalling the method we use to store tetrahedra, nt can be easily computed through the their first three fields.

Tool forces

the index of its second end; its rest length, r:

Mass spring models

its elastic coefficient, k; its damping coefficient, d.

Mass spring models allow to compute an approximation of physical behaviour of soft tissues. They are used in graphics to render deformable objects, cloths, hairs etc. A mass spring model is usually obtained sampling the volume that represent a body in tetrahedra. At each vertex of each tetrahedron a mass point is placed, while for each edge there are a spring characterized by a rest length and an elastic coefficient and a damper with a damping coefficient (see Figure 1)

The index of its first end can be calculated as v ∗ width + u. To store tetrahedra information we generate a texture stack in which at position (u, v) is stored the tetrahedron that uses the point (u, v). Each tetrahedron is therefore stored four times. Since the first point of the solid can be inferred, tetrahedra contains: the index of the second point; the index of the third point; the index of the fourth point; the rest volume, Vr ;

Our implementation allow the user to interact with deformable models using virtual tools that can push or pull the surface of the model. To obtain the forces and torques to feed a haptic device it is necessary to follow three steps: first we compute the contribute of each point in contact with the tool to the overall torques and forces. The partial values have to be stored in two distinct textures, one for the forces and one for the torques, that have the same dimensions of the mass texture, even if the values are computed for the contact points only. The partial values has then to be reduced to a couple of 3 float array. The only way to do this on the graphic card memory is through the reduction operator that reduces iteratively half the dimension of the textures. Finally the values are moved from the video card memory to the main memory asyncronously, that is through a non locking readback that eliminates the latency of a syncronous GPU-CPU transfer.

Force calculation

Results

The forces that considered during the integration are: the elastic force, the damping force and the volume conservation force. To obtain the elastic and the damping forces we use a fragment shader that for each spring compute:   l F = [k(klk − r) + d(∆v)] klk

We implemented our method using OpenGl Shading Language and R we tested it on two different architectures: the first is an Intel XeonTM¡¡INFO SUL PROCESSORE¿¿ with ¡¡INFO SULLA RAM¿¿ R QuadroFXTM3450, the second is an Intel equipped with an NVIDIA CoreTM 2 Duo, with 2 GB of RAM and an NVIDIA GeForceGOTM7900. The graphic processing unit of the two boards are quite different: the former board is equipped with a sixth generation GPU while the latter is powered by a seventh generation GPU. To make the code runs on both graphics boards we had to neglect some optimization that the newer chipset would allow, but even without such optimization the framerate we get is enough for a realistic and stable haptic interaction. Simulation results are presented in Table 1.

Figure 1: A simple mass spring model construction Mass spring models are based on linear spring, so the approximation they provide is realistic only when the deformation remains below a threshold that is usually considered as the 10% of the total size of the object. The simple structure of the model allow fast topology changes like cuts, tears or sutures. One simulation step for a mass spring model request to evaluate the force exerted by springs and dampers and to balance them with external forces in order to obtain the new body configuration. At each temporal step t, for each spring s the current length l has to be calculate. The difference between the rest length and the current length, weighted by the spring elastic model gives the elastic force, while the difference between the velocities of the two ends of the spring, weighted by the damping ratio gives the damping forces. The sum of external and internal forces are then used to obtain the new point positions with an explicit integration scheme.

GPU specifications

Graphical processing units (or GPUs) are vectorial processors that can be found on current graphic boards and that are based on few aritmethic units commonly called shader units. They are designed to provide a number of graphics primitive operations in a way that makes running them much faster than drawing directly to the screen with the host CPU. The GPUs ability in handling 3D or even 4D vectors and the speed they can perform vector and matrix operations made them very primising for some classes of scientific calculations. Pipelines in shader units are quite simple and they do not perform branch prediction or other advanced optimization, causing for loops and complex conditions to be unefficient. There are, moreover, some big limitations also on data that can be stored: current hardware impose a maximum size of 4096 elements on each dimension of the texture (so it is usually necessary to use bidimensional textures) and a maximum of 4 scalar values for its elements. Scalar values should be simple float, as GPUs badly handle integer values, and the programmer should try to keep useful values in elements as close as possible to 4 to maximize performances. So exploiting GPUs computational power is not just a matter of rewriting code, usually it needs the algorithms to be completely re-designed.

where l and ∆v are the difference of positions and speed, respectively, between the two ends of the spring, and r is the spring rest length. The resulting forces are then accumulated using a blending function. Since not all the points of the model has the same valence some elements of spring textures are empty. To optimize the computation of the spring forces those empty values should be contiguous. Masses are therefore ordered by their valence. Masses with high valence get lower position, while masses with fewer neighbours get higher indexes. In this way the textures that are generated have the useful values in the lower part, and the useless values can easily be ignored. In Figure 2 an example of the distribution of the valences of a sample liver model we use is shown. In Figure 3 the textures generated usign the described methodfor a dummy model that has 3 points with valence 3, 18 points with valence 2, and 10 points with valence 1.

Model

Liver Bunny5 Bunny6 Parameters Points 7750 1617 6792 Springs 48254 8871 38030 Computation times (ms) QuadroFX 3450 0.689 0.179 0.609 GeForceGO 7900 0.468 0.093 0.406 XeonTM3.00 GHz 5.5 0.99 4.47

Bunny7 28292 159353 2.77 2.06 28.45

It is important to note that for a model of a liver made of more than 7700 masses, 38000 tetrahedra and 48000 springs, we are able to obtain a framerate of ¡¡1100 fps¿¿, with physical simulation, force and torque computation, graphic and haptic rendering. Moreover we connected our simulator to a NASA JPL FRHC (Force Reflecting Hand Controller) through a LAN and we obtained a smooth and realistic interaction between the virtual probe and the virtual organ and a stable force feedback.

Figure 2: The distribution of the valences of a sample model

Data structures Figure 4: Some screenshots of a tool interacting with a model

http://metropolis.sci.univr.it

Suggest Documents