polygon_mesh_to_triangle_mesh.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
  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 "polygon_mesh_to_triangle_mesh.h"
  9. template <typename Index, typename DerivedF>
  10. IGL_INLINE void igl::polygon_mesh_to_triangle_mesh(
  11. const std::vector<std::vector<Index> > & vF,
  12. Eigen::PlainObjectBase<DerivedF>& F)
  13. {
  14. using namespace std;
  15. using namespace Eigen;
  16. int m = 0;
  17. // estimate of size
  18. for(typename vector<vector<Index > >::const_iterator fit = vF.begin();
  19. fit!=vF.end();
  20. fit++)
  21. {
  22. if(fit->size() >= 3)
  23. {
  24. m += fit->size() - 2;
  25. }
  26. }
  27. // Resize output
  28. F.resize(m,3);
  29. {
  30. int k = 0;
  31. for(typename vector<vector<Index > >::const_iterator fit = vF.begin();
  32. fit!=vF.end();
  33. fit++)
  34. {
  35. if(fit->size() >= 3)
  36. {
  37. typename vector<Index >::const_iterator cit = fit->begin();
  38. cit++;
  39. typename vector<Index >::const_iterator pit = cit++;
  40. for(;
  41. cit!=fit->end();
  42. cit++,pit++)
  43. {
  44. F(k,0) = *(fit->begin());
  45. F(k,1) = *pit;
  46. F(k,2) = *cit;
  47. k++;
  48. }
  49. }
  50. }
  51. assert(k==m);
  52. }
  53. }
  54. #ifdef IGL_STATIC_LIBRARY
  55. // Explicit template instanciation
  56. template void igl::polygon_mesh_to_triangle_mesh<int, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(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> >&);
  57. #endif