list_to_matrix.cpp 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "list_to_matrix.h"
  2. #include <cassert>
  3. #include <cstdio>
  4. #include "max_size.h"
  5. #include "min_size.h"
  6. #define VERBOSE
  7. #include "verbose.h"
  8. template <typename T, class Mat>
  9. IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat & M)
  10. {
  11. // number of columns
  12. int m = V.size();
  13. if(m == 0)
  14. {
  15. fprintf(stderr,"Error: list_to_matrix() list is empty()\n");
  16. return false;
  17. }
  18. // number of rows
  19. int n = igl::min_size(V);
  20. if(n != igl::max_size(V))
  21. {
  22. fprintf(stderr,"Error: list_to_matrix()"
  23. " list elements are not all the same size\n");
  24. return false;
  25. }
  26. assert(n != -1);
  27. // Resize output
  28. M.resize(m,n);
  29. // Loop over rows
  30. for(int i = 0;i<m;i++)
  31. {
  32. // Loop over cols
  33. for(int j = 0;j<n;j++)
  34. {
  35. M(i,j) = V[i][j];
  36. }
  37. }
  38. return true;
  39. }
  40. #ifndef IGL_HEADER_ONLY
  41. // Explicit template specialization
  42. #endif