cdt.cpp 3.2 KB

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