slice.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_H
  9. #define IGL_SLICE_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. // Act like the matlab X(row_indices,col_indices) operator
  16. //
  17. // Inputs:
  18. // X m by n matrix
  19. // R list of row indices
  20. // C list of column indices
  21. // Output:
  22. // Y #R by #C matrix
  23. template <typename T>
  24. IGL_INLINE void slice(
  25. const Eigen::SparseMatrix<T>& X,
  26. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  27. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  28. Eigen::SparseMatrix<T>& Y);
  29. // Wrapper to only slice in one direction
  30. //
  31. // Inputs:
  32. // dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  33. //
  34. // Note: For now this is just a cheap wrapper.
  35. template <typename Mat>
  36. IGL_INLINE void slice(
  37. const Mat& X,
  38. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  39. const int dim,
  40. Mat& Y);
  41. template <typename DerivedX>
  42. IGL_INLINE void slice(
  43. const Eigen::PlainObjectBase<DerivedX> & X,
  44. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  45. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  46. Eigen::PlainObjectBase<DerivedX> & Y);
  47. template <typename DerivedX>
  48. IGL_INLINE void slice_mask(
  49. const Eigen::PlainObjectBase<DerivedX> & X,
  50. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  51. const Eigen::Array<bool,Eigen::Dynamic,1> & C,
  52. Eigen::PlainObjectBase<DerivedX> & Y);
  53. template <typename DerivedX>
  54. IGL_INLINE void slice_mask(
  55. const Eigen::PlainObjectBase<DerivedX> & X,
  56. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  57. const int dim,
  58. Eigen::PlainObjectBase<DerivedX> & Y);
  59. template <typename DerivedX>
  60. IGL_INLINE void slice(
  61. const Eigen::PlainObjectBase<DerivedX> & X,
  62. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  63. Eigen::PlainObjectBase<DerivedX> & Y);
  64. // VectorXi Y = slice(X,R);
  65. template <typename DerivedX>
  66. IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice(
  67. const Eigen::PlainObjectBase<DerivedX> & X,
  68. const Eigen::Matrix<int,Eigen::Dynamic,1> & R);
  69. template <typename DerivedX>
  70. IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice(
  71. const Eigen::PlainObjectBase<DerivedX>& X,
  72. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  73. const int dim);
  74. template <typename DerivedX>
  75. IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
  76. const Eigen::PlainObjectBase<DerivedX> & X,
  77. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  78. const Eigen::Array<bool,Eigen::Dynamic,1> & C);
  79. template <typename DerivedX>
  80. IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
  81. const Eigen::PlainObjectBase<DerivedX> & X,
  82. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  83. const int dim);
  84. }
  85. #ifndef IGL_STATIC_LIBRARY
  86. # include "slice.cpp"
  87. #endif
  88. #endif