TriStripVisitor 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifndef OSGUTIL_TRISTRIPVISITOR
  14. #define OSGUTIL_TRISTRIPVISITOR 1
  15. #include <osg/NodeVisitor>
  16. #include <osg/Geode>
  17. #include <osg/Geometry>
  18. #include <osgUtil/Optimizer>
  19. #include <set>
  20. namespace osgUtil {
  21. /** A tri stripping visitor for converting Geometry surface primitives into tri strips.
  22. * The current implementation is based upon Tanguy Fautre's triangulation code.
  23. */
  24. class OSGUTIL_EXPORT TriStripVisitor : public BaseOptimizerVisitor
  25. {
  26. public:
  27. /// default to traversing all children.
  28. TriStripVisitor(Optimizer* optimizer=0) :
  29. BaseOptimizerVisitor( optimizer, Optimizer::TRISTRIP_GEOMETRY),
  30. _cacheSize( 16 ),
  31. _minStripSize( 2 ),
  32. _generateFourPointPrimitivesQuads ( false ),
  33. _mergeTriangleStrips( false ),
  34. _indexMesh( true )
  35. {}
  36. /** Convert mesh primitives in Geometry into Tri Strips.
  37. * Converts all primitive types except points
  38. * and lines, linestrips which it leaves unchanged.
  39. */
  40. void stripify(osg::Geometry& drawable);
  41. void mergeTriangleStrips(osg::Geometry::PrimitiveSetList& primitives);
  42. /** Stripify (make into strips of tria or quads) the accumulated list of Geometry drawables.*/
  43. void stripify();
  44. /// Accumulate the Geometry drawables to make into strips.
  45. virtual void apply(osg::Geometry& geom);
  46. inline void setCacheSize( unsigned int size )
  47. {
  48. _cacheSize = size;
  49. }
  50. inline unsigned int getCacheSize() const
  51. {
  52. return _cacheSize;
  53. }
  54. inline void setMinStripSize( unsigned int size )
  55. {
  56. _minStripSize = size;
  57. }
  58. inline unsigned int getMinStripSize() const
  59. {
  60. return _minStripSize;
  61. }
  62. inline void setIndexMesh( bool allow )
  63. {
  64. _indexMesh = allow;
  65. }
  66. inline bool getIndexMesh() const
  67. {
  68. return _indexMesh;
  69. }
  70. void setGenerateFourPointPrimitivesQuads(bool flag) { _generateFourPointPrimitivesQuads = flag; }
  71. bool getGenerateFourPointPrimitivesQuads() const { return _generateFourPointPrimitivesQuads; }
  72. void setMergeTriangleStrips(bool flag) { _mergeTriangleStrips = flag; }
  73. bool getMergeTriangleStrips() const { return _mergeTriangleStrips; }
  74. private:
  75. typedef std::set<osg::Geometry*> GeometryList;
  76. unsigned int _cacheSize;
  77. unsigned int _minStripSize;
  78. GeometryList _geometryList;
  79. bool _generateFourPointPrimitivesQuads;
  80. bool _mergeTriangleStrips;
  81. bool _indexMesh;
  82. };
  83. }
  84. #endif