cat.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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_CAT_H
  9. #define IGL_CAT_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Sparse>
  13. #include <Eigen/Dense>
  14. #include <vector>
  15. namespace igl
  16. {
  17. /// Perform concatenation of a two _sparse_ matrices along a single dimension
  18. /// If dim == 1, then C = [A;B]; If dim == 2 then C = [A B].
  19. /// This is an attempt to act like matlab's cat function.
  20. ///
  21. /// @tparam Scalar scalar data type for sparse matrices like double or int
  22. /// @tparam Mat matrix type for all matrices (e.g. MatrixXd, SparseMatrix)
  23. /// @tparam MatC matrix type for output matrix (e.g. MatrixXd) needs to support
  24. /// resize
  25. /// @param[in] dim dimension along which to concatenate, 1 or 2
  26. /// @param[in] A first input matrix
  27. /// @param[in] B second input matrix
  28. /// @param[out] C output matrix
  29. ///
  30. template <typename Scalar>
  31. IGL_INLINE void cat(
  32. const int dim,
  33. const Eigen::SparseMatrix<Scalar> & A,
  34. const Eigen::SparseMatrix<Scalar> & B,
  35. Eigen::SparseMatrix<Scalar> & C);
  36. /// Perform concatenation of a two _dense_ matrices along a single dimension
  37. /// If dim == 1, then C = [A;B]; If dim == 2 then C = [A B].
  38. ///
  39. /// @param[in] dim dimension along which to concatenate, 1 or 2
  40. /// @param[in] A first input matrix
  41. /// @param[in] B second input matrix
  42. /// @param[out] C output matrix
  43. ///
  44. /// \note If you're using Dense matrices you might be better off using the << operator
  45. template <typename Derived, class MatC>
  46. IGL_INLINE void cat(
  47. const int dim,
  48. const Eigen::MatrixBase<Derived> & A,
  49. const Eigen::MatrixBase<Derived> & B,
  50. MatC & C);
  51. /// Perform concatenation of a two _dense_ matrices along a single dimension
  52. /// If dim == 1, then C = [A;B]; If dim == 2 then C = [A B].
  53. ///
  54. /// @param[in] dim dimension along which to concatenate, 1 or 2
  55. /// @param[in] A first input matrix
  56. /// @param[in] B second input matrix
  57. /// @return C output matrix
  58. ///
  59. /// \note If you're using Dense matrices you might be better off using the << operator
  60. template <class Mat>
  61. IGL_INLINE Mat cat(const int dim, const Mat & A, const Mat & B);
  62. /// Concatenate a "matrix" of sub-blocks
  63. /// C = [A0;A1;A2;...;An] where Ai = [A[i][0] A[i][1] ... A[i][m]];
  64. ///
  65. /// @param[in] A a list of list of matrices (sizes must be compatibile)
  66. /// @param[out] C output matrix
  67. template <class Mat>
  68. IGL_INLINE void cat(const std::vector<std::vector< Mat > > & A, Mat & C);
  69. /// Concatenate a std::vector of matrices along the specified dimension
  70. ///
  71. /// @param[in] dim dimension along which to concatenate, 1 or 2
  72. /// @param[in] A std::vector of eigen matrices. Must have identical # cols if dim == 1 or rows if dim == 2
  73. /// @param[out] C output matrix
  74. template <typename T, typename DerivedC>
  75. IGL_INLINE void cat(const int dim, const std::vector<T> & A, Eigen::PlainObjectBase<DerivedC> & C);
  76. }
  77. #ifndef IGL_STATIC_LIBRARY
  78. # include "cat.cpp"
  79. #endif
  80. #endif