From ce6a316bde97e9fb84566a9e572d4768a036d8b0 Mon Sep 17 00:00:00 2001 From: Julien Valentin Date: Tue, 29 Aug 2017 17:24:35 +0200 Subject: [PATCH] cleanup --- include/osgAnimation/RigTransformSoftware | 22 +++++++----- src/osgAnimation/RigTransformSoftware.cpp | 43 +++-------------------- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/include/osgAnimation/RigTransformSoftware b/include/osgAnimation/RigTransformSoftware index fa8aabcb9..1632eff96 100644 --- a/include/osgAnimation/RigTransformSoftware +++ b/include/osgAnimation/RigTransformSoftware @@ -40,17 +40,23 @@ namespace osgAnimation //to call when a skeleton is reacheable from the rig to prepare technic data virtual bool prepareData(RigGeometry&); - class BonePtrWeight: public BoneWeight + class BonePtrWeight: std::pair< osg::observer_ptr< Bone >, float> { public: - BonePtrWeight(const std::string& name, float weight, Bone *bptr=0) :BoneWeight(name,weight), _boneptr(bptr) {} - BonePtrWeight(const BonePtrWeight &bw2) : BoneWeight(bw2), _boneptr(bw2._boneptr) {} + BonePtrWeight(Bone*bone, float weight) :std::pair< osg::observer_ptr< Bone >, float>(bone,weight) {} + BonePtrWeight(const BonePtrWeight &bw2) : std::pair< osg::observer_ptr< Bone >, float>(bw2.first.get(),bw2.getWeight()) {} - const Bone * getBonePtr()const{return _boneptr.get();} - void setBonePtr(Bone*b){_boneptr=b;} - - protected: - osg::observer_ptr< Bone > _boneptr; + inline const Bone * getBonePtr() const {return first.get();} + inline void setBonePtr(Bone*b){first=b;} + inline const float & getWeight() const {return second;} + inline void setWeight(float b) {second=b;} + inline bool operator<(const BonePtrWeight &b1) const{ + if (getBonePtr() < b1.getBonePtr()) + return true; + else if (getBonePtr() > b1.getBonePtr()) + return false; + return (getWeight() < b1.getWeight()); + } }; typedef std::vector BonePtrWeightList; diff --git a/src/osgAnimation/RigTransformSoftware.cpp b/src/osgAnimation/RigTransformSoftware.cpp index ff241bc91..676cad8ea 100644 --- a/src/osgAnimation/RigTransformSoftware.cpp +++ b/src/osgAnimation/RigTransformSoftware.cpp @@ -36,43 +36,8 @@ RigTransformSoftware::RigTransformSoftware(const RigTransformSoftware& rts,const } -// sort by name and weight -struct SortByNameAndWeight : public std::less -{ - bool operator()(const RigTransformSoftware::BonePtrWeight& b0, - const RigTransformSoftware::BonePtrWeight& b1) const - { - if (b0.getBoneName() < b1.getBoneName()) - return true; - else if (b0.getBoneName() > b1.getBoneName()) - return false; - return (b0.getWeight() < b1.getWeight()); - } -}; typedef std::vector BonePtrWeightList; -struct SortByBoneWeightList : public std::less -{ - bool operator()(const BonePtrWeightList& b0, - const BonePtrWeightList& b1) const - { - if (b0.size() < b1.size()) - return true; - else if (b0.size() > b1.size()) - return false; - - int size = b0.size(); - for (int i = 0; i < size; i++) - { - if (SortByNameAndWeight()(b0[i], b1[i])) - return true; - else if (SortByNameAndWeight()(b1[i], b0[i])) - return false; - } - return false; - } -}; - void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const RigGeometry&rig ){ ///1 Create Index2Vec @@ -104,7 +69,7 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig const unsigned int &index = iw.getIndex(); float weight = iw.getWeight(); - _vertex2Bones[index].push_back(BonePtrWeight(inflist.getBoneName(), weight,bone)); + _vertex2Bones[index].push_back(BonePtrWeight(bone, weight)); } } @@ -132,15 +97,15 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig ///in order to minimize weighted matrices computation on update _uniqInfluenceSet2VertIDList.clear(); - typedef std::map UnifyBoneGroup; + typedef std::map UnifyBoneGroup; UnifyBoneGroup unifyBuffer; vertexID=0; ; for (std::vector::iterator it = _vertex2Bones.begin(); it != _vertex2Bones.end(); ++it,++vertexID) { - BonePtrWeightList bones = *it; + BonePtrWeightList &bones = *it; // sort the vector to have a consistent key - std::sort(bones.begin(), bones.end(), SortByNameAndWeight() ); + std::sort(bones.begin(), bones.end() ); // we use the vector as key to differentiate group UnifyBoneGroup::iterator result = unifyBuffer.find(bones); if (result != unifyBuffer.end())