sortrows.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. /// @tparam DerivedX derived scalar type, e.g. Eigen::MatrixXi or Eigen::MatrixXd
  18. /// @tparam DerivedI derived integer type, e.g. Eigen::MatrixXi
  19. /// @param[in] X m by n matrix whose entries are to be sorted
  20. /// @param[in] ascending sort ascending (true, matlab default) or descending (false)
  21. /// @param[out] Y m by n matrix whose entries are sorted (**should not** be same
  22. /// reference as X)
  23. /// @param[out] I m list of indices so that Y = X(I,:);
  24. template <typename DerivedX, typename DerivedY,typename DerivedI>
  25. IGL_INLINE void sortrows(
  26. const Eigen::DenseBase<DerivedX>& X,
  27. const bool ascending,
  28. Eigen::PlainObjectBase<DerivedY>& Y,
  29. Eigen::PlainObjectBase<DerivedI>& I);
  30. /// \overload
  31. template <typename DerivedX, typename DerivedY>
  32. IGL_INLINE void sortrows(
  33. const Eigen::DenseBase<DerivedX>& X,
  34. const bool ascending,
  35. Eigen::PlainObjectBase<DerivedY>& Y);
  36. }
  37. #ifndef IGL_STATIC_LIBRARY
  38. # include "sortrows.cpp"
  39. #endif
  40. #endif