topological_hole_fill.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Zhongshi Jiang <[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 "topological_hole_fill.h"
  9. template <
  10. typename DerivedF,
  11. typename VectorIndex,
  12. typename DerivedF_filled>
  13. IGL_INLINE void igl::topological_hole_fill(
  14. const Eigen::MatrixBase<DerivedF> & F,
  15. const std::vector<VectorIndex> & holes,
  16. Eigen::PlainObjectBase<DerivedF_filled> &F_filled)
  17. {
  18. int n_filled_faces = 0;
  19. int num_holes = holes.size();
  20. int real_F_num = F.rows();
  21. const int V_rows = F.maxCoeff()+1;
  22. for (int i = 0; i < num_holes; i++)
  23. n_filled_faces += holes[i].size();
  24. F_filled.resize(n_filled_faces + real_F_num, 3);
  25. F_filled.topRows(real_F_num) = F;
  26. int new_vert_id = V_rows;
  27. int new_face_id = real_F_num;
  28. for (int i = 0; i < num_holes; i++, new_vert_id++)
  29. {
  30. int it = 0;
  31. int back = holes[i].size() - 1;
  32. F_filled.row(new_face_id++) << holes[i][it], holes[i][back], new_vert_id;
  33. while (it != back)
  34. {
  35. F_filled.row(new_face_id++)
  36. << holes[i][(it + 1)],
  37. holes[i][(it)], new_vert_id;
  38. it++;
  39. }
  40. }
  41. assert(new_face_id == F_filled.rows());
  42. assert(new_vert_id == V_rows + num_holes);
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. template void igl::topological_hole_fill<Eigen::Matrix<int, -1, -1, 0, -1, -1>, std::vector<int, std::allocator<int> > >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  46. #endif