From 6624f3aa6203ac671e5c94a48b77cc493a10afab Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 6 Feb 2006 19:16:04 +0000 Subject: [PATCH] Improved default settings, re-enambled smoothing and tri stripping of sampled data. --- include/osgUtil/Simplifier | 12 ++++++++++-- src/osgUtil/Simplifier.cpp | 9 +++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/osgUtil/Simplifier b/include/osgUtil/Simplifier index 434c1c7ec..dc41f129e 100644 --- a/include/osgUtil/Simplifier +++ b/include/osgUtil/Simplifier @@ -28,14 +28,21 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor { public: - Simplifier(float sampleRatio=1.0f, float maximumError=0.0f); + Simplifier(float sampleRatio=1.0f, float maximumError=FLT_MAX, float maximumLength=0.0); void setSampleRatio(float sampleRatio) { _sampleRatio = sampleRatio; } float getSampleRatio() const { return _sampleRatio; } + /** Set the maximum point error that all point removals must be less than to permit removal of a point. + * Note, Only used when down sampling. i.e. sampleRatio < 1.0*/ void setMaximumError(float error) { _maximumError = error; } float getMaximumError() const { return _maximumError; } + + /** Set the maximum length target that all edges must be shorted than. + * Note, Only used when up sampling i.e. sampleRatio > 1.0.*/ + void setMaximumLength(float length) { _maximumLength = length; } + float getMaximumLength() const { return _maximumLength; } class ContinueSimplificationCallback : public osg::Referenced { @@ -64,7 +71,7 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor virtual bool continueSimplificationImplementation(float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const { if (getSampleRatio()<1.0) return ((float)numRemainingPrimitives > ((float)numOriginalPrimitives) * getSampleRatio()) && nextError<=getMaximumError(); - else return ((float)numRemainingPrimitives < ((float)numOriginalPrimitives) * getSampleRatio()); + else return ((float)numRemainingPrimitives < ((float)numOriginalPrimitives) * getSampleRatio()) && nextError>getMaximumLength(); } @@ -93,6 +100,7 @@ class OSGUTIL_EXPORT Simplifier : public osg::NodeVisitor float _sampleRatio; float _maximumError; + float _maximumLength; osg::ref_ptr _continueSimplificationCallback; diff --git a/src/osgUtil/Simplifier.cpp b/src/osgUtil/Simplifier.cpp index 2ffacecf4..dc7803423 100644 --- a/src/osgUtil/Simplifier.cpp +++ b/src/osgUtil/Simplifier.cpp @@ -53,7 +53,7 @@ public: EdgeCollapse(): - _computeErrorMetricUsingLength(false) { osg::notify(osg::NOTICE)<<"EdgeCollapse() CONSTRUCTOR"<getPrimitiveSetList().clear(); _geometry->addPrimitiveSet(primitives); -#if 0 +#if 1 osgUtil::SmoothingVisitor::smooth(*_geometry); osgUtil::TriStripVisitor stripper; @@ -1680,10 +1680,11 @@ void EdgeCollapse::copyBackToGeometry() } -Simplifier::Simplifier(float sampleRatio, float maximumError): +Simplifier::Simplifier(float sampleRatio, float maximumError, float maximumLength): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _sampleRatio(sampleRatio), - _maximumError(maximumError) + _maximumError(maximumError), + _maximumLength(maximumLength) { }