Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to somehow keep the information about the index. I can see two ways of doing this :</p> <p>1-Since you represent your point by a vector, you can had another dimension that will represent the orginal index :</p> <blockquote> <p>//Adding index info, inportant that your index be the last dimension , otherwise the sort is incorrect for(auto point = vector.begin(),unsigned int index=0;point != vector.end(); ++point,++index){ point->push_back(index) };</p> </blockquote> <p>Then sort the same way you are doing now :</p> <blockquote> <p>sort(vector.begin(), vector.end())</p> </blockquote> <p>and you access the original index with A[0][n]</p> <p>The cool thing about that is that it allow you to keep track of the index in a very convenient way, but you need to be able to modify the representation of your point.</p> <p>2- The other way is to have an external table of indices and sort that using custom comp. operator :</p> <p>you start by creating a vector of indices</p> <blockquote> <p>std::vector indices(vector.size());</p> <p>for(unsigned int index =0;index != indicies.size(); ++point){ indicies[index] = index ; };</p> <p>//and sort...</p> <p>std::sort(indices.begin(),indices.end(),[&amp;](unsigned int i,unsigned int j) { return vector[i] &lt; vector[j]})</p> </blockquote> <p>now you need an additional level of indirection to go trough your points in the sorted order : A[indices[0]],A[indices[1]],... So the original position of A[indices[x]] is simply x</p> <p>The main to remember between those two ways of doing it is that in the first you move your data around and not in the second , depending on what you are doing on your points, one might be better that the order</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload