unique.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. // Act like matlab's [C,IA,IC] = unique(X,'rows')
  32. //
  33. // Templates:
  34. // DerivedA derived scalar type, e.g. MatrixXi or MatrixXd
  35. // DerivedIA derived integer type, e.g. MatrixXi
  36. // DerivedIC derived integer type, e.g. MatrixXi
  37. // Inputs:
  38. // A m by n matrix whose entries are to unique'd according to rows
  39. // Outputs:
  40. // C #C vector of unique rows in A
  41. // IA #C index vector so that C = A(IA,:);
  42. // IC #A index vector so that A = C(IC,:);
  43. template <typename DerivedA, typename DerivedIA, typename DerivedIC>
  44. IGL_INLINE void unique_rows(
  45. const Eigen::PlainObjectBase<DerivedA>& A,
  46. Eigen::PlainObjectBase<DerivedA>& C,
  47. Eigen::PlainObjectBase<DerivedIA>& IA,
  48. Eigen::PlainObjectBase<DerivedIC>& IC);
  49. }
  50. #ifdef IGL_HEADER_ONLY
  51. # include "unique.cpp"
  52. #endif
  53. #endif