Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Seminar Mechanik

Sorting Algorithms for Geometric Methods in Acoustics


Student: Roberto Luis Gomez Lizarraga Matriculation Number: 20833124 STUD number: 299

Advisor: Dipl.-Ing. Katrin Hge

Institut fr Modellierung und Berechnung


Technische Universitt Hamburg - Harburg

Hamburg, January 2011

Table of Contents 1 Introduction .......................................................................3


1.1 Room Acoustics ....................................................................................... 3 1.2 Geometric Queries .................................................................................. 4
1.2.1 Intersection Test ................................................................................................................ 4 1.2.2 Point in Polygon Test .......................................................................................................... 5

1.3 Definition of Spatial Data Structure ........................................................ 6 1.4 Need for Sorting Algorithms.................................................................... 6

2 Ray Tracing Method .........................................................8 3 Types of Spatial Data Structures ...................................10


3.1 Bounding Volume Hierarchies ............................................................... 10
3.1.1 Spheres ............................................................................................................................. 12 3.1.2 Axis Aligned Bounding Boxes ........................................................................................... 12 3.1.3 Oriented Bounding Boxes ................................................................................................ 12

3.2 Binary Space Partitioning Trees ............................................................. 13


3.2.1 Axis Aligned ...................................................................................................................... 13 3.2.2 Polygon Aligned ................................................................................................................ 15 3.2.3 Creating a Polygon Aligned BSP Tree ............................................................................... 16

3.3 Quadtree and Octree ............................................................................ 17

4 Example Using BSP Tree for Acoustic Application.....19


4.1 Ray Tracing without Using BSP Tree ...................................................... 19 4.2 Creating The BSP Tree ........................................................................... 20 4.3 Ray Tracing with BSP Tree ..................................................................... 22 4.4 Comparison and Conclusions ................................................................ 24

References ...........................................................................25
2

1. Introduction
1.1 Room Acoustics
The reproduction or simulation of the interaction between a sound source (or several) and a listener inside an arbitrary room with an arbitrary geometry is nowadays a topic of interest in research. Applications include virtual reality environment, building design such as concert halls, auditoriums, even aircraft interiors, etc. Most of the applications take into account a human listener. This means that two ears must be considered. This is called binaural hearing, and it is the reason why humans can localize sound. To correctly simulate the sound behavior within the room, position, level, and directivity of each primary sound source located inside the room as well as their corresponding sound field propagation and reflections from walls, must be synthesized and reproduced according to the current sender and receivers positions. The objective is to calculate the binaural room impulse response (BRIR). The BRIR represents the rooms acoustical fingerprint for a certain sender /Receiver position. This provides the possibility to reproduce the same sound signal at the receivers eardrums that a real listening situation would produce. Thus determination of the BRIR is the key for a realistic binaural room acoustical simulation. Theoretically the determination of an exact BRIR for a given virtual room geometry would have to take into account an infinite number of sound reflections with all their corresponding sound properties, which is practically impossible. Therefore, approximate methods which still provide a quite accurate sound field reproduction are needed. In any case, human auditory system is unable to evaluate all sound-related information. In general, there are three types of approaches: wave-based methods, radiosity methods and geometrical methods. Wave-based methods include finite element methods and boundary element method. The biggest disadvantage of these numerical approaches is their computational cost, but these are the most accurate.
3

Radiosity approaches divide the room into smaller subspaces. Instead of solving partial differential equations, they are based on determining sound energy exchanges between these subspaces, which assumes that only diffuse reflections exist. As this is usually not the case, it fails to determine an accurate room impulse response. Still, is very good for calculation of late response and rooms reverberation time. Geometric methods assume that the wavelength of sound is relatively small compared to the rooms dimensions and large with regard to the roughness and curvature of the rooms walls. Under these assumptions, the sound waves can be treated like light rays that follow the optical law of reflection. So far sound reproduction and simulation are well studied for noninteractive applications, which are mostly unfit for the demands of real-time applications because the approximate approaches are still a time-expensive computation process. In the case of virtual reality applications, interactivity is allowed and the position of the listener may be controlled by the user. Therefore, real-time room acoustical simulations are needed. Up to now, only geometrical approaches have been appropriate for real-time acoustical simulations. The reason for this is the fast computation of simple geometric queries.

1.2

Geometric Queries

