refactor: remove totally VertexInfluence (renamed BoneInfluenceList) everywhere

This commit is contained in:
Julien Valentin 2017-08-30 11:12:17 +02:00
parent fae9729560
commit fe99b568a0
9 changed files with 53 additions and 72 deletions

View File

@ -136,10 +136,6 @@ void initVertexMap(osgAnimation::Bone* b0,
{ {
osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap; osgAnimation::VertexInfluenceMap* vim = new osgAnimation::VertexInfluenceMap;
(*vim)[b0->getName()].setBoneName(b0->getName());
(*vim)[b1->getName()].setBoneName(b1->getName());
(*vim)[b2->getName()].setBoneName(b2->getName());
for (int i = 0; i < (int)array->size(); i++) for (int i = 0; i < (int)array->size(); i++)
{ {
float val = (*array)[i][0]; float val = (*array)[i][0];

View File

@ -46,25 +46,15 @@ namespace osgAnimation
typedef std::vector<BoneWeight> BoneWeightList; typedef std::vector<BoneWeight> BoneWeightList;
typedef std::vector<unsigned int> IndexList; typedef std::vector<unsigned int> IndexList;
class OSGANIMATION_EXPORT BoneInfluenceList : public IndexWeightList
{
public:
const std::string& getBoneName() const { return _name;}
void setBoneName(const std::string& name) { _name = name;}
protected: class VertexInfluenceMap : public std::map<std::string, IndexWeightList> , public osg::Object
// the name is the bone to link to
std::string _name;
};
class VertexInfluenceMap : public std::map<std::string, BoneInfluenceList> , public osg::Object
{ {
public: public:
META_Object(osgAnimation, VertexInfluenceMap); META_Object(osgAnimation, VertexInfluenceMap);
VertexInfluenceMap() {} VertexInfluenceMap() {}
VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop): VertexInfluenceMap(const osgAnimation::VertexInfluenceMap& org, const osg::CopyOp& copyop):
std::map<std::string, BoneInfluenceList>(org), std::map<std::string, IndexWeightList>(org),
osg::Object(org, copyop) osg::Object(org, copyop)
{} {}
///normalize per vertex weights given numvert of the attached mesh ///normalize per vertex weights given numvert of the attached mesh

View File

@ -280,8 +280,9 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
mapit != vertexInfluenceMap->end(); mapit != vertexInfluenceMap->end();
++mapit) ++mapit)
{ {
const BoneInfluenceList& boneinflist = mapit->second; const IndexWeightList& boneinflist = mapit->second;
for(BoneInfluenceList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit) const std::string& bonename = mapit->first;
for(IndexWeightList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
{ {
const IndexWeight& iw = *infit; const IndexWeight& iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.getIndex();
@ -289,30 +290,24 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
FloatInt &sum=sums[index]; FloatInt &sum=sums[index];
if (boneinflist.getBoneName().empty()) {
OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << index << " is not assigned to a bone" << std::endl;
}
//_vertex2Bones[index].push_back(VertexInfluenceSet::BoneWeight(vi.getName(), weight));;
if(fabs(weight) > 1e-4) // don't use bone with weight too small if(fabs(weight) > 1e-4) // don't use bone with weight too small
{ {
if ((boneName2PaletteIndex= _boneNameToPalette.find(boneinflist.getBoneName())) != _boneNameToPalette.end()) if ((boneName2PaletteIndex= _boneNameToPalette.find(bonename)) != _boneNameToPalette.end())
{ {
boneNameCountMap[boneinflist.getBoneName()]++; boneNameCountMap[bonename]++;
vertexIndexWeight[index].push_back(IndexWeight(boneName2PaletteIndex->second,weight)); vertexIndexWeight[index].push_back(IndexWeight(boneName2PaletteIndex->second,weight));
} }
else else
{ {
BoneMap::const_iterator bonebyname; BoneMap::const_iterator bonebyname;
if ((bonebyname=boneMap.find(boneinflist.getBoneName())) == boneMap.end()) if ((bonebyname=boneMap.find(bonename)) == boneMap.end())
{ {
OSG_WARN << "RigTransformHardware::createPalette can't find bone " << boneinflist.getBoneName() << "in skeleton bonemap: skip this influence" << std::endl; OSG_WARN << "RigTransformHardware::createPalette can't find bone " << bonename << "in skeleton bonemap: skip this influence" << std::endl;
continue; continue;
} }
boneNameCountMap[boneinflist.getBoneName()] = 1; // for stats boneNameCountMap[bonename] = 1; // for stats
_boneNameToPalette[boneinflist.getBoneName()] = _bonePalette.size() ; _boneNameToPalette[bonename] = _bonePalette.size() ;
vertexIndexWeight[index].push_back(IndexWeight(_bonePalette.size(),weight)); vertexIndexWeight[index].push_back(IndexWeight(_bonePalette.size(),weight));
_bonePalette.push_back(bonebyname->second); _bonePalette.push_back(bonebyname->second);
sum.first+=weight; sum.first+=weight;
@ -321,7 +316,7 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
} }
else else
{ {
OSG_WARN << "RigTransformHardware::createPalette Bone " << boneinflist.getBoneName() << " has a weight " << weight << " for vertex " << index << " this bone will not be in the palette" << std::endl; OSG_WARN << "RigTransformHardware::createPalette Bone " << bonename << " has a weight " << weight << " for vertex " << index << " this bone will not be in the palette" << std::endl;
} }
maxBonePerVertex = osg::maximum(maxBonePerVertex, sum.second); maxBonePerVertex = osg::maximum(maxBonePerVertex, sum.second);

View File

@ -49,21 +49,23 @@ void RigTransformSoftware::buildMinimumUpdateSet(const BoneMap&boneMap,const Rig
it != _vertexInfluenceMap->end(); it != _vertexInfluenceMap->end();
++it) ++it)
{ {
const BoneInfluenceList& inflist = it->second; const IndexWeightList& inflist = it->second;
if (inflist.getBoneName().empty()) { const std::string& bonename = it->first;
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone BoneInfluenceList" << std::endl;
if (bonename.empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone IndexWeightList" << std::endl;
} }
BoneMap::const_iterator bmit = boneMap.find(inflist.getBoneName()); BoneMap::const_iterator bmit = boneMap.find(bonename);
if (bmit == boneMap.end() ) if (bmit == boneMap.end() )
{ {
if (_invalidInfluence.find(inflist.getBoneName()) != _invalidInfluence.end()) { if (_invalidInfluence.find(bonename) != _invalidInfluence.end()) {
_invalidInfluence[inflist.getBoneName()] = true; _invalidInfluence[bonename] = true;
OSG_WARN << "RigTransformSoftware Bone " << inflist.getBoneName() << " not found, skip the influence group " << std::endl; OSG_WARN << "RigTransformSoftware Bone " << bonename << " not found, skip the influence group " << std::endl;
} }
continue; continue;
} }
Bone* bone = bmit->second.get(); Bone* bone = bmit->second.get();
for(BoneInfluenceList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit) for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{ {
const IndexWeight &iw = *infit; const IndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.getIndex();

View File

@ -36,8 +36,8 @@ void VertexInfluenceMap::normalize(unsigned int numvert) {
std::vector<PerVertWeights > localstore; std::vector<PerVertWeights > localstore;
localstore.resize(numvert); localstore.resize(numvert);
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) { for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) {
BoneInfluenceList &curvecinf=mapit->second; IndexWeightList &curvecinf=mapit->second;
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) { for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeight& inf=*curinf; IndexWeight& inf=*curinf;
localstore[inf.first].first+=inf.second; localstore[inf.first].first+=inf.second;
localstore[inf.first].second.push_back(&inf.second); localstore[inf.first].second.push_back(&inf.second);
@ -65,14 +65,16 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
typedef std::set<BoneWeight,invweight_ordered > BoneWeightOrdered; typedef std::set<BoneWeight,invweight_ordered > BoneWeightOrdered;
std::map<int,BoneWeightOrdered > tempVec2Bones; std::map<int,BoneWeightOrdered > tempVec2Bones;
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) { for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit)
BoneInfluenceList &curvecinf=mapit->second; {
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) { const std::string& bonename=mapit->first;
IndexWeightList &curvecinf=mapit->second;
for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeight& inf=*curinf; IndexWeight& inf=*curinf;
if( curvecinf.getBoneName().empty()) { if( bonename.empty()) {
OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << inf.first << " is not assigned to a bone" << std::endl; OSG_WARN << "VertexInfluenceSet::buildVertex2BoneList warning vertex " << inf.first << " is not assigned to a bone" << std::endl;
} }
else if(inf.second>minweight)tempVec2Bones[inf.first].insert(BoneWeight(curvecinf.getBoneName(), inf.second)); else if(inf.second>minweight)tempVec2Bones[inf.first].insert(BoneWeight(bonename, inf.second));
} }
} }
this->clear(); this->clear();
@ -87,15 +89,13 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
if(sum>1e-4){ if(sum>1e-4){
sum=1.0f/sum; sum=1.0f/sum;
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()]; IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum)); inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum));
} }
} }
}else{ }else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) { for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()]; IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
inf.push_back(IndexWeight(mapit->first,bwit->getWeight())); inf.push_back(IndexWeight(mapit->first,bwit->getWeight()));
} }
@ -110,17 +110,17 @@ void VertexInfluenceMap::computePerVertexInfluenceList(std::vector<BoneWeightLis
it != end(); it != end();
++it) ++it)
{ {
const BoneInfluenceList& inflist = it->second; const IndexWeightList& inflist = it->second;
if (inflist.getBoneName().empty()) { if (it->first.empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone BoneInfluenceList" << std::endl; OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone IndexWeightList" << std::endl;
} }
for(BoneInfluenceList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit) for(IndexWeightList::const_iterator infit=inflist.begin(); infit!=inflist.end(); ++infit)
{ {
const IndexWeight &iw = *infit; const IndexWeight &iw = *infit;
const unsigned int &index = iw.getIndex(); const unsigned int &index = iw.getIndex();
float weight = iw.getWeight(); float weight = iw.getWeight();
vertex2Bones[index].push_back(BoneWeight(inflist.getBoneName(), weight));; vertex2Bones[index].push_back(BoneWeight(it->first, weight));;
} }
} }
} }

