1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGUTIL_TRISTRIPVISITOR
15#define OSGUTIL_TRISTRIPVISITOR 1
17#include <osg/NodeVisitor>
19#include <osg/Geometry>
21#include <osgUtil/Optimizer>
27/** A tri stripping visitor for converting Geometry surface primitives into tri strips.
28 * The current implementation is based upon Tanguy Fautre's triangulation code.
30class OSGUTIL_EXPORT TriStripVisitor : public BaseOptimizerVisitor
34 /// default to traversing all children.
35 TriStripVisitor(Optimizer* optimizer=0) :
36 BaseOptimizerVisitor( optimizer, Optimizer::TRISTRIP_GEOMETRY),
39 _generateFourPointPrimitivesQuads ( false ),
40 _mergeTriangleStrips( false ),
44 /** Convert mesh primitives in Geometry into Tri Strips.
45 * Converts all primitive types except points
46 * and lines, linestrips which it leaves unchanged.
48 void stripify(osg::Geometry& drawable);
50 void mergeTriangleStrips(osg::Geometry::PrimitiveSetList& primitives);
52 /** Stripify (make into strips of tria or quads) the accumulated list of Geometry drawables.*/
55 /// Accumulate the Geometry drawables to make into strips.
56 virtual void apply(osg::Geometry& geom);
58 inline void setCacheSize( unsigned int size )
63 inline unsigned int getCacheSize() const
68 inline void setMinStripSize( unsigned int size )
73 inline unsigned int getMinStripSize() const
78 inline void setIndexMesh( bool allow )
83 inline bool getIndexMesh() const
88 void setGenerateFourPointPrimitivesQuads(bool flag) { _generateFourPointPrimitivesQuads = flag; }
89 bool getGenerateFourPointPrimitivesQuads() const { return _generateFourPointPrimitivesQuads; }
91 void setMergeTriangleStrips(bool flag) { _mergeTriangleStrips = flag; }
92 bool getMergeTriangleStrips() const { return _mergeTriangleStrips; }
96 typedef std::set<osg::Geometry*> GeometryList;
98 unsigned int _cacheSize;
99 unsigned int _minStripSize;
100 GeometryList _geometryList;
101 bool _generateFourPointPrimitivesQuads;
102 bool _mergeTriangleStrips;