full.h 997 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef IGL_FULL_H
  2. #define IGL_FULL_H
  3. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  4. #include <Eigen/Dense>
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // Convert a sparsematrix into a full one
  9. // Templates:
  10. // T should be a eigen sparse matrix primitive type like int or double
  11. // Input:
  12. // A m by n sparse matrix
  13. // Output:
  14. // B m by n dense/full matrix
  15. template <typename T>
  16. inline void full(
  17. const Eigen::SparseMatrix<T> & A,
  18. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B);
  19. }
  20. // Implementation
  21. template <typename T>
  22. inline void igl::full(
  23. const Eigen::SparseMatrix<T> & A,
  24. Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & B)
  25. {
  26. B = Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>::Zero(A.rows(),A.cols());
  27. // Iterate over outside
  28. for(int k=0; k<A.outerSize(); ++k)
  29. {
  30. // Iterate over inside
  31. for(typename Eigen::SparseMatrix<T>::InnerIterator it (A,k); it; ++it)
  32. {
  33. B(it.row(),it.col()) = it.value();
  34. }
  35. }
  36. }
  37. #endif