• No results found

Bricking and Scaling

When our research began, the graphics hardware was limited to textures whose dimen- sions were a power of two, so in order to work with volumes with different sizes it was necessary to split the volume into smaller parts, each one of which respects that limita- tion. This operation is called bricking, and the volume parts are then commonly referred to as bricks. Each brick will have its own texture, extracted from the full volume. In our case, we used the OSCVR library [21], which already provided the bricking algorithm. Nevertheless, it was not possible to apply the formulation described in section 5.3.1.1, as the original, full-sized texture will not be available to each brick.

Therefore an alternative approach was developed: the full volume is first split into the 27 regions outlined in section 5.3.1.1. Each region u is defined primarily by:

• Minimum and maximum limits, before distortion: (minxu, minyu, minzu) and

(maxxu, maxyu, maxzu)

• Minimum and maximum limits, after distortion: (dminxu, dminyu, dminzu) and

(dmaxxu, dmaxyu, dmaxzu)

To find the distorted limits, one must first compute the new boundary of the focus region after distortion, as figure 6.1 shows in 2D. As these values are in voxel coordinates, to simplify further calculations we also normalize the coordinates so the volume occupies the unit cube. Hence for the x dimension, the boundary of the focus region would be obtained by:

x0min = xf− mag · sx vmaxx

x0max = xf+ mag · sx vmaxx

The limits of the focus region are then used in the specification of the limits of all other regions. For example, considering the region marked as R in the figure, the original limits for x would be minxR = xmin and maxxR= xmax, while the distorted limits for x would be

dminxR= x0minand dmaxxR= x0max.

The whole idea behind this method is the correct scaling and positioning of each region, hence now we need to find out which scaling factor to use for each dimension in this region. The six scaling factors - (scalex−, scalex+) and the respective ones for y and

Chapter 6 90 Hardware-accelerated Methods (0,0) sx sy (1,1)

R

Original focus region

Enlarged focus region (mag = 2) (xf, yf)

x

min

x

max

x

0min

x

0max

Figure 6.1: Calculating the distorted boundary (x0min, x0max) of the focus region in 2D: (xmin, ymin) denote the original boundary (without distortion), (x f , y f ) is the region centre, (sx, sy) are half of the dimensions of the original region and mag is the magnification factor being applied.

Chapter 6 91 Hardware-accelerated Methods

appropriate ones from the set already computed, according to the region being considered. So if we use the same region R as an example, the scaling factors for x and y would be:

SxR = mag SyR = scaley+

as the region R is within the focus region in x but after its limits in y.

However, as we cannot guarantee that the lower left corner of the region is at the origin of the coordinate system, we then compute a translation to move that corner to the origin (see figure 6.2a):

tx1R= −minxR

Now the region can be scaled, using the scaling factors selected before (figure 6.2b). Finally, the lower left corner of the region - now at (0, 0) - must be translated to the corresponding distorted position (figure 6.2c), which naturally is:

tx2R= dminxR

In summary, the algorithm has the following preprocessing steps: • Split the volume into 27 regions

• Compute the six scaling factors (see section 5.3.1.1) • For each region u

– Determine the minimum/maximum limits (normal and distorted) – Obtain the scaling factors for x, y and z

– Obtain the two translations for each dimension

– Split each region into the number of bricks needed to tessellate it – Create all required bricks, associating the region number to each The rendering algorithm will then:

• Sort all bricks in back to front order • To draw each brick:

Chapter 6 92 Hardware-accelerated Methods (0,0) (1,1)

R

(xf, yf) (0,0) (1,1) (xf, yf) (a) (b) (0,0) (1,1) (xf, yf) (0,0) (1,1) (xf, yf) (c) (d)

Figure 6.2: Bricking and scaling method in 2D: computing the translation to move the region lower left corner to the origin (a); result after translating the region (b); scaling the region according to its scaling factors - in this case, an enlargement is taking place in the x dimension and a compression in the y dimension - and computing the translation to move the region to the final position (c); final region correctly positioned and scaled (d).

Chapter 6 93 Hardware-accelerated Methods

– Identify which region u the brick is in (from the stored region number) – Apply a translation of (tx1u,ty1u,tz1u)

– Apply a scale of (Sxu, Syu, Szu)

– Apply a translation of (tx2u,ty2u,tz2u)

– Render the brick normally

Finally, it is important to note that this process will produce many more bricks than the quantity originally needed to tessellate the full volume. But the data is still the same, no distortion takes place on the bricks themselves. It is only during the rendering process of each brick that the distortion will be applied, using the previous algorithm.

This bricking method has the following disadvantages:

• it requires the volume to be split into 27 sub-volumes, which means that new texture memory will have to be allocated and portions of the original texture will need to be copied to the texture memory associated with each region - this requires processing time.

• it is very difficult to implement non-linear distortion methods such as the 3D Carte- sian fisheye, as each brick can only be scaled linearly (through trilinear interpolation by the graphics hardware).

Because of those disadvantages, further research was targeted at the development of better methods. The availability of new GPUs with advanced programming capabilities (such as fragment shading) allowed us to design methods that exploited different approaches to achieve distortion. These methods also try to put less overhead on the CPU, in the search of an optimal balance between CPU and GPU use. We have used OpenGL Shading Language (GLSL) [142], in order to achieve graphics hardware independence and to ease maintenance of the code.