.
Voxel-Based Rendering 01.september.1997 GFX

by Hin Jang

Rendering photo-realistic, complex terrain features at near-interactive rates requires innovative techniques. A polygonal model and geometric pipeline can be used but this introduces massive storage requirements and, ideally, a parallel implementation of the algorithm. Using a voxel-based model, however, can achieve the same results at a much lower hardware requirement. As a software solution, the method is portable so it can be integrated into any flight simulation system regardless of hardware architecture. The rendering algorithm described herein is a simple ray casting accelerated by ray coherence and multiresolution traversal [3].

An image in the voxel-based model is defined by the location of the camera, the field of view and its orientation. Each ray emanating from the viewpoint traverses above the terrain voxels until it intersects the terrain. Traversal is based on a discrete grid traversal where the steps along the ray are performed on the projection on the ray rather than in object space. Upon intersection, the colour is sampled and mapped back to the source pixel. No explicit intersection calculation is performed, however. Instead, the heights along the ray are incrementally sampled and compared to the terrain height below the ray. Assuming the camera does not roll, the algorithm makes use of ray coherence to accelerate rendering. Ray coherence exploits the fact that a ray cast from a pixel vertically adjacent intersects the terrain further away from the viewpoint than that of the ray below. In other words, ray i + 1 traverses a distance no shorter than the distance of ray i. Rather than having to traverse each ray from the viewpoint, traversal of ray i + 1 begins at the intersection of ray i. Such rays diverge with distance due to perspective projection resulting in nonuniform sampling rates of terrain voxels. Close voxels tend to be oversampled and far voxels tend to be undersampled. Multiresolution traversal ensures that sampling is proportional to the number of rays. The pseudocode shown below generates a single column of the image.


   VoxelColumn()
   {
      E  = location of eye
      P  = location of bottom pixel of column
      Up = vector direction of image columns
      x  = E.x
      y  = E.y
      n  = distance between x and end of the terrain

      /* assuming fixed point arithmetic, the floor() function on y
         can be replaced by a shift operation.  the fraction part,
         w = y - floor(y), is used for linear interpolation of the
         sampling point.  interpolation is required because the exact
         point of intersection lies between (x, floor(y)) and
         (x, floor(y) + 1) */

      while (n--) {
         while (z < height(x, floor(y))) {
            w = y - floor(y)
            colour = Sample(x, floor(y), w)
            PutPixel()
            if (n < 1) return
            P += Up
            Q = P - E
            z = P.z + (x - P.x) * Q.z / Q.x
         }
         x += Sign(Q.x)
         y += Q.y / Q.x
         z += Q.z / Q.x
      }
   }

Vector Q is the direction of the ray emanating from P. For each iteration of the inner loop, P is incremented by Up to the next pixel and Q is updated to the new ray. For each iteration of the outer loop, the values of x, y and z are incrementally updated to the next voxel along the ray.



[1] Akeley, K., "Reality Engine Graphics," Computer Graphics, SIGGRAPH 1993 Proceedings, 27(4):109-116

[2] Chen, E.S., and L. Williams, "View Interpolation for Image Synthesis," Computer Graphics, SIGGRAPH 1993 Proceedings, 27(4):279-288

[3] Cohen-Or, D., E. Rich, U. Lerner, and V.Shenkar, "A Real-Time Photorealistic Visual Flythrough," IEEE Transactions on Visualisation and Computer Graphics, 2(3):255-265, September 1996


.
Surface Approximation Using Wavelets 24.november.1997 GFX

by Hin Jang

Wavelets are used to represent functions in an elegant manner. The function can be an image, curve, or surface. With its initial use in approximation theory and signal processing, wavelets can also be applied to image editing, image compression, global illumination and surface reconstruction and approximation. A method to triangulate a surface using wavelets first transforms the surface data grid into a quadtree data structure. Each quadtree cell is triangulated using a look-up table containing all possible triangles at some resolution m. To decide whether a given mesh vertex can be removed, a wavelet transform is applied to the data. This transform yields detail signals, an abstraction of the local frequency characteristics of the data. The amplitude of the detail signals is then used to decide the removal of points. The wavelet transform can also yield detail signals at different frequencies. The degree at which a dataset is triangulated can therefore be controlled [2].

Wavelets defined
Suppose there exists a one-dimensional function I(x) with the following values


   15  9  1  3

Averaging these values, pairwise, yields a lower resolution function

      12  2

Any lost information, due to decomposition, is captured in detail coefficients. For the first coefficient, the digit three is chosen because the average computed is three less than 15 and three more than nine. The second coefficient is negative one, since 2 + (-1) = 1 and 2 - (-1) = 3. Applying the procedure recursively gives full decomposition of the function.
Resolution            Averages           Detail Coefficients

    4               15  9  1  3

    2                  12  2                    3  -1

    1                    7                        5

The wavelet transform of the original four-value function is the single coeffecient representing the overall average of values followed by the detail coefficients in order of increasing resolution.

   7  5  3  -1

