sortrows.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // DerivedIX 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
  25. // IX m by n matrix of indices so that if dim = 1, then in matlab notation
  26. // for j = 1:n, Y(:,j) = X(I(:,j),j); end
  27. template <typename DerivedX, typename DerivedIX>
  28. IGL_INLINE void sortrows(
  29. const Eigen::PlainObjectBase<DerivedX>& X,
  30. const bool ascending,
  31. Eigen::PlainObjectBase<DerivedX>& Y,
  32. Eigen::PlainObjectBase<DerivedIX>& IX);
  33. }
  34. #ifdef IGL_HEADER_ONLY
  35. # include "sortrows.cpp"
  36. #endif
  37. #endif