.
NURBS 06.september.1997 GFX

by Hin Jang

Non-uniform rational B-splines (NURBS) provide a unified mathematical form for representing freeform shapes and analytical curves or surfaces. Evaluation of these functions is reasonably fast and computationally stable. They are invariant under parallel and perspective projection and also scaling, rotation and shear operations. A great variety of shapes can be created by manipulating the weights and control points of NURBS. The manner in which these shapes are formed is not always clear, however. Should a control point be moved, a weight changed or both? There exists a simple technique for NURBS shape modification that is based on easily understood geometric concepts. By selecting an arbitrary point O there is the added flexibility of determining how the spline changes given a displacement of a control point [7].

NURBS curves and surfaces defined
B-splines are a class of splines that consist of curve segments whose polynomial coefficients depend on tangent vectors to these segments. The endpoints of these vectors define the shape of the spline and are therefore called control points. The joining point between two segments is called a knot. These knots are spaced at non-uniform intervals of the parametric variable t. The values of x(t), y(t) and z(t) of the spline are rational numbers; the ratio of two polynomials of degree p.

A non-uniform rational B-spline curve p(t) is a polynomial function of the form

                  n
           1     ----
   p(t) = ----   \      wi Pi Ni,p(t)
          w(t)   /
                 ----
                  i=0

             n
            ----
   w(t) =   \      wi Ni,p(t)
            /
            ----
             i=0
There are n + 1 control points Pi and wi are the weights [5]. Ni, p(t) are the normalised B-spline basis functions.
            | 1  if ti <= t < ti+1
   Ni,0(t) = |
            | 0  otherwise


                t - ti
   Ni,p(t) = ------------- Ni,p-1(t)  +
               ti+p - ti

              ti+p+1 - ti
             ------------- Ni+1, p-1(t)
             ti+p+1 - ti+1
The polynomials, defined recursively, are of degree p and are defined over the entire curve. The knots, ti, form a knot vector
   T = {t0, t1, ..., tm}
and are defined on the interval [0, 1]. The number of knots, the number of control points and the degree of the basis functions are related by the formula
m = n + p + 1
The curve p(t) can also be written in terms of rational basis functions Ri, p(t)
             n
            ----
   p(t) =   \      Pi Ri,p(t)
            /
            ----
             i=0

              wiNi,p(t)
   Ri,p(t) = ---------
               w(t)
These rational functions form a partition of unity
          n 
         ----
   1 =   \      Ri,p(t)
         /
         ----
          i=0
A non-uniform rational B-spline surface p(u, v) is defined as

                       n     m 
                1     ----  ----
   p(u, v) = -------  \     \     wij Pij Nij(u, v)
             w(u, v)  /     /
                      ----  ----
                      i=0   j=0


               n      m
              ----  ----
   w(u, v) =  \     \     wij Nij(u, v)
              /     /
              ----  ----
              i=0   j=0

where Pij = (x, y, z)ij form a control net, wij are the weights assigned to each control point of the net, and Nij(u, v) denotes the bivariate, normalised B-splines of degree p and q in the u and v directions, respectively, defined over the knot vectors
   U = {0, 0, ..., 0, up+1, ..., ur-p-1, 1, 1, ... 1}
   V = {0, 0, ..., 0, vq+1, ..., vs-q-1, 1, 1, ... 1}
where
   r = n + p + 1
   s = m + q + 1
These rational functions also form a partition of unity and can be written in terms of rational basis functions.

NURBS shape modification
Displacing a control point pk along direction v for a distance dk gives rise to a new location pk*

   pk* = pk + dkv

   |v| = 1
Moving one control point pk affects the curve only in the span [tk, tk+p+1). There is an additive effect when moving n control points where
          ----
   d(t) = \      dk Rk(t)
          /
          ----
            k
The new curve p*(t) is translated, as a result of moving one or more control points, in direction v for a distance d(t).
   p*(t) = p(t) + vd(t)

   d(t) = dkRk(t)
Changing the weight wk of the kth control point by a non-negative value hk gives rise to wk* where
   wk* = hkwk
With origin O = pk, the reassignment of wk lifts point pkw along the z axis.
   pkw = (0, 0, wk)

   (pkw)* = (0, 0, hkwk)
