unique_edge_map.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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((size_t)EMAP.size() == ne);
  33. for(uE2EType e = 0;e<(uE2EType)ne;e++)
  34. {
  35. uE2E[EMAP(e)].push_back(e);
  36. }
  37. }
  38. #ifdef IGL_STATIC_LIBRARY
  39. // Explicit template specialization
  40. template void igl::unique_edge_map<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, long>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&, std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >&);
  41. template void igl::unique_edge_map<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, long>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&, std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >&);
  42. template void igl::unique_edge_map<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::Matrix<int, -1, 1, 0, -1, 1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, 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> >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
  43. template void igl::unique_edge_map<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, 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> >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
  44. #endif