1.2.1 Intersection Test There are several types of intersection tests used in different kinds of applications, e.g. box with box, ray with triangles, ray with point, and all sort of combinations within. In the context of geometric acoustic methods an intersection test between a line segment formed by two points (i.e. sound source and listener) and a plane is widely used in, for example, image source method. The intersection can be easily determined just by checking the positions of the line segments starting and end points relative to the plane. If both points lie on the same side, there is no intersection. If the points lie on different sides, the line segments intersection with the partitioning plane has to be determined. If this intersection point is located inside

the segment, an intersection occurred. In order to test if the intersection point is located inside the polygon, a point in polygon test is performed. This test is explained next. 1.2.2 Point in Polygon Test A point in polygon test consists in testing whether a point lies inside, outside or on the boundaries of a polygon. This type of test is very common and a very basic operation in computer graphics as well as in room acoustics simulation programs. There are many different types of point in polygon test algorithms and every each of these has particular advantages, disadvantages or assumptions depending on the type of problem. In addition, some approaches use preprocessing information to speed up the algorithms, but consume more memory, whereas others perform the test exclusively during run time. For polygon-based virtual environments, such as the ones used in room acoustics simulations, convex polygons are a common type of polygons used. This comes handy because then is possible to pre-process all required information for the point-in-polygon test. This approach is based on the Hesse normal form. After the polygon is projected onto an appropriate two-dimensional plane, the projected edges (or infinite planes) are transformed into the Hesse normal form. Each infinite plane divides space into 2 half spaces, having outward-pointing normal vectors as shown in figure 1.1.

Fig. 1.1.- As seen in the picture, the test dot T is inside the polygon when it is behind all polygons walls. Otherwise point in polygon test fails.

If the point being tested is on the interior side of each half-space, the point must be within the polygon because of the convex property of the polygon. And advantage of this algorithm is that it can be cancelled if the point is outside once. To test whether the point is inside or outside the edge, dot product between T and the edge under test is used.

1.3 Definition of Spatial Data Structure


A spatial data structure is one that organizes geometry in some n-dimensional space. These data structures can be used to accelerate geometric queries such as the ones seen previously. Such queries are used in a wide variety of operations, such as culling algorithms, during intersection testing and ray tracing, and for collision detection. The organization of spatial data structures is usually hierarchical. This means, loosely speaking, that the topmost level encloses the level below it, which encloses the level below that level, and so on. Thus, the structure is nested and of recursive nature. The main reason for using a hierarchy is that different types of queries get significantly faster, typically an improvement from O(n) to O(log n). It should also be noted that the construction of most spatial data structures is expensive and is often done as a preprocess. Then, lazy evaluations and incremental updates are possible in real time.

1.4 Need of Sorting Algorithms


When using geometric methods to calculate the BRIR of a room, there is an excessive number of geometric queries used. This is due to the fact that sound waves are treated like light rays so there is an enormous quantity of intersection test to find intersection between rays and the rooms walls which usually leads to poor performance. Nevertheless, fast algorithms are needed to comply with the demand of a real-time application such as in virtual reality environments. It is possible to speed up such test very efficiently by means of spatial data structures, which originate in the field of computer graphics. The most effective of these data structures usually sort geometry hierarchically in some n-dimensional space and are of a recursive nature, making possible a remarkable acceleration of queries such as culling
6

algorithms and intersection tests. This way, the use of spatial data structures to sort the room geometry and accelerate computation time for different types of queries is justified in cases where computation time is critical, such as in virtual reality applications.

2. Ray Tracing Method


Stochastic ray tracing method is a Monte Carlo method in which sound is radiated as a bunch of particles. The number of particles used is a crucial feature of the algorithm. First, the sound source radiates an impulse. To simulate this, particles are started at the same initial time in various directions. Each ray carries certain energy, propagates at the speed of sound and once in a while hits the room boundary, for simplicity called a wall throughout. It is reflected from the wall, hits another wall and so on. Each wall absorption reduces the particles energy.

Fig. 2.1.- An example of room geometry where the source and detector position is illustrated, as well as how one of the particles reaches the detector.

By means of particle detectors (objects with certain volume), the particles energy and the time elapsed since radiation from the source are registered. The number of counts represents the energy detected at the receiver.
Fig. 2.2.- Shows how the energy is stored in the correct time interval to form the Histogram.

Due to the frequency of absorption, ray tracing must be repeated for the frequency bands of interest, usually octave bands or one third octave bands. Air attenuation can also be modeled by reducing the rays energy according to the flight distance and the attenuation coefficient.