The new curve p*(t) is then
            p(t)
   p*(t) = ------
            h(t)

           w*(t)
   h(t) = ------  =  1 + (hk - 1) Rk(t)
           w(t)
Each point corresponding to t sweeps out straight line segments through O = pk and p(t) as the weight varies. The curve is affected over the span [tk, tk+p+1). The consequences derived from the pair of equations are: p*(t) is a functional perspective transformation, with center O, of the original curve [7]. The origin O, however, can be an arbrtrary point. Reassigning a new weight lifts the desired control point pkw in a radial direction passing through O.
   pkw = (xkwk, ykwk, wk)

   (pkw)* = (xkwk, ykwk, hkwk)
and
   pk* = pk / hk

   wk* = hkwk
These four equations for an arbritrary point O correspond with the equations where O is a control point. This correspondance leads to the same expression for p*(t). The geometric significance also coincide and lead to the following control interface: and furthermore The displacement dpk of control point pk and a simultaneous reassignment of its weight wk is also a perspective functional transformation [5]. The center of this transformation is such that
   pk* - O = ceiling(pk - O) / hk
The point is then
                 hk
   O = pk  +  ------- dpk
               hk - 1

Moving a set of points wk* at the same has an additive effect on the factor h(t)
                ----
   h(t) = 1  +  \     (hk - 1)Rk(t)
                /
                ----
                  k
Two cases arise from this movement:

The notion of perspective functional transformations can also be applied to NURBS surfaces. If a control point pk, l moves along the radial direction through O and its weight changes, the new point pk, l* and weight wk, l* are

   p*k, l = pk, l / hk

   w*k, l = hk, lwk, l
The new surface p*(u, v) is
              p(u, v)
   p*(u, v) = -------
              h(u, v)

   h(u, v) = 1 + (hk, l - 1) Rk, l(u, v)

Rendering NURBS curves and surfaces
The pseudocode to render a NURBS curve is


   RenderCurve(curve, epsilon)
   {
      if (control points are within 'epsilon' of a line)
          DrawLine(curve)
      else {
          SubdivideCurve(curve, leftCurve, rightCurve)
          RenderCurve(leftCurve, epsilon)
          RenderCurve(rightCurve, epsilon)
      }
   }
The pseudocode to render a NURBS surface is

   RenderSurface(surface, epsilon)
   {
      if (control points are within 'epsilon' of a plane)
          DrawQuad(surface)
      else {
          SubdivideSurface(surface, surfaceNE, surfaceNW,
                           surfaceSW, surfaceSE)
          RenderSurface(surfaceNE, epsilon)
          RenderSurface(surfaceNW, epsilon)
          RenderSurface(surfaceSW, epsilon)
          RenderSurface(surfaceSE, epsilon)
      }
   }



[1] Coons, S.A., "Surfaces for Computer-Aided Design of Space Forms," technical report MAC-TR-41, MIT, Cambridge, Mass., 1967

[2] Foley, J.D., A. van Dam, S.K. Feiner, and J.F. Hughes, Computer Graphics Principles and Practice, Second Edition, Addison-Wesley, Reading, 1990, 495-504

[3] Forrest, R.A., Curves and Surfaces for Computer-Aided Design, doctoral disseration, Cambridge University, Cambridge, United Kingdom, 1968

[4] Luken, W.L., and F. Cheng, "Comparison of Surface and Derivative Evaluation Methods for the Rendering of NURB Surfaces," ACM Transactions on Graphics, 15(2):153-178, April 1996

[5] Piegl, L., "On NURBS: A Survey," IEEE Computer Graphics and Applications, 11(1):55-71, January 1991

[6] Risenfeld, R.F., Applications of B-Spline Approximations to Geometric Problems of Computer-Aided Design, Ph.D. dissertation, Syracuse Univeristy, Syracuse, N.Y., 1973

[7] Sanchez-Reyes, J., "A Simple Technique for NURBS Shape Modification," IEEE Computer Graphics and Applications, 17(1):52-59, January 1997

[8] Versprille, K.J., Computer-Aided Design Applications of the B-Spline Approximation Form, Ph.D. dissertation, Syracuse Univeristy, Syracuse, N.Y., 1975

[9] Wyvill, G., D. McRobie and M. Gigante, "Modeling with Features," IEEE Computer Graphics and Applications, 17(5):43-46, September 1997


