unique.h 2.0 KB

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