Quadrature Prefiltering | 10.january.1997 | GFX |
by Hin Jang
Converting a continuous image to a discrete image results in aliasing, a visible artifact characterised by moire patterns. Prefiltering limits the spectrum of the continuous image before sampling takes place. Quadrature prefiltering is an algorithm that generates much less aliasing artifacts than other methods including uniform super sampling and stochastic sampling [2].
The value of the desired output image Ipix(n1, n2) is given by the volume under h(x,y) within the area of Iideal(n1 - x, n2 - y)
|\ |\ | | Ipix(n1 , n2) = | | h(x,y)Iideal(n1 - x, n2 - y) dxdy | | \| \|Evaluation of this area integral is simplified by applying Greene's Theorem for bounded regions. In this case, the area is the sum of the edge integrals e of Iideal. Thus,
Ipix(n1 , n2) = e0 + e1 + ... + enAssuming a constant Iideal(x,y),
d f(y) |\ |\ | | e = K | | h(x,y) dxdy | | \| \| c 0
Gaussian Quadrature
Gaussian quadrature can be used to approximate the definite integral of some
function [1]. The solution is the weighted sum of the values
of the function at n sample points vj
using weights wj. The simplest form of
Gaussian quadrature estimates the integral of r(v) over (-1, 1).
1 |\ n | ---- | r(v)dv = \ wjr(vj) | / \| ---- -1 j = 1The order of quadrature is n. The sample points vj and weights wj are constants. These values have been tabulated and published [3] and little improvement is acheived beyond n = 5 [2].
degree n points vj weights wj 5 0.9061798456 0.2369268850 0.5384693101 0.4786286705 0.0 0.5688888889 -0.9061798456 0.2369268850 -0.5384693101 0.4786286705The n samples points vj are the roots of the nth Legendre polynomial Pn(v) defined recursively as
P0(v) = 0 P1(v) = v 2n + 3 n + 1 Pn+2(v) = ------ vPn+1(v) - ----- Pn(v) n + 2 n + 2 n >= 0The n weights wj are found by solving
1 n |\ ------ | | | (v - vk) wj = | | | -------- dv | | | (vj - vk) \| k = 1 -1 k != jThe general form of Gaussian quadrature is
d |\ n | d - c ---- | r(v)dv = ----- \ wjr(pj) | 2 / \| ---- c j = 1where
(d - c)vj + (d + c) pj = ------------------ 2
Quadrature Prefiltering
The edge integral ei can now be solved
using the above equation. If we rewrite the integral as such
d |\ | e = K | L(fi(y),y) dy | \| cwhere
d |\ | L(x,y) = | h(x,y) dx | \| cUsing Gaussian quadrature, the final usable form of the edge integral is
d |\ | e = K | L(fi(y),y) dy | \| c n d - c ---- = K ----- \ wjL(fi(pj), pj) 2 / ---- j = 1Evaluating L is inefficient, especially for large values of n. The use of a lookup table will increase calculation speed where the values of L(x, y) are stored in a line integral table LT(s, t) where
xs |\ | LT(s, t) = L(xs, yt) = | h(x, yt)dx | \| 0
[1] Burden, R. L., and Faires, J.D., Numerical Analysis, 4th ed., PWS-Kent Publishing, Boston MA, 200-203, 1989[2] Guenter, B., and Tumblin, J., "Quadrature Prefiltering for High Quality Antialiasing," ACM Transactions on Graphics, 15(4):332-353, October 1996
[3] Stroud, A. H., and Secrest, D., Gaussian Quadrature Formulas, Prentice-Hall, Englewood Cliffs, NJ, 1996
.
Delaunay Triangulation | 01.may.1997 | GFX |
by Hin Jang
Triangulation is the process of subdividing an area into triangles. Delaunay triangulation has the properties where 1) the circumcircle of each triangle contains no points of the triangulation and 2) given four points and the associated quadrilateral, the diagonal that splits the polygon into two triangles maximises the the lesser of the internal angles. Of the several algorithms [4, 5, 6, 7], the one that uses a uniform grid has been shown to exhibit linear time complexity [1].
Given a set of points in R², these points are placed into a data structure where a third point c can be determined efficiently such that <a, b, c> is a Delaunay triangle. Herein, a uniform grid is laid over the set of points. To compute this grid, the first step is to calculate the min-max box of the data set. The box is offset by the point coincidence tolerance TOL so that any points that lie of a grid line will be handled appropriately.
xmin = xmin - TOL xmax = xmax + TOL ymin = ymin - TOL ymax = ymax + TOLThe size of the grid is the sqaure root of
(xmax - xmin)(ymax - ymin) ---------------------------- nwhere n is the number of points in the data set. The number of grid cells in the x and y directions is given by
x_res = int((xmax - xmin) / size) + 1 y_res = int((ymax - ymin) / size) + 1where int( ) is a cast operator to covert a double precision number into an integer. With the grid structure now established, to place each data point into one and only one grid cell the following steps are required:
grid_x = (xi - xmin) / size grid_y = (yi - ymin) / size i_cell = int(grid_x) j_cell = int(grix_y)
Each data point is associated with the following data structure
typedef struct cellnode Cell; struct cellnode { int used, vertex_number; double x, y; Cell *previous_point, *next_point, *next_node; };where used is a flag to indicate whether a point is used to form a triangle, vertex_number is a number between 0 and n. The normalised coordinates of the point are x and y. previous_point and next_point are pointers to establish a certain ordering in the trianguation process, and next_node points to the next node in the same cell.
The triangulation process involves three steps
Any point can be the start point but for efficiency the algorithm selects one that is more or less at the center.
(m, n) = (x_res/2, y_res/2)
With the start point P1 the algorithm computes the first edge by using the following method
The found point P2 is the closest point to P1 and the edge <P1 , P2> is used to start the triangulation.
To find the third point Pi so the triangle <P1, Pi, P2> satisfies the Delaunay criteria, the algorithm does the following:
The found point forms the third vertex of the Delaunay triangle.
the algorithm subdivides the start edge and places the two half edges <P1, P2 > and <P2, P1 > into a circular queue called the edge list. The algorithm then uses the queue to add triangles in a circular fashion.
[1] Brown, P.J.C., Three Examples of Incremental Delaunay Triangulation Algorithms for Terrain Modeling, Computer Laboratory, University of Cambridge, UK, July 1995[2] Fang, T., and L. A. Piegl, "Delaunay Triangulation Using a Uniform Grid", IEEE Computer Graphics and Applications, 13(3):36-47, May 1993
[3] Garland, M., and P.S. Heckbert, Fast Polygonal Approximation of Terrains and Height Fields, CMU-CS-95-181, School of Computer Science, Carnegie Mellon University, September 1995
[4] Leach, G., Improving Worst-Case Optimal Delaunay Triangulation Algorithms, Department of Computer Science, Royal Melbourne Institute of Technology, Melborne, Australia, June 15, 1992
[5] Midtbø, T., Spatial Modeling by Delaunay Networks of Two and Three Dimensions, Department of Survey and Mapping, Norwegian Institute of Technology, University of Trodheim, February 1993
[6] Shewchuk, J.R., Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulation, School of Computer Science, Carnegie Mellon University, May 1996
[7] Su, P., and R.L.S. Drysdale, A Comparison of Sequential Delaunay Triangulation Algorithms, Imperative Internet Technologies, April 1996
.
Parametric Line-Clipping | 07.december.1996 | GFX |
by Hin Jang
Liang and Barsky developed a parametric line-clipping algorithm that is especially fast and efficient given an upright two or three dimensional clip region [3]. Herein is a very brief overview of the algorithm. The clip region is a rectangle defined by edges Ei, where i = 0, 1, 2, 3, having outward pointing normals Ni.
Given a line segment P0 P1 clipped against Ei the intersection point is
P(t) = P0 + (P1 - P0)twhere t = 0 at P0 and t = 1 at P1. To solve for t, consider a point PEi on edge Ei. The dot product
Ni . [P(t) - PEi]is equal to zero. As such, substituting for P(t),
Ni . [P0 + (P1 - P0)t - PEi] = 0 Ni . (P0 - PEi) + Ni . (P1 - P0)t = 0Letting D = P1 - P0 gives rise to
Ni . (P0 - PEi) t = --------------- - Ni . D[1]. The above equation can be used to find the intersection(s) between P0P1 and each edge of the rectangle. In this case, at most, four values of t are generated. The next step is to determine which values of t correspond to an intersection with the clip rectangle. We can classify these points as either "potentially entering" (PE) or "potentially leaving" (PL).
P1 | / | |/ | PL | /| | / | | / | ------+-------PL--+------ | / | | / | | / | | / | ------+--PE-------+------ | / | |/ | PE | /| | / | | / P0A point is PE if the dot product Ni . D < 0. A point is PL if the dot product Ni . D > 0. The line we want is defined by a (PE, PL) pair where tE = 0 is the lower bound of PE; tL = 1 is the upper bound of PL; and tE < tL [1]. These restrictions contribute to the algorithm's trivial rejection criteria as shown here.
The algorithm can be extended to clip a line in R3 against the six clipping planes of a view frustum. Assuming the volume is defined by the planes
x = z, x = -z, y = z, y = -z, z = -zmin, z = -zmaxthe implementation is as follows.
[1] Foley, J.D., A. van Dam, S.K. Feiner, and J.F. Hughes, Computer Graphics Principles and Practice, Second Edition, Addison-Wesley, Reading, 120, 1990[2] Liang, Y.D., B.A., Barsky, and M. Slater, Some Improvements to a Parametric Line Clipping Algorithm,, CSD-92-688, Computer Science Division, University of California, Berkeley, 1992
[3] Liang, Y.D., and Barsky, B., "A New Concept and Method for Line Clipping," ACM Transactions on Graphics, 3(1):1-22, January 1984