VR-Forces 4.7 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) 2018 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 #include <vrvOsg/vrvOsg.h>
12 #include <osg/observer_ptr>
13 #include <osg/ref_ptr>
14 
15 #include <osgEarth/Map>
16 #include <osgEarth/SceneGraphCallback>
17 #include <boost/unordered_map.hpp>
18 
19 #include <set>
20 #include <string>
21 
22 // Forward declarations
23 namespace osg {
24  class Node;
25 }
26 namespace osgEarth {
27  class MapNode;
28  class ModelLayer;
29 }
30 
31 namespace makVrv
32 {
33  class FeaturePageObserver;
34 
44  class DT_DLL_VRVOSG DtOsgEarthFeatureDataBroker : public osg::Referenced
45  {
46  public:
47  // Callback to invoke when new data merges into the scene graph.
48  class DT_DLL_VRVOSG Callback : public osg::Referenced
49  {
50  public:
51  virtual void onLayerLoaded(const osgEarth::MapNode* mapNode,
52  const osgEarth::ModelLayer* layer) =0;
53 
56  virtual void onDataPreMerge(const osgEarth::Map* map,
57  const osgEarth::ModelLayer* layer,
58  osg::Node* newData) = 0;
59 
62  virtual void onDataLoaded(const osgEarth::Map* map,
63  const osgEarth::ModelLayer* layer,
64  const osg::Node* newData) = 0;
65 
66  // Implementation of this method is optional; currently both speedtree
67  // and buoys/beacons have their own mechanism that they use (but should
68  // switch over to this eventually); and some users (like the texture installer)
69  // don't need to know when stuff pages out.
70  virtual void onDataUnloaded(const osgEarth::Map* map, const osgEarth::ModelLayer* layer, const osg::Node* oldData)
71  {
72  }
73  };
74 
75  public:
76  // Constructs a broker for the specified map node.
77  DtOsgEarthFeatureDataBroker(osgEarth::MapNode* mapNode, DtDe& de);
78 
79  // Install a callback.
80  //sending an empty string for the registrant makes this callback applied to all features regardless of name.
81  void addCallback(const std::string& registrant, Callback* cb);
82 
83  // Whether to run state sharing optimization after invoking
84  // all the callbacks. Default = true.
85  void setOptimizeStateSharing(bool value);
86  bool getOptimizeStateSharing() const;
87 
88  public: // internal functions
89 
90  // Adds a model layer to the broker. You normally do not need to
91  // call this directly; the object will discover model layers in the
92  // Map model automatically.
93  void addModelLayer(osgEarth::ModelLayer* layer);
94 
95  // Internal function that's called after a new map layer is
96  // loaded in the MapNode.
97  void notifyNewLayer(osgEarth::ModelLayer* layer);
98 
99  // Internal function that's called before new data for the model
100  // layer merges into the scene graph. This is called internally;
101  // there is no need to call it yourself.
102  // Potentially called in a background thread so be careful about threading issues
103  void notifyPreMergeData(osgEarth::ModelLayer* layer, osg::Node* node);
104 
105  // Internal function that's called after new data for the model
106  // layer merges into the scene graph. This is called internally;
107  // there is no need to call it yourself.
108  void notifyNewData(osgEarth::ModelLayer* layer, osg::Node* data);
109 
110  // When new data arrives, an osg::observer is attached to it; this method
111  // is called when the observer detects the deletion of the data
112  void notifyDataDeleted(osgEarth::ModelLayer* layer, osg::Node* data);
113 
114  protected:
115  virtual ~DtOsgEarthFeatureDataBroker();
116 
121  bool readFeatureNameRegistrationFile( const std::string& path,
122  const std::string& filename );
123 
124  protected:
125  std::string getFeatureNameFromModelLayer( const osgEarth::ModelLayer& layer );
126 
127  protected:
129 
130  protected:
131 
132  typedef osg::ref_ptr<osgEarth::SceneGraphCallback> SceneGraphCallbackRefPtr;
133  osg::observer_ptr<osgEarth::MapNode> myMapNode;
134  osg::ref_ptr<osgEarth::MapCallback> myMapCallback;
135  std::set<SceneGraphCallbackRefPtr> myOperations;
139 
140  typedef osg::ref_ptr<Callback> CallbackRefPtr;
141  typedef boost::unordered_multimap<std::string, CallbackRefPtr>
143  typedef std::pair<FeatureDataCallbackMap::iterator,
144  FeatureDataCallbackMap::iterator> RangeIterFeatureDataCallbacks;
145  typedef std::pair<FeatureDataCallbackMap::const_iterator,
146  FeatureDataCallbackMap::const_iterator>
148 
150 
151  typedef std::set<CallbackRefPtr> CallbackRefSet;
152  //Callbacks which run on all features regardless of their name.
153  // Add to this list by calling addCallback with "" as the class name.
155 
156  typedef boost::unordered_map<std::string, std::vector<std::string> >
158 
159  typedef boost::unordered_map<std::string,
160  std::vector<std::string> >::iterator RegistrantToFeaturesMapIter;
161 
163 
164  //added to speed up lookup since building the config structure is slow currently
165  boost::unordered_map<const osgEarth::ModelLayer*, std::string> myFeatureNameLookup;
166 
167  typedef boost::unordered_map<osg::Node*, FeaturePageObserver*> MapPagesToObservers;
169  };
170 }
171 

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)