slice_mask.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_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. // Inputs:
  19. // X m by n matrix
  20. // R m list of row bools
  21. // C n list of column bools
  22. // Output:
  23. // Y #trues-in-R by #trues-in-C matrix
  24. //
  25. // See also: slice_mask
  26. template <typename DerivedX>
  27. IGL_INLINE void slice_mask(
  28. const Eigen::PlainObjectBase<DerivedX> & X,
  29. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  30. const Eigen::Array<bool,Eigen::Dynamic,1> & C,
  31. Eigen::PlainObjectBase<DerivedX> & Y);
  32. template <typename DerivedX>
  33. IGL_INLINE void slice_mask(
  34. const Eigen::PlainObjectBase<DerivedX> & X,
  35. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  36. const int dim,
  37. Eigen::PlainObjectBase<DerivedX> & Y);
  38. //
  39. // This templating is bad because the return type might not have the same
  40. // size as `DerivedX`. This will probably only work if DerivedX has Dynamic
  41. // as it's non-trivial sizes or if the number of rows in R happens to equal
  42. // the number of rows in `DerivedX`.
  43. template <typename DerivedX>
  44. IGL_INLINE DerivedX slice_mask(
  45. const Eigen::PlainObjectBase<DerivedX> & X,
  46. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  47. const Eigen::Array<bool,Eigen::Dynamic,1> & C);
  48. template <typename DerivedX>
  49. IGL_INLINE DerivedX slice_mask(
  50. const Eigen::PlainObjectBase<DerivedX> & X,
  51. const Eigen::Array<bool,Eigen::Dynamic,1> & R,
  52. const int dim);
  53. }
  54. #ifndef IGL_STATIC_LIBRARY
  55. # include "slice_mask.cpp"
  56. #endif
  57. #endif