VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtDynamicTerrainFeature.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvUtil/vrvUtil.h>
15 
16 #include <boost/function.hpp>
17 #include <boost/signals2.hpp>
18 #include <boost/enable_shared_from_this.hpp>
19 
20 #include <tbb/spin_rw_mutex.h>
21 
22 #include <map>
23 
24 class DtString;
25 
26 namespace makVrv
27 {
28  class DtDynamicTerrainGeometry;
29  class DtDynamicTerrainChange;
30  class DtDynamicTerrainWorld;
31  class DtDynamicTerrainIndex;
32  class DtDynamicTerrainChanges;
33 
55 
83  : public DtDisconnectable
84  , public boost::enable_shared_from_this<DtDynamicTerrainFeature>
85 
86  {
87  public:
88  class Link;
89  class RequestInfo;
90 
95  {
96  public:
98  RequestHandle();
99 
103  void removeTerrainChange();
104 
107  void releaseOwnership();
108 
109  private:
110  friend class DtDynamicTerrainWorld;
112 
113  explicit RequestHandle(
114  const boost::shared_ptr<DtDynamicTerrainFeature::RequestInfo>&);
115 
116  boost::weak_ptr<DtDynamicTerrainFeature::RequestInfo> myRequest;
117  };
118 
119  static unsigned long long GetObjectCount();
120 
123 
125  virtual ~DtDynamicTerrainFeature();
126 
129  virtual bool matches(const DtDynamicTerrainChange&) const = 0;
130  virtual bool matches(const DtDynamicTerrainGeometry&) const = 0;
131 
133  virtual const DtDynamicTerrainGeometry* geometry() const = 0;
134 
136  virtual const DtDynamicTerrainGeometry* originalGeometry() const;
137 
143  virtual void changeState(const DtDynamicTerrainChanges& history) = 0;
144 
148 
149 
150  typedef boost::function<void (const DtDynamicTerrainFeature&)> Callback;
151 
152  typedef
153  boost::function<void (const DtDynamicTerrainFeature&, const DtDynamicTerrainChanges&)>
155 
161  virtual boost::signals2::connection connectToChangeSignal(const ChangeCallback& callback) const;
162 
167  virtual boost::signals2::connection connectToPageOutSignal(const Callback& callback) const;
168 
170 
175 
176 
177  virtual DtString description() const = 0;
178 
179  virtual const DtDynamicTerrainFeature* parentFeature() const;
181 
195  virtual void iterateCommands(
196  const boost::function<void (const DtDynamicTerrainChange&)>&) const;
197 
199  void changed();
200 
203  bool pageOut();
204 
207  void changes(const boost::function<void (const DtDynamicTerrainChanges&)>& callback) const;
208 
210  RequestHandle addChangeRequest(DtDynamicTerrainChange* change);
211  RequestHandle addChangeRequest(double time, DtDynamicTerrainChange* change);
212 
213  protected:
216 
217  void indexDoubleAscending(const DtString& key);
218  void indexDoubleDescending(const DtString& key);
219  void indexIntAscending(const DtString& key);
220  void indexIntDescending(const DtString& key);
221  void indexStringAscending(const DtString& key);
222  void indexStringDescending(const DtString& key);
223 
224  void setupIndex(const DtString& key, DtDynamicTerrainIndex* index);
226 
227  private:
228  friend class Link;
229 
230  typedef boost::signals2::signal<void (const DtDynamicTerrainFeature&)> Signal;
231 
232  typedef boost::signals2::signal<
235 
236  typedef std::map<RequestInfo*, boost::shared_ptr<Link> > LinkInfoMap;
237 
238  // functions for creating and breaking the links
239  bool makeLinkToRequest(const boost::shared_ptr<Link>& link);
240  void breakLinkToRequest(LinkInfoMap::iterator);
241 
242  mutable ChangeSignal myChangeSignal; // implements connectToChangeSignal
243  mutable Signal myPageOutSignal; // implements connectToRemoveSignal
244 
247 
248  typedef tbb::spin_rw_mutex Mutex;
249  mutable Mutex myMutex;
250 
251  // Container which holds links to all the requests that match the feature.
253 
254  typedef std::map<DtString, DtDynamicTerrainIndex*> IndexMap;
256  };
257 
262  {
263  public:
264  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
265 
267  virtual ~DtDynamicTerrainIndex();
268 
273  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
274 
279  virtual const DtDynamicTerrainChange* firstChange() const = 0;
280 
282  virtual bool addValue(
283  const boost::shared_ptr<DtDynamicTerrainFeature::Link>& link,
284  const DtString& key) = 0;
285  };
286 
288  {
289  public:
290  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
291 
293  virtual ~DtDynamicTerrainChanges();
294 
299  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
300 
303  virtual const DtDynamicTerrainIndex* indexFor(const DtString& key) const = 0;
304  };
305 
306  // Represents the link between a change request and a feature that is made when the feature
307  // determines that the request applies to it. The objects are managed by shared pointers
308  // and live two separate containers, one in the request info and one in the feature info.
309  // The feature holds them in a map from the time of the request to the link, so that the
310  // map implements the time line. The request holds the links in an unordered list since it
311  // does not care anything about the order of changes to the various features it has applied to.
313  {
314  public:
315  static unsigned long long GetObjectCount();
316 
317  // Create link between a feature and a request.
318  // This will create the object and insert it into the feature and request.
319  // Neither parameter can be null.
320  static bool Create(
321  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
322  const boost::shared_ptr<RequestInfo>& reqInfo);
323 
324  ~Link();
325 
326  RequestInfo& request() { return *myRequestInfo; }
327  DtDynamicTerrainFeature& feature() { return *myFeatureInfo; }
328 
329  private:
330  Link(
331  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
332  const boost::shared_ptr<RequestInfo>& reqInfo);
333 
334  const boost::shared_ptr<RequestInfo> myRequestInfo;
335  const boost::shared_ptr<DtDynamicTerrainFeature> myFeatureInfo;
336  };
337 
338  // Bookkeeping info for an individual change request.
339  // Holds the list of links that this change request applies to.
340  class DT_DLL_VRVUTIL DtDynamicTerrainFeature::RequestInfo
341  : public DtDisconnectable
342  {
343  public:
344  friend class Link;
345 
346  static unsigned long long GetObjectCount();
347 
348  // takes ownership of command
349  explicit RequestInfo(DtDynamicTerrainChange* command);
350 
351  virtual ~RequestInfo();
352 
353  const DtDynamicTerrainChange& command() const;
354 
355  // called by DtDynamicTerrainWorld::RequestHandle to remove the request
356  void pageOut();
357 
358  private:
359  typedef std::list<boost::shared_ptr<Link> > LinkList;
360 
361  // functions for creating and breaking the links
362  void makeLinkToFeature(const boost::shared_ptr<Link>& link);
363  void breakLinkToFeature(LinkList::iterator i);
364 
365  // command of this request
366  boost::scoped_ptr<DtDynamicTerrainChange> myCommand;
367 
368  // mutex only protects myLinksToFeatures, all other members not changed after initial setup
369  typedef tbb::spin_mutex Mutex;
370  mutable Mutex myMutex;
371  // list of links to the features we've linked to
373  };
374 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)