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;
(*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++)
{
float val = (*array)[i][0];

View File

@ -46,25 +46,15 @@ namespace osgAnimation
typedef std::vector<BoneWeight> BoneWeightList;
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:
// the name is the bone to link to
std::string _name;
};
class VertexInfluenceMap : public std::map<std::string, BoneInfluenceList> , public osg::Object
class VertexInfluenceMap : public std::map<std::string, IndexWeightList> , public osg::Object
{
public:
META_Object(osgAnimation, VertexInfluenceMap);
VertexInfluenceMap() {}
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)
{}
///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)
{
const BoneInfluenceList& boneinflist = mapit->second;
for(BoneInfluenceList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
const IndexWeightList& boneinflist = mapit->second;
const std::string& bonename = mapit->first;
for(IndexWeightList::const_iterator infit = boneinflist.begin(); infit!=boneinflist.end(); ++infit)
{
const IndexWeight& iw = *infit;
const unsigned int &index = iw.getIndex();
@ -289,30 +290,24 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
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 ((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));
}
else
{
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;
}
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));
_bonePalette.push_back(bonebyname->second);
sum.first+=weight;
@ -321,7 +316,7 @@ bool RigTransformHardware::buildPalette(BoneMap&boneMap ,RigGeometry&rig) {
}
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);

View File

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

View File

@ -36,8 +36,8 @@ void VertexInfluenceMap::normalize(unsigned int numvert) {
std::vector<PerVertWeights > localstore;
localstore.resize(numvert);
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) {
BoneInfluenceList &curvecinf=mapit->second;
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeightList &curvecinf=mapit->second;
for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
IndexWeight& inf=*curinf;
localstore[inf.first].first+=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;
std::map<int,BoneWeightOrdered > tempVec2Bones;
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit) {
BoneInfluenceList &curvecinf=mapit->second;
for(BoneInfluenceList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++curinf) {
for(VertexInfluenceMap::iterator mapit=this->begin(); mapit!=this->end(); ++mapit)
{
const std::string& bonename=mapit->first;
IndexWeightList &curvecinf=mapit->second;
for(IndexWeightList::iterator curinf=curvecinf.begin(); curinf!=curvecinf.end(); ++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;
}
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();
@ -87,15 +89,13 @@ void VertexInfluenceMap::cullInfluenceCountPerVertex(unsigned int numbonepervert
if(sum>1e-4){
sum=1.0f/sum;
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.push_back(IndexWeight(mapit->first, bwit->getWeight()*sum));
}
}
}else{
for(BoneWeightOrdered::iterator bwit=bwset.begin(); bwit!=bwset.end(); ++bwit) {
BoneInfluenceList & inf= (*this)[bwit->getBoneName()];
inf.setBoneName(bwit->getBoneName());
IndexWeightList & inf= (*this)[bwit->getBoneName()];
inf.push_back(IndexWeight(mapit->first,bwit->getWeight()));
}
@ -110,17 +110,17 @@ void VertexInfluenceMap::computePerVertexInfluenceList(std::vector<BoneWeightLis
it != end();
++it)
{
const BoneInfluenceList& inflist = it->second;
if (inflist.getBoneName().empty()) {
OSG_WARN << "RigTransformSoftware::VertexInfluenceMap contains unamed bone BoneInfluenceList" << std::endl;
const IndexWeightList& inflist = it->second;
if (it->first.empty()) {
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 unsigned int &index = iw.getIndex();
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());
if(!vertices) continue;
osgAnimation::BoneInfluenceList vxtInf = (*itMap).second;
osgAnimation::IndexWeightList vxtInf = (*itMap).second;
//Expand the boundingBox with each vertex
for(unsigned int j = 0; j < vxtInf.size(); j++) {

View File

@ -200,9 +200,9 @@ protected:
BoneNameBoneMap::iterator bone_it = boneMap.find(vertexInfluencePair->first);
if(bone_it == boneMap.end()) continue;
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);
}
}

View File

@ -804,17 +804,16 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
for (int i = 0; i < nbGroups; i++)
{
int nbVertexes = 0;
std::string name;
std::string bonename;
if (fr.matchSequence("osgAnimation::VertexInfluence %s %i {"))
{
name = fr[1].getStr();
bonename = fr[1].getStr();
fr[2].getInt(nbVertexes);
fr += 4;
iteratorAdvanced = true;
}
osgAnimation::BoneInfluenceList vi;
vi.setBoneName(name);
osgAnimation::IndexWeightList vi;
vi.reserve(nbVertexes);
for (int j = 0; j < nbVertexes; j++)
{
@ -833,7 +832,7 @@ bool RigGeometry_readLocalData(Object& obj, Input& fr)
{
fr+=1;
}
(*vmap)[name] = vi;
(*vmap)[bonename] = vi;
}
if (!vmap->empty())
geom.setInfluenceMap(vmap.get());
@ -863,8 +862,8 @@ bool RigGeometry_writeLocalData(const Object& obj, Output& fw)
name = "Empty";
fw.indent() << "osgAnimation::VertexInfluence \"" << name << "\" " << it->second.size() << " {" << std::endl;
fw.moveIn();
const osgAnimation::BoneInfluenceList& vi = it->second;
for (osgAnimation::BoneInfluenceList::const_iterator itv = vi.begin(); itv != vi.end(); itv++)
const osgAnimation::IndexWeightList& vi = it->second;
for (osgAnimation::IndexWeightList::const_iterator itv = vi.begin(); itv != vi.end(); itv++)
{
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;
for ( unsigned int i=0; i<size; ++i )
{
std::string name;
std::string bonename;
unsigned int viSize = 0;
is >> is.PROPERTY("VertexInfluence");
is.readWrappedString(name);
is.readWrappedString(bonename);
viSize = is.readSize(); is >> is.BEGIN_BRACKET;
osgAnimation::BoneInfluenceList vi;
vi.setBoneName( name );
osgAnimation::IndexWeightList vi;
vi.reserve( viSize );
for ( unsigned int j=0; j<viSize; ++j )
{
@ -30,7 +29,7 @@ static bool readInfluenceMap( osgDB::InputStream& is, osgAnimation::RigGeometry&
is >> index >> weight;
vi.push_back( osgAnimation::IndexWeight(index, weight) );
}
(*map)[name] = vi;
(*map)[bonename] = vi;
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 )
{
std::string name = itr->first;
const osgAnimation::BoneInfluenceList& vi = itr->second;
const osgAnimation::IndexWeightList& vi = itr->second;
if ( name.empty() ) name = "Empty";
os << os.PROPERTY("VertexInfluence");
os.writeWrappedString(name);
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 )
{
os << vitr->first << vitr->second << std::endl;