项目作者: delfrrr

项目描述 :
A really fast C++ library for Delaunay triangulation of 2D points
高级语言: C++
项目地址: git://github.com/delfrrr/delaunator-cpp.git
创建时间: 2018-08-16T05:23:54Z
项目社区:https://github.com/delfrrr/delaunator-cpp

开源协议:MIT License

下载


delaunator-cpp

A really fast C++ library for
Delaunay triangulation of 2D points.

delaunator-cpp is a C++ port from https://github.com/mapbox/delaunator a JavaScript implementation of very fast 2D Delaunay algorithm.

Build Status
badge

Features

  • Probably the fastest C++ open source 2D Delaunay implementation
  • Example showing triangulation of GeoJson points

Usage

examples/basic.cpp

  1. #include <delaunator.hpp>
  2. #include <cstdio>
  3. int main() {
  4. /* x0, y0, x1, y1, ... */
  5. std::vector<double> coords = {-1, 1, 1, 1, 1, -1, -1, -1};
  6. //triangulation happens here
  7. delaunator::Delaunator d(coords);
  8. for(std::size_t i = 0; i < d.triangles.size(); i+=3) {
  9. printf(
  10. "Triangle points: [[%f, %f], [%f, %f], [%f, %f]]\n",
  11. d.coords[2 * d.triangles[i]], //tx0
  12. d.coords[2 * d.triangles[i] + 1], //ty0
  13. d.coords[2 * d.triangles[i + 1]], //tx1
  14. d.coords[2 * d.triangles[i + 1] + 1],//ty1
  15. d.coords[2 * d.triangles[i + 2]], //tx2
  16. d.coords[2 * d.triangles[i + 2] + 1] //ty2
  17. );
  18. }
  19. }

See more examples here

Benchmarks

  1. Run on (4 X 2300 MHz CPU s)
  2. 2018-09-29 09:27:28
  3. ------------------------------------------------------------
  4. Benchmark Time CPU Iterations
  5. ------------------------------------------------------------
  6. BM_45K_geojson_nodes 22 ms 22 ms 32
  7. BM_uniform/2000 1 ms 1 ms 982
  8. BM_uniform/100000 63 ms 62 ms 9
  9. BM_uniform/200000 140 ms 140 ms 4
  10. BM_uniform/500000 400 ms 399 ms 2
  11. BM_uniform/1000000 994 ms 993 ms 1

Library is ~10% faster then JS version for 1M uniform points (details)