15 void addJointEffect(
int jointId,
float weight) {
16 auto jointID_it = m_jointIDs.begin();
17 auto weight_it = m_weights.begin();
18 for (
const auto& weight_object : m_weights) {
19 if (weight > weight_object) {
20 m_jointIDs.insert(jointID_it++, jointId);
21 m_weights.insert(weight_it++, weight);
25 m_jointIDs.push_back(jointId);
26 m_weights.push_back(weight);
29 void limitJointNumber(
int max) {
30 if (m_jointIDs.size() > max) {
31 std::vector<float> topWeights;
32 topWeights.resize(max);
33 float total = saveTopWeights(topWeights);
34 refillWeightList(topWeights, total);
35 removeExcessJointIds(max);
36 }
else if (m_jointIDs.size() < max) {
37 fillEmptyWeights(max);
42 const std::vector<int>& getJointIDs()
const {
46 const std::vector<float>& getWeights()
const {
51 void fillEmptyWeights(
int max) {
52 m_jointIDs.reserve(max);
53 m_weights.reserve(max);
54 while (m_jointIDs.size() < max) {
55 m_jointIDs.push_back(0);
56 m_weights.push_back(0);
60 float saveTopWeights(std::vector<float>& topWeightsArray) {
62 auto size = topWeightsArray.size();
63 for (
int i = 0; i < size; ++i) {
64 topWeightsArray[i] = m_weights[i];
65 total += topWeightsArray[i];
70 void refillWeightList(
const std::vector<float>& topWeights,
float total) {
72 m_weights.reserve(topWeights.size());
73 for (
const auto& topWeight : topWeights) {
74 m_weights.push_back(std::fmin(topWeight / total, 1));
78 void removeExcessJointIds(
int max) {
79 while (m_jointIDs.size() > max) {
80 m_jointIDs.erase(m_jointIDs.begin() + m_jointIDs.size() - 1);
85 std::vector<int> m_jointIDs;
86 std::vector<float> m_weights;