unique.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef IGL_UNIQUE_H
  2. #define IGL_UNIQUE_H
  3. #include "igl_inline.h"
  4. #include <vector>
  5. #include <Eigen/Core>
  6. namespace igl
  7. {
  8. // Act like matlab's [C,IA,IC] = unique(X)
  9. //
  10. // Templates:
  11. // T comparable type T
  12. // Inputs:
  13. // A #A vector of type T
  14. // Outputs:
  15. // C #C vector of unique entries in A
  16. // IA #C index vector so that C = A(IA);
  17. // IC #A index vector so that A = C(IC);
  18. template <typename T>
  19. IGL_INLINE void unique(
  20. const std::vector<T> & A,
  21. std::vector<T> & C,
  22. std::vector<size_t> & IA,
  23. std::vector<size_t> & IC);
  24. // Act like matlab's [C,IA,IC] = unique(X,'rows')
  25. //
  26. // Templates:
  27. // DerivedA derived scalar type, e.g. MatrixXi or MatrixXd
  28. // DerivedIA derived integer type, e.g. MatrixXi
  29. // DerivedIC derived integer type, e.g. MatrixXi
  30. // Inputs:
  31. // A m by n matrix whose entries are to unique'd according to rows
  32. // Outputs:
  33. // C #C vector of unique rows in A
  34. // IA #C index vector so that C = A(IA,:);
  35. // IC #A index vector so that A = C(IC,:);
  36. template <typename DerivedA, typename DerivedIA, typename DerivedIC>
  37. IGL_INLINE void unique_rows(
  38. const Eigen::PlainObjectBase<DerivedA>& A,
  39. Eigen::PlainObjectBase<DerivedA>& C,
  40. Eigen::PlainObjectBase<DerivedIA>& IA,
  41. Eigen::PlainObjectBase<DerivedIC>& IC);
  42. }
  43. #ifdef IGL_HEADER_ONLY
  44. # include "unique.cpp"
  45. #endif
  46. #endif