sortrows.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_SORTROWS_H
  9. #define IGL_SORTROWS_H
  10. #include "igl_inline.h"
  11. #include <vector>
  12. #include <Eigen/Core>
  13. namespace igl
  14. {
  15. // Act like matlab's [Y,I] = sortrows(X)
  16. //
  17. // Templates:
  18. // DerivedX derived scalar type, e.g. MatrixXi or MatrixXd
  19. // DerivedI derived integer type, e.g. MatrixXi
  20. // Inputs:
  21. // X m by n matrix whose entries are to be sorted
  22. // ascending sort ascending (true, matlab default) or descending (false)
  23. // Outputs:
  24. // Y m by n matrix whose entries are sorted (**should not** be same
  25. // reference as X)
  26. // I m list of indices so that
  27. // Y = X(I,:);
  28. template <typename DerivedX, typename DerivedI>
  29. IGL_INLINE void sortrows(
  30. const Eigen::PlainObjectBase<DerivedX>& X,
  31. const bool ascending,
  32. Eigen::PlainObjectBase<DerivedX>& Y,
  33. Eigen::PlainObjectBase<DerivedI>& I);
  34. }
  35. #ifndef IGL_STATIC_LIBRARY
  36. # include "sortrows.cpp"
  37. #endif
  38. #endif