There are two options for modeling absorption. It is obvious that the energy can be reduced by multiplying the incident energy by the factor (1-). The alternative is to apply stochastic annihilation of particles. Both algorithms yield identical results in the limit of large numbers, but they differ in computation time and accuracy. In absorption by multiplication, the particle starts with energy e0 and is traced until a maximum travel time tmax, or until a minimum energy, emin, is reached. In the method of absorption by annihilation, a random number z (0,1) is compared with the absorption coefficient, . If z<, the particle is annihilated and the next particle is traced; see flow diagram in figure. As long as there is absorption somewhere in the room, we do not need to fix another truncation criterion such as tmax or emin. The most inner loop of ray tracing algorithms is the test of whether a ray (particle), represented as a line segment, a) is hitting a plane and b) if the intersection point is inside or outside a wall polygon. At this step, the actual straight line and the direction of propagation, thus, a vector is known. Also known is the set of polygons. The polygons qualified (those located in forward direction of the ray) are transformed in 2-D coordinate systems of the polygon planes and the procedure explained in section 1.2.2 is performed. If the intersection point is inside the polygon, the new travel line will be input variable for the next plane hit. Before reflection takes place, wall materials affect sound by absorption, scattering and diffraction.

Fig. 2.3.- Flow diagram for ray tracing method. Point in polygon test is performed in wall reflection instruction.

3. Types of Spatial Data Structures


3.1 Boundary Volume Hierarchies
A bounding volume is a volume that encloses a set of objects. The point of a BV is that it should be a much simpler geometrical shape than the contained objects, so that doing tests using a BV can be done much faster than using the objects themselves. As shown figure 3.1, there are many types of BV Shapes. We will shortly review the most important ones.

Fig. 3.1.- Shows different types of bounding volume shapes sorted by computational cost and by how good they approximate their shape to the contained object.

In a BVH, the scene is organized in a hierarchical tree structure consisting of a root, internal nodes, and leaves. The topmost node is the root, which has no parents. A leaf node holds the actual geometry of the bounded object and it does not have any children. In contrast, an internal node has pointers to its children. The root is thus an internal node, unless it has a bounding volume that encloses the geometry in its entire subtree. BVHs are also excellent for performing various queries. For example, assume that a ray should be intersected with a scene, and the first intersection found should be returned. To use a BVH for this, testing starts at the root. If the ray misses the roots BV, then the ray misses all geometry contained in the BVH. Otherwise, testing continues recursively, that is, the BVs of the children of the root are tested. As soon as a BV is missed by the ray, testing can terminate on that subtree of the BVH. If the ray hits a leaf nodes BV, the ray is tested
10

against the geometry at this node. The performance gains come partly from the fact that testing the ray with the BV is faster. Normally we do not know which child of a BV is closest without testing, so we must test all children in arbitrary order. A Binary Spatial Partitioning (BSP) tree has an advantage over normal BVHs in that it can guarantee front-to-back ordering. However, binary BVHs can also achieve this advantage by keeping track of the axis used to split the set of objects into the two children (see section 3.1.3). BVHs can be used for dynamic scenes as well. When an object contained in a BV has moved, simply check whether it is still contained in its parents BV. If it is, then the BVH is still valid. Otherwise, the object node is removed and the parents BV recomputed. The node is then recursively inserted back into the tree from the root. Another method is to grow the parents BV to hold the child recursively up the tree as needed. With either method, the tree can become unbalanced and inefficient as more and more edits are performed. Another approach is to put a BV around the limits of movement of the object over some period of time. This is called temporal bounding volume. As seen in figure 3.1, there are many types of BV shapes. It depends on the shape of the objects enclosed to select the right type of enclosure shape for the BV. One of the factors taken into account to judge whether a shape is optimal or not is the amount of free space left by the objects that exist in the environment after being put into the BV with the shape selected. Some examples are shown in figure 3.2.

Fig. 3.2.- Shows how the shape of the contained objects are a key factor to select the type of bounding shape.

11

3.1.1 Spheres Each sphere is represented by its center coordinates and its radius.

Fig. 3.3.- Shows an example of BVH using spherical bounding shapes (or circles in 2-D).

3.1.2 Axis Alligned Bounding Boxes This type of BV consists of using a rectangular box aligned to the coordinate axes.

Fig. 3.4.Shows an example of AABB.

3.1.3

Oriented Bounding Boxes

