matrix_to_list.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #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. // Template:
  18. // Mat Matrix type, must implement:
  19. // .resize(m,n)
  20. // .row(i) = Row
  21. // T type that can be safely cast to type in Mat via '='
  22. // Inputs:
  23. // M an m by n matrix
  24. // Outputs:
  25. // V a m-long list of vectors of size n
  26. //
  27. // See also: list_to_matrix
  28. template <typename DerivedM>
  29. IGL_INLINE void matrix_to_list(
  30. const Eigen::DenseBase<DerivedM> & M,
  31. std::vector<std::vector<typename DerivedM::Scalar > > & V);
  32. // Convert a matrix to a list (std::vector) of elements in column-major
  33. // ordering.
  34. //
  35. // Inputs:
  36. // M an m by n matrix
  37. // Outputs:
  38. // V an m*n list of elements
  39. template <typename DerivedM>
  40. IGL_INLINE void matrix_to_list(
  41. const Eigen::DenseBase<DerivedM> & M,
  42. std::vector<typename DerivedM::Scalar > & V);
  43. // Return wrapper
  44. template <typename DerivedM>
  45. IGL_INLINE std::vector<typename DerivedM::Scalar > matrix_to_list(
  46. const Eigen::DenseBase<DerivedM> & M);
  47. }
  48. #ifndef IGL_STATIC_LIBRARY
  49. # include "matrix_to_list.cpp"
  50. #endif
  51. #endif