unique_edge_map.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "unique_edge_map.h"
  2. #include "all_edges.h"
  3. #include "unique_simplices.h"
  4. #include <cassert>
  5. #include <algorithm>
  6. template <
  7. typename DerivedF,
  8. typename DerivedE,
  9. typename DeriveduE,
  10. typename DerivedEMAP,
  11. typename uE2EType>
  12. IGL_INLINE void igl::unique_edge_map(
  13. const Eigen::PlainObjectBase<DerivedF> & F,
  14. Eigen::PlainObjectBase<DerivedE> & E,
  15. Eigen::PlainObjectBase<DeriveduE> & uE,
  16. Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
  17. std::vector<std::vector<uE2EType> > & uE2E)
  18. {
  19. using namespace Eigen;
  20. using namespace std;
  21. // All occurances of directed edges
  22. all_edges(F,E);
  23. const size_t ne = E.rows();
  24. // This is 2x faster to create than a map from pairs to lists of edges and 5x
  25. // faster to access (actually access is probably assympotically faster O(1)
  26. // vs. O(log m)
  27. Matrix<typename DerivedEMAP::Scalar,Dynamic,1> IA;
  28. unique_simplices(E,uE,IA,EMAP);
  29. uE2E.resize(uE.rows());
  30. // This does help a little
  31. for_each(uE2E.begin(),uE2E.end(),[](vector<uE2EType > & v){v.reserve(2);});
  32. assert(EMAP.size() == ne);
  33. for(uE2EType e = 0;e<ne;e++)
  34. {
  35. uE2E[EMAP(e)].push_back(e);
  36. }
  37. }