Consist of a rectangular box with an arbitrary orientation. A variation of this type is called binary BVH, which consist of having a BVH that is always split into two BVs at each level of the tree. The same idea behind binary BVH can be extended to other bounding shapes.

Fig. 3.5.- Shows a binary BVH with OBB.

12

3.2 Binary Space Partitioning Trees


Different from Boundary Volume Hierarchies, which are based on the subdivision of the object in a predefined bounded volume shape, space subdivision based data structures and all its variants such as octrees, quadtrees and binary space partitioning trees, sort the objects inside the scene hierarchically and according to the region in which the objects are. This information is encoded into the data structure. Most of the variants of BSPs are irregular. This means that the space can be subdivided arbitrarily. There are two noticeably different variants for BSPs: axis-aligned and polygonaligned. The trees are created by using a plane to divide the space into two, and then sorting the geometry into these two spaces. This division is done recursively. One interesting property that these trees have is that if the trees are traversed in a certain way, the geometrical contents of the tree can be sorted front-to-back from any point of view. This sorting is approximate for axis-aligned and exact for polygon-aligned BSPs. This is in contrast to BVHs, which usually do not include any type of sorting. The same idea can also be extended for 2 dimensional scenes and scenes of more than 3 dimensions. In general, for a N-dimensional space, the scene is subdivided in Ndimensional subspaces by a N-1 dimensional hyper plane. 3.2.1 Axis Alligned The idea behind an axis-aligned BSP is to recursively subdivide the box that represents the scene into smaller boxes and so on, by using a plane aligned with the orthogonal axes of the scene. One axis of the box is chosen, and a perpendicular plane is generated that divides the space into two boxes. Some schemes fix this partitioning plane so that it divides the box exactly in half; others allow the plane to vary in position. An object intersecting the plane can be treated in any number of ways. For example, it could be stored at this level of the tree, or made a member of both child boxes, or truly split by the plane into two separate objects. Storing at the tree level has the advantage that there is only one copy of the object in the tree, making object deletion straightforward. However, small objects intersected by the
13

splitting plane become lodged in the upper levels of the tree, which tends to be inefficient. Placing intersected objects into both children can give tighter bounds to larger objects, as all objects percolate down to one or more leaf nodes, but only those they overlap. A mailboxing scheme (also called timestamping) is then used to mark the object when it is first encountered when rendering a frame, e.g., with the number of the frame. When the object is encountered again in another leaf node, its mailbox is checked and the object ignored if it has already been sent to the screen for this frame. One disadvantage here is that large objects could be duplicated into many leaf nodes, costing time and memory. However, a more important, though subtle, problem is that every objects timestamp must be both read and written. Doing so can cause the memory cache to be invalidated and so cause significant slowdowns. Each child box contains some number of objects, and this plane-splitting procedure is repeated, subdividing each AABB recursively until some criterion is fulfilled to halt the process. An example of axis-aligned BSP tree is shown in figure 3.6.

Fig. 3.6.- An example of axis aligned BSP tree.

The axis and placement of the splitting plane is important for maximizing efficiency. One strategy for splitting a nodes box is to cycle through the axes. That is, at the root, the box is always split along the x-axis, its children are split along y, the grandchildren along z, then the cycle repeats. Another strategy is to find the largest side of the box and split the box along this direction. Geometric probability theory is also useful in determining a nearoptimal axis and split location. The idea is to avoid splitting objects as much as possible, along with finding two child nodes that together minimize the number of objects in a child multiplied by surface area or mean width of that child.

14

3.2.2 Polygon Aligned This data structure is particularly useful for rendering static or rigid geometry in an exact sorted order. It also has occasional use, such as for collision detection. In this scheme, a polygon is chosen as the divider, splitting space into two halves. That is, at the root, a polygon is selected. The plane in which the polygon lies is used to divide the rest of the polygons in the scene into two sets. Any polygon that is intersected by the dividing plane is broken into two separate pieces along the intersection line. Now in each half space of the dividing plane, another polygon is chosen as a divider, which divides only the polygons in its half-space. This is done recursively until all polygons are in the BSP tree. Creating an efficient polygon-aligned BSP tree is a time-consuming process, and such trees are normally computed once and stored for reuse. An example of polygon-aligned is shown in figure 3.7.

Fig. 3.7.- Shows a polygon aligned BSP tree.

