concat.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef IGL_CONCAT_H
  2. #define IGL_CONCAT_H
  3. #include <Eigen/Dense>
  4. namespace igl
  5. {
  6. // Concatenates dense matrices
  7. // Templates:
  8. // T should be a eigen matrix primitive type like int or double
  9. // Inputs:
  10. // A first matrix
  11. // B second matrix
  12. // horiz if true, matrices are concatenated horizontally
  13. // Output:
  14. // O if horiz = false return [A;B] else [A,B]
  15. template <typename T>
  16. inline void concat(
  17. const T A,
  18. const T B,
  19. const bool horiz,
  20. T& O);
  21. template <typename T>
  22. inline T concat(
  23. const T A,
  24. const T B,
  25. bool horiz = false
  26. );
  27. }
  28. // Implementation
  29. #include <cstdio>
  30. template <typename T>
  31. inline void igl::concat(
  32. const T A,
  33. const T B,
  34. const bool horiz,
  35. T& O)
  36. {
  37. if (horiz)
  38. {
  39. // O = [A,B]
  40. assert(A.rows() == B.rows());
  41. O = T(A.rows(),A.cols()+B.cols());
  42. O << A,B;
  43. }
  44. else
  45. {
  46. // O = [A;B]
  47. assert(A.cols() == B.cols());
  48. O = T(A.rows()+B.rows(),A.cols());
  49. O << A,B;
  50. }
  51. }
  52. template <typename T>
  53. inline T igl::concat(
  54. const T A,
  55. const T B,
  56. bool horiz
  57. )
  58. {
  59. T O = T(1,1);
  60. concat(A,B,horiz,O);
  61. return O;
  62. }
  63. #endif