| 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 | |
|---|
| 25 | namespace osgUtil { |
|---|
| 26 | |
|---|
| 27 | /** A tri stripping visitor for converting Geometry surface primitives into tri strips. |
|---|
| 28 | * The current implemention is based upon Tanguy Fautre's triangulation code. |
|---|
| 29 | */ |
|---|
| 30 | class 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 | {} |
|---|
| 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 | /** Stripify (make into strips of tria or quads) the accumulated list of Geometry drawables.*/ |
|---|
| 49 | void stripify(); |
|---|
| 50 | |
|---|
| 51 | /// Accumulate the Geometry drawables to make into strips. |
|---|
| 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() const |
|---|
| 60 | { |
|---|
| 61 | return _cacheSize; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | inline void setMinStripSize( unsigned int size ) |
|---|
| 65 | { |
|---|
| 66 | _minStripSize = size; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | inline unsigned int getMinStripSize() const |
|---|
| 70 | { |
|---|
| 71 | return _minStripSize; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | void setGenerateFourPointPrimitivesQuads(bool flag) { _generateFourPointPrimitivesQuads = flag; } |
|---|
| 76 | bool getGenerateFourPointPrimitivesQuads() const { return _generateFourPointPrimitivesQuads; } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | private: |
|---|
| 80 | |
|---|
| 81 | typedef std::set<osg::Geometry*> GeometryList; |
|---|
| 82 | |
|---|
| 83 | unsigned int _cacheSize; |
|---|
| 84 | unsigned int _minStripSize; |
|---|
| 85 | GeometryList _geometryList; |
|---|
| 86 | bool _generateFourPointPrimitivesQuads; |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | #endif |
|---|