OpenSceneGraph 3.6.5
Simplifier
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_SIMPLIFIER
15#define OSGUTIL_SIMPLIFIER 1
16
17#include <osg/NodeVisitor>
18#include <osg/Geode>
19#include <osg/Geometry>
20
21#include <osgUtil/Export>
22
23namespace osgUtil {
24
28{
29 public:
30
31 Simplifier(double sampleRatio=1.0, double maximumError=FLT_MAX, double maximumLength=0.0);
32
34
35 void setSampleRatio(float sampleRatio) { _sampleRatio = sampleRatio; }
36 float getSampleRatio() const { return _sampleRatio; }
37
40 void setMaximumError(float error) { _maximumError = error; }
41 float getMaximumError() const { return _maximumError; }
42
45 void setMaximumLength(float length) { _maximumLength = length; }
46 float getMaximumLength() const { return _maximumLength; }
47
48 void setDoTriStrip(bool on) { _triStrip = on; }
49 bool getDoTriStrip() const { return _triStrip; }
50
51 void setSmoothing(bool on) { _smoothing = on; }
52 bool getSmoothing() const { return _smoothing; }
53
55 {
56 public:
58 virtual bool continueSimplification(const Simplifier& simplifier, float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
59 {
60 return simplifier.continueSimplificationImplementation(nextError, numOriginalPrimitives, numRemainingPrimitives);
61 }
62
63 virtual bool requiresDownSampling(const Simplifier& simplifier) const
64 {
65 return simplifier.requiresDownSamplingImplementation();
66 }
67
68 protected:
70 };
71
75
76
77 bool continueSimplification(float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
78 {
79 if (_continueSimplificationCallback.valid()) return _continueSimplificationCallback->continueSimplification(*this, nextError, numOriginalPrimitives, numRemainingPrimitives);
80 else return continueSimplificationImplementation(nextError, numOriginalPrimitives, numRemainingPrimitives);
81 }
82
83 virtual bool continueSimplificationImplementation(float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
84 {
85 if (getSampleRatio()<1.0) return ((float)numRemainingPrimitives > ((float)numOriginalPrimitives) * getSampleRatio()) && nextError<=getMaximumError();
86 else return ((float)numRemainingPrimitives < ((float)numOriginalPrimitives) * getSampleRatio()) && nextError>getMaximumLength();
87 }
88
90 {
91 if (_continueSimplificationCallback.valid()) return _continueSimplificationCallback->requiresDownSampling(*this);
93 }
94
96 {
97 return getSampleRatio()<1.0;
98 }
99
100 virtual void apply(osg::Geometry& geom)
101 {
102 simplify(geom);
103 }
104
106 void simplify(osg::Geometry& geometry);
107
108 typedef std::vector<unsigned int> IndexList;
109
111 void simplify(osg::Geometry& geometry, const IndexList& protectedPoints);
112
113
114 protected:
115
121
123
124};
125
126
127}
128
129#endif
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
Definition Geometry:31
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
void simplify(osg::Geometry &geometry, const IndexList &protectedPoints)
a list of point indices
ContinueSimplificationCallback * getContinueSimplificationCallback()
Definition Simplifier:73
bool getSmoothing() const
Definition Simplifier:52
double _maximumError
Definition Simplifier:117
void setDoTriStrip(bool on)
Definition Simplifier:48
double _maximumLength
Definition Simplifier:118
float getSampleRatio() const
Definition Simplifier:36
META_NodeVisitor(osgUtil, Simplifier) void setSampleRatio(float sampleRatio)
Definition Simplifier:33
float getMaximumLength() const
Definition Simplifier:46
void setMaximumLength(float length)
Set the maximum length target that all edges must be shorted than.
Definition Simplifier:45
bool _triStrip
Definition Simplifier:119
void setSmoothing(bool on)
Definition Simplifier:51
virtual bool continueSimplificationImplementation(float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
Definition Simplifier:83
const ContinueSimplificationCallback * getContinueSimplificationCallback() const
Definition Simplifier:74
bool continueSimplification(float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
Definition Simplifier:77
bool getDoTriStrip() const
Definition Simplifier:49
void simplify(osg::Geometry &geometry)
simply the geometry.
std::vector< unsigned int > IndexList
Definition Simplifier:108
void setMaximumError(float error)
Set the maximum point error that all point removals must be less than to permit removal of a point.
Definition Simplifier:40
bool requiresDownSampling() const
Definition Simplifier:89
virtual bool requiresDownSamplingImplementation() const
Definition Simplifier:95
osg::ref_ptr< ContinueSimplificationCallback > _continueSimplificationCallback
Definition Simplifier:122
float getMaximumError() const
Definition Simplifier:41
bool _smoothing
Definition Simplifier:120
double _sampleRatio
Definition Simplifier:116
virtual void apply(osg::Geometry &geom)
Definition Simplifier:100
void setContinueSimplificationCallback(ContinueSimplificationCallback *cb)
Definition Simplifier:72
Simplifier(double sampleRatio=1.0, double maximumError=FLT_MAX, double maximumLength=0.0)
virtual bool continueSimplification(const Simplifier &simplifier, float nextError, unsigned int numOriginalPrimitives, unsigned int numRemainingPrimitives) const
return true if mesh should be continued to be simplified, return false to stop simplification.
Definition Simplifier:58
virtual bool requiresDownSampling(const Simplifier &simplifier) const
Definition Simplifier:63
virtual ~ContinueSimplificationCallback()
Definition Simplifier:69
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.