cdt.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "../slice_mask.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. typedef typename DerivedV::Scalar Scalar;
  26. typedef Eigen::Matrix<Scalar,Eigen::Dynamic,2> MatrixX2S;
  27. //MatrixX2S BV;
  28. //Eigen::MatrixXi BE;
  29. //igl::bounding_box(V,BV,BE);
  30. //WV.resize(V.rows()+BV.rows(),2);
  31. //WV<<V,BV;
  32. //WE.resize(E.rows()+BE.rows(),2);
  33. //WE<<E,(BE.array()+V.rows());
  34. WV = V;
  35. WE = E;
  36. Eigen::VectorXi _;
  37. igl::remove_duplicate_vertices(DerivedWV(WV),DerivedWE(WE),1e-10,WV,_,J,WE);
  38. // Remove degenerate edges
  39. igl::slice_mask(DerivedWE(WE),(WE.array().col(0) != WE.array().col(1)).eval(),1,WE);
  40. // c flag must be present
  41. igl::triangle::triangulate(DerivedWV(WV),WE,DerivedWV(),flags,WV,WF);
  42. Eigen::VectorXi UJ;
  43. igl::remove_unreferenced(DerivedV(WV),Eigen::MatrixXi(WF),WV,WF,UJ);
  44. for(int i=0;i<WE.rows();i++) for(int j=0;j<WE.cols();j++) WE(i,j)=UJ(WE(i,j));
  45. // Remove edges from box
  46. //WE.conservativeResize(WE.rows()-BE.rows(),2);
  47. for(int i=0;i<J.size();i++) J(i)=UJ(J(i));
  48. //J.conservativeResize(J.size()-BV.rows());
  49. }
  50. #ifdef IGL_STATIC_LIBRARY
  51. // Explicit template instantiation
  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, 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> >&);
  54. // generated by autoexplicit.sh
  55. 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> >&);
  56. #endif