Templatized Geometry Library
Affine (and to some extent, projective) geometry is the foundation for almost all graphics programming. A common library to express basic geometric data types, e.g., vectors and points, and operations on those data types, e.g., vector arithmetics, dot and cross products and transformations, can significantly speed up development of graphics applications. To be most useful, such a library should be generic, i.e., offer data types and operations for n-dimensional geometry on arbitrary underlying field types, while at the same time performing as well as special-purpose handwritten code. The C++ template and inline mechanisms can be used to achieve both goals at the same time, and can as well be used to perform semantics enforcement at compile-time; for example, adding two affine points or creating a vector with the wrong number of components should generate compiler errors.
The main goals were to design and implement a geometry library that is powerful and general enough to be used in a wide variety of geometry-related projects. The library should offer the following features/functionality:
- Offer basic data types and operations for n-dimensional Euclidean, affine and projective geometry:
- Data types for Euclidean/affine vectors, affine points and homogenuous vectors
- Full set of vector space operations.
- Full set of affine point space operations.
- Offer several types of linear transformations:
- Rigid body transformations (rotation and translation).
- Scaled rigid body transformations (rotation, translation and uniform scaling).
- General affine transformations.
- General projective transformations.
- Offer higher-level geometry constructs:
- Boxes, spheres, cylinders etc. with ray intersection queries.
- Bezier curves and surfaces, B-spline curves and surfaces.
- Points with associated data values and spatial data structures such as kd-trees for visualization.
- Provide maximum generality using template mechanism:
- All data types templatized by vector space dimension to allow n-dimensional geometry.
- All data types templatized by underlying field type to allow trade-off between accuracy, speed and memory requirements, as well as to allow user-defined field data types.
- Violation of semantics of Euclidean/affine/projective geometry generate compile-time errors.
- Use inlining extensively to approach performance of special-purpose hand-written code.
- Use type definitions extensively to simplify writing generic code using generic data types.
The current version of the templatized geometry library offers all functionality described above. The library API is frozen at version 2.1, and the library is currently undergoing testing by myself and other researchers at IDAV. All source code needed to compile and use the library can be downloaded from the download page.
Note: Support for templates is fundamentally broken in all Microsoft C++ compilers I've tried, up to and including the version that ships with Visual Studio .net 2003. I've heard rumors that the newest release has better support, but I'm not holding my breath. To use the TGL under Windows, you would either have to use the GNU C++ compiler (but I don't know whether that can generate native Windows applications), or the Intel C++ compiler. That one is very good, and it compiles TGL without problems. It also generates much better code than the Microsoft compilers, and drops right into the Visual Studio IDE. Alas, it is not free.
10/27/2006: Updated version of TGL (version 2.1) now available on the download page. The code is an up-to-the-minute snapshot from my development directories, and contains quite a few improvements compared to the previous release. With the help of Braden Pellett, the library now builds under Mac OS X. I'll have to try building under Windows again, but I fear it will still not work.
11/30/2004: I've just put the second version of the templatized geometry library on the download page. There are major improvements, especially in the transformation hierarchy, and some code reorganizations to work better with new C++ compilers. API changes compared to version 1.0 are minor; the big exception is that the old Transformation class has been renamed to ProjectiveTransformation, to better fit the naming scheme.
Pages In This Section
- Design Philosophy
- Fundamental design approaches used in the templatized geometry library, and the reasoning behind them. Users should be aware of these to make optimal use of the library.
- Scalar Field Type Requirements
- Required interface for user-defined data types that are to be used as scalar types for geometry objects.
- Vector Space Algebra
- A very brief overview of axioms and definitions regarding algebraic structures fundamental to geometry - groups, rings, fields, vector spaces. By no means a tutorial!
- Download page for all source code necessary to compile and use the templatized geometry library.
- Library Documentation
- Detailed documentation of all classes and operations provided by the templatized geometry library.