slice_sorted.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Jérémie Dumas <[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_SORTED_H
  9. #define IGL_SLICE_SORTED_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. /// Act like the matlab X(row_indices,col_indices) operator, where row_indices,
  16. /// col_indices are non-negative integer indices. This version is about 2x faster
  17. /// than igl::slice, but it assumes that the indices to slice with are already sorted.
  18. ///
  19. /// @param[in] X m by n matrix
  20. /// @param[in] R list of row indices
  21. /// @param[in] C list of column indices
  22. /// @param[out] Y #R by #C matrix
  23. ///
  24. /// \see slice
  25. template <typename TX, typename TY, typename DerivedR, typename DerivedC>
  26. IGL_INLINE void slice_sorted(
  27. const Eigen::SparseMatrix<TX> &X,
  28. const Eigen::DenseBase<DerivedR> &R,
  29. const Eigen::DenseBase<DerivedC> &C,
  30. Eigen::SparseMatrix<TY> &Y);
  31. }
  32. #ifndef IGL_STATIC_LIBRARY
  33. #include "slice_sorted.cpp"
  34. #endif
  35. #endif