slice_into.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. #ifndef IGL_SLICE_INTO_H
  9. #define IGL_SLICE_INTO_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. /// Act like the matlab Y(row_indices,col_indices) = X
  17. ///
  18. /// @param[in] X xm by xn rhs matrix
  19. /// @param[in] R list of row indices
  20. /// @param[in] C list of column indices
  21. /// @param[in] Y ym by yn lhs matrix
  22. /// @param[out] Y ym by yn lhs matrix, same as input but Y(R,C) = X
  23. template <typename T, typename DerivedR, typename DerivedC>
  24. IGL_INLINE void slice_into(
  25. const Eigen::SparseMatrix<T>& X,
  26. const Eigen::MatrixBase<DerivedR> & R,
  27. const Eigen::MatrixBase<DerivedC> & C,
  28. Eigen::SparseMatrix<T>& Y);
  29. /// \overload
  30. template <typename DerivedX, typename DerivedY, typename DerivedR, typename DerivedC>
  31. IGL_INLINE void slice_into(
  32. const Eigen::MatrixBase<DerivedX> & X,
  33. const Eigen::MatrixBase<DerivedR> & R,
  34. const Eigen::MatrixBase<DerivedC> & C,
  35. Eigen::PlainObjectBase<DerivedY> & Y);
  36. /// \overload
  37. /// \brief Wrapper to only slice in one direction
  38. ///
  39. /// @param[int] dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  40. ///
  41. /// \note For now this is just a cheap wrapper.
  42. template <typename MatX, typename MatY, typename DerivedR>
  43. IGL_INLINE void slice_into(
  44. const MatX & X,
  45. const Eigen::MatrixBase<DerivedR> & R,
  46. const int dim,
  47. MatY& Y);
  48. /// \overload
  49. /// \brief Vector version
  50. template <typename DerivedX, typename DerivedR, typename DerivedY>
  51. IGL_INLINE void slice_into(
  52. const Eigen::MatrixBase<DerivedX>& X,
  53. const Eigen::MatrixBase<DerivedR>& R,
  54. Eigen::PlainObjectBase<DerivedY>& Y);
  55. }
  56. #ifndef IGL_STATIC_LIBRARY
  57. # include "slice_into.cpp"
  58. #endif
  59. #endif