triangle_fan.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "triangle_fan.h"
  2. #include "exterior_edges.h"
  3. #include "list_to_matrix.h"
  4. IGL_INLINE void igl::triangle_fan(
  5. const Eigen::MatrixXi & E,
  6. Eigen::MatrixXi & cap)
  7. {
  8. using namespace std;
  9. using namespace Eigen;
  10. // Handle lame base case
  11. if(E.size() == 0)
  12. {
  13. cap.resize(0,E.cols()+1);
  14. return;
  15. }
  16. // "Triangulate" aka "close" the E trivially with facets
  17. // Note: in 2D we need to know if E endpoints are incoming or
  18. // outgoing (left or right). Thus this will not work.
  19. assert(E.cols() == 2);
  20. // Arbitrary starting vertex
  21. int s = E(int(((double)rand() / RAND_MAX)*E.rows()),0);
  22. vector<vector<int> > lcap;
  23. for(int i = 0;i<E.rows();i++)
  24. {
  25. // Skip edges incident on s (they would be zero-area)
  26. if(E(i,0) == s || E(i,1) == s)
  27. {
  28. continue;
  29. }
  30. vector<int> e(3);
  31. e[0] = s;
  32. e[1] = E(i,0);
  33. e[2] = E(i,1);
  34. lcap.push_back(e);
  35. }
  36. list_to_matrix(lcap,cap);
  37. }
  38. IGL_INLINE Eigen::MatrixXi igl::triangle_fan( const Eigen::MatrixXi & E)
  39. {
  40. Eigen::MatrixXi cap;
  41. triangle_fan(E,cap);
  42. return cap;
  43. }