Added Simplifier::requiresDownSampling()/requiresDownSamplingImplementation() to make it possible for the

Simplfifer::ContinueSimplificationCallback to be able to decide whether up or downsampling is required,
removing the previous hardwards reliance on getSampleRatio<1.0.
This commit is contained in:
Robert Osfield 2016-01-18 11:50:07 +00:00
parent e9179aaa4b
commit 7409820a8f
2 changed files with 20 additions and 2 deletions

View File

@ -59,6 +59,11 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor
{
return simplifier.continueSimplificationImplementation(nextError, numOriginalPrimitives, numRemainingPrimitives);
}
virtual bool requiresDownSampling(const Simplifier& simplifier) const
{
return simplifier.requiresDownSamplingImplementation();
}
protected:
virtual ~ContinueSimplificationCallback() {}
@ -80,7 +85,17 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor
if (getSampleRatio()<1.0) return ((float)numRemainingPrimitives > ((float)numOriginalPrimitives) * getSampleRatio()) && nextError<=getMaximumError();
else return ((float)numRemainingPrimitives < ((float)numOriginalPrimitives) * getSampleRatio()) && nextError>getMaximumLength();
}
bool requiresDownSampling() const
{
if (_continueSimplificationCallback.valid()) return _continueSimplificationCallback->requiresDownSampling(*this);
else return requiresDownSamplingImplementation();
}
virtual bool requiresDownSamplingImplementation() const
{
return getSampleRatio()<1.0;
}
virtual void apply(osg::Geode& geode)
{

View File

@ -1744,14 +1744,17 @@ void Simplifier::simplify(osg::Geometry& geometry, const IndexList& protectedPoi
{
OSG_INFO<<"++++++++++++++simplifier************"<<std::endl;
bool downSample = requiresDownSampling();
EdgeCollapse ec;
ec.setComputeErrorMetricUsingLength(getSampleRatio()>=1.0);
ec.setComputeErrorMetricUsingLength(!downSample);
ec.setGeometry(&geometry, protectedPoints);
ec.updateErrorMetricForAllEdges();
unsigned int numOriginalPrimitives = ec._triangleSet.size();
if (getSampleRatio()<1.0)
if (downSample)
{
while (!ec._edgeSet.empty() &&
continueSimplification((*ec._edgeSet.begin())->getErrorMetric() , numOriginalPrimitives, ec._triangleSet.size()) &&