.
Volume Rendering 05.october.1997 GFX

by Hin Jang

Volume rendering is the simulation of the propagation of light through a medium. As light traverses the volume, it may be absorbed, scattered or emitted at some point p(x, y, z). Each sample is distinguished by some measureable property set V = {v0 , ... , vn}. A constant-valued region in the volume that surrounds a sample is known as a volume cell, or voxel. Samples are usually taken at regular intervals along the three orthogonal axes and are stored in a spatial data structure. Rendering algorithms operate on the data structure in image-order, object-order, or domain-order. Rays that are cast into the volume where contributions of all voxels along the path are calculated to yield a pixel value is an image-order method. In object-order methods, the image footprint of each voxel is used to distribute its energy onto a local set pixels. Domain-order methods transform the volume data into some intermediate domain from which projection onto image space can be accomplished efficiently.

Lacroute developed a rendering algorithm that employs the features of image-order and object-order methods together with shear-warp factorisation. The viewing matrix is factored into a three-dimensional shear parallel to the cross-section of the volume data, a projection to form an intermediate image, and a two-dimensional warp to yield the final image [2]. Factorisation permits efficient and synchronous access to the spatial data structures that separately encode the opacity and occulsion of voxels. Resampling is limited to two steps and the volume is traversed only once.

Volume Rendering Equation
Assuming light consists of discrete packets of energy known as photons the flow of these members through a medium eventually reaches equilibrium at time t. An energy balance equation describes the energy input and output at some specified point r in a given direction w. The equation further states that the change of radiance L(r, w) along this path equals the sum of three terms

