slice.h 3.1 KB

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