slice_into.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #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. // Inputs:
  19. // X xm by xn rhs matrix
  20. // R list of row indices
  21. // C list of column indices
  22. // Y ym by yn lhs matrix
  23. // Output:
  24. // Y ym by yn lhs matrix, same as input but Y(R,C) = X
  25. template <typename T>
  26. IGL_INLINE void slice_into(
  27. const Eigen::SparseMatrix<T>& X,
  28. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  29. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  30. Eigen::SparseMatrix<T>& Y);
  31. template <typename DerivedX>
  32. IGL_INLINE void slice_into(
  33. const Eigen::PlainObjectBase<DerivedX> & X,
  34. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  35. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  36. Eigen::PlainObjectBase<DerivedX> & Y);
  37. // Wrapper to only slice in one direction
  38. //
  39. // Inputs:
  40. // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  41. //
  42. // Note: For now this is just a cheap wrapper.
  43. template <typename Mat>
  44. IGL_INLINE void slice_into(
  45. const Mat& X,
  46. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  47. const int dim,
  48. Mat& Y);
  49. template <typename DerivedX>
  50. IGL_INLINE void slice_into(
  51. const Eigen::PlainObjectBase<DerivedX> & X,
  52. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  53. Eigen::PlainObjectBase<DerivedX> & Y);
  54. }
  55. #ifdef IGL_HEADER_ONLY
  56. # include "slice_into.cpp"
  57. #endif
  58. #endif