delaunay_triangulation.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Qingnan Zhou <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "delaunay_triangulation.h"
  9. #include "flip_edge.h"
  10. #include "lexicographic_triangulation.h"
  11. #include "unique_edge_map.h"
  12. #include "is_delaunay.h"
  13. #include <vector>
  14. #include <sstream>
  15. template<
  16. typename DerivedV,
  17. typename Orient2D,
  18. typename InCircle,
  19. typename DerivedF>
  20. IGL_INLINE void igl::delaunay_triangulation(
  21. const Eigen::MatrixBase<DerivedV>& V,
  22. Orient2D orient2D,
  23. InCircle incircle,
  24. Eigen::PlainObjectBase<DerivedF>& F)
  25. {
  26. assert(V.cols() == 2);
  27. typedef typename DerivedF::Scalar Index;
  28. igl::lexicographic_triangulation(V, orient2D, F);
  29. const size_t num_faces = F.rows();
  30. if (num_faces == 0) {
  31. // Input points are degenerate. No faces will be generated.
  32. return;
  33. }
  34. assert(F.cols() == 3);
  35. typedef Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,2> MatrixX2I;
  36. MatrixX2I E,uE;
  37. Eigen::VectorXi EMAP;
  38. std::vector<std::vector<Index> > uE2E;
  39. igl::unique_edge_map(F, E, uE, EMAP, uE2E);
  40. bool all_delaunay = false;
  41. while(!all_delaunay) {
  42. all_delaunay = true;
  43. for (size_t i=0; i<uE2E.size(); i++) {
  44. if (uE2E[i].size() == 2) {
  45. if (!is_delaunay(V,F,uE2E,incircle,i)) {
  46. all_delaunay = false;
  47. flip_edge(F, E, uE, EMAP, uE2E, i);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. #ifdef IGL_STATIC_LIBRARY
  54. // Explicit template instantiation
  55. template void igl::delaunay_triangulation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  56. #endif