It is generally best to form a balanced tree, i.e., one where the depth of each leaf node is the same, or at most off by one. A totally unbalanced tree is inefficient. An example would be a tree where each selected splitting polygon divides the space into one empty space, and the other space contains the rest of the polygons. There are many different strategies for finding a polygon used for splitting that gives a good tree. One simple strategy is the least-crossed criterion. First, a number of candidate polygons are randomly selected. The polygon whose plane splits the fewest other polygons is used.

15

The polygon-aligned BSP tree has some useful properties. One is that for a given view, the structure can be traversed strictly from back to front (or front to back). This is in comparison to the axis-aligned BSP tree, which normally gives only a rough sorted order. For example, consider what is seen by a viewer v in the last figure. Regardless of the viewing direction and frustum, v is to the left of the splitting plane formed by A. So C, F, and G are behind B, D, and E. Comparing v to the splitting plane of C, we find G to be on the opposite side of this plane, so it is displayed first. A test of Bs plane determines that E should be displayed before D. The back-to-front order is then G, C, F, A, E, B, D. Note that this order does not guarantee that one object is closer to the viewer than another; rather it provides a strict occlusion order, a subtle difference. For example, polygon F is closer to v than polygon E, even though it is farther back in occlusion order. 3.2.3 Creating a Polygon Aligned BSP Tree The goal of BSP-tree creation is to subdivide a current set of polygons recursively until only convex subsets remain. The crucial part is to choose an appropriate partitioner from the polygon set. Two factors are important. The resulting sets of polygons for the two subspaces should be nearly equal in size to obtain a balanced tree. On the other hand, polygons that are cross by the partitioner need to be split, and the resulting polygons must be assigned to their respective set. Since this operation increases the overall polygon count, these cuts should be kept at a minimum level. A criterion that reflects these two aspects measures the ratio r(p) between the number of polygons in front of the partitioner p and the number of polygons behind the same partitioner p. The other aspect is the number of polygons s(p) that must be split when choosing p as partitioner.

The plane of polygon p is chosen as partitioner if it has an acceptable ratio and results in the lowest number of splits s(p). The definition of acceptable is specified by a threshold t:r(p) is acceptable if r(p)>t. If t is small, a small number of polygon splits is preferred, which on the other hand causes the BSP tree to be unbalanced. A high value of t results in a

16

more balanced tree, but also a lot of polygon splits. Therefore the best choice of t is scene dependent.

3.3 Quadtrees and Octrees


The octree is similar to the axis-aligned BSP tree. A box is split simultaneously along all three axes, and the split point must be the center of the box. This creates eight new boxes (hence the name octree). This makes the structure regular, which can make some queries more efficient. An octree is constructed by enclosing the entire scene in a minimal axis-aligned box. The rest of the procedure is recursive in nature and ends when a stopping criterion is fulfilled. As with axis-aligned BSP trees, these criteria can include reaching a maximum recursion depth, or obtaining a certain number of primitives in a box. If a criterion is met, the algorithm binds the primitives to the box and terminates the recursion. Otherwise, it subdivides the box along its main axes using three planes, thereby forming eight equalsized boxes. Each new box is tested and possibly subdivided again into 2 x 2 x 2 smaller boxes. An octree is illustrated in figure 3.8.

Fig. 3.8.- Shows an octree example.

Quadtrees are the two-dimensional equivalent of octrees, with a third axis being ignored. They can be useful in situations where there is little advantage to categorizing the data along all three axes. A quadtree is shown in figure 3.9.

17

Fig. 3.8.- Shows an octree example.

Octrees can be used in the same manner as axis-aligned BSP trees, and thus, can handle the same types of queries. They are also used in occlusion culling algorithms. A BSP tree can, in fact, give the partitioning of space as an octree. If a cell is first split along the middle of, say, the X-axis, then the two children are split along the middle of, say, Y, and finally those children are split in the middle along Z, eight equal-sized cells are formed that are the same as those created by one application of an octree division. One source of efficiency for the octree is that it does not need to store information needed by more flexible BSP tree structures. Axis-aligned BSP trees can still be more efficient, as the additional memory cost and traversal time due to the need for retrieving the splitting planes location can be outweighed by the savings from better plane placement. In general, there is no overall best efficiency scheme; it depends on the nature of the underlying geometry, the use pattern of how the structure is accessed, and the architecture of the hardware running the code, to name a few factors.

18

4. Example using BSP tree for acoustic application


