VR-Forces Developer's Guide
 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) 2024 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 <unordered_map>
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:
69  virtual void onLayerLoaded(const osgEarth::MapNode* mapNode,
70  osgEarth::Layer* layer) =0;
71 
73  virtual void onLayerOpened(const osgEarth::MapNode* mapNode,
74  osgEarth::Layer* layer);
75 
77  virtual void onLayerClosed(const osgEarth::MapNode* mapNode,
78  osgEarth::Layer* layer);
79 
82  virtual void onDataPreMerge(const osgEarth::Layer* layer,
83  osg::Node* newData) = 0;
84 
87  virtual void onDataLoaded(const osgEarth::Layer* layer,
88  const osg::Node* newData) = 0;
89 
90  // Implementation of this method is optional; currently both speedtree
91  // and buoys/beacons have their own mechanism that they use (but should
92  // switch over to this eventually); and some users (like the texture installer)
93  // don't need to know when stuff pages out.
94  virtual void onDataUnloaded(const osgEarth::Layer* layer, const osg::Node* oldData);
95 
98  virtual float callbackOrder();
99 
102  DtIndirectFadeParameters parseFadeParametersForLayer(const osgEarth::MapNode* mapNode, osgEarth::Layer* layer);
103 
105  virtual const std::string& instanceClassName() const = 0;
106 
107  protected:
109  static bool isModelLayer(const osgEarth::Layer* layer);
110  };
111 
113  {
114  public:
115  //Function for sorting callbacks based on their callback order parameter
116  bool operator()(Callback* a, Callback* b) const
117  {
118  if (a->callbackOrder() != b->callbackOrder())
119  return a->callbackOrder() < b->callbackOrder();
120  else
121  return a < b;
122  }
123  };
124 
126  typedef std::set<CallbackRefPtr, CallbackSortFunction> SortedCallbackRefSet;
127 
128  protected:
130  DtOsgEarthFeatureDataBroker(osgEarth::MapNode* mapNode, DtDe& de);
131 
134 
136  virtual ~DtOsgEarthFeatureDataBroker();
137 
138  private:
143 
144  public:
145  // Install a callback.
146  //sending an empty string for the registrant makes this callback applied to all features regardless of name.
147  void addCallback(const std::string& registrant, Callback* cb);
148 
149  // Whether to run state sharing optimization after invoking
150  // all the callbacks. Default = true.
151  void setOptimizeStateSharing(bool value);
152  bool isOptimizeStateSharing() const;
153 
154  public: // internal functions
155 
156  // Adds a layer to the broker. You normally do not need to
157  // call this directly; the object will discover layers in the
158  // Map model automatically.
159  void addLayer(osgEarth::Layer* layer);
160 
161  // Internal function that's called after a new map layer is
162  // loaded in the MapNode.
163  void notifyNewLayer(osgEarth::Layer* layer);
164 
165  // Internal function that's called after a map layer is
166  // opened in the MapNode.
167  void notifyLayerOpened(osgEarth::Layer* layer);
168 
169  // Internal function that's called after a map layer is
170  // closed in the MapNode.
171  void notifyLayerClosed(osgEarth::Layer* layer);
172 
175  bool layerHasCallback(const osgEarth::Layer* layer, const std::string& className);
176 
177  // Internal function that's called before new data for the
178  // layer merges into the scene graph. This is called internally;
179  // there is no need to call it yourself.
180  // Potentially called in a background thread so be careful about threading issues
181  void notifyPreMergeData(osgEarth::Layer* layer, osg::Node* node);
182 
183  // Internal function that's called after new data for the
184  // layer merges into the scene graph. This is called internally;
185  // there is no need to call it yourself.
186  void notifyNewData(osgEarth::Layer* layer, osg::Node* data);
187 
188  // When new data arrives, an osg::observer is attached to it; this method
189  // is called when the observer detects the deletion of the data
190  void notifyDataDeleted(osgEarth::Layer* layer, osg::Node* data);
191 
193  DtDe& getDe() { return myDe; }
194 
195  protected:
196 
201  bool readFeatureNameRegistrationFile( const std::string& path,
202  const std::string& filename );
203 
204  protected:
206  std::string getFeatureNameFromLayer( const osgEarth::Layer& layer );
207  protected:
209 
210  protected:
211 
213  osg::observer_ptr<osgEarth::MapNode> myMapNode;
215  std::set<SceneGraphCallbackRefPtr> myOperations;
219 
220  typedef std::unordered_multimap<std::string, CallbackRefPtr>
222  typedef std::pair<FeatureDataCallbackMap::iterator,
223  FeatureDataCallbackMap::iterator> RangeIterFeatureDataCallbacks;
224  typedef std::pair<FeatureDataCallbackMap::const_iterator,
225  FeatureDataCallbackMap::const_iterator>
227 
229 
230  typedef std::unordered_map<std::string, SortedCallbackRefSet>
232 
234 
235  //Callbacks which run on all features regardless of their name.
236  // Add to this list by calling addCallback with "" as the class name.
238 
239  typedef std::unordered_map<std::string, std::vector<std::string> >
241 
242  typedef std::unordered_map<std::string,
243  std::vector<std::string> >::iterator RegistrantToFeaturesMapIter;
244 
246 
247  //added to speed up lookup since building the config structure is slow currently
248  std::unordered_map<const osgEarth::Layer*, std::string> myFeatureNameLookup;
249 
250  typedef std::unordered_map<osg::Node*, FeaturePageObserver*> MapPagesToObservers;
252 
254  };
255 
260  {
261 
262  public:
265 
268 
269  private:
274 
275  public:
278  static DtOsgEarthFeatureDataBrokerCreator& instance(DtDe& de);
279 
281  static void registerInstance(DtDe& de,
283 
285  virtual DtOsgEarthFeatureDataBroker* create(osgEarth::MapNode* mapNode, DtDe& de);
286 
287  };
288 }
289 
osg::ref_ptr< Callback > CallbackRefPtr
Definition: DtOsgEarthFeatureDataBroker.h:125
static const float OsgEarthDynamicTerrainInstallerOrder
Definition: DtOsgEarthFeatureDataBroker.h:48
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
std::pair< FeatureDataCallbackMap::iterator, FeatureDataCallbackMap::iterator > RangeIterFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:223
osg::observer_ptr< osgEarth::MapNode > myMapNode
Definition: DtOsgEarthFeatureDataBroker.h:213
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
bool myShareState
Definition: DtOsgEarthFeatureDataBroker.h:217
static const float OsgEarthStreamedFeatureCallbackOrder
Definition: DtOsgEarthFeatureDataBroker.h:47
The DtOsgEarthFeatureDataBrokerCreator creator for the DtOsgEarthFeatureDataBroker class...
Definition: DtOsgEarthFeatureDataBroker.h:259
static const float OsgEarthEffectTextureInstallerCallbackOrder
Definition: DtOsgEarthFeatureDataBroker.h:46
std::unordered_map< std::string, std::vector< std::string > >::iterator RegistrantToFeaturesMapIter
Definition: DtOsgEarthFeatureDataBroker.h:243
osg::ref_ptr< osgEarth::SceneGraphCallback > SceneGraphCallbackRefPtr
Definition: DtOsgEarthFeatureDataBroker.h:212
static const float DefaultOrder
Definition: DtOsgEarthFeatureDataBroker.h:45
static const char * theFeatureDataBrokerRegistrantToFeatureList
Definition: DtOsgEarthFeatureDataBroker.h:208
OpenThreads::Mutex myMapMutex
Definition: DtOsgEarthFeatureDataBroker.h:218
Definition: DtOsgEarthFeatureDataBroker.h:112
DtDe & getDe()
get the De
Definition: DtOsgEarthFeatureDataBroker.h:193
RegistrantToFeaturesMap myRegistrantToFeaturesMap
Definition: DtOsgEarthFeatureDataBroker.h:245
static const float OsgEarthLightPointInstallerOrder
Definition: DtOsgEarthFeatureDataBroker.h:49
std::unordered_map< const osgEarth::Layer *, std::string > myFeatureNameLookup
Definition: DtOsgEarthFeatureDataBroker.h:248
DtOsgEarthFeatureDataBroker listens to osgEarth feature layers (i.e. model layers with a feature sour...
Definition: DtOsgEarthFeatureDataBroker.h:60
MapPagesToObservers myMapPagesToObservers
Definition: DtOsgEarthFeatureDataBroker.h:251
DtDe & myDe
Definition: DtOsgEarthFeatureDataBroker.h:216
Contains makVrv::DtVirtualBaseClass class.
SortedCallbackRefSet myAllFeatureCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:237
std::pair< FeatureDataCallbackMap::const_iterator, FeatureDataCallbackMap::const_iterator > ConstRangeIterFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:226
std::set< SceneGraphCallbackRefPtr > myOperations
Definition: DtOsgEarthFeatureDataBroker.h:215
std::unordered_multimap< std::string, CallbackRefPtr > FeatureDataCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:221
std::unordered_map< osg::Node *, FeaturePageObserver * > MapPagesToObservers
Definition: DtOsgEarthFeatureDataBroker.h:250
struct for holding the fade parameters used by the indirect rendering cull compute shader ...
Definition: DtIndirectFadeParameters.h:17
OpenThreads::Mutex Mutex
Definition: DtOsgThreadingUtils.h:12
std::set< CallbackRefPtr, CallbackSortFunction > SortedCallbackRefSet
Definition: DtOsgEarthFeatureDataBroker.h:126
std::unordered_map< std::string, std::vector< std::string > > RegistrantToFeaturesMap
Definition: DtOsgEarthFeatureDataBroker.h:240
DtOsgShaderManager injects custom shaders into the scenes, and keeps their uniform parameters set to ...
Definition: DtOsgShaderManager.h:41
Definition: DtOsgEarthFeatureDataBroker.h:65
Contains DLL export macros.
DtOsgShaderManager & myShaderManager
Definition: DtOsgEarthFeatureDataBroker.h:253
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
osg::ref_ptr< osgEarth::MapCallback > myMapCallback
Definition: DtOsgEarthFeatureDataBroker.h:214
std::unordered_map< std::string, SortedCallbackRefSet > LayerToCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:231
LayerToCallbackMap myLayerToCallbackMap
Definition: DtOsgEarthFeatureDataBroker.h:233
bool operator()(Callback *a, Callback *b) const
Definition: DtOsgEarthFeatureDataBroker.h:116
virtual float callbackOrder()
used to specify an order that the callbacks should run. Defaults to 1.0; lower callbacks are run firs...
Contains makVrv::DtIndirectFadeParameters class.
FeatureDataCallbackMap myFeatureDataCallbacks
Definition: DtOsgEarthFeatureDataBroker.h:228

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)