topological_hole_fill.cpp 2.0 KB

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