1

I am doing animation with opengl and I have 2 vectors. 1 is an int vector of Bone IDs and 1 is a float vector of weight values. For example, bone_ids[1] corresponds to weight_values[1] or whatever the index is. What I need to do is get the top 3 greatest floats from the weight_values vector but I also need to rearrange the bone_ids array in the exact same way. So if weight_values[1] is moved to weight_values[0] because it is the highest number, I need to move bone_ids[1] to bone_ids[0] as well. An example might be:

int bone_ids = { 1, 2, 2, 3, 2, 0, 1};
int weight_values = { 0.4162, 0.0213, 0.6213, 0.71, 0.09232, 0.5, 0 };

I can easily do this with std::sort and then std::reverse with the weight values and the just grab the first 3 values however I could not find a way to also reorganize the same way with the bone_ids since the bone ids just need to follow the same moves as the weight values.

I only need to grab the top 3 weight values and their top 3 weight ids if that helps. My idea was to just sort the array from highest to lowest and then grab the top 3 weights but I realized I need the bone_ids too and it wouldn't work with that.

username3630
  • 111
  • 1
  • 7
  • 3
    **Protip:** Vectors needs to be declared with `std:vector<>`. Those two lines of code doesn't works in the way you're thinking. They're not arrays either. – Rohan Bari Aug 17 '20 at 08:02
  • [How can I sort two vectors in the same way, with criteria that uses only one of the vectors?](https://stackoverflow.com/questions/17074324/how-can-i-sort-two-vectors-in-the-same-way-with-criteria-that-uses-only-one-of) – Evg Aug 17 '20 at 08:05

1 Answers1

0

Try it using set<unordered_map<int,int> st;

where you map your bone_ids, weight values. and add the mapping to set. It will sort it automatically

Mahesh Sv
  • 41
  • 4