#include "sort.h" #include "SortableRow.h" #include "reorder.h" #include "IndexComparison.h" #include #include template IGL_INLINE void igl::sort( const Eigen::PlainObjectBase& X, const int dim, const bool ascending, Eigen::PlainObjectBase& Y, Eigen::PlainObjectBase& IX) { using namespace Eigen; // dim must be 2 or 1 assert(dim == 1 || dim == 2); // Resize output Y.resize(X.rows(),X.cols()); IX.resize(X.rows(),X.cols()); // idea is to process each column (or row) as a std vector // get number of columns (or rows) int num_outer = (dim == 1 ? X.cols() : X.rows() ); // get number of rows (or columns) int num_inner = (dim == 1 ? X.rows() : X.cols() ); // loop over columns (or rows) for(int i = 0; i index_map(num_inner); std::vector data(num_inner); for(int j = 0;j IGL_INLINE void igl::sort( const std::vector & unsorted, const bool ascending, std::vector & sorted, std::vector & index_map) { // Original unsorted index map index_map.resize(unsorted.size()); for(size_t i=0;i& >(unsorted)); // if not ascending then reverse if(!ascending) { std::reverse(index_map.begin(),index_map.end()); } // make space for output without clobbering sorted.resize(unsorted.size()); // reorder unsorted into sorted using index map igl::reorder(unsorted,index_map,sorted); } #ifndef IGL_HEADER_ONLY // Explicit template specialization // generated by autoexplicit.sh template void igl::sort, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::sort, Eigen::Matrix >(Eigen::PlainObjectBase > const&, int, bool, Eigen::PlainObjectBase >&, Eigen::PlainObjectBase >&); template void igl::sort > >(std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >&, std::vector >&); template void igl::sort(std::vector > const&, bool, std::vector >&, std::vector >&); template void igl::sort > >(std::vector >, std::allocator > > > const&, bool, std::vector >, std::allocator > > >&, std::vector >&); #endif