Professional Documents
Culture Documents
Sorting Algorithms For Geometric Methods in Acoustics: Seminar Mechanik
Sorting Algorithms For Geometric Methods in Acoustics: Seminar Mechanik
1.3 Definition of Spatial Data Structure ........................................................ 6 1.4 Need for Sorting Algorithms.................................................................... 6
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.
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.
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.
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.
3.1.3
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.
12
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.
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.
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.
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
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
Fig. 4.1.- Room geometry configuration example to perform ray tracing method.
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.
Ratio r(p)
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)
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
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.
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.
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.
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