cat.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 ouput 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, 0 or 1
  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. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "cat.cpp"
  62. #endif
  63. #endif