rows_to_matrix.cpp 1.2 KB

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