cat.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_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. namespace igl
  15. {
  16. // If you're using Dense matrices you might be better off using the << operator
  17. // This is an attempt to act like matlab's cat function.
  18. // Perform concatenation of a two matrices along a single dimension
  19. // If dim == 1, then C = [A;B]. If dim == 2 then C = [A B]
  20. //
  21. // Template:
  22. // Scalar scalar data type for sparse matrices like double or int
  23. // Mat matrix type for all matrices (e.g. MatrixXd, SparseMatrix)
  24. // MatC matrix type for output matrix (e.g. MatrixXd) needs to support
  25. // resize
  26. // Inputs:
  27. // A first input matrix
  28. // B second input matrix
  29. // dim dimension along which to concatenate, 1 or 2
  30. // Outputs:
  31. // C output matrix
  32. //
  33. template <typename Scalar>
  34. IGL_INLINE void cat(
  35. const int dim,
  36. const Eigen::SparseMatrix<Scalar> & A,
  37. const Eigen::SparseMatrix<Scalar> & B,
  38. Eigen::SparseMatrix<Scalar> & C);
  39. template <typename Derived, class MatC>
  40. IGL_INLINE void cat(
  41. const int dim,
  42. const Eigen::MatrixBase<Derived> & A,
  43. const Eigen::MatrixBase<Derived> & B,
  44. MatC & C);
  45. // Wrapper that returns C
  46. template <class Mat>
  47. IGL_INLINE Mat cat(const int dim, const Mat & A, const Mat & B);
  48. // Note: Maybe we can autogenerate a bunch of overloads D = cat(int,A,B,C),
  49. // E = cat(int,A,B,C,D), etc.
  50. // Concatenate a "matrix" of blocks
  51. // C = [A0;A1;A2;...;An] where Ai = [A[i][0] A[i][1] ... A[i][m]];
  52. //
  53. // Inputs:
  54. // A a matrix (vector of row vectors)
  55. // Output:
  56. // C
  57. template <class Mat>
  58. IGL_INLINE void cat(const std::vector<std::vector< Mat > > & A, Mat & C);
  59. // Concatenate a std::vector of matrices along the specified dimension
  60. //
  61. // Inputs:
  62. // dim dimension along which to concatenate, 1 or 2
  63. // A std::vector of eigen matrices. Must have identical # cols if dim == 1 or rows if dim == 2
  64. // Outputs:
  65. // C output matrix
  66. template <typename T, typename DerivedC>
  67. IGL_INLINE void cat(const int dim, const std::vector<T> & A, Eigen::PlainObjectBase<DerivedC> & C);
  68. }
  69. #ifndef IGL_STATIC_LIBRARY
  70. # include "cat.cpp"
  71. #endif
  72. #endif