THE BOOST.POLYGON VORONOI LIBRARY
The Voronoi extension of the Boost.Polygon library provides functionality to construct a Voronoi diagram of a set of points and linear segments in 2D space with the following set of limitations:
Fully Functional with SegmentsThere are just a few implementations of the Voronoi diagram construction algorithm that can handle input data sets that contain linear segment, even considering the commercial libraries. Support of the segments allows to discretize any input geometry (sampled floating-point coordinates can be scaled and snapped to the integer grid): circle, ellipse, parabola. This functionality allows to compute the medial axis transform of the arbitrary set of input geometries, with direct applications in the computer vision projects.
Robustness and EfficiencyRobustness issues can be divided onto the two main categories: memory management issues and numeric stability issues. The implementation avoids the first type of the issues using pure STL data structures, thus there is no presence of the new operator in the code. The second category of the problems is resolved using the multiprecision geometric predicates. Even for the commercial libraries, usage of such predicates results in a vast performance slowdown. The Voronoi implementation overcomes this by avoiding the multiprecision computations in the 95% of the cases and uses the efficient, floating-point based predicates. Such preciates don't produce the correct result always, however the library embeds the relative error arithmetic apparatus to identify such situations and switch to the higher precision predicates when appropriate. As the result, the implementation has a solid performance comparing to the other known libraries (more details in the benchmarks).
Precision of the Output StructuresThe Voronoi implementation guaranties, that the relative error of the coordinates of the output geometries is at most 64 machine epsilons (6 bits of mantissa, for the IEEE-754 floating-point type), while on average it's slightly lower. This means, that the precision of the output geometries can be increased simply by using a floating-point type with the larger mantissa. The practical point of this statements is explained in the following table:
During the finalization step the implementation unites the Voronoi vertices whose both coordinates are situated within the relative error range equal to 128 machine epsilons and removes any Voronoi edges between those. This is the only case, that might cause differences between the algorithm output topology and theoretically precise one, and practically means the following: for the Voronoi diagram of a set of solid bodies inside the Solar System (radius 242 metres) and the long double (64 bit mantissa) output coordinate type the maximum absolute error within the Solar System rectangle will be equal to 2-64 * 242 * 26 = 2-18 metres; as the result, vertices with both coordinates that are within 2-18 metres (8 micrometres or the size of a bacteria) will be considered equal and united.
Simple InterfaceThe boost/polygon/voronoi.hpp library header defines the following static functions to integrate the Voronoi library functionality with the Boost.Polygon interfaces:
The following two lines of code construct the Voronoi diagram of a set of points (as long as the corresponding input geometry type satisfies the Boost.Polygon concept model):
construct_voronoi(points.begin(), points.end(), &vd);
The library provides the clear interfaces to associate the user data with the output geometries and efficiently traverse the Voronoi graph. More details on those topics are covered in the basic Voronoi tutorial. Advanced usage of the library with the configuration of the coordinate types is explained in the advanced Voronoi tutorial. The library allows users to implement their own Voronoi diagram / Delaunay triangulation construction routines based on the Voronoi builder API.
No Third Party DependenciesThe Voronoi extension of the Boost.Polygon library doesn't depend on any 3rd party code and contains single dependency on the Boost libraries: boost/cstdint.hpp. All the required multiprecision types and related functionality are encapsulated as part of the implementation. The library is fast to compile (3 public and 4 private heades), has strong cohesion between its components and is clearly modularized from the rest of the Boost.Polygon library, with the optional integration through the voronoi.hpp header.
Extensible for the User Provided Coordinate TypesThe implementation is coordinate type agnostic. As long as the user provided types satisfy the set of the requirements of the Voronoi builder coordinate type traits, no additional changes are needed neither to the algorithm, nor to the implementation of the predicates. For example, it's possible to construct the Voronoi diagram with the 256-bit integer input coordinate type and 512-bit output floating-point type without making any changes to the library.
Future DevelopmentBelow one may find the list of the main directions for the future development of the library.
The high-priority tasks that already have the approximate implementation plan are the following (some of those may be proposed as future GSoC projects):
Theoretical ResearchThe Voronoi library was developed as part of the Google Summer of Code 2010. The library was actively maintained for the last three years and involved the strong mathematical research in the field of algorithms, data structures, relative error arithmetic and numerical robustness. Nowadays one can often read a scientific paper, that contains non-practical theoretical results or implementation with benchmarks nobody else can reproduce. The opposite story is with the Voronoi library, that contains complete implementation of the Voronoi diagram construction algorithm and benchmarks one may run on his/her PC. Upon the community request, more documentation on the theoretical aspects of the implementation will be published. The authors would like to acknowledge the Steven Fortune's article "A Sweepline algorithm for Voronoi diagrams", that covers fundamental ideas of the current implementation.