Given this transform, the image can be reconstructed to any resolution by recursively adding or subtracting the detail coefficients, along with constant offsets to these coefficients, from lower resolution images.

Rather than a series of coefficients, the image can be regarded as a set of piecewise constant functions on the half-open interval [0, 1). A one pixel image is a function that is constant over the entire interval. The vector space that contains this image is denoted as V 0. A two-pixel image has two constant pieces over the intervals [0, 1/2) and [1/2, 1). The vector space containing these two pieces is V 1. The space V j contains all piecewise constant functions on the interval [0, 1), with the interval divided equally into 2 j different pieces [4]. Since all vectors are defined on the unit interval in V j, these functions are also contained in vector space V j+1. As such, a piecewise constant function of two intervals, for example, can be described as a piecewise constant function of four intervals.

The basis for the vector space V j is given by a set of scaling functions. The simplest basis for one-dimensional functions is the Haar basis, a set of scaled and translated box functions.

   øij(x)  :=  ø(2jx - i),   i = 0, ... ,2j - 1

where
             |  1   for 0 <= x < 1
   ø(x)  :=  |
             |  0   otherwise

A vector space in V j+1 that contains functions orthogonal to the functions in V j is known as the orthogonal complement W j. The functions that span W j are called wavelets and have the following properties

The inner product of two functions defined on the vector space V j, for the example used herein, is
                   1
                 |\
                 |
   < f, g >  =   |  f(x) g(x) dx
                 |
                \|
                  0

The wavelets corresponding to the scaling functions of V j are defined as
   uij(x)  :=  u(2jx - i),   i = 0, ... ,2j
where
             |  1   for 0 <= x < 1/2
   u(x)  :=  | -1   for 1/2 <= x < 1
             |  0   otherwise

With ø(x) and u(x) defined, the original function I(x) can be expressed as a linear combination of these basis functions [4]. In the expressions that follow, the coefficients c and d are the ones calculated previously as pairwise averages.

The original function in V 2 is

   I(x)  =  c02ø02(x)  +  c12ø12(x)  +  c22ø22(x)  +  c32ø32(x)


                   +-----+
         = 15  x   |     |__________________

                         +-----+
         +  9  x   ______|     |____________

                               +-----+
         +  1  x   ____________|     |______

                                     +-----+
         +  3  x   __________________|     |

In terms of basis functions in V 1 and W 1, the expression for I(x) is
   I(x)  =  c01ø01(x)  +  c11ø11(x)  +  d01u01(x)  +  d11u11(x)


                   +-----------+
         = 12  x   |           |____________

                               +-----------+
         +  2  x   ____________|           |

                   +-----+
         +  3  x   |     |     _____________
                         |     |
                         +-----+

                               +-----+
         + -1  x   ____________|     |
                                     |     |
                                     +-----+

As the sum of basis functions V 0, W 0 and W 1, the expression for I(x) is
   I(x)  =  c00ø00(x)  +  d00u00(x)  +  d01u01(x)  +  d11u11(x)


                   +-----------------------+
         =  7  x   |                       |

                   +-----------+
         +  5  x   |           |
                               |           |
                               +-----------+

                   +-----+
         +  3  x   |     |     _____________
                         |     |
                         +-----+

                               +-----+
         + -1  x   ____________|     |
                                     |     |
                                     +-----+

Haar wavelets can be generalised to higher dimensions. The two-dimensional basis consists of a single course scaling function and all possible scales and translates of three wavelet functions [4].

   øø(x,y)  :=  ø(x)ø(y)

   øu(x,y)  :=  ø(x)u(y)
   uø(x,y)  :=  u(x)ø(y)
   uu(x,y)  :=  u(x)u(y)

The scaling function in three dimensions is

   ø(x,y,z)  :=  ø(x)ø(y)ø(z)

and the wavelets are

   u1(x,y,z)  :=  ø(x)ø(y)u(z)
   u2(x,y,z)  :=  ø(x)u(y)ø(z)
   u3(x,y,z)  :=  ø(x)u(y)u(z)
   u4(x,y,z)  :=  u(x)ø(y)ø(z)
   u5(x,y,z)  :=  u(x)ø(y)u(z)
   u6(x,y,z)  :=  u(x)u(y)ø(z)
   u7(x,y,z)  :=  u(x)u(y)u(z)

Surface Approximation Method
All vertices that define the surface are represented in a quadtree data structure. Each quadtree cell is then triangulated. After this mesh is created, a two-dimensional wavelet transform is applied onto the initial data set and the detail signals are reconstructed iteratively. The resulting coefficients are analysed to determine whether the surface can be approximated with larger triangles. A wavelet space filter is used to localise the area on which the approximation occurs. This filter is a Gaussian weighting function, centered at (x, y), scaled by (px, py) and rotated by P, that surrounds the region of interest (ROI) in the initial data set. At transform resolution m, the weighting function is

                  -(Rm pm)T (Rm pm) + 1
   gm(xm, ym)  =  e

