path_to_edges.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "path_to_edges.h"
  2. template <typename DerivedI, typename DerivedE>
  3. IGL_INLINE void igl::path_to_edges(
  4. const Eigen::MatrixBase<DerivedI> & I,
  5. Eigen::PlainObjectBase<DerivedE> & E,
  6. bool make_loop)
  7. {
  8. // Check that I is 1 dimensional
  9. assert(I.size() == I.rows() || I.size() == I.cols());
  10. if(make_loop) {
  11. E.conservativeResize(I.size(), 2);
  12. for(int i = 0; i < I.size() - 1; i++) {
  13. E(i, 0) = I(i);
  14. E(i, 1) = I(i + 1);
  15. }
  16. E(I.size() - 1, 0) = I(I.size() - 1);
  17. E(I.size() - 1, 1) = I(0);
  18. } else {
  19. E.conservativeResize(I.size()-1, 2);
  20. for(int i = 0; i < I.size()-1; i++) {
  21. E(i, 0) = I(i);
  22. E(i, 1) = I(i+1);
  23. }
  24. }
  25. }
  26. template <typename Index, typename DerivedE>
  27. IGL_INLINE void igl::path_to_edges(
  28. const std::vector<Index> & I,
  29. Eigen::PlainObjectBase<DerivedE> & E,
  30. bool make_loop)
  31. {
  32. igl::path_to_edges(Eigen::Map<const Eigen::Matrix<Index, -1, 1>>(I.data(), I.size()), E, make_loop);
  33. }
  34. #ifdef IGL_STATIC_LIBRARY
  35. template void igl::path_to_edges<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, bool);
  36. template void igl::path_to_edges<int, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::vector<int, std::allocator<int> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, bool);
  37. #endif