reorder.cpp 2.5 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. #include "reorder.h"
  9. #include "SortableRow.h"
  10. #ifndef IGL_NO_EIGEN
  11. #include <Eigen/Core>
  12. #endif
  13. // This implementation is O(n), but also uses O(n) extra memory
  14. template< class T >
  15. IGL_INLINE void igl::reorder(
  16. const std::vector<T> & unordered,
  17. std::vector<size_t> const & index_map,
  18. std::vector<T> & ordered)
  19. {
  20. // copy for the reorder according to index_map, because unsorted may also be
  21. // sorted
  22. std::vector<T> copy = unordered;
  23. ordered.resize(index_map.size());
  24. for(int i = 0; i<(int)index_map.size();i++)
  25. {
  26. ordered[i] = copy[index_map[i]];
  27. }
  28. }
  29. #ifdef IGL_STATIC_LIBRARY
  30. // Explicit template specialization
  31. // generated by autoexplicit.sh
  32. template void igl::reorder<double>(std::vector<double, std::allocator<double> > const&, std::vector<size_t, std::allocator<size_t> > const&, std::vector<double, std::allocator<double> >&);
  33. template void igl::reorder<int>(std::vector<int, std::allocator<int> > const&, std::vector<size_t, std::allocator<size_t> > const&, std::vector<int, std::allocator<int> >&);
  34. # ifndef IGL_NO_EIGEN
  35. template void igl::reorder<igl::SortableRow<Eigen::Matrix<int, -1, 1, 0, -1, 1> > >(std::vector<igl::SortableRow<Eigen::Matrix<int, -1, 1, 0, -1, 1> >, std::allocator<igl::SortableRow<Eigen::Matrix<int, -1, 1, 0, -1, 1> > > > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<igl::SortableRow<Eigen::Matrix<int, -1, 1, 0, -1, 1> >, std::allocator<igl::SortableRow<Eigen::Matrix<int, -1, 1, 0, -1, 1> > > >&);
  36. template void igl::reorder<igl::SortableRow<Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(std::vector<igl::SortableRow<Eigen::Matrix<double, -1, 1, 0, -1, 1> >, std::allocator<igl::SortableRow<Eigen::Matrix<double, -1, 1, 0, -1, 1> > > > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<igl::SortableRow<Eigen::Matrix<double, -1, 1, 0, -1, 1> >, std::allocator<igl::SortableRow<Eigen::Matrix<double, -1, 1, 0, -1, 1> > > >&);
  37. # endif
  38. template void igl::reorder<long>(std::vector<long, std::allocator<long> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&, std::vector<long, std::allocator<long> >&);
  39. #endif