slice.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef IGL_SLICE_H
  2. #define IGL_SLICE_H
  3. #include "igl_inline.h"
  4. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // THIS MAY HAVE BEEN SUPERSEDED BY EIGEN'S select FUNCTION
  9. //
  10. // Act like the matlab X(row_indices,col_indices) operator
  11. //
  12. // Inputs:
  13. // X m by n matrix
  14. // R list of row indices
  15. // C list of column indices
  16. // Output:
  17. // Y #R by #C matrix
  18. template <typename T>
  19. IGL_INLINE void slice(
  20. const Eigen::SparseMatrix<T>& X,
  21. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  22. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  23. Eigen::SparseMatrix<T>& Y);
  24. // Wrapper to only slice in one direction
  25. //
  26. // Inputs:
  27. // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  28. template <typename T>
  29. IGL_INLINE void slice(
  30. const Eigen::SparseMatrix<T>& X,
  31. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  32. const int dim,
  33. Eigen::SparseMatrix<T>& Y);
  34. template <typename DerivedX>
  35. IGL_INLINE void slice(
  36. const Eigen::PlainObjectBase<DerivedX> & X,
  37. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  38. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  39. Eigen::PlainObjectBase<DerivedX> & Y);
  40. template <typename DerivedX>
  41. IGL_INLINE void slice(
  42. const Eigen::PlainObjectBase<DerivedX> & X,
  43. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  44. Eigen::PlainObjectBase<DerivedX> & Y);
  45. }
  46. #ifdef IGL_HEADER_ONLY
  47. # include "slice.cpp"
  48. #endif
  49. #endif