ComputeBoundsVisitor 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 OSG_COMPUTEBOUNDSVISITOR
  14. #define OSG_COMPUTEBOUNDSVISITOR 1
  15. #include <osg/NodeVisitor>
  16. #include <osg/BoundingBox>
  17. #include <osg/Polytope>
  18. namespace osg {
  19. class OSG_EXPORT ComputeBoundsVisitor : public osg::NodeVisitor
  20. {
  21. public:
  22. ComputeBoundsVisitor(TraversalMode traversalMode = TRAVERSE_ALL_CHILDREN);
  23. META_NodeVisitor(osg, ComputeBoundsVisitor)
  24. virtual void reset();
  25. osg::BoundingBox& getBoundingBox() { return _bb; }
  26. void getPolytope(osg::Polytope& polytope, float margin=0.1) const;
  27. void getBase(osg::Polytope& polytope, float margin=0.1) const;
  28. void apply(osg::Drawable& drawable);
  29. void apply(osg::Transform& transform);
  30. inline void pushMatrix(osg::Matrix& matrix) { _matrixStack.push_back(matrix); }
  31. inline void popMatrix() { _matrixStack.pop_back(); }
  32. void applyBoundingBox(const osg::BoundingBox&);
  33. typedef std::vector<osg::Matrix> MatrixStack;
  34. const MatrixStack& getMatrixStack() const { return _matrixStack; }
  35. protected:
  36. MatrixStack _matrixStack;
  37. osg::BoundingBox _bb;
  38. };
  39. }
  40. #endif