slice_cached.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Daniele Panozzo <daniele.panozzo@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_CACHED_H
  9. #define IGL_SLICE_CACHED_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. // Act like the matlab X(row_indices,col_indices) operator, where row_indices,
  17. // col_indices are non-negative integer indices. This is a fast version of
  18. // igl::slice that can analyze and store the sparsity structure. It is slower
  19. // at the irst evaluation (slice_cached_precompute), but faster on the
  20. // subsequent ones.
  21. //
  22. // Inputs:
  23. // X m by n matrix
  24. // R list of row indices
  25. // C list of column indices
  26. //
  27. // Output:
  28. // Y #R by #C matrix
  29. // data Temporary data used by slice_cached to repeat this operation
  30. //
  31. // Usage:
  32. //
  33. // // Construct and slice up Laplacian
  34. // SparseMatrix<double> L,L_sliced;
  35. // igl::cotmatrix(V,F,L);
  36. // // Normal igl::slice call
  37. // igl::slice(L,in,in,L_in_in);
  38. // // Fast version
  39. // static VectorXi data; // static or saved in a global state
  40. // if (data.size() == 0)
  41. // igl::slice_cached_precompute(L,in,in,data,L_sliced);
  42. // else
  43. // igl::slice_cached(L,data,L_sliced);
  44. template <typename TX, typename TY, typename DerivedI>
  45. IGL_INLINE void slice_cached_precompute(
  46. const Eigen::SparseMatrix<TX>& X,
  47. const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
  48. const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
  49. Eigen::MatrixBase<DerivedI>& data,
  50. Eigen::SparseMatrix<TY>& Y
  51. );
  52. template <typename TX, typename TY, typename DerivedI>
  53. IGL_INLINE void slice_cached(
  54. const Eigen::SparseMatrix<TX>& X,
  55. const Eigen::MatrixBase<DerivedI>& data,
  56. Eigen::SparseMatrix<TY>& Y
  57. );
  58. }
  59. #ifndef IGL_STATIC_LIBRARY
  60. # include "slice_cached.cpp"
  61. #endif
  62. #endif