OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShadowVolumeOccluder.h
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_SHADOWVOLUMEOCCLUDER
15 #define OSG_SHADOWVOLUMEOCCLUDER 1
16 
17 #include <osg/Polytope>
18 #include <osg/ConvexPlanarOccluder>
19 #include <osg/Node>
20 
21 namespace osg {
22 
23 class CullStack;
24 
27 {
28 
29  public:
30 
31 
32  typedef std::vector<Polytope> HoleList;
33 
35  _volume(svo._volume),
36  _nodePath(svo._nodePath),
37  _projectionMatrix(svo._projectionMatrix),
38  _occluderVolume(svo._occluderVolume),
39  _holeList(svo._holeList) {}
40 
42  _volume(0.0f) {}
43 
44 
45  bool operator < (const ShadowVolumeOccluder& svo) const { return getVolume()>svo.getVolume(); } // not greater volume first.
46 
48  bool computeOccluder(const NodePath& nodePath,const ConvexPlanarOccluder& occluder,CullStack& cullStack,bool createDrawables=false);
49 
50 
51  inline void disableResultMasks();
52 
53  inline void pushCurrentMask();
54  inline void popCurrentMask();
55 
56 
59  bool matchProjectionMatrix(const osg::Matrix& matrix) const
60  {
61  if (_projectionMatrix.valid()) return matrix==*_projectionMatrix;
62  else return false;
63  }
64 
65 
68  inline void setNodePath(NodePath& nodePath) { _nodePath = nodePath; }
69  inline NodePath& getNodePath() { return _nodePath; }
70  inline const NodePath& getNodePath() const { return _nodePath; }
71 
72 
75  float getVolume() const { return _volume; }
76 
78  Polytope& getOccluder() { return _occluderVolume; }
79 
81  const Polytope& getOccluder() const { return _occluderVolume; }
82 
84  HoleList& getHoleList() { return _holeList; }
85 
87  const HoleList& getHoleList() const { return _holeList; }
88 
89 
92  bool contains(const std::vector<Vec3>& vertices);
93 
96  bool contains(const BoundingSphere& bound);
97 
100  bool contains(const BoundingBox& bound);
101 
102  inline void transformProvidingInverse(const osg::Matrix& matrix)
103  {
104  _occluderVolume.transformProvidingInverse(matrix);
105  for(HoleList::iterator itr=_holeList.begin();
106  itr!=_holeList.end();
107  ++itr)
108  {
109  itr->transformProvidingInverse(matrix);
110  }
111  }
112 
113 
114  protected:
115 
116  float _volume;
120  HoleList _holeList;
121 };
122 
123 
125 typedef std::vector<ShadowVolumeOccluder> ShadowVolumeOccluderList;
126 
127 
129 {
130  //std::cout<<"ShadowVolumeOccluder::disableResultMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
132  for(HoleList::iterator itr=_holeList.begin();
133  itr!=_holeList.end();
134  ++itr)
135  {
136  itr->setResultMask(0);
137  }
138 }
139 
141 {
142  //std::cout<<"ShadowVolumeOccluder::pushCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
144  if (!_holeList.empty())
145  {
146  for(HoleList::iterator itr=_holeList.begin();
147  itr!=_holeList.end();
148  ++itr)
149  {
150  itr->pushCurrentMask();
151  }
152  }
153 }
154 
156 {
158  if (!_holeList.empty())
159  {
160  for(HoleList::iterator itr=_holeList.begin();
161  itr!=_holeList.end();
162  ++itr)
163  {
164  itr->popCurrentMask();
165  }
166  }
167  //std::cout<<"ShadowVolumeOccluder::popCurrentMasks() - _occluderVolume.getMaskStack().size()="<<_occluderVolume.getMaskStack().size()<<" "<<_occluderVolume.getCurrentMask()<<std::endl;
168 }
169 
170 } // end of namespace
171 
172 #endif
#define OSG_EXPORT
Definition: Export.h:43
std::vector< Polytope > HoleList
void setResultMask(ClippingMask mask)
Definition: Polytope.h:176
std::vector< ShadowVolumeOccluder > ShadowVolumeOccluderList
void setNodePath(NodePath &nodePath)
const HoleList & getHoleList() const
ShadowVolumeOccluder(const ShadowVolumeOccluder &svo)
void transformProvidingInverse(const osg::Matrix &matrix)
void pushCurrentMask()
Definition: Polytope.h:185
ref_ptr< const RefMatrix > _projectionMatrix
void popCurrentMask()
Definition: Polytope.h:190
bool matchProjectionMatrix(const osg::Matrix &matrix) const
Definition: AlphaFunc.h:19
const Polytope & getOccluder() const
std::vector< Node * > NodePath
Definition: Node.h:44
const NodePath & getNodePath() const