unique.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. typename DerivedIA,
  49. typename DerivedIC>
  50. IGL_INLINE void unique(
  51. const Eigen::PlainObjectBase<DerivedA> & A,
  52. Eigen::PlainObjectBase<DerivedC> & C);
  53. // Act like matlab's [C,IA,IC] = unique(X,'rows')
  54. //
  55. // Templates:
  56. // DerivedA derived scalar type, e.g. MatrixXi or MatrixXd
  57. // DerivedIA derived integer type, e.g. MatrixXi
  58. // DerivedIC derived integer type, e.g. MatrixXi
  59. // Inputs:
  60. // A m by n matrix whose entries are to unique'd according to rows
  61. // Outputs:
  62. // C #C vector of unique rows in A
  63. // IA #C index vector so that C = A(IA,:);
  64. // IC #A index vector so that A = C(IC,:);
  65. template <typename DerivedA, typename DerivedIA, typename DerivedIC>
  66. IGL_INLINE void unique_rows(
  67. const Eigen::PlainObjectBase<DerivedA>& A,
  68. Eigen::PlainObjectBase<DerivedA>& C,
  69. Eigen::PlainObjectBase<DerivedIA>& IA,
  70. Eigen::PlainObjectBase<DerivedIC>& IC);
  71. }
  72. #ifndef IGL_STATIC_LIBRARY
  73. # include "unique.cpp"
  74. #endif
  75. #endif