https://github.com/HTDerekLiu/surface_multigrid_code
Revision 2a5ce10bcc87d1ae648b298a39eec2f368b24b24 authored by HTDerekLiu on 24 May 2021, 13:03:36 UTC, committed by HTDerekLiu on 24 May 2021, 13:03:36 UTC
1 parent 5d998ed
Raw File
Tip revision: 2a5ce10bcc87d1ae648b298a39eec2f368b24b24 authored by HTDerekLiu on 24 May 2021, 13:03:36 UTC
add balloon
Tip revision: 2a5ce10
sort_vec.cpp
#include "sort_vec.h"

void sort_vec(
  const Eigen::VectorXd & vec, 
  Eigen::VectorXd & sorted_vec,  
  Eigen::VectorXi & ind)
{
  // https://www.programmersought.com/article/343692646/
  using namespace Eigen;
  using namespace std;

  ind=VectorXi::LinSpaced(vec.size(),0,vec.size()-1);//[0 1 2 3 ... N-1]
  auto rule=[vec](int i, int j)->bool{
    return vec(i)<vec(j);
  }; // regular expression, as a predicate of sort
  std::sort(ind.data(),ind.data()+ind.size(),rule);
  //The data member function returns a pointer to the first element of VectorXd, similar to begin()
  sorted_vec.resize(vec.size());
  for(int i=0;i<vec.size();i++){
    sorted_vec(i)=vec(ind(i));
  }
}

void sort_vec(
  const Eigen::VectorXi & vec, 
  Eigen::VectorXi & sorted_vec,  
  Eigen::VectorXi & ind)
{
  // https://www.programmersought.com/article/343692646/
  using namespace Eigen;
  using namespace std;

  ind=VectorXi::LinSpaced(vec.size(),0,vec.size()-1);//[0 1 2 3 ... N-1]
  auto rule=[vec](int i, int j)->bool{
    return vec(i)<vec(j);
  }; // regular expression, as a predicate of sort
  std::sort(ind.data(),ind.data()+ind.size(),rule);
  //The data member function returns a pointer to the first element of VectorXd, similar to begin()
  sorted_vec.resize(vec.size());
  for(int i=0;i<vec.size();i++){
    sorted_vec(i)=vec(ind(i));
  }
}
back to top