list_to_matrix.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_LIST_TO_MATRIX_H
  9. #define IGL_LIST_TO_MATRIX_H
  10. #include "igl_inline.h"
  11. #include <vector>
  12. #include <array>
  13. #include <Eigen/Core>
  14. namespace igl
  15. {
  16. /// Convert a list (std::vector) of row vectors of the same length to a matrix
  17. ///
  18. /// @tparam T type that can be safely cast to type in Mat via '='
  19. /// @tparam Mat Matrix type, must implement:
  20. /// .resize(m,n)
  21. /// .row(i) = Row
  22. /// @param[in] V a m-long list of vectors of size n
  23. /// @param[out] M an m by n matrix
  24. /// @return true on success, false on errors
  25. template <typename T, typename Derived>
  26. IGL_INLINE bool list_to_matrix(
  27. const std::vector<std::vector<T > > & V,
  28. Eigen::PlainObjectBase<Derived>& M);
  29. /// \overload
  30. template <typename T, size_t N, typename Derived>
  31. IGL_INLINE bool list_to_matrix(
  32. const std::vector<std::array<T, N> > & V,
  33. Eigen::PlainObjectBase<Derived>& M);
  34. /// \overload
  35. /// \brief Vector version.
  36. template <typename T, typename Derived>
  37. IGL_INLINE bool list_to_matrix(const std::vector<T > & V,Eigen::PlainObjectBase<Derived>& M);
  38. /// Convert a list of row vectors of `n` or less to a matrix and pad on
  39. /// the right with `padding`.
  40. ///
  41. /// @param[in] V a m-long list of vectors of size <=n
  42. /// @param[in] n number of columns
  43. /// @param[in] padding value to fill in from right for short rows
  44. /// @param[out] M an m by n matrix
  45. template <typename T, typename Derived>
  46. IGL_INLINE bool list_to_matrix(
  47. const std::vector<std::vector<T > > & V,
  48. const int n,
  49. const T & padding,
  50. Eigen::PlainObjectBase<Derived>& M);
  51. }
  52. #ifndef IGL_STATIC_LIBRARY
  53. # include "list_to_matrix.cpp"
  54. #endif
  55. #endif