main.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <igl/opengl/glfw/Viewer.h>
  2. #include <igl/triangle/triangulate.h>
  3. // Input polygon
  4. Eigen::MatrixXd V;
  5. Eigen::MatrixXi E;
  6. Eigen::MatrixXd H;
  7. // Triangulated interior
  8. Eigen::MatrixXd V2;
  9. Eigen::MatrixXi F2;
  10. int main(int argc, char *argv[])
  11. {
  12. using namespace Eigen;
  13. using namespace std;
  14. // Create the boundary of a square
  15. V.resize(8,2);
  16. E.resize(8,2);
  17. H.resize(1,2);
  18. // create two squares, one with edge length of 4,
  19. // one with edge length of 2
  20. // both centered at origin
  21. V << -1,-1, 1,-1, 1,1, -1, 1,
  22. -2,-2, 2,-2, 2,2, -2, 2;
  23. // add the edges of the squares
  24. E << 0,1, 1,2, 2,3, 3,0,
  25. 4,5, 5,6, 6,7, 7,4;
  26. // specify a point that is inside a closed shape
  27. // where we do not want triangulation to happen
  28. H << 0,0;
  29. // Triangulate the interior
  30. // a0.005 means that the area of each triangle should
  31. // not be greater than 0.005
  32. // q means that no angles will be smaller than 20 degrees
  33. // for a detailed set of commands please refer to:
  34. // https://www.cs.cmu.edu/~quake/triangle.switch.html
  35. igl::triangle::triangulate(V,E,H,"a0.005q",V2,F2);
  36. // Plot the generated mesh
  37. igl::opengl::glfw::Viewer viewer;
  38. viewer.data().set_mesh(V2,F2);
  39. viewer.launch();
  40. }