root/OpenSceneGraph/trunk/examples/osgdepthpartition/DistanceAccumulator.h @ 4622

Revision 4622, 2.9 kB (checked in by robert, 8 years ago)

From Ravi Mathur, "New functionality is the ability to automatically determine the
maximum traversal depth necessary to obtain an accurate estimate of
the minimum number of required cameras. In addition, the user can
specify an absolute maximum traversal depth that will not be exceeded."

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#ifndef _OF_DISTANCEACCUMULATOR_
2#define _OF_DISTANCEACCUMULATOR_
3
4#include <osg/Group>
5#include <osg/NodeVisitor>
6#include <osg/Polytope>
7#include <osg/fast_back_stack>
8
9#define CURRENT_CLASS DistanceAccumulator
10/**********************************************************
11 * Ravi Mathur
12 * OpenFrames API, class DistanceAccumulator
13 * Class that traverses the scene and computes the distance to each
14 * visible drawable, and splits up the scene if the drawables are
15 * too far away (in the z direction) from each other.
16**********************************************************/
17class CURRENT_CLASS : public osg::NodeVisitor
18{
19  public:
20        typedef std::pair<double, double> DistancePair;
21        typedef std::vector<DistancePair> PairList;
22
23        CURRENT_CLASS();
24
25        virtual void apply(osg::Node &node);
26        virtual void apply(osg::Projection &proj);
27        virtual void apply(osg::Transform &transform);
28        virtual void apply(osg::Geode &geode);
29
30        // Specify the modelview & projection matrices
31        void setMatrices(const osg::Matrix &modelview,
32                         const osg::Matrix &projection);
33
34        // Reset visitor before a new traversal
35        virtual void reset();
36
37        // Create a (near,far) distance pair for each camera of the specified
38        // distance pair list and distance limits.
39        void computeCameraPairs();
40
41        // Get info on the cameras that should be used for scene rendering
42        PairList& getCameraPairs() { return _cameraPairs; }
43
44        // Get info on the computed distance pairs
45        PairList& getDistancePairs() { return _distancePairs; }
46
47        // Get info on the computed nearest/farthest distances
48        DistancePair& getLimits() { return _limits; }
49
50        // Set/get the desired near/far ratio
51        void setNearFarRatio(double ratio);
52        inline double getNearFarRatio() const { return _nearFarRatio; }
53
54        inline void setMaxDepth(unsigned int depth) { _maxDepth = depth; }
55        inline unsigned int getMaxDepth() const { return _maxDepth; }
56
57  protected:
58        virtual ~CURRENT_CLASS();
59
60        void pushLocalFrustum();
61        void pushDistancePair(double zNear, double zFar);
62        bool shouldContinueTraversal(osg::Node &node);
63
64        // Stack of matrices accumulated during traversal
65        osg::fast_back_stack<osg::Matrix> _viewMatrices;
66        osg::fast_back_stack<osg::Matrix> _projectionMatrices;
67
68        // Main modelview/projection matrices
69        osg::Matrix _modelview, _projection;
70
71        // The view frusta in local coordinate space
72        osg::fast_back_stack<osg::Polytope> _localFrusta;
73
74        // Bounding box corners that should be used for cull computation
75        typedef std::pair<unsigned int, unsigned int> bbCornerPair;
76        osg::fast_back_stack<bbCornerPair> _bbCorners;
77
78        // Nar/far planes that should be used for each camera
79        PairList _cameraPairs;
80
81        // Accumulated pairs of min/max distances
82        PairList _distancePairs;
83
84        // The closest & farthest distances found while traversing
85        DistancePair _limits;
86
87        // Ratio of nearest/farthest clip plane for each section of the scene
88        double _nearFarRatio;
89
90        // Maximum depth to traverse to
91        unsigned int _maxDepth, _currentDepth;
92};
93#undef CURRENT_CLASS
94
95#endif
Note: See TracBrowser for help on using the browser.