In this chapter we will see the difference in using the ray tracing method (discussed in section 2) without using a sorting algorithm, compared to using a polygon aligned BSP tree. For this example, we will only analyze one ray. The direction of the ray will be such that it will hit the receiver. The idea is to compare both results and see the difference with respect to computing time. Figure 4.1 shows a simple, obviously not convex set of polygons for which the ray tracing method will be applied. The dot marked as S represents the sender. The dot marked as L represents the listener.

Fig. 4.1.- Room geometry configuration example to perform ray tracing method.

4.1 Ray Tracing without BSP tree


The direction of the ray that we will analyze is shown in figure 4.2.

Fig. 4.2.- Room geometry that shows the trajectory of the ray being analyzed.

Recall from figure 2.3 that after shooting the ray, the instruction called wall reflection must be executed. In order to do so, we must first find the wall from which the ray will be reflected. To do that we need to perform point in polygon tests to all walls in the scene, check which ones actually are hit by the ray and select the one that is closer to the sender.
19

After finding the wall from where the ray will be reflected, absorption and some other sound propagation phenomena are simulated. Then, intersection with detector is verified. If the energy of the ray is still within limits, the process is repeated. For the case of our example, this means that in order for the ray to reach the detector, 8 point in polygon tests should be evaluated for each arrow in figure 4.2, as well as one detector intersection test. In total, 16 point in polygon tests plus 2 detection test are performed.

4.2 Creating the BSP Tree


First, we must create the BSP in order to use it in the example. As the BSP tree will be used under real-time conditions, it is strongly recommended to balance it. At the beginning the BSP tree only consists of an empty node, which is called the trees root. Now we have to determine which polygon complies with the criterions explained in section 3.2.3. It is suitable to choose the plane spanned by polygon 6 as the first partitioner as seen in figure 4.2. Polygon 4 would fit as well. Although, using polygon 6 causes a split of polygon 1 into two new polygons (1a and 1b), it provides the best ratio r(p) and the smallest number of splits, according to table 4.1.

Fig. 4.3.- Using polygon 6 as first partitioner in the tree

Polygon used as partitioner p 0, 1, 2, 3, 7 4,6 5

Number of polygons intersected s(p) 0 1 2

Number of polygons in front 0 5 6

Number of polygons behind 7 3 3

Ratio r(p)

0.0 0.6 0.5

Table 4.1.- Analysis of possible first partitioners.

20

The chosen partitioning plane is stored in the BSP trees node and subdivides the room geometry into two new sets of polygons. The BSP trees branches are designated with a plus, meaning the partition lies in front of the dividing plane, or a minus, representing the behind subset. Convex subsets are stored in leaves of the BSP trees (denoted by squares), whereas nonconvex subsets have to be further subdivided until only convex sets remain. In this case the behind branch leads to leaf L1, which contains a convex set of polygons. The set of polygons lying on the positive side of the partitioner is not convex, so the respective BSP-tree branch points to the hexagon representing the remaining subset. As the negative branch already points to a leaf, only a new partitioner has to be specified for the residual nonconvex polygon set. Polygons that are coplanar to the current partitioning plane do not have to be considered in subsequent steps, as they do not provide any additional information for the partitioning process. The planes spanned by polygon 4 or polygon 5 can be chosen for subdividing the remaining space, as they both provide the same ratio r(p) and the same number of splits s(p). This can be seen in table 4.2. Polygon used as partitioner p 1b, 2, 3 4 5 Number of polygons intersected s(p) 0 1 1 Number of polygons in front 0 2 3 Number of polygons behind 4 3 2 Ratio r(p)

0.0 0.666 0.666

Table 4.2.- Analysis of second partitioner.

In figure 4.3 the residual nonconvex polygon set is divided by polygon 4, which results in a split of polygon 1b into polygons 1b and 1c, whereas the partitioner is stored in the newly created node. As both novel subsets are convex the nodes outgoing branches point to the new leaves L2 and L3, which store the sets of polygons lying on the positive (leaf L2) or on the negative (leaf L3) side of the partitioner. The termination condition for BSP-tree creation is reached at this point, because the whole room geometry is now subdivided into convex subspaces.

21

Fig. 4.4.- Using polygon 4 as second partitioner in the tree.

4.3 Ray Tracing with BSP tree


