GGL    Boost C++ Libraries

Generic Geometry Library

Generic Geometry Library

Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam, the Netherlands.
Copyright © 2008-2009 Bruno Lalande, Paris, France.
Copyright © 2009 Mateusz Loskot, Cadcorp, London, UK.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Introduction

The Generic Geometry Library, GGL, currently in Formal Review, defines concepts for geometries and implements some algorithms on such geometries.

GGL contains a dimension-agnostic, coordinate-system-agnostic and scalable kernel, based on concepts, meta-functions and tag- dispatching. On top of that kernel, algorithms are built: area, length, perimeter, centroid, convex hull, intersection (clipping), within (point in polygon), distance, envelope (bounding box), simplify, transform, convert, and more. The library is also designed to support high precision arithmetic numbers, such as GMP.

GGL contains instantiable geometry classes, but library users can also use their own. Using registration macros or traits classes their geometries can be adapted to fulfil the GGL-concepts.

The GGL might be used in all domains where geometry plays a role: mapping and GIS, gaming, computer graphics and widgets, robotics, astronomy... The core is designed to be as generic as possible and support those domains. However, for now the development has been mostly GIS-oriented.

GGL supports the extension model, the same way as GIL also applies it. An extension is (mostly) something more specific to domains like mentioned above.

The library follows existing conventions:

This Generic Geometry Library (ggl) is now being reviewed by the Boost Community

The library can be downloaded from the Boost Sandbox, go to the Download page for more information.

A (recently started) GGL Wiki is here: http://trac.osgeo.org/ggl/wiki

Quick start

It is not possible to show the whole library at a glance. A few very small examples are shown below.

It should be possible to use a very small part of the library, for example only the distance between two points.

    int a[2] = {1,1};
    int b[2] = {2,3};
    double d = distance(a, b);
    std::cout << "Distance a-b is:" << d << std::endl;

Other often used algorithms are point-in-polygon:

    ring_2d poly;
    double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}};
    append(poly, points);
    boost::tuple<double, double> p = boost::make_tuple(3.7, 2.0);
    std::cout << "Point p is in polygon? " << (within(p, poly) ? "YES" : "NO")  << std::endl;

or area:

    std::cout << "Area: " << area(poly) << std::endl;

It is possible, by the nature of a template library, to mix the point types declared above:

    double d2 = distance(a, p);
    std::cout << "Distance a-p is:" << d2 << std::endl;

The pieces above generate this output:

output_main.png

It is also possible to use non-Cartesian points. For example: points on a sphere. When then an algorithm such as distance is used the library "inspects" that it is handling spherical points and calculates the distance over the sphere, instead of applying the Pythagorean theorem.

Finally an example from a totally different domain: developing window-based applications, for example using QtWidgets. We check if two rectangles overlap and if so, move the second one to another place:

    QRect r1(100, 200, 15, 15);
    QRect r2(110, 210, 20, 20);
    if (overlaps(r1, r2))
    {
        assign(r2, 200, 300, 220, 320);
    }

More examples are on the page Examples


November 5, 2009

Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam
Copyright © 2008-2009 Bruno Lalande, Paris
Copyright © 2009 Mateusz Loskot, Cadcorp, London
Documentation is generated by Doxygen