rows_to_matrix.cpp 913 B

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