In order to use the recently made BSP structure for our ray tracing example, first the position of the sender inside the scene has to be determined. Concerning the BSP tree, this means that the leaf node has to be found that represents the rooms subspace containing the receiver. The tree querying starts with the BSP trees root node, and the receivers position is classified to be in front of the node-stored partitioner. As the new traversed branch leads to another internal node, querying continues as shown in figure 4.5. Now the receivers position has to be determined relative to the new partitioner stored in node 4 and is classified as behind the partitioning plane. The subsegment is split again, and its appropriate part is moved along the negative branch to leaf L3. The position of the sender is now identified and therefore the starting point for shooting rays.

Fig. 4.5.Traversed path followed to find the source leaf position.

Now we can shoot the ray. The actual position of the ray starts within the sender, i.e., leaf 3. The objective is to now to which wall will the ray hit, so we traverse around the tree to
22

find in which leaf is this intersection going to take place. First, we must perform a point in polygon test to wall 4 to see if the ray is leaving L3 or not, giving a positive answer (See purple arrow in figure 4.6). Since we now already that L3 is not the hit point, we need to ask the tree wheter the ray stays in L2 or goes to L1. To do this, a point in polygon test is done to wall 6 giving a positive answer. This means that the ray should hit in one of the polygons of L1 (See figure 4.6). To know which one, point in polygon test is performed to all of them and the closer in position is the intersected wall.

Fig. 4.6.Traversed path followed to find the first wall intersected.

After simulating absorption and other phenomena, a new direction for the ray is obtained (purple arrow in figure 4.7) and, again, intersected wall must be found. The same process is done. A point in polygon test to wall 6 is performed to see if the ray leaves L1 giving a positive answer. Then another point in polygon test to wall 4 to see whether ray stays in L2 or goes to L3. Once in L3, all polygons from the leaf should be tested and the closer is selected.

Fig. 4.7.Traversed path followed to find the second wall intersected.

23

In total, 10 point in polygon test were performed, 6 tests less when compared to the lack of use of a BSP tree. Regarding detection tests, we can take advantage of the tree structure so that a detection test will only need to be performed when the ray traverses in the leaf where the detector is located. This means, that for this example 2 detection should be performed, one for the ray leaving the sender position and another when it is approaching the receiver.

4.4 Comparison and Conclusions


We were able to see that there is an improvement in the ray tracing method when using a BSP tree. There was a significant reduction in the amount of point in polygon test being made by the algorithm. In general, the use of sorting algorithms by means of spatial data structures makes possible to accelerate geometric methods in room acoustics. This is the reason why geometric methods are specially suited for virtual reality environment applications, that require a real-time operation and hence a fast response. Also note that the reduction from 16 to 10 point in polygon tests was obtained from a scene with only 8 walls. Nevertheless the amount of walls may go up to 100 in the case of a church for example. Figure 4.8 shows the typical improvements in computing time gained when using a BSP. Note that this improvement is from O(n) to O(log n) where n is the number of walls in the scene. That is, the improvement is much bigger as the number of walls in the scene increases.

Fig. 4.8.- Graph that shows a typical improvement in computing time when using BSP.

24

References
Schrder, D. Lentz, T. Real-Time Processing of Image Sources using Binary Space Partitioning. AES e-Library, 2006. Rescheleit, M. Implementierung und Validierung eines Rechenmodells zur Bestimmung des Schalldruckpegels in Flugzeugkabinen. TUHH, Institut fr Modellierung und Berechnung DPL-002/2010, 2010. Foley, J., van Dam, A., Feiner, S. K., Hughes, J. F. (1995) Computer Graphics: Principles and Practice. Addison-Wesley, 1995. Vorlnder, M. Auralization: Fundamentals of Acoustics, Modelling, Simulation, Algorithms and Acoustic Virtual Reality. Berlin: Springer-Verlag, 2008. Mezger, J. Bounding Volume Hierarchies. in: Eurographics Tutorials (part of the tutorial: Collision handling in dynamic simulation environments), 2005. http://www.gris.uni-tuebingen.de/people/staff/jmezger/papers/bvh.pdf (accesed on january, 2011). Akenine-Moller, T. Haines, E. Hoffman, N. Real-time Rendering. 3rd edition. A K Peters/CRC Press, 2008. Samet, H. Spatial Data Structures in Modern Database Systems: The Object Model, Interoperability, and Beyond, W. Kim. Reading: Addison Wesley/ACM Press, 1995, 361385. http://www.yaldex.com/games-programming/0672323699_ch08lev1sec10.html

25

You might also like