openscenegraph
CollectOccludersVisitor
Go to the documentation of this file.
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 OSG_COLLECTOCCLUDERSVISITOR
15#define OSG_COLLECTOCCLUDERSVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/CullStack>
19
20#include <set>
21
22namespace osg {
23
24class OSG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::CullStack
25{
26 public:
27
28
29 typedef std::set<ShadowVolumeOccluder> ShadowVolumeOccluderSet;
30
31 CollectOccludersVisitor();
32 virtual ~CollectOccludersVisitor();
33
34 META_NodeVisitor(osg, CollectOccludersVisitor)
35
36 virtual Object* cloneType() const { return new CollectOccludersVisitor(); }
37
38 virtual void reset();
39
40 virtual float getDistanceToEyePoint(const Vec3& pos, bool withLODScale) const;
41 virtual float getDistanceToViewPoint(const Vec3& pos, bool withLODScale) const;
42
43 virtual float getDistanceFromEyePoint(const Vec3& pos, bool withLODScale) const;
44
45 virtual void apply(osg::Node&);
46 virtual void apply(osg::Transform& node);
47 virtual void apply(osg::Projection& node);
48
49 virtual void apply(osg::Switch& node);
50 virtual void apply(osg::LOD& node);
51 virtual void apply(osg::OccluderNode& node);
52
53 /** Sets the minimum shadow occluder volume that an active occluder
54 * must have. vol is units relative the clip space volume where 1.0
55 * is the whole clip space. */
56 void setMinimumShadowOccluderVolume(float vol) { _minimumShadowOccluderVolume = vol; }
57 float getMinimumShadowOccluderVolume() const { return _minimumShadowOccluderVolume; }
58
59 /** Sets the maximum number of occluders to have active for culling
60 * purposes. */
61 void setMaximumNumberOfActiveOccluders(unsigned int num) { _maximumNumberOfActiveOccluders = num; }
62 unsigned int getMaximumNumberOfActiveOccluders() const { return _maximumNumberOfActiveOccluders; }
63
64 void setCreateDrawablesOnOccludeNodes(bool flag) { _createDrawables=flag; }
65 bool getCreateDrawablesOnOccludeNodes() const { return _createDrawables; }
66
67 void setCollectedOccluderSet(const ShadowVolumeOccluderSet& svol) { _occluderSet = svol; }
68 ShadowVolumeOccluderSet& getCollectedOccluderSet() { return _occluderSet; }
69 const ShadowVolumeOccluderSet& getCollectedOccluderSet() const { return _occluderSet; }
70
71 /** Removes occluded occluders for the collected occluders list, then
72 * discards all but MaximumNumberOfActiveOccluders of occluders,
73 * discarding the occluders with the lowest shadow occluder volume. */
74 void removeOccludedOccluders();
75
76
77 protected:
78
79 /** Prevents unwanted copy construction. */
80 //CollectOccludersVisitor(const CollectOccludersVisitor&):osg::NodeVisitor(),osg::CullStack() {}
81
82 /** Prevents unwanted copy operator. */
83 CollectOccludersVisitor& operator = (const CollectOccludersVisitor&) { return *this; }
84
85 inline void handle_cull_callbacks_and_traverse(osg::Node& node)
86 {
87 /*osg::NodeCallback* callback = node.getCullCallback();
88 if (callback) (*callback)(&node,this);
89 else*/ if (node.getNumChildrenWithOccluderNodes()>0) traverse(node);
90 }
91
92 inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
93 {
94 /*osg::NodeCallback* callback = node.getCullCallback();
95 if (callback) (*callback)(&node,this);
96 else*/ if (node.getNumChildrenWithOccluderNodes()>0) acceptNode->accept(*this);
97 }
98
99 float _minimumShadowOccluderVolume;
100 unsigned _maximumNumberOfActiveOccluders;
101 bool _createDrawables;
102 ShadowVolumeOccluderSet _occluderSet;
103
104};
105
106}
107
108#endif
109