The integral form is
                                           r
                                          |\
                -t(r, r^)                 |    -t(r, r')
   L(r, w)  =  e           LB(r^, w)  +   |   e          Q(r', w) dr'
                                          |
                                         \|
                                           r^
where Evaluation of the energy balance equation can be simplified by the assumed condition that all photons only scatter once, absorption between the light source and the scattering event does not occur, and that energy entering the volume originates from a finite set of point sources [2]. This yields the volume rendering equation
                         x'
                      |\
                      |
              x^   -  |    p(x'') dx''
            |\        |
            |        \|
            |           x
   L(x)  =  |     e                      E(x') dx'
            |
            |
           \|
              x
where x is the distance along the ray and x^ is the point at which the ray exits the volume. Given that dx is some sample spacing along the ray and
                                             -pi dx
   opacity of sample i     =   ai   =   1 - e

   colour of sample i      =   Ci   =  (Ei/ai) dx

   premultiplied colour    =   ci   =   Ciai
   and opacity
then, for n sample points
            n - 1          i - 1
            ----           ------
   L(x)  =  \      ci   .   |  |    1 - aj
            /               |  |
            ----            |  |
            i = 0          j = 0
An image-order algorithm evaluates L(x) for each viewing ray that passes through the volume. The necessity to traverse the spatial data structure of the volume for each ray makes interactive rendering rates only possible on large parallel systems. Exploiting coherence and the notion of space-leaping, however, are possible optimisation paths [4].

Shear-Warp Factorisation
In sheared object space, all viewing rays are parallel to the third coordinate axis [2]. This intermediate domain allows for efficient filtering and projection to image space techniques. The factorisation of the viewing matrix is

   Mview  =  P . S . Mwarp
where P transposes the coordinate system so that the z-axis is the principle viewing axis, S transforms the volume into sheared object space, and Mwarp transforms sheared object coordinates into image coordinates. For prespective projections,
         |  1      0      0      0  |
   S  =  |  0      1      0      0  |
         | s'x    s'y      1     s'w |
         |  0      0      0      1  |
For a cross-section slice z0 of the volume, matrix S translates the voxels by (z0s'x, z0s'y) and scales them by 1 / (1 + z0s'w). The warp from sheared object space to image space is defined as
   Mwarp  =  S-1 . P-1 . Mview

Volume Rendering Algorithm
The algorithm uses a pair of data structures to render the volume. The first is a run-length encoded representation of the voxels. The encoded scanlines consist of two types of runs, transparent and non-transparent. Rendering the volume involves skipping the transparent runs, and thus eliminating unnecessary work. The second data structure is a run-length encoded representation of the pixels in the intermediate domain (ie. sheared object space). For each opaque image pixel in the run-length encoding, there is a pointer to the next non-opaque pixel in the same scanline. The rendering algorithm traverses through both the voxel runs and the pixel runs in scanline order. The rate of traversal, however, is not the same for both data structures. Voxel scanlines may need to be traversed more than twice for proper resampling. With the ability to simultaneously skip transparent voxels and opaque pixels, the relatively expensive calculations are restricted to only non-transparent and visible portions of the original volume.

The boundary of each sample varies in object space due to perspective projection. The definition of opacity is dependent on a constant sample spacing dx. Along a given viewing ray, dx is constant, but increases slightly between adjacent voxels as a function of distance along the ray. A precomputed lookup table can be used to establish the correct opacity value, an interpolated value between two opacities if necessary.



[1] Kaufman, A.E., "Volume Visualisation," ACM Computing Surveys, 28(1):165-167, March 1996

[2] Lacroute, P.G., Fast Volume Rendering Using a Shear-Warp Factorisation of the Viewing Transformation, Technical Report CSL-TR-95-678, Departments of Electrical Engineering and Computer Science, Stanford University, September 1995

[3] Marschner, S.R. and R.J. Lobb, "An Evaluation of Reconstruction Filters for Volume Rendering," 1994 IEEE Visualisation Confernence, 100-107

[4] Yagel, R., and Z. Shi, "Accelerating Volume Animation by Space-Leaping," 1993 IEEE Visualisation Conference, 62-69


.
Radiosity Methods 28.october.1997 GFX

by Hin Jang

Radiosity is the rate at which energy leaves a surface. A Lambertian surface is one that reflects an amount of light from a unit differential area dA proportional to the cosine of the angle between the surface normal N and the direction of the light source [2]. For an environment consisting of such surfaces, the radiosity equation is

                         |\
                         |
   B(x)  =  Be(x) + p(x) |  G(x, x')B(x') dx'
                         |
                        \|


         =  Be(x) + p(x)E(x)

         =  Be(x) + Br(x)

where B(x), the radiosity at point x measured in energy per unit time per unit area, is the sum of emitted radiosity B e (x) and the reflected radiosity B r (x). Reflectivity, a function of wavelength, is denoted p(x). The integral is taken over the hemisphere about x. G(x, x') accounts for the relative orientation, distance and visibility of the surfaces.
                   cos(tx) cos(tx')
   G(x, x')  =   --------------------  V(x, x')
                    pi |x - x'|2

V(x, x') is equal to one if point x' is visible from point x, zero otherwise. E(x) is irradiance, the amount of energy per unit area received from other surfaces.

Solving the radiosity equation involves projecting the emittance and reflectance functions onto a set of basis functions. For radiosity B(x), its approximation is B^(x), a linear combination of n basis functions {Ni}i = 1, ..., n. The approximation for reflectivity p(x) is similarly defined.

                        n 
                       ----
   B(x)  ~=  B^(x)  =  \      BiNi(x)
                       /
                       ----
                       i=1


                        n
                       ----
   p(x)  ~=  p^(x)  =  \      plNl(x)
                       /
                       ----
                       l=1

where B i and p l are the coefficients of the chosen orthonormal bases. The coefficients B i are the inner product <B - B^, N i> [6]. As such, the approximation of B(x) can be written as
                        n 
                       ----
   B(x)  ~=  B^(x)  =  \      <B, Ni> Ni(x)
                       /
                       ----
                       i=1

The solution to the original radiosity equation for receiving surface i is approximated by the following linear system
                             n
                            ----
   B(x)  =  Bi  =  Bei   +   \      KijBj
                            /
                            ----
                            j=1

where
           |\            |\
           |             |
   Kij  =  |    p^(x) dx  |    G(x, x')Nj(x')Ni(x) dx'
           |             |
          \|            \|

The reflected radiosity B r (x) is
                            n               n
                           ----            ----
   Br(x)  =  p^(x)E(x)  =  \     plNl(x)   \      EiNi(x)
                           /               /
                           ----            ----
                           l=1             i=1

If the radiosity equation is decomposed as follows

the radiosity equation becomes
   B(x)  =  Be(x) + K(B)(x)

         =  Be(x) + S o G(B)(x)

and the linear system can be written as
                   n
                  ----
   Bi  =  Bei  +   \      KijBj
                  /
                  ----
                  j=1


                   n            n
                  ----         ----
       =  Bei  +   \      Sik   \      GkjBj
                  /            /
                  ----         ----
                  k=1          j=1

where
    Kij  =  <S o G(Nj), Ni>

    Gkj  =  <G(Nj), Nk>

    Sik  =  <S(Nk), Ni>

             n
            ----
         =  \      pl<Nl Nk Ni>
            /
            ----
            l=1
The decomposition into operators G and S allows for efficient representation of each operator individually [3].

Hierarchical Radiosity
For n elements in an environment, a linear system of n equations must be solved to yield the radiosity solution. This requires an algorithm to compute n * n coefficients representing the interaction of light energy between each pair of elements. To avoid the enormous computational complexity, the operations can be decomposed into n blocks for a given accuracy [9]. In each block, the magnitude of interaction is about the same. The approach of hierarchical radiosity subdivides, recursively, each input surface into a set of subpatches until the measure of interaction is constant across a given subpatch [7]. Each node in the hierarchy represents an area of the original surface. Two nodes are linked if the interaction between them can be computed to within some predefined accuracy.

The following code fragment establishes all linkages between initial patches p and q. FormFactor( ) computes the percentage of light interaction as the integral of G(x, x'), defined eariler, with respect to the area of the receiver patch, taking into account, also, the degree of occlusion. If either form factor is larger than the estimate Fe, the patch is subdivided into four new quadrilaterials. The subdivision is stored in quadtree data structure. Subdivide( ) returns false if the patch cannot be subdivided further, in that its area is less than Ae.


   void Refine(Patch *p, Patch *q, double Fe, double Ae)
   {
      double   Fpq, Fqp;

      Fpq = FormFactor(p, q);
      Fqp = FormFactor(q, p);

      if (Fpq < Fe && Fqp < Fe)
          Link(p, q);
      else {
          if (Fpq > Fqp) {
              if (Subdivide(q, Ae)) {
                Refine(p, q->ne, Fe, Ae);
                Refine(p, q->nw, Fe, Ae);
                Refine(p, q->se, Fe, Ae);
                Refine(p, q->sw, Fe, Ae);
              } else Link(p, q);
          } else {
              if (Subdivide(p, Ae)) {
                Refine(q, p->ne, Fe, Ae);
                Refine(q, p->nw, Fe, Ae);
                Refine(q, p->se, Fe, Ae);
                Refine(q, p->sw, Fe, Ae);
              } else Link(p, q);
          }
      }
   }
           
Once all form factors have been determined, the radiosity for each patch is calculated. Gather( ) accumlates the total amount of energy received by a patch directly and from its parent subpatches. The average brightness of each patch is stored in B and its diffuse colour in is stored in Cd. The brightness, gathered from the list of all interactions in q, is stored in Bg.

   void Gather(Patch *p)
   {
      Patch    *q;
      double   Fpq;

      if (p != NULL) {
         p->Bg = 0.0;
         for (q = p->interactions; q != NULL; q = q->next) {
            Fpq = FormFactor(p, q)
            p->Bg += Fpq * p->Cd * q->B;
         }
         Gather(p->ne);
         Gather(p->nw);
         Gather(p->se);
         Gather(p->sw);
      }
   }

The disadvantage of hierarchical radiosity is that shadow boundaries tend to be jagged because subdivision occurs regularly and, therefore, does not follow the contour of the shadow. One way to remove the discontinuities is to mesh the environment along the curve. This method of discontinuity meshing, however, increases the number of surfaces in a scene, magnifying the computational complexity.

Galerkin Radiosity
The accuracy to which radiosity is computed in the previous method is dependent on surface geometry. Complex interactions among non-planar surfaces require finer subdivision, at the cost of greater computation, since the bases are assumed to be piecewise constant across the subpatches. One way to avoid the limiting feature of hierarchical radiosity is to project the functions onto a higher order basis. Galerkin radiosity is a means by which the integral equation for radiosity can be solved in terms of a basis set of non-constant functions across a surface [12]. The basis set is {Tk(s, t) | k = 0, 1 ... n}, where s and t are the parametric variables of the surface and k denotes a particular function of the set. {Tk(s, t)} is an orthonormal set of basis functions where the coefficients for a given radiosity function over surface i is


   Bki  =  <Bi, Tk>

so that the original function can be approximated with
                  n
                 ----
   Bi(s, t)  ~=  \     Bki Tk(s, t)
                 /
                 ----
                 k=1

Applying the Galerkin method for radiosity begins with the radiosity equation of two variables
                                  |\  |\
                                  |   |
   B(s, t)  =  Be(s, t) + p(s, t) |   |  G(s, t, u, v)B(u, v) dudv
                                  |   |
                                 \|  \|

Expanding B(u, v) in terms of the basis set {Tl(u, v)} gives
                                    |\  |\
                                    |   |
   B(s, t)  =  Be(s, t) + p(s, t)Bl |   |  G(s, t, u, v)Tl(u, v) dudv
                                    |   |
                                   \|  \|

By taking the inner product of both sides with the kth basis set function Tk(s, t), the radiosity equation can be written as a matrix equation
                   ----
   Bki  -  Eki  =   \     Blj Kklij
                   /
                   ----
                   j, l

where Kklij, Bki, and Eki are the form factors, patch radiosities, and emittances, respectively. The radiosity solution computed by this method is a list of basis set expansion coefficients Bki for each surface i and basis function k [12]. The radiance at a point (s, t) on surface i is recovered from these coefficients using
                  n
                 ----
   Bi(s, t)  ~=  \     Bki Tk(s, t)
                 /
                 ----
                 k=1

Galerkin radiosity allows direct evaluation of the radiosity equation without the need to tesselate a curved surface. Meshing is only required when two surfaces are extremely close to each other and is not needed to model variations in intensity across a surface [12].



[1] Bastos, R., M. Goslin, and H. Zhang, Efficient Rendering of Radiosity Using Textures and Bicubic Reconstruction, TR-96-025, Department of Computer Science, University of North Carolina, Chapel Hill, 1996

[2] Foley, J.D., A. van Dam, S.K. Feiner, and J.F. Hughes, Computer Graphics Principles and Practice, Second Edition, Addison-Wesley, Reading, 723-724, 1990

[3] Gershbein, R., P. Schroder, and P. Hanrahan, Textures and Radiosity: Controlling Emission and Reflection with Texture Maps, Research Report CS-TR-449-94, Department of Computer Science, Princeton University, 1993

[4] Gershbein, R., An Adaptive Gauss Method For Computing Irradiance Coefficients of Galerkin Radiosity Systems, TR-485-95, Department of Computer Science, Princeton University, 1995

[5] Goral C.M., K.E. Torrance, D.P. Greenberg, and B. Battaile, "Modeling the Interaction of Light Between Diffuse Surfaces," Computer Graphics, 18(3):213-222, July 1984

[6] Gortler, S.J., P. Schröder, M.F. Cohen, and P. Hanrahan, "Wavelet Radiosity," Computer Graphics, SIGGRAPH 1993 Proceedings, 27(4):221-230

[7] Hanrahan, P., D. Salzman, and L. Aupperle, "A Rapid Hierarchical Radiosity Algorithm," Computer Graphics, SIGGRAPH 1991 Proceedings, 25(4):197-206

[8] Kajiya, J.T., "The Rendering Equation," Computer Graphics, SIGGRAPH 1986 Proceedings, 20(4):143-149

[9] Lischinski, D., F. Tampieri, and D.P. Greenberg, "Combining Hierarchical Radiosity and Discontinuity Meshing," Computer Graphics, SIGGRAPH 1993 Proceedings, 27(4):199-208

[10] Pellegrini, M., "Monte Carlo Approximation of Form Factors with Error Bounded a Priori," ACM Proceedings of the Eleventh Annual Symposium on Computational Geomerty, 287-296, 1995

[11] Smits, B., J. Arvo, and D. Greenberg, "A Clustering Algorithm for Radiosity in Complex Environments," Computer Graphics, SIGGRAPH 1994 Proceedings, 28(4):435-442

[12] Zatz, H.R., "Galerkin Radiosity: A Higher Order Solution for Global Illumination," Computer Graphics, SIGGRAPH 1993 Proceedings, 27(4):213-220