VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 #include <boost/optional.hpp>
20 
21 #include <tbb/spin_rw_mutex.h>
22 
23 #include <map>
24 
25 class DtString;
26 
27 namespace makVrv
28 {
29  class DtDynamicTerrainGeometry;
30  class DtDynamicTerrainChange;
31  class DtDynamicTerrainWorld;
32  class DtDynamicTerrainIndex;
33  class DtDynamicTerrainChanges;
34 
56 
84  : public DtDisconnectable
85  , public boost::enable_shared_from_this<DtDynamicTerrainFeature>
86 
87  {
88  public:
89  class Link;
90  class RequestInfo;
91 
96  {
97  public:
99  RequestHandle();
100 
104  void removeTerrainChange();
105 
108  void releaseOwnership();
109 
110  private:
111  friend class DtDynamicTerrainWorld;
113 
114  explicit RequestHandle(
115  const boost::shared_ptr<DtDynamicTerrainFeature::RequestInfo>&);
116 
117  boost::weak_ptr<DtDynamicTerrainFeature::RequestInfo> myRequest;
118  };
119 
120  static unsigned long long GetObjectCount();
121 
124 
126  virtual ~DtDynamicTerrainFeature();
127 
132  virtual bool matches(const DtDynamicTerrainChange&, bool useOriginalGeometry = false) const = 0;
133  virtual bool matches(const DtDynamicTerrainGeometry&, bool useOriginalGeometry = false) const = 0;
134 
136  virtual const DtDynamicTerrainGeometry* geometry() const = 0;
137 
139  virtual const DtDynamicTerrainGeometry* originalGeometry() const;
140 
142  virtual boost::optional<DtString> featureAttribute(const DtString& key) const;
143 
145  virtual bool isInDefaultState() const = 0;
146 
149  virtual bool lastStateWasDefaultState() const = 0;
150 
156  virtual void changeState(const DtDynamicTerrainChanges& history) = 0;
157 
161 
162 
163  typedef boost::function<void (const DtDynamicTerrainFeature&)> Callback;
164 
165  typedef
166  boost::function<void (const DtDynamicTerrainFeature&, const DtDynamicTerrainChanges&)>
168 
174  virtual boost::signals2::connection connectToChangeSignal(const ChangeCallback& callback) const;
175 
180  virtual boost::signals2::connection connectToPageOutSignal(const Callback& callback) const;
181 
183 
188 
189 
190  virtual DtString description() const = 0;
191 
192  virtual const DtDynamicTerrainFeature* parentFeature() const;
194 
208  virtual void iterateCommands(
209  const boost::function<void (const DtDynamicTerrainChange&)>&) const;
210 
212  void changed();
213 
216  bool pageOut();
217 
220  void changes(const boost::function<void (const DtDynamicTerrainChanges&)>& callback) const;
221 
223  RequestHandle addChangeRequest(DtDynamicTerrainChange* change);
224  RequestHandle addChangeRequest(double time, DtDynamicTerrainChange* change);
225 
226  protected:
229 
230  void indexDoubleAscending(const DtString& key);
231  void indexDoubleDescending(const DtString& key);
232  void indexIntAscending(const DtString& key);
233  void indexIntDescending(const DtString& key);
234  void indexStringAscending(const DtString& key);
235  void indexStringDescending(const DtString& key);
236 
237  void setupIndex(const DtString& key, DtDynamicTerrainIndex* index);
239 
240  private:
241  friend class Link;
242 
243  typedef boost::signals2::signal<void (const DtDynamicTerrainFeature&)> Signal;
244 
245  typedef boost::signals2::signal<
248 
249  typedef std::map<RequestInfo*, boost::shared_ptr<Link> > LinkInfoMap;
250 
251  // functions for creating and breaking the links
252  bool makeLinkToRequest(const boost::shared_ptr<Link>& link);
253  void breakLinkToRequest(LinkInfoMap::iterator);
254 
255  mutable ChangeSignal myChangeSignal; // implements connectToChangeSignal
256  mutable Signal myPageOutSignal; // implements connectToRemoveSignal
257 
260 
261  typedef tbb::spin_rw_mutex Mutex;
262  mutable Mutex myMutex;
263 
264  // Container which holds links to all the requests that match the feature.
266 
267  typedef std::map<DtString, DtDynamicTerrainIndex*> IndexMap;
269  };
270 
275  {
276  public:
277  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
278 
280  virtual ~DtDynamicTerrainIndex();
281 
286  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
287 
292  virtual const DtDynamicTerrainChange* firstChange() const = 0;
293 
295  virtual bool addValue(
296  const boost::shared_ptr<DtDynamicTerrainFeature::Link>& link,
297  const DtString& key) = 0;
298  };
299 
301  {
302  public:
303  typedef boost::function<void (const DtDynamicTerrainChange&)> IterateRequestCallback;
304 
306  virtual ~DtDynamicTerrainChanges();
307 
312  virtual void iterateRequests(const IterateRequestCallback& callback) const = 0;
313 
316  virtual const DtDynamicTerrainIndex* indexFor(const DtString& key) const = 0;
317  };
318 
319  // Represents the link between a change request and a feature that is made when the feature
320  // determines that the request applies to it. The objects are managed by shared pointers
321  // and live two separate containers, one in the request info and one in the feature info.
322  // The feature holds them in a map from the time of the request to the link, so that the
323  // map implements the time line. The request holds the links in an unordered list since it
324  // does not care anything about the order of changes to the various features it has applied to.
326  {
327  public:
328  static unsigned long long GetObjectCount();
329 
330  // Create link between a feature and a request.
331  // This will create the object and insert it into the feature and request.
332  // Neither parameter can be null.
333  static bool Create(
334  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
335  const boost::shared_ptr<RequestInfo>& reqInfo);
336 
337  virtual ~Link();
338 
339  RequestInfo& request() { return *myRequestInfo; }
340  DtDynamicTerrainFeature& feature() { return *myFeatureInfo; }
341 
342  private:
343  Link(
344  const boost::shared_ptr<DtDynamicTerrainFeature>& featureInfo,
345  const boost::shared_ptr<RequestInfo>& reqInfo);
346 
347  const boost::shared_ptr<RequestInfo> myRequestInfo;
348  const boost::shared_ptr<DtDynamicTerrainFeature> myFeatureInfo;
349  };
350 
351  // Bookkeeping info for an individual change request.
352  // Holds the list of links that this change request applies to.
353  class DT_DLL_VRVUTIL DtDynamicTerrainFeature::RequestInfo
354  : public DtDisconnectable
355  {
356  public:
357  friend class Link;
358 
359  static unsigned long long GetObjectCount();
360 
361  // takes ownership of command
362  explicit RequestInfo(DtDynamicTerrainChange* command);
363 
364  virtual ~RequestInfo();
365 
366  const DtDynamicTerrainChange& command() const;
367 
368  // called by DtDynamicTerrainWorld::RequestHandle to remove the request
369  void pageOut();
370 
371  private:
372  typedef std::list<boost::shared_ptr<Link> > LinkList;
373 
374  // functions for creating and breaking the links
375  void makeLinkToFeature(const boost::shared_ptr<Link>& link);
376  void breakLinkToFeature(LinkList::iterator i);
377 
378  // command of this request
379  boost::scoped_ptr<DtDynamicTerrainChange> myCommand;
380 
381  // mutex only protects myLinksToFeatures, all other members not changed after initial setup
382  typedef tbb::spin_mutex Mutex;
383  mutable Mutex myMutex;
384  // list of links to the features we've linked to
386  };
387 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)