VR-Forces 4.8 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgEarthFeatureDataBroker.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
15 
17 
18 #include <osg/observer_ptr>
19 #include <osg/ref_ptr>
20 
21 #include <osgEarth/Map>
22 #include <osgEarth/SceneGraphCallback>
23 #include <boost/unordered_map.hpp>
24 
25 #include <set>
26 #include <string>
27 
28 // Forward declarations
29 namespace osg {
30  class Node;
31 }
32 namespace osgEarth {
33  class MapNode;
34  class Layer;
35 }
36 
37 namespace makVrv
38 {
39  class FeaturePageObserver;
40  class DtOsgShaderManager;
41 
42  // namespace to delineate these orders from makVrv
43  namespace DtOsgEarthFeatureDataBrokerCallbackOrders
44  {
45  const static float DefaultOrder = 1.0f;
47  const static float OsgEarthStreamedFeatureCallbackOrder = 2.0f;
48  const static float OsgEarthDynamicTerrainInstallerOrder = 5.0f;
49  const static float OsgEarthLightPointInstallerOrder = 7.0f; //needs to be after the dynamic terrain installer
50  }
51 
55 
60  class DT_DLL_VRVOSG DtOsgEarthFeatureDataBroker : public osg::Referenced
61  {
62 
63  public:
64  // Callback to invoke when new data merges into the scene graph.
65  class DT_DLL_VRVOSG Callback : public osg::Referenced
66  {
67  public:
68  virtual void onLayerLoaded(const osgEarth::MapNode* mapNode,
69  osgEarth::Layer* layer) =0;
70 
73  virtual void onDataPreMerge(const osgEarth::Map* map,
74  const osgEarth::Layer* layer,
75  osg::Node* newData) = 0;
76 
79  virtual void onDataLoaded(const osgEarth::Map* map,
80  const osgEarth::Layer* layer,
81  const osg::Node* newData) = 0;
82 
83  // Implementation of this method is optional; currently both speedtree
84  // and buoys/beacons have their own mechanism that they use (but should
85  // switch over to this eventually); and some users (like the texture installer)
86  // don't need to know when stuff pages out.
87  virtual void onDataUnloaded(const osgEarth::Map* map, const osgEarth::Layer* layer, const osg::Node* oldData)
88  {
89  }
90 
93  virtual float callbackOrder()
94  {
96  }
97 
98  DtIndirectFadeParameters parseFadeParametersForLayer(const osgEarth::MapNode* mapNode, osgEarth::Layer* layer);
99 
101  virtual const std::string& instanceClassName() const = 0;
102 
103  protected:
104  static bool isModelLayer(const osgEarth::Layer* layer);
105  };
106 
108  {
109  public:
110  bool operator()(Callback* a, Callback* b) const
111  {
112  if (a->callbackOrder() != b->callbackOrder())
113  return a->callbackOrder() < b->callbackOrder();
114  else
115  return a < b;
116  }
117  };
118 
120  typedef std::set<CallbackRefPtr, CallbackSortFunction> SortedCallbackRefSet;
121 
122  protected:
124  DtOsgEarthFeatureDataBroker(osgEarth::MapNode* mapNode, DtDe& de);
125 
128 
130  virtual ~DtOsgEarthFeatureDataBroker();
131 
132  private:
137 
138  public:
139  // Install a callback.
140  //sending an empty string for the registrant makes this callback applied to all features regardless of name.
141  void addCallback(const std::string& registrant, Callback* cb);
142 
143  // Whether to run state sharing optimization after invoking
144  // all the callbacks. Default = true.
145  void setOptimizeStateSharing(bool value);
146  bool getOptimizeStateSharing() const;
147 
148  public: // internal functions
149 
150  // Adds a layer to the broker. You normally do not need to
151  // call this directly; the object will discover layers in the
152  // Map model automatically.
153  void addLayer(osgEarth::Layer* layer);
154 
155  // Internal function that's called after a new map layer is
156  // loaded in the MapNode.
157  void notifyNewLayer(osgEarth::Layer* layer);
158 
161  bool layerHasCallback(const osgEarth::Layer* layer, const std::string& className);
162 
163  // Internal function that's called before new data for the
164  // layer merges into the scene graph. This is called internally;
165  // there is no need to call it yourself.
166  // Potentially called in a background thread so be careful about threading issues
167  void notifyPreMergeData(osgEarth::Layer* layer, osg::Node* node);
168 
169  // Internal function that's called after new data for the
170  // layer merges into the scene graph. This is called internally;
171  // there is no need to call it yourself.
172  void notifyNewData(osgEarth::Layer* layer, osg::Node* data);
173 
174  // When new data arrives, an osg::observer is attached to it; this method
175  // is called when the observer detects the deletion of the data
176  void notifyDataDeleted(osgEarth::Layer* layer, osg::Node* data);
177 
178  DtDe& getDe() { return myDe; }
179 
180  protected:
181 
186  bool readFeatureNameRegistrationFile( const std::string& path,
187  const std::string& filename );
188 
189  protected:
190  std::string getFeatureNameFromLayer( const osgEarth::Layer& layer );
191  protected:
193 
194  protected:
195 
197  osg::observer_ptr<osgEarth::MapNode> myMapNode;
199  std::set<SceneGraphCallbackRefPtr> myOperations;
203 
204  typedef boost::unordered_multimap<std::string, CallbackRefPtr>
206  typedef std::pair<FeatureDataCallbackMap::iterator,
207  FeatureDataCallbackMap::iterator> RangeIterFeatureDataCallbacks;
208  typedef std::pair<FeatureDataCallbackMap::const_iterator,
209  FeatureDataCallbackMap::const_iterator>
211 
213 
214  typedef boost::unordered_map<std::string, SortedCallbackRefSet>
216 
218 
219  //Callbacks which run on all features regardless of their name.
220  // Add to this list by calling addCallback with "" as the class name.
222 
223  typedef boost::unordered_map<std::string, std::vector<std::string> >
225 
226  typedef boost::unordered_map<std::string,
227  std::vector<std::string> >::iterator RegistrantToFeaturesMapIter;
228 
230 
231  //added to speed up lookup since building the config structure is slow currently
232  boost::unordered_map<const osgEarth::Layer*, std::string> myFeatureNameLookup;
233 
234  typedef boost::unordered_map<osg::Node*, FeaturePageObserver*> MapPagesToObservers;
236 
238  };
239 
244  {
245 
246  public:
249 
252 
253  private:
258 
259  public:
262  static DtOsgEarthFeatureDataBrokerCreator& instance(DtDe& de);
263 
265  static void registerInstance(DtDe& de,
267 
269  virtual DtOsgEarthFeatureDataBroker* create(osgEarth::MapNode* mapNode, DtDe& de);
270 
271  };
272 }
273 
boost::unordered_map< osg::Node *, FeaturePageObserver * > MapPagesToObservers
Definition: DtOsgEarthFeatureDataBroker.h:234
boost::unordered_map< std::string, std::vector< std::string > >::iterator RegistrantToFeaturesMapIter
Definition: DtOsgEarthFeatureDataBroker.h:227
osg::ref_ptr< Callback > CallbackRefPtr
Definition: DtOsgEarthFeatureDataBroker.h:119
static const float OsgEarthDynamicTerrainInstallerOrder
Definition: DtOsgEarthFeatureDataBroker.h:48
virtual void onDataUnloaded(const osgEarth::Map *map, const osgEarth::Layer *layer, const osg::Node *oldData)
Definition: DtOsgEarthFeatureDataBroker.h:87
Virtual base class.
Definition: DtVirtualBaseClass.h:22
struct for holding the fade parameters used by the indirect rendering cull compute shader ...
Definition: DtGpuCullingAndLodDefines.h:21
std::pair< FeatureDataCallbackMap::iterator, FeatureDataCallbackMap::iterator > RangeIterFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:207
osg::observer_ptr< osgEarth::MapNode > myMapNode
Definition: DtOsgEarthFeatureDataBroker.h:197
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool myShareState
Definition: DtOsgEarthFeatureDataBroker.h:201
static const float OsgEarthStreamedFeatureCallbackOrder
Definition: DtOsgEarthFeatureDataBroker.h:47
boost::unordered_multimap< std::string, CallbackRefPtr > FeatureDataCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:205
The DtOsgEarthFeatureDataBrokerCreator creator for the DtOsgEarthFeatureDataBroker class...
Definition: DtOsgEarthFeatureDataBroker.h:243
static const float OsgEarthEffectTextureInstallerCallbackOrder
Definition: DtOsgEarthFeatureDataBroker.h:46
osg::ref_ptr< osgEarth::SceneGraphCallback > SceneGraphCallbackRefPtr
Definition: DtOsgEarthFeatureDataBroker.h:196
boost::unordered_map< std::string, std::vector< std::string > > RegistrantToFeaturesMap
Definition: DtOsgEarthFeatureDataBroker.h:224
static const float DefaultOrder
Definition: DtOsgEarthFeatureDataBroker.h:45
static const char * theFeatureDataBrokerRegistrantToFeatureList
Definition: DtOsgEarthFeatureDataBroker.h:192
OpenThreads::Mutex myMapMutex
Definition: DtOsgEarthFeatureDataBroker.h:202
Definition: DtOsgEarthFeatureDataBroker.h:107
DtDe & getDe()
Definition: DtOsgEarthFeatureDataBroker.h:178
RegistrantToFeaturesMap myRegistrantToFeaturesMap
Definition: DtOsgEarthFeatureDataBroker.h:229
static const float OsgEarthLightPointInstallerOrder
Definition: DtOsgEarthFeatureDataBroker.h:49
boost::unordered_map< const osgEarth::Layer *, std::string > myFeatureNameLookup
Definition: DtOsgEarthFeatureDataBroker.h:232
DtOsgEarthFeatureDataBroker listens to osgEarth feature layers (i.e.
Definition: DtOsgEarthFeatureDataBroker.h:60
MapPagesToObservers myMapPagesToObservers
Definition: DtOsgEarthFeatureDataBroker.h:235
DtDe & myDe
Definition: DtOsgEarthFeatureDataBroker.h:200
Contains makVrv::DtVirtualBaseClass class.
SortedCallbackRefSet myAllFeatureCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:221
std::pair< FeatureDataCallbackMap::const_iterator, FeatureDataCallbackMap::const_iterator > ConstRangeIterFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:210
std::set< SceneGraphCallbackRefPtr > myOperations
Definition: DtOsgEarthFeatureDataBroker.h:199
OpenThreads::Mutex Mutex
Definition: DtOsgThreadingUtils.h:12
std::set< CallbackRefPtr, CallbackSortFunction > SortedCallbackRefSet
Definition: DtOsgEarthFeatureDataBroker.h:120
Declarations for classes used in DtICullingAndLOD.
DtOsgShaderManager injects custom shaders into the scenes, and keeps their uniform parameters set to ...
Definition: DtOsgShaderManager.h:55
Definition: DtOsgEarthFeatureDataBroker.h:65
Contains DLL export macros.
DtOsgShaderManager & myShaderManager
Definition: DtOsgEarthFeatureDataBroker.h:237
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
osg::ref_ptr< osgEarth::MapCallback > myMapCallback
Definition: DtOsgEarthFeatureDataBroker.h:198
LayerToCallbackMap myLayerToCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:217
boost::unordered_map< std::string, SortedCallbackRefSet > LayerToCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:215
bool operator()(Callback *a, Callback *b) const
Definition: DtOsgEarthFeatureDataBroker.h:110
virtual float callbackOrder()
used to specify an order that the callbacks should run.
Definition: DtOsgEarthFeatureDataBroker.h:93
FeatureDataCallbackMap myFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:212

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)