triangulate.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "triangulate.h"
  2. template <typename Index, typename DerivedF>
  3. IGL_INLINE void igl::triangulate(
  4. const std::vector<std::vector<Index> > & vF,
  5. Eigen::PlainObjectBase<DerivedF>& F)
  6. {
  7. using namespace std;
  8. using namespace Eigen;
  9. int m = 0;
  10. // estimate of size
  11. for(typename vector<vector<Index > >::const_iterator fit = vF.begin();
  12. fit!=vF.end();
  13. fit++)
  14. {
  15. if(fit->size() >= 3)
  16. {
  17. m += fit->size() - 2;
  18. }
  19. }
  20. // Resize output
  21. F.resize(m,3);
  22. {
  23. int k = 0;
  24. for(typename vector<vector<Index > >::const_iterator fit = vF.begin();
  25. fit!=vF.end();
  26. fit++)
  27. {
  28. if(fit->size() >= 3)
  29. {
  30. typename vector<Index >::const_iterator cit = fit->begin();
  31. cit++;
  32. typename vector<Index >::const_iterator pit = cit++;
  33. for(;
  34. cit!=fit->end();
  35. cit++,pit++)
  36. {
  37. F(k,0) = *(fit->begin());
  38. F(k,1) = *pit;
  39. F(k,2) = *cit;
  40. k++;
  41. }
  42. }
  43. }
  44. assert(k==m);
  45. }
  46. }
  47. #ifndef IGL_HEADER_ONLY
  48. // Explicit template instanciation
  49. template void igl::triangulate<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> >&);
  50. #endif