list_to_matrix.h 1.6 KB

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