View File

@ -51,7 +51,7 @@ void ComputeAABBOnBoneVisitor::computeBoundingBoxOnBones() {
osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(rigGeometry->getVertexArray()); osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array*>(rigGeometry->getVertexArray());
if(!vertices) continue; if(!vertices) continue;
osgAnimation::BoneInfluenceList vxtInf = (*itMap).second; osgAnimation::IndexWeightList vxtInf = (*itMap).second;
//Expand the boundingBox with each vertex //Expand the boundingBox with each vertex
for(unsigned int j = 0; j < vxtInf.size(); j++) { for(unsigned int j = 0; j < vxtInf.size(); j++) {

View File

@ -200,9 +200,9 @@ protected:
BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first); BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first);
if(bone_it == boneMap.end()) continue; if(bone_it == boneMap.end()) continue;
osg::ref_ptr<osgAnimation::Bone> bone = bone_it->second; osg::ref_ptr<osgAnimation::Bone> bone = bone_it->second;
const osgAnimation::BoneInfluenceList& vertexInfluence = (*vertexInfluencePair).second; const osgAnimation::IndexWeightList& vertexInfluence = (*vertexInfluencePair).second;
for(osgAnimation::BoneInfluenceList::const_iterator vertexIndexWeight = vertexInfluence.begin(); vertexIndexWeight != vertexInfluence.end(); ++vertexIndexWeight) { for(osgAnimation::IndexWeightList::const_iterator vertexIndexWeight = vertexInfluence.begin(); vertexIndexWeight != vertexInfluence.end(); ++vertexIndexWeight) {
rigGeometryInfluenceByBoneMap[bone.get()][*rigGeometry].addWeight((*vertexIndexWeight).second); rigGeometryInfluenceByBoneMap[bone.get()][*rigGeometry].addWeight((*vertexIndexWeight).second);
} }
} }

