matrix_to_list.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "matrix_to_list.h"
  2. #include <Eigen/Dense>
  3. template <typename DerivedM>
  4. IGL_INLINE void igl::matrix_to_list(
  5. const Eigen::MatrixBase<DerivedM> & M,
  6. std::vector<std::vector<typename DerivedM::Scalar > > & V)
  7. {
  8. using namespace std;
  9. V.resize(M.rows(),vector<typename DerivedM::Scalar >(M.cols()));
  10. // loop over rows
  11. for(int i = 0;i<M.rows();i++)
  12. {
  13. // loop over cols
  14. for(int j = 0;j<M.cols();j++)
  15. {
  16. V[i][j] = M(i,j);
  17. }
  18. }
  19. }
  20. template <typename DerivedM>
  21. IGL_INLINE void igl::matrix_to_list(
  22. const Eigen::MatrixBase<DerivedM> & M,
  23. std::vector<typename DerivedM::Scalar > & V)
  24. {
  25. using namespace std;
  26. V.resize(M.size());
  27. // loop over rows
  28. for(int i = 0;i<M.size();i++)
  29. {
  30. V[i] = M[i];
  31. }
  32. }
  33. template <typename DerivedM>
  34. IGL_INLINE std::vector<typename DerivedM::Scalar > igl::matrix_to_list(
  35. const Eigen::MatrixBase<DerivedM> & M)
  36. {
  37. std::vector<typename DerivedM::Scalar> V;
  38. matrix_to_list(M,V);
  39. return V;
  40. }
  41. #ifndef IGL_HEADER_ONLY
  42. // Explicit template specialization
  43. // generated by autoexplicit.sh
  44. template std::vector<Eigen::Matrix<double, -1, 1, 0, -1, 1>::Scalar, std::allocator<Eigen::Matrix<double, -1, 1, 0, -1, 1>::Scalar> > igl::matrix_to_list<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&);
  45. // generated by autoexplicit.sh
  46. template std::vector<Eigen::Matrix<int, -1, 1, 0, -1, 1>::Scalar, std::allocator<Eigen::Matrix<int, -1, 1, 0, -1, 1>::Scalar> > igl::matrix_to_list<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&);
  47. //template void igl::matrix_to_list<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, double>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&);
  48. //template void igl::matrix_to_list<Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
  49. template void igl::matrix_to_list<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar, std::allocator<Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar> >, std::allocator<std::vector<Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar, std::allocator<Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar> > > >&);
  50. template void igl::matrix_to_list<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<std::vector<Eigen::Matrix<int, -1, -1, 0, -1, -1>::Scalar, std::allocator<Eigen::Matrix<int, -1, -1, 0, -1, -1>::Scalar> >, std::allocator<std::vector<Eigen::Matrix<int, -1, -1, 0, -1, -1>::Scalar, std::allocator<Eigen::Matrix<int, -1, -1, 0, -1, -1>::Scalar> > > >&);
  51. template void igl::matrix_to_list<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, std::vector<Eigen::Matrix<double, -1, 1, 0, -1, 1>::Scalar, std::allocator<Eigen::Matrix<double, -1, 1, 0, -1, 1>::Scalar> >&);
  52. #endif