The matrix R m is the affine transform of the Gaussian

          |   cosP    sinP      x cosP + y sinP  |
          |   ----    ----    - ---------------  |
          |    pxm     pxm              px         |
          |                                      |
          |                                      |
   R  =   | - sinP    cosP      x sinP - y cosP  |
          |   ----    ----      ---------------  |
          |    pym     pym              py         |
          |                                      |
          |                                      |
          |     0       0              1         |

[2]. p m = (x m, y m, 1) T is the position in homogenous coordinates. Within the ROI at resolution m, each 2 m + 1th mesh vertex can be removed if and only if
  1. the sum of the squares of its difference signal and those within a four-neighbourhood at resolution m is less than some value e
  2. the four surrounding vertices at resolution m - 1 were previously removed
  3. the resulting cell is not adjacent to any cell with a higher resolution than m - 2
If some vertex n is removed, for example, the linear interpolation between n - 1 and n + 1 is sufficient to realise the approximation. The final triangulation step employs a lookup table consisting of all possible triangulations at mesh resolution m.



[1] Gortler, S.J., Wavelet Methods for Computer Graphics, TR-477-94, Ph.D. dissertation, Department of Computer Science, Princeton University, January 1995

[2] Gross, M.H., O.G. Staadt, and R. Gatti, "Efficient Triangular Surface Approximations Using Wavelets and Quadtree Data Structures," IEEE Transactions on Visualisation and Computer Graphics, 2(2):130-143, June 1996

[3] Mallat, S., "A Theory for Multiresolution Signal Decomposition: The Wavelet Representation," IEEE Transactions on Pattern Analysis and Machine Intelligence, 11(7):674-693, July 1989

[4] Stollnitz, E.J., T.D. DeRose, and D.H. Salesin, Wavelets for Computer Graphics: A Primer, Technical Report 94-09-11, Department of Computer Science and Engineering, University of Washington, 1994


.
Quaternions 14.december.1997 GFX

by Hin Jang

Quaternions are the invention of 19th century Irish mathematician, Sir William Rowan Hamilton [1]. Occupying four-dimensional space H, quaternions specify elegantly rotations and orientations of coordinate axes with four real numbers. The notation for an arbitrary rotation about an arbitrary axis is borrowed from the engineering disciplines [2]. Basic operations, however, are represented in a manner similar to algebraic systems in the complex domain and in R3.

H is spanned by a real axis and three orthogonal axes. The basis vectors, i, j, k are called principle imaginaries where


   i  =  (1, 0, 0)
   j  =  (0, 1, 0)
   k  =  (0, 0, 1)

and

   i2  =  j2  =  k2  =  ijk  =  -1

Rotation in quaternionic space is caused by multiplication

   ij  =   k,     jk  =   i,     ki  =   j
   ji  =  -k,     kj  =  -i,     ik  =  -j

A quaternion q is defined as the sum of real part a and pure part v = xi + yj + zk. If a = 0, then q is called a pure quaternion. Given q0 = a0 + v0 and q1 = a1 + v1, then

   q0 + q1  =  (a0 + a1)  +  (v0 + v1)

and

   q0q1  =  a0a1  -  v0.v1  +  a0v1  +  a1v0  +  v0 × v1

The notation for quaternions decompose into a form that resembles the complex number a + bu. The conjugate of q is q~ = a - bu and its magnitude is the square root of a2 + b2. If |q| = 1, then q is called a unit quaternion and q-1 = q~.

Rotation of ø about some axis u is denoted by the unit quaternion

              1             1   
   q  =  cos --- ø  +  sin --- ø u
              2             2

[5]. The expression e u ø is equivalent to cosø + usinø. Thus,
          
           u ø/2
   q  =  e

Note that e u ø / 2 is not the natural number e raised to some exponent, but is simply an expression of a rotation of ø about the axis u. The rotation R(q) = R(e u ø / 2) of unit quaternion q about an arbitrary vector v yields a new pure quaternion q* where

   q*  =  qvq-1



[1] Hamilton, W.R., Elements of Quaternions, Longmans Green, London, England, 1866

[2] Hart, J.C., G.K. Francis, and L.H. Kauffman, "Visualising Quaternion Rotation," ACM Transactions on Graphics, 13(3):256-276, July 1994

[3] Francis, G.K., and L.H. Kauffman, "Air on the Dirac Strings," Mathematical Legacy of Wilhelm Magnus, AMS, Providence, Rhode Island, 1994

[4] Kim, M.J., M.S. Kim, and S.Y. Shin, "A General Construction for Unit Quaternion Curves with Simple High Order Derivatives," Computer Graphics, SIGGRAPH 1995 Proceedings, 29(4):369-376

[5] Shoemake, K., "Animating Rotation with Quaternion Curves," Computer Graphics, 19(3):245-254, July 1985