A Simple and Fast Hardware-Accelerated Point-In-Polygon Test

A Simple and Fast Hardware-Accelerated Point-In-Polygon Test

A SIMPLE AND FAST HARDWARE-ACCELERATED POINT-IN-POLYGON TEST F. Mart´ınez, A. J. Rueda, F. R. Feito Departamento de Informa´tica, University of Jaen,´ Campus Las Lagunillas, Jaen,´ Spain Keywords: Point-in-polygon test, hardware-accelerated algorithms. Abstract: The new generations of GPUs bring us a set of new basic operations or tools that allow us to design new solutions to traditional problems in Computer Graphics. In this paper we present two approaches for the point- in-polygon problem based on the occlusion query extensions supported by modern GPUs. Both approaches are fast and their execution times do not depend on the number of edges of the polygon. Besides, one of the tests allows multiple point-in-polygon queries to be done in parallel with CPU computations. 1 INTRODUCTION Moller and Haines, 2002). These algorithms try to avoid drawing objects that are hidden by other objects in the scene. In this paper we show how this occlu- The 2D point-in-polygon test is a basic geometric sion query mechanism can also be used to develop operation in Computer Graphics, GIS and other ar- two original and efficient point-in-polygon tests. The eas. We can roughly classify point-in-polygon ap- main advantages of the tests are: they are easy to un- proaches into two categories. In the first one the derstand and they have a straightforward implementa- algorithms work with the set of edges of the poly- tion, they work with any kind of polygon, they are fast gon, neither preprocessing nor additional data struc- and their execution times do not depend on the num- ture are needed. An example of these methods is ber of edges of the polygon. Besides, one of the tests the crossings test of Shimrat (Shimrat, 1962) as cor- allows multiple point-in-polygon queries to be done rected by Hacker (Hacker, 1962). In the second cat- in parallel with CPU computations. egory, a preprocessing of the polygon —normally The remainder of the paper is structured as fol- a decomposition— is done, and an alternative data lows. Section 2 explains the picking algorithm structure to the set of edges of the polygon is built. based on graphics hardware mentioned in this in- This alternative data structure implies additional stor- troduction. Section 3 describes the first point- age requirements. However, the approaches into this in-polygon test, which is based on the OpenGL’s category are very fast. Examples of this kind of al- HP occlusion test extension. In Section 4 the sec- gorithms are the grid method (Antonio, 1992) and the ond point-in-polygon test, which is based on the triangle fan methods, as the Spackman test (Spack- OpenGL’s NV occlusion query extension, is de- man, 1993). scribed. In Section 5 we compare our point-in- Traditionally, point-in-polygon test algorithms polygon tests with other well known tests. Finally, have been implemented in the CPU because it is a Section 6 brings conclusions. relatively simple and efficient operation. However, the new generation of GPUs allows us to design new solutions to the point-in-polygon problem. In (Han- rahan and Haeberli, 1990) graphics hardware is used 2 GRAPHICS HARDWARE to support picking, an operation quite similar to the BASED PICKING point-in-polygon test. The occlusion query mechanism of modern GPUs In this section we describe a picking algorithm sup- is used in occlusion culling algorithms (Akenine- ported by graphics hardware developed by Hanrahan 161 Martínez F., J. Rueda A. and R. Feito F. (2007). A SIMPLE AND FAST HARDWARE-ACCELERATED POINT-IN-POLYGON TEST. In Proceedings of the Second International Conference on Computer Graphics Theory and Applications - GM/R, pages 161-165 DOI: 10.5220/0002072501610165 Copyright c SciTePress GRAPP 2007 - International Conference on Computer Graphics Theory and Applications and Haeberli (Hanrahan and Haeberli, 1990). At a whether a 2D point p = (x,y) is inside the polygon, “preprocessing” stage a scene is rendered in an off- an occlusion test with a 3D point p2 = (x,y,z) is done, screen buffer, with each polygon having a unique where z is such that p2 is positioned in a plane far- color that will be used as an identifier. When the ther, from the observer’s point of view, than the plane user wants to pick an object clicks on a pixel, and the where the polygon was drawn. If point p2 fails the object can be efficiently determined looking up the occlusion test, then it is occluded by the polygon and pixel’s color identifier in the off-screen buffer. it can be concluded that p falls into the polygon —see Obviously, the same idea can be used to solve the Figure 1.b). If p2 passes the occlusion test, it is not the point-in-polygon problem. The polygon can be occluded by the polygon, so p is outside the polygon drawn with a color c different from the background —see Figure 1.c). color in an off-screen buffer in 2D. We can say that A possible implementation of the test can be seen point p falls inside the polygon if the color of its as- next. sociated pixel in the off-screen buffer is c. An OpenGL implementation of a point-in- bool inclusiontest (Point p) { polygon test that uses this strategy can be seen next. GLboolean result; bool inclusiontest (Point p) glEnable (GL_OCCLUSION_TEST_HP); { glBegin (GL_POINTS); GLfloat pixels[1][1][1]; glVertex3f (p.x, p.y, -0.5); GLint x = p.x * X_BUFFER_SIZE/X_IMAGE_SIZE; glEnd (); GLint y = p.y * Y_BUFFER_SIZE/Y_IMAGE_SIZE; glDisable (GL_OCCLUSION_TEST_HP); glReadPixels(x, y, 1, 1, GL_RED, GL_FLOAT, glGetBooleanv (GL_OCCLUSION_TEST_RESULT_HP, pixels); &result); return pixels[0][0][0] == 1; return !result; } } At the preprocessing stage the polygon is drawn In this implementation the polygon is drawn in a with RGB color (1,0,0), i.e. red, in an black off-screen P-buffer. In order to draw an arbitrary polygon we buffer, i.e. with RGB color (0,0,0), using a 2D ortho- have considered two approaches: the first one is to use graphic projection. To test whether point p is inside the OpenGL’s tessellation algorithm, and the second the polygon, the coordinates (x, y) of its associated one is based on using the stencil buffer (A. Rueda and pixel in the off-screen buffer are first computed. Then, Ruiz, 2004). We have chosen the latter because it is the red component of pixel (x, y) is read from the off- faster for complex polygons. screen buffer, if its value is 1 then p falls inside the polygon. 4 A POINT-IN-POLYGON TEST 3 A POINT-IN-POLYGON TEST BASED ON THE BASED ON THE NV OCCLUSION QUERY HP OCCLUSION TEST EXTENSION EXTENSION The point-in-polygon test presented in this section is The OpenGL’s HP occlusion test extension is in- basically the same that the one presented in the pre- tended for testing the visibility of an object, where vious section. The only difference is that this test “visible” means that at least one of its pixels passes uses the OpenGL’s NV occlusion query extension to the stencil and depth tests. An obvious application of query whether the point is occluded by the poly- this extension is occlusion culling. Before rendering gon. However, this extension allows multiple point- an object in a scene, an occlusion test can be done in-polygon queries to be done in parallel with CPU with the object bounding volume, if the test fails the computations. object does not need to be rendered and some perfor- The NV occlusion query extension provides an mance can be gained. alternative occlusion query that overcome two limi- This extension can also be used to develop a point- tations of the HP occlusion test extension. First, in- in-polygon test as follows. At a preprocessing stage stead of returning a boolean value, it returns the num- the filled polygon is drawn in an off-screen buffer on a ber of pixels of the object that pass the stencil and plane orthogonal to the observer’s line of sight, using depth tests. This is useful in occlusion culling be- an orthographic projection —see Figure 1.a). To test cause provides more information about the visibility 162 A SIMPLE AND FAST HARDWARE-ACCELERATED POINT-IN-POLYGON TEST Viewing volume Line of sight Observer Observer (a) Preprocessing (b) The occlusion test fails Observer (c) The occlusion test succeeds Figure 1: Example of HP occlusion test. of the object. For instance, an application could de- glVertex3f (points[i].x, points[i].y, -0.5); cide not to draw an object if less than a threshold num- glEnd (); ber of pixels of its bounding volume pass the test, or to glEndOcclusionQueryNV(); draw it with a low-detail model. However, our point- } // CPU computation can be done here in-polygon test will not benefit from this feature be- ... cause we only test the visibility of a point —which it // occlusion results are asked is drawn with only one pixel—, so we get the same for (int i = 0; i < points.size (); i++) { information with both occlusion queries. glGetOcclusionQueryuivNV(occlusionQueries[i], The second improvement of this extension is that GL_PIXEL_COUNT_NV, &pixelCount); allows for issuing an occlusion query before asking result[i] = pixelCount == 0; } for the result of a previous query, so that multiple oc- clusion queries, and therefore point-in-polygon tests, In the first cycle the occlusion queries are issued, can be solved in parallel with CPU computation. each query tests how many pixels of a query point Next we show an implementation of a point-in- pass the depth test.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us