matrix_to_list.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. #ifndef IGL_MATRIX_TO_LIST_H
  9. #define IGL_MATRIX_TO_LIST_H
  10. #include "igl_inline.h"
  11. #include <vector>
  12. #include <Eigen/Dense>
  13. namespace igl
  14. {
  15. /// Convert a matrix to a list (std::vector) of row vectors of the same size
  16. ///
  17. /// @tparam Mat Matrix type, must implement:
  18. /// .resize(m,n)
  19. /// .row(i) = Row
  20. /// @tparam T type that can be safely cast to type in Mat via '='
  21. /// @param[in] M an m by n matrix
  22. /// @param[out] V a m-long list of vectors of size n
  23. ///
  24. /// \see list_to_matrix
  25. template <typename DerivedM>
  26. IGL_INLINE void matrix_to_list(
  27. const Eigen::MatrixBase<DerivedM> & M,
  28. std::vector<std::vector<typename DerivedM::Scalar > > & V);
  29. /// Convert a matrix to a list (std::vector) of elements in column-major
  30. /// ordering.
  31. ///
  32. /// @param[in] M an m by n matrix
  33. /// @param[out] V an m*n list of elements
  34. template <typename DerivedM>
  35. IGL_INLINE void matrix_to_list(
  36. const Eigen::MatrixBase<DerivedM> & M,
  37. std::vector<typename DerivedM::Scalar > & V);
  38. /// \overload
  39. template <typename DerivedM>
  40. IGL_INLINE std::vector<typename DerivedM::Scalar > matrix_to_list(
  41. const Eigen::MatrixBase<DerivedM> & M);
  42. }
  43. #ifndef IGL_STATIC_LIBRARY
  44. # include "matrix_to_list.cpp"
  45. #endif
  46. #endif