VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
geometryDuplicateRemover.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
11 
12 #include <boost/unordered/unordered_set.hpp>
13 #include <boost/tuple/tuple.hpp>
14 
15 #include <tbb/spin_mutex.h>
16 
17 #include <vrfutil/objectCounter.h>
18 
19 #pragma once
20 
22 namespace MAKVRinTerra
23 {
25  : public DtObjectDebugger<DtGeometryDuplicateRemover>
26  {
27  public:
28  typedef boost::unordered_set<DtFeatureGeometry::Hash> HashSet;
29 
30  bool has(const DtFeatureGeometry& g) const
31  {
32  Mutex::scoped_lock lock(myMutex);
33  return myHashSet.find(g.hash()) != myHashSet.end();
34  }
35 
36  bool insert(const DtFeatureGeometry& g)
37  {
38  return insert(g.hash());
39  }
40 
41  bool insert(const std::string& h)
42  {
43  HashSet::iterator iter;
44  bool inserted;
45 
46  Mutex::scoped_lock lock(myMutex);
47  boost::tie(iter, inserted) = myHashSet.insert(h);
48 
49  return inserted;
50  }
51 
52  protected:
53  typedef tbb::spin_mutex Mutex;
54  mutable Mutex myMutex;
55 
57  };
58 
59  template <typename F>
61  {
62  public:
63  typedef boost::function<void (const F&)> ForEachFunction;
64 
66 
68  : myFunc(func)
69  {
70  assert(myFunc);
71  }
72 
73  bool isDuplicate(const F& feature)
74  {
75  boost::optional<std::string> attr = feature.template attributeAs<std::string>("MAK_FID");
76 
77  if (attr)
78  {
79  if (attr->empty())
80  return false;
81 
82  return !insert(*attr);
83  }
84 
85  return !insert(feature.geometry());
86  }
87 
88  void operator()(const F& feature) const
89  {
90  if (!const_cast<DtFeatureDuplicateRemover*>(this)->isDuplicate(feature))
91  myFunc(feature);
92  }
93 
94  void call(ForEachFunction func, const F& feature)
95  {
96  if (!isDuplicate(feature))
97  func(feature);
98  }
99 
100  protected:
102  };
103 
104  template <typename F>
106  : public DtObjectDebugger< DtSharedFeatureDuplicateRemover<F> >
107  {
108  public:
109  typedef boost::function<void (const F&)> ForEachFunction;
110 
111  typedef boost::shared_ptr<DtFeatureDuplicateRemover<F> > BasePtr;
112 
115  {
116  }
117 
118  bool isDuplicate(const F& feature)
119  {
120  return myRemover->isDuplicate(feature);
121  }
122 
123  void operator()(const F& feature) const
124  {
125  (*myRemover)(feature);
126  }
127 
128  void call(ForEachFunction func, const F& feature) const
129  {
130  myRemover->call(func, feature);
131  }
132 
134  : myRemover(r)
135  {
136  assert(myRemover);
137  }
138 
139  private:
141  };
142 
143  template <typename FS>
145  : public FS::ScopedWrapper
146  , public DtObjectDebugger< DtDeduplicatingFeatureSet<FS> >
147  {
148  public:
149  typedef typename FS::ScopedWrapper Parent;
150  typedef typename FS::Feature Feature;
151  typedef typename FS::ForEachFunction ForEachFunction;
152 
153  explicit DtDeduplicatingFeatureSet(FS* fs)
154  : Parent(fs)
155  {
156  }
157 
158  void forEachFeatureParallel(const ForEachFunction& func) const
159  {
161  Parent::forEachFeatureParallel(boost::ref(dedupe));
162  }
163 
164  typename FS::DetachCallback forEachFeatureAsync(const ForEachFunction& func) const
165  {
170  return Parent::forEachFeatureAsync(func);
171  }
172 
173  FS* filter(
174  const DtQuery& query,
175  const boost::optional<DtFeatureGeometry>& geom,
176  DtLoadType load) const
177  {
178  std::auto_ptr<FS> fs(Parent::filter(query, geom, load));
179  if (!fs.get())
180  return 0;
181 
182  return new DtDeduplicatingFeatureSet(fs.release());
183  }
184 
186  {
187  return new DtDeduplicatingFeatureSet(*this);
188  }
189 
190  protected:
192  : Parent(fs.getPtr()->clone())
193  {
194  }
195  };
196 }
197 

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)