openscenegraph
TriStripVisitor
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_TRISTRIPVISITOR
15#define OSGUTIL_TRISTRIPVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Geode>
19#include <osg/Geometry>
20
21#include <osgUtil/Optimizer>
22
23#include <set>
24
25namespace osgUtil {
26
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.
29 */
30class OSGUTIL_EXPORT TriStripVisitor : public BaseOptimizerVisitor
31{
32 public:
33
34 /// default to traversing all children.
35 TriStripVisitor(Optimizer* optimizer=0) :
36 BaseOptimizerVisitor( optimizer, Optimizer::TRISTRIP_GEOMETRY),
37 _cacheSize( 16 ),
38 _minStripSize( 2 ),
39 _generateFourPointPrimitivesQuads ( false ),
40 _mergeTriangleStrips( false ),
41 _indexMesh( true )
42 {}
43
44 /** Convert mesh primitives in Geometry into Tri Strips.
45 * Converts all primitive types except points
46 * and lines, linestrips which it leaves unchanged.
47 */
48 void stripify(osg::Geometry& drawable);
49
50 void mergeTriangleStrips(osg::Geometry::PrimitiveSetList& primitives);
51
52 /** Stripify (make into strips of tria or quads) the accumulated list of Geometry drawables.*/
53 void stripify();
54
55 /// Accumulate the Geometry drawables to make into strips.
56 virtual void apply(osg::Geometry& geom);
57
58 inline void setCacheSize( unsigned int size )
59 {
60 _cacheSize = size;
61 }
62
63 inline unsigned int getCacheSize() const
64 {
65 return _cacheSize;
66 }
67
68 inline void setMinStripSize( unsigned int size )
69 {
70 _minStripSize = size;
71 }
72
73 inline unsigned int getMinStripSize() const
74 {
75 return _minStripSize;
76 }
77
78 inline void setIndexMesh( bool allow )
79 {
80 _indexMesh = allow;
81 }
82
83 inline bool getIndexMesh() const
84 {
85 return _indexMesh;
86 }
87
88 void setGenerateFourPointPrimitivesQuads(bool flag) { _generateFourPointPrimitivesQuads = flag; }
89 bool getGenerateFourPointPrimitivesQuads() const { return _generateFourPointPrimitivesQuads; }
90
91 void setMergeTriangleStrips(bool flag) { _mergeTriangleStrips = flag; }
92 bool getMergeTriangleStrips() const { return _mergeTriangleStrips; }
93
94 private:
95
96 typedef std::set<osg::Geometry*> GeometryList;
97
98 unsigned int _cacheSize;
99 unsigned int _minStripSize;
100 GeometryList _geometryList;
101 bool _generateFourPointPrimitivesQuads;
102 bool _mergeTriangleStrips;
103 bool _indexMesh;
104};
105
106}
107
108#endif