View File

@ -804,17 +804,16 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
for (int i = 0; i < nbGroups; i++) for (int i = 0; i < nbGroups; i++)
{ {
int nbVertexes = 0; int nbVertexes = 0;
std::string name; std::string bonename;
if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {")) if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {"))
{ {
name = fr[1].getStr(); bonename = fr[1].getStr();
fr[2].getInt(nbVertexes); fr[2].getInt(nbVertexes);
fr += 4; fr += 4;
iteratorAdvanced = true; iteratorAdvanced = true;
} }
osgAnimation::BoneInfluenceList vi; osgAnimation::IndexWeightList vi;
vi.setBoneName(name);
vi.reserve(nbVertexes); vi.reserve(nbVertexes);
for (int j = 0; j < nbVertexes; j++) for (int j = 0; j < nbVertexes; j++)
{ {
@ -833,7 +832,7 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
{ {
fr+=1; fr+=1;
} }
(*vmap)[name] = vi; (*vmap)[bonename] = vi;
} }
if (!vmap->empty()) if (!vmap->empty())
geom.setInfluenceMap(vmap.get()); geom.setInfluenceMap(vmap.get());
@ -863,8 +862,8 @@ bool RigGeometry_writeLocalData(const Object& obj, Output& fw)
name = "Empty"; name = "Empty";
fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl; fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl;
fw.moveIn(); fw.moveIn();
const osgAnimation::BoneInfluenceList& vi = it->second; const osgAnimation::IndexWeightList& vi = it->second;
for (osgAnimation::BoneInfluenceList::const_iterator itv = vi.begin(); itv != vi.end(); itv++) for (osgAnimation::IndexWeightList::const_iterator itv = vi.begin(); itv != vi.end(); itv++)
{ {
fw.indent() << itv->first << " " << itv->second << std::endl; fw.indent() << itv->first << " " << itv->second << std::endl;
} }

View File

@ -14,14 +14,13 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry&
unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET;
for ( unsigned int i=0; i<size; ++i ) for ( unsigned int i=0; i<size; ++i )
{ {
std::string name; std::string bonename;
unsigned int viSize = 0; unsigned int viSize = 0;
is >> is.PROPERTY("VertexInfluence"); is >> is.PROPERTY("VertexInfluence");
is.readWrappedString(name); is.readWrappedString(bonename);
viSize = is.readSize(); is >> is.BEGIN_BRACKET; viSize = is.readSize(); is >> is.BEGIN_BRACKET;
osgAnimation::BoneInfluenceList vi; osgAnimation::IndexWeightList vi;
vi.setBoneName( name );
vi.reserve( viSize ); vi.reserve( viSize );
for ( unsigned int j=0; j<viSize; ++j ) for ( unsigned int j=0; j<viSize; ++j )
{ {
@ -30,7 +29,7 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry&
is >> index >> weight; is >> index >> weight;
vi.push_back( osgAnimation::IndexWeight(index, weight) ); vi.push_back( osgAnimation::IndexWeight(index, weight) );
} }
(*map)[name] = vi; (*map)[bonename] = vi;
is >> is.END_BRACKET; is >> is.END_BRACKET;
} }
is >> is.END_BRACKET; is >> is.END_BRACKET;
@ -47,14 +46,14 @@ static bool writeInfluenceMap( osgDB::OutputStream& os, const osgAnimation::RigG
itr!=map->end(); ++itr ) itr!=map->end(); ++itr )
{ {
std::string name = itr->first; std::string name = itr->first;
const osgAnimation::BoneInfluenceList& vi = itr->second; const osgAnimation::IndexWeightList& vi = itr->second;
if ( name.empty() ) name = "Empty"; if ( name.empty() ) name = "Empty";
os << os.PROPERTY("VertexInfluence"); os << os.PROPERTY("VertexInfluence");
os.writeWrappedString(name); os.writeWrappedString(name);
os.writeSize(vi.size()) ; os << os.BEGIN_BRACKET << std::endl; os.writeSize(vi.size()) ; os << os.BEGIN_BRACKET << std::endl;
for ( osgAnimation::BoneInfluenceList::const_iterator vitr=vi.begin(); for ( osgAnimation::IndexWeightList::const_iterator vitr=vi.begin();
vitr != vi.end(); ++vitr ) vitr != vi.end(); ++vitr )
{ {
os << vitr->first << vitr->second << std::endl; os << vitr->first << vitr->second << std::endl;