matrix_to_list.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "matrix_to_list.h"
  9. #include <Eigen/Dense>
  10. template <typename DerivedM>
  11. IGL_INLINE void igl::matrix_to_list(
  12. const Eigen::MatrixBase<DerivedM> & M,
  13. std::vector<std::vector<typename DerivedM::Scalar > > & V)
  14. {
  15. using namespace std;
  16. V.resize(M.rows(),vector<typename DerivedM::Scalar >(M.cols()));
  17. // loop over rows
  18. for(int i = 0;i<M.rows();i++)
  19. {
  20. // loop over cols
  21. for(int j = 0;j<M.cols();j++)
  22. {
  23. V[i][j] = M(i,j);
  24. }
  25. }
  26. }
  27. template <typename DerivedM>
  28. IGL_INLINE void igl::matrix_to_list(
  29. const Eigen::MatrixBase<DerivedM> & M,
  30. std::vector<typename DerivedM::Scalar > & V)
  31. {
  32. using namespace std;
  33. V.resize(M.size());
  34. // loop over rows
  35. for(int i = 0;i<M.size();i++)
  36. {
  37. V[i] = M[i];
  38. }
  39. }
  40. template <typename DerivedM>
  41. IGL_INLINE std::vector<typename DerivedM::Scalar > igl::matrix_to_list(
  42. const Eigen::MatrixBase<DerivedM> & M)
  43. {
  44. std::vector<typename DerivedM::Scalar> V;
  45. matrix_to_list(M,V);
  46. return V;
  47. }
  48. #ifndef IGL_HEADER_ONLY
  49. // Explicit template specialization
  50. // generated by autoexplicit.sh
  51. 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&);
  52. // generated by autoexplicit.sh
  53. 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&);
  54. //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> > > >&);
  55. //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> > > >&);
  56. 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> > > >&);
  57. 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> > > >&);
  58. 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> >&);
  59. #endif