reorder.cpp 1.9 KB

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