slice_mask.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_MASK_H
  9. #define IGL_SLICE_MASK_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Sparse>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. /// Act like the matlab X(row_mask,col_mask) operator, where
  16. /// row_mask, col_mask are non-negative integer indices.
  17. ///
  18. /// @param[in] X m by n matrix
  19. /// @param[in] R m list of row bools
  20. /// @param[in] C n list of column bools
  21. /// @param[out] Y #trues-in-R by #trues-in-C matrix
  22. ///
  23. /// \see slice
  24. template <typename XType, typename YType>
  25. IGL_INLINE void slice_mask(
  26. const Eigen::SparseMatrix<XType> & X,
  27. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  28. const Eigen::Array<bool,Eigen::Dynamic,1> & C,
  29. Eigen::SparseMatrix<YType> & Y);
  30. /// \overload
  31. ///
  32. /// \brief Wrapper to only slice in one direction
  33. ///
  34. /// @param[int] dim dimension to slice in 1 or 2, dim=1 --> X(R,:), dim=2 --> X(:,R)
  35. template <typename XType, typename YType>
  36. IGL_INLINE void slice_mask(
  37. const Eigen::SparseMatrix<XType> & X,
  38. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  39. const int dim,
  40. Eigen::SparseMatrix<YType> & Y);
  41. /// \overload
  42. ///
  43. /// \deprecated
  44. ///
  45. /// See slice.h for more details
  46. template <typename DerivedX,typename DerivedY>
  47. IGL_INLINE void slice_mask(
  48. const Eigen::DenseBase<DerivedX> & X,
  49. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  50. const Eigen::Array<bool,Eigen::Dynamic,1> & C,
  51. Eigen::PlainObjectBase<DerivedY> & Y);
  52. template <typename DerivedX,typename DerivedY>
  53. IGL_INLINE void slice_mask(
  54. const Eigen::DenseBase<DerivedX> & X,
  55. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  56. const int dim,
  57. Eigen::PlainObjectBase<DerivedY> & Y);
  58. /// \overload
  59. /// \note This templating is bad because the return type might not have the same
  60. /// size as `DerivedX`. This will probably only work if DerivedX has Dynamic
  61. /// as it's non-trivial sizes or if the number of rows in R happens to equal
  62. /// the number of rows in `DerivedX`.
  63. template <typename DerivedX>
  64. IGL_INLINE DerivedX slice_mask(
  65. const Eigen::DenseBase<DerivedX> & X,
  66. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  67. const Eigen::Array<bool,Eigen::Dynamic,1> & C);
  68. /// \overload
  69. template <typename DerivedX>
  70. IGL_INLINE DerivedX slice_mask(
  71. const Eigen::DenseBase<DerivedX> & X,
  72. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  73. const int dim);
  74. }
  75. #ifndef IGL_STATIC_LIBRARY
  76. # include "slice_mask.cpp"
  77. #endif
  78. #endif