Restructured merge geometry code to make it easier to follow
This commit is contained in:
parent
2946ea0759
commit
7ed0389051
@ -1887,55 +1887,40 @@ bool Optimizer::MergeGeometryVisitor::mergeGroup(osg::Group& group)
|
|||||||
// then build merge list using _targetMaximumNumberOfVertices
|
// then build merge list using _targetMaximumNumberOfVertices
|
||||||
bool needToDoMerge = false;
|
bool needToDoMerge = false;
|
||||||
// dequeue each DuplicateList when vertices limit is reached or when all elements has been checked
|
// dequeue each DuplicateList when vertices limit is reached or when all elements has been checked
|
||||||
for(;!mergeListChecked.empty();)
|
for(MergeList::iterator itr=mergeListChecked.begin(); itr!=mergeListChecked.end(); ++itr)
|
||||||
{
|
{
|
||||||
MergeList::iterator itr=mergeListChecked.begin();
|
|
||||||
DuplicateList& duplicateList(*itr);
|
DuplicateList& duplicateList(*itr);
|
||||||
if (duplicateList.size()==0)
|
if (duplicateList.size()==0)
|
||||||
{
|
{
|
||||||
mergeListChecked.erase(itr);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duplicateList.size()==1)
|
if (duplicateList.size()==1)
|
||||||
{
|
{
|
||||||
mergeList.push_back(duplicateList);
|
mergeList.push_back(duplicateList);
|
||||||
mergeListChecked.erase(itr);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int numVertices(duplicateList.front()->getVertexArray() ? duplicateList.front()->getVertexArray()->getNumElements() : 0);
|
unsigned int totalNumberVertices = 0;
|
||||||
DuplicateList::iterator eachGeom(duplicateList.begin()+1);
|
DuplicateList subset;
|
||||||
// until all geometries have been checked or _targetMaximumNumberOfVertices is reached
|
for(DuplicateList::iterator ditr = duplicateList.begin();
|
||||||
for(;eachGeom!=duplicateList.end(); ++eachGeom)
|
ditr != duplicateList.end();
|
||||||
|
++ditr)
|
||||||
{
|
{
|
||||||
unsigned int numAddVertices((*eachGeom)->getVertexArray() ? (*eachGeom)->getVertexArray()->getNumElements() : 0);
|
osg::Geometry* geometry = ditr->get();
|
||||||
if ((numVertices+numAddVertices)>_targetMaximumNumberOfVertices)
|
unsigned int numVertices = (geometry->getVertexArray() ? geometry->getVertexArray()->getNumElements() : 0);
|
||||||
|
if ((totalNumberVertices+numVertices)>_targetMaximumNumberOfVertices && !subset.empty())
|
||||||
{
|
{
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
numVertices += numAddVertices;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// push back if bellow the limit
|
mergeList.push_back(subset);
|
||||||
if (eachGeom==duplicateList.end())
|
subset.clear();
|
||||||
{
|
totalNumberVertices = 0;
|
||||||
if (duplicateList.size()>1) needToDoMerge = true;
|
|
||||||
mergeList.push_back(duplicateList);
|
|
||||||
mergeListChecked.erase(itr);
|
|
||||||
}
|
}
|
||||||
// else split the list to store what is below the limit and retry on what is above
|
totalNumberVertices += numVertices;
|
||||||
else
|
subset.push_back(geometry);
|
||||||
{
|
if (subset.size()>1) needToDoMerge = true;
|
||||||
mergeList.push_back(DuplicateList());
|
|
||||||
DuplicateList* duplicateListResult = &mergeList.back();
|
|
||||||
duplicateListResult->insert(duplicateListResult->end(),duplicateList.begin(),eachGeom);
|
|
||||||
duplicateList.erase(duplicateList.begin(),eachGeom);
|
|
||||||
if (duplicateListResult->size()>1) needToDoMerge = true;
|
|
||||||
}
|
}
|
||||||
|
if (!subset.empty()) mergeList.push_back(subset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needToDoMerge)
|
if (needToDoMerge)
|
||||||
|
Loading…
Reference in New Issue
Block a user