OpenFrames
DepthPartitioner.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  ***********************************/
16 
21 #ifndef _OF_DEPTHPARTITIONER_
22 #define _OF_DEPTHPARTITIONER_
23 
24 #include <OpenFrames/Export.h>
26 #include <osg/Camera>
27 #include <osgViewer/View>
28 
29 namespace OpenFrames
30 {
31  class DepthPartitionCallback;
32 
42  class OF_EXPORT DepthPartitioner : public virtual osg::Referenced
43  {
44  public:
46 
48  bool setViewToPartition(osgViewer::View *view);
49  osgViewer::View* getViewToPartition() { return _view; }
50 
52  DepthPartitionCallback* getCallback() { return _dpCallback; }
53 
55  osg::Camera* getDPCamera() { return _dpMainSlaveCamera; }
56 
57  protected:
59 
60  osg::ref_ptr<osg::Camera> _dpMainSlaveCamera;
61  osg::ref_ptr<DepthPartitionCallback> _dpCallback;
62  osgViewer::View *_view;
63  };
64 
76  class OF_EXPORT DepthPartitionCallback : public osg::View::Slave::UpdateSlaveCallback
77  {
78  public:
80 
82  void reset() { _cameraManager->reset(); }
83 
85  void setMaxTraversalDepth(unsigned int depth)
86  { _distAccumulator->setMaxDepth(depth); }
87 
88  unsigned int getMaxTraversalDepth() const
89  { return _distAccumulator->getMaxDepth(); }
90 
92  virtual void updateSlave(osg::View& view, osg::View::Slave& slave);
93 
95  struct CameraManager : public virtual osg::Referenced
96  {
97  CameraManager() {}
98  virtual ~CameraManager() {}
99 
100  // Get the internal name of a camera
101  virtual std::string getCameraName(unsigned int camNum) = 0;
102 
103  // Create a new camera and add it as a slave to the main view
104  virtual void enableCamera(unsigned int camNum,
105  osg::Camera* mainCam,
106  const double &zNear, const double &zFar) = 0;
107 
108  // Disable all cameras after specified start camera number
109  virtual void disableCameras(unsigned int start) = 0;
110 
111  // Clear all internal cameras and revert the CameraManger to an unused
112  // and empty state
113  virtual void reset() = 0;
114 
115  // Specify minimum allowable near plane distance
116  virtual double getMinZNear() { return 1.0e-5; }
117  };
118 
120  void setCameraManager(CameraManager *cameraManager);
121 
122  protected:
123  virtual ~DepthPartitionCallback();
124 
125  // The NodeVisitor that computes depth partitions for the scene
126  osg::ref_ptr<DistanceAccumulator> _distAccumulator;
127 
128  // The camera manager that creates cameras
129  osg::ref_ptr<CameraManager> _cameraManager;
130 
131  unsigned int _numActiveCameras;
132  };
133 
134 } // !namespace OpenFrames
135 
136 #endif
osg::Camera * getDPCamera()
Definition: DepthPartitioner.hpp:55
This class sets up depth partitioning.
Definition: DepthPartitioner.hpp:42
Definition: CoordinateAxes.hpp:29
Definition: DepthPartitioner.hpp:95
void setMaxTraversalDepth(unsigned int depth)
Definition: DepthPartitioner.hpp:85
DepthPartitionCallback * getCallback()
Definition: DepthPartitioner.hpp:52
void reset()
Definition: DepthPartitioner.hpp:82
This class analyzes and partitions a scene for rendering.
Definition: DepthPartitioner.hpp:76