list_to_matrix.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "list_to_matrix.h"
  2. #include <cassert>
  3. #include <cstdio>
  4. #include <Eigen/Dense>
  5. #include "max_size.h"
  6. #include "min_size.h"
  7. #define VERBOSE
  8. #include "verbose.h"
  9. template <typename T, class Mat>
  10. IGL_INLINE bool igl::list_to_matrix(const std::vector<std::vector<T > > & V,Mat & M)
  11. {
  12. // number of rows
  13. int m = V.size();
  14. if(m == 0)
  15. {
  16. //fprintf(stderr,"Error: list_to_matrix() list is empty()\n");
  17. //return false;
  18. M.resize(0,0);
  19. return true;
  20. }
  21. // number of columns
  22. int n = igl::min_size(V);
  23. if(n != igl::max_size(V))
  24. {
  25. fprintf(stderr,"Error: list_to_matrix()"
  26. " list elements are not all the same size: (min: %d, max: %d)\n",
  27. n,igl::max_size(V));
  28. return false;
  29. }
  30. assert(n != -1);
  31. // Resize output
  32. M.resize(m,n);
  33. // Loop over rows
  34. for(int i = 0;i<m;i++)
  35. {
  36. // Loop over cols
  37. for(int j = 0;j<n;j++)
  38. {
  39. M(i,j) = V[i][j];
  40. }
  41. }
  42. return true;
  43. }
  44. template <typename T, class Mat>
  45. IGL_INLINE bool igl::list_to_matrix(const std::vector<T > & V,Mat & M)
  46. {
  47. // number of rows
  48. int m = V.size();
  49. if(m == 0)
  50. {
  51. //fprintf(stderr,"Error: list_to_matrix() list is empty()\n");
  52. //return false;
  53. M.resize(0,0);
  54. return true;
  55. }
  56. // Resize output
  57. M.resize(m,1);
  58. // Loop over rows
  59. for(int i = 0;i<m;i++)
  60. {
  61. M(i) = V[i];
  62. }
  63. return true;
  64. }
  65. #ifndef IGL_HEADER_ONLY
  66. // Explicit template specialization
  67. // generated by autoexplicit.sh
  68. template bool igl::list_to_matrix<double, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::vector<double, std::allocator<double> > const&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&);
  69. // generated by autoexplicit.sh
  70. template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  71. // generated by autoexplicit.sh
  72. template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  73. // generated by autoexplicit.sh
  74. template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  75. // generated by autoexplicit.sh
  76. template bool igl::list_to_matrix<int, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>&);
  77. // generated by autoexplicit.sh
  78. template bool igl::list_to_matrix<double, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
  79. // generated by autoexplicit.sh
  80. template bool igl::list_to_matrix<double, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>&);
  81. template bool igl::list_to_matrix<bool, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<bool, std::allocator<bool> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  82. template bool igl::list_to_matrix<bool, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<std::vector<bool, std::allocator<bool> >, std::allocator<std::vector<bool, std::allocator<bool> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  83. template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(std::vector<int, std::allocator<int> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  84. template bool igl::list_to_matrix<int, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
  85. template bool igl::list_to_matrix<int, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::vector<int, std::allocator<int> > const&, Eigen::Matrix<double, -1, -1, 0, -1, -1>&);
  86. template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
  87. template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 1, -1, 2> >&);
  88. template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >&);
  89. template bool igl::list_to_matrix<int, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(std::vector<int, std::allocator<int> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&);
  90. template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > >(std::vector<int, std::allocator<int> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  91. #endif