Applied Mathematical Sciences, Vol. 8, 2014, no. 24, 1171-1176 HIKARI Ltd, www.m-hikari.com http://dx.doi.org/10.12988/ams.2014.4159 New Reliable Algorithm of Ray Tracing through Hexahedral Mesh R. P. Koptelov Ural Federal University 19 Mira St., Ekaterinburg, 620002, Russia A. V. Lapteva Ural Federal University 19 Mira St., Ekaterinburg, 620002, Russia Copyright 2014 R. P. Koptelov and A. V. Lapteva. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited. Abstract It is shown that some rays loss if the standard method of ray tracing with non uniform mesh is used. A new method is proposed which solves that problem of loosed rays. The method is slightly faster than the standard one. Keywords: ray tracing, mesh, hexahedron 1. Introduction Ray tracing is one of the most known methods for computation of light radiosity [4] or radiative heat rate [7]. Ray tracing is very time consuming therefore geometrical data structure is always used to accelerate the process. Such data structure may be kd-tree, Bounding Volume Hierarchy, uniform or hierarchical grid (mesh), see classic book [4] or modern review [11]. One separate data structure is non uniform mesh which is an approximation of initial model geometry. Last time an interest to using non uniform mesh is increased [3,6,8,9], but ray tracing methods for this data structure are not advanced.
1172 R. P. Koptelov and A. V. Lapteva There are several algorithms of ray tracing with uniform mesh (see the review [2]) differ in finding next cell and in calculation type (real or integer), but unfortunately they can t be applied for non uniform mesh. 2. Meshes used in the study Three meshes were used for tests in this study (fig. 1): a) Uniform cubic mesh a cube with 10 cells along all directions. Cells vertices are generated as follows: x = i; y = j; z = k. b) Oblique-angled uniform mesh with 10 cells along all directions. Cells vertices are generated as follows: x = i + 0.15j + 0.15k; y = j; z = k. Value 0.15 is chosen unconditionally and has no importance in the study. c) Non uniform mesh approximation of half of cylinder with longitudinal hole. This mesh with 14x29x11 cells was built in Gambit program. FIg. 1 Used meshes, ix, iy, iz directions of increasing i,j,k respectively 3. Standard ray tracing with non uniform hexahedral mesh Standard ray tracing is the following: for current cell ray-face intersections are tested until intersected face is not found [7] outlet face. Inlet face is not considered. In first ray-plane intersection point is calculated and then point in quadrilateral test is executed [1]. Quadrilateral is represented by intersection of four halfplanes. If point belongs to all four halfplanes then it belongs to the quadrilateral too [5]. Another way to bisect the quadrilateral into two triangles
New reliable algorithm of ray tracing 1173 [7] and to execute ray-triangle intersection tests [10]. In other relevant works [6,8,9] only tetrahedral mesh is used. Described standard method was applied to three meshes at fig. 1. Rays were traced such that each ray was started and finished at centers of two different boundary faces. It was found that ray can travel very close or exactly through an edge between two cells or through a vertex between eight cells. In this cases no faces intersected by the ray is found due to calculation errors. In other words algorithm reports that ray doesn t exit from any face of current cell and further tracing is impossible. So, some rays are loosed. Number of loosed rays for various meshes is shown in table 1. Table 1. Rays loosing with standard ray tracing Mesh Traced rays Loosed rays a 179700 24708 (13.8 %) b 179700 22758 (12.7 %) c 1197378 42 (0.0035 %) Obvious way is to introduce a tolerance in point in quadrilateral test, i.e. virtually expand faces, but as shown further this doesn t solve the problem. Suppose it is needed to determine outlet face for cell C1 (fig. 2a). If face 2 is tested first then face 2 becomes outlet face and at the next step outlet face for cell C2 will be searched. But face 4 is not intersected by the ray, so ray tracing fails even with introduced tolerance. Another case is shown at fig. 2b: ray passes face 3 and goes into C3. Ray-face intersections against faces 4,5,6 is initiated. If face 4 is tested first then algorithm will report that ray outs through face 4 fail case. Summary, introduced tolerance is not a solution of loosing rays problem. FIg. 2 2D illustration of various ray loosing cases
1174 R. P. Koptelov and A. V. Lapteva 5 New reliable ray tracing algorithm without ray loosing Let first remember standard ray-plane intersection algorithm [1]: 1) Let one has line equation x r = O + tr with O - point at the line, R - direction vector; and plane equation N x p + D = 0 with N - plane normal vector, D - distance from the plane to the origin. 2) Test that line is not parallel to the plane: z = R N > ε, ε - tolerance. 3) Calculate distance from O to intersection point at the plane: t p = ( D + O N ) / z. 4) Calculate intersection point in Cartesian coordinates: x = O + t R. Basic idea of proposed reliable method: if no intersected faces were found forcibly choose the face with minimum distance from O. But this is not enough, for example, if current cell is C3 (fig. 2b), then among faces 4, 5 and 6 face 4 is the nearest. Plane of face 4 is even closer to O than plane of face 3. Therefore solution is to take into account faces orientation. Let all faces are oriented outside of the current cell (fig. 2c). Then only faces that have acute angle between ray and their normal vectors ( R N > 0 ) have to be tested. If no intersection is found choose the face with minimum distance from O among faces with R N > 0. Proposed method is applied to ray tracing through three meshes (fig. 1) and no rays were loosed. Normal vectors are precomputed and stored separately for each cell to accelerate ray tracing. In proposed algorithm ray-face intersection point calculation and point in quadrilateral test are not mandatory. Both algorithms are reliable and have similar performance. Performance of three ray tracing methods (standard, new one with calculation of ray-face intersection point and new one without calculation of ray-face intersection point) is shown in table 2. Table 2. Ray tracing time Time, sec Mesh New method Standard With calculation of Without calculation of method intersection point intersection point a 1.0741 1.1828 1.2238 b 1.1089 1.18 1.2018 c 9.87 9.32 9.18 p
New reliable algorithm of ray tracing 1175 Standard method shows the smallest time for meshes a and b because for loosen rays (13.8 % and 12.7 %) tracing was performed only partially. If all rays are traced properly then standard method may give more time by values 13.8 % and 12.7 %, i.e. 1.22 and 1.25 sec respectively more than those of new method. New method with calculation of intersection point is faster than new method without calculation of intersection point for meshes a and b, and is slower for mesh c. Advantage of the first variant is that process is stopped as soon as first face is intersected by the ray, other faces are rejected. Advantage of the second variant is that Cartesian coordinates of intersection point and point in quadrilateral test are rejected. 6. Conclusions Khown methods of ray tracing through uniform mesh cannot be applied for non uniform mesh, and standard method of ray tracing through non uniform mesh leads to problem of loosen rays if ray travels very close or exactly through an edge between two cells or through a vertex between eight cells. New reliable ray tracing method is proposed that ensures right tracing of all rays through non uniform mesh: 1) For each cell all faces are oriented outside of the current cell. 2) Only faces having acute angle between ray and their normal vectors have to be tested. 3) If no intersected faces were found forcibly choose the face with minimum distance from ray start. Normal vectors are precomputed and stored separately for each cell to accelerate ray tracing. Possible subject for future work is saving storage space. References [1] D. Badouel. An Efficient Ray-Polygon Intersection. In A. Glassner, editor, Graphics Gems I, pages 390-393. Academic Press, 1990. [2] B. Cosenza. A survey on exploiting grids for ray tracing. Eurographics Italian Chapter Conference, 2008, pp. 89-96. [3] J. Favre, R. Lohner. Ray tracing with a space-filling finite element mesh». International journal for numerical methods in engineering, 1994, 37, pp. 3571-3580.
1176 R. P. Koptelov and A. V. Lapteva [4] A.S. Glassner. An introduction to ray tracing, Academic Press, 1989. [5] E. Haines, Point in Poligon Strategies. In P.S. Heckbert, editor, Graphics Gems IV, pp. 24-46. Academic Press, 1995. [6] A. Lagae, P. Dutre. Accelerating ray tracing using constrained tetrahedralizations. Eurographics Symposium on Rendering, 2008, 27(4), pp. 1303-1312. [7] S. Mazumder. Methods to accelerate ray tracing in the Monte Carlo method for surface-to-surface radiation transport. Trans. ASME. J. Heat Transfer, 2008, Vol: 128, No: 9. [8] G. Marmitt, P. Slusallek. Fast ray traversal of unstructured volume data using Plucker tests. Technical report. Computer Graphics Lab, Saarland University, 2005. [9] G. Marmitt, P. Slusallek. Fast ray traversal of tetrahedral and hexahedral meshes for direct volume rendering. Eurographics IEEE-VGTC Symposium on Rendering, 2006. [10] T. Müller and B. Trumbore, Fast, Minimum Storage Ray-Triangle Intersection, Journal of Graphics Tools, 1997, pp.22-28. [11] I. Wald, W.R. Mark, J. Gunther, S. Boulos, T. Ize et al. State of the Art in Ray Tracing Animated Scenes Computer graphics forum, 2009, 28(6) pp. 1691-1722. Received: January 31, 2014