root/OpenSceneGraph/trunk/include/osgUtil/TriStripVisitor @ 3432

Revision 3432, 3.2 kB (checked in by robert, 9 years ago)

From Geoff Michel, typos and spelling fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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 implemention is based up Tanguy Fautre's triangulation code.
29  */
30class OSGUTIL_EXPORT TriStripVisitor : public osg::NodeVisitor
31{
32    public:
33
34        /// default to traversing all children.
35        TriStripVisitor(Optimizer* =0) :
36                osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ),
37                _cacheSize( 16 ),
38                _minStripSize( 2 ),
39                _generateFourPointPrimitivesQuads ( false)
40        {}
41
42        /** Convert mesh primitives in Geometry into Tri Strips.
43          * Converts all primitive types except points
44          * and lines, linestrips which it leaves unchanged.
45          */
46        void stripify(osg::Geometry& drawable);
47
48        /** Stripfy the accumulated list of Geometry drawables.*/
49        void stripify();
50
51        /// accumulate the Geometry drawables to stripify
52        virtual void apply(osg::Geode& geode);
53
54        inline void setCacheSize( unsigned int size )
55        {
56            _cacheSize = size;
57        }
58       
59        inline unsigned int getCacheSize()
60        {
61            return _cacheSize;
62        }
63
64        inline const unsigned int getCacheSize() const
65        {
66            return _cacheSize;
67        }
68       
69        inline void setMinStripSize( unsigned int size )
70        {
71            _minStripSize = size;
72        }
73       
74        inline unsigned int getMinStripSize()
75        {
76            return _minStripSize;
77        }
78
79        inline const unsigned int getMinStripSize() const
80        {
81            return _minStripSize;
82        }
83       
84        inline bool isOperationPermissibleForObject(const osg::Object* object) const
85        {
86            return _optimizer ? _optimizer->isOperationPermissibleForObject(object,osgUtil::Optimizer::TRISTRIP_GEOMETRY) : true;
87        }
88       
89        void setGenerateFourPointPrimitivesQuads(bool flag) { _generateFourPointPrimitivesQuads = flag; }
90        bool getGenerateFourPointPrimitivesQuads() const { return _generateFourPointPrimitivesQuads; }
91       
92
93    private:
94   
95        typedef std::set<osg::Geometry*> GeometryList;
96
97        Optimizer*   _optimizer;
98        unsigned int _cacheSize;
99        unsigned int _minStripSize;
100        GeometryList _geometryList;
101        bool         _generateFourPointPrimitivesQuads;
102};
103
104}
105
106#endif
Note: See TracBrowser for help on using the browser.