cdt.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "cdt.h"
  2. #include "../bounding_box.h"
  3. #include "../triangle/triangulate.h"
  4. #include "../remove_duplicate_vertices.h"
  5. #include "../remove_unreferenced.h"
  6. #include "../placeholders.h"
  7. template <
  8. typename DerivedV,
  9. typename DerivedE,
  10. typename DerivedWV,
  11. typename DerivedWF,
  12. typename DerivedWE,
  13. typename DerivedJ>
  14. IGL_INLINE void igl::triangle::cdt(
  15. const Eigen::MatrixBase<DerivedV> & V,
  16. const Eigen::MatrixBase<DerivedE> & E,
  17. const std::string & flags,
  18. Eigen::PlainObjectBase<DerivedWV> & WV,
  19. Eigen::PlainObjectBase<DerivedWF> & WF,
  20. Eigen::PlainObjectBase<DerivedWE> & WE,
  21. Eigen::PlainObjectBase<DerivedJ> & J)
  22. {
  23. assert(V.cols() == 2);
  24. assert(E.cols() == 2);
  25. //MatrixX2S BV;
  26. //Eigen::MatrixXi BE;
  27. //igl::bounding_box(V,BV,BE);
  28. //WV.resize(V.rows()+BV.rows(),2);
  29. //WV<<V,BV;
  30. //WE.resize(E.rows()+BE.rows(),2);
  31. //WE<<E,(BE.array()+V.rows());
  32. WV = V;
  33. WE = E;
  34. Eigen::VectorXi _;
  35. igl::remove_duplicate_vertices(DerivedWV(WV),DerivedWE(WE),1e-10,WV,_,J,WE);
  36. // Remove degenerate edges
  37. const Eigen::Array<bool,Eigen::Dynamic,1> keep = (WE.array().col(0) != WE.array().col(1));
  38. WE = WE(keep,igl::placeholders::all).eval();
  39. // c flag must be present
  40. igl::triangle::triangulate(DerivedWV(WV),WE,DerivedWV(),flags,WV,WF);
  41. Eigen::VectorXi UJ;
  42. igl::remove_unreferenced(DerivedV(WV),Eigen::MatrixXi(WF),WV,WF,UJ);
  43. for(int i=0;i<WE.rows();i++) for(int j=0;j<WE.cols();j++) WE(i,j)=UJ(WE(i,j));
  44. // Remove edges from box
  45. //WE.conservativeResize(WE.rows()-BE.rows(),2);
  46. for(int i=0;i<J.size();i++) J(i)=UJ(J(i));
  47. //J.conservativeResize(J.size()-BV.rows());
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template instantiation
  51. // generated by autoexplicit.sh
  52. template void igl::triangle::cdt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  53. // generated by autoexplicit.sh
  54. template void igl::triangle::cdt<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  55. #endif