unique.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_UNIQUE_H
  9. #define IGL_UNIQUE_H
  10. #include "igl_inline.h"
  11. #include <vector>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. // Act like matlab's [C,IA,IC] = unique(X)
  16. //
  17. // Templates:
  18. // T comparable type T
  19. // Inputs:
  20. // A #A vector of type T
  21. // Outputs:
  22. // C #C vector of unique entries in A
  23. // IA #C index vector so that C = A(IA);
  24. // IC #A index vector so that A = C(IC);
  25. template <typename T>
  26. IGL_INLINE void unique(
  27. const std::vector<T> & A,
  28. std::vector<T> & C,
  29. std::vector<size_t> & IA,
  30. std::vector<size_t> & IC);
  31. template <typename T>
  32. IGL_INLINE void unique(
  33. const std::vector<T> & A,
  34. std::vector<T> & C);
  35. template <
  36. typename DerivedA,
  37. typename DerivedC,
  38. typename DerivedIA,
  39. typename DerivedIC>
  40. IGL_INLINE void unique(
  41. const Eigen::PlainObjectBase<DerivedA> & A,
  42. Eigen::PlainObjectBase<DerivedC> & C,
  43. Eigen::PlainObjectBase<DerivedIA> & IA,
  44. Eigen::PlainObjectBase<DerivedIC> & IC);
  45. template <
  46. typename DerivedA,
  47. typename DerivedC>
  48. IGL_INLINE void unique(
  49. const Eigen::PlainObjectBase<DerivedA> & A,
  50. Eigen::PlainObjectBase<DerivedC> & C);
  51. // Act like matlab's [C,IA,IC] = unique(X,'rows')
  52. //
  53. // Templates:
  54. // DerivedA derived scalar type, e.g. MatrixXi or MatrixXd
  55. // DerivedIA derived integer type, e.g. MatrixXi
  56. // DerivedIC derived integer type, e.g. MatrixXi
  57. // Inputs:
  58. // A m by n matrix whose entries are to unique'd according to rows
  59. // Outputs:
  60. // C #C vector of unique rows in A
  61. // IA #C index vector so that C = A(IA,:);
  62. // IC #A index vector so that A = C(IC,:);
  63. template <typename DerivedA, typename DerivedIA, typename DerivedIC>
  64. IGL_INLINE void unique_rows(
  65. const Eigen::PlainObjectBase<DerivedA>& A,
  66. Eigen::PlainObjectBase<DerivedA>& C,
  67. Eigen::PlainObjectBase<DerivedIA>& IA,
  68. Eigen::PlainObjectBase<DerivedIC>& IC);
  69. }
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "unique.cpp"
  72. #endif
  73. #endif