VR-Forces 4.1.1 Class Documentation
featureGeometry.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
13 #include <features/proj.h>
14 
15 #include <boost/function.hpp>
16 
17 #include <iosfwd>
18 
19 namespace tbb
20 {
21  class recursive_mutex;
22 }
23 
24 namespace MAKVRinTerra
25 {
38  {
39  public:
42 
48  enum Type
49  {
50  UnknownType = -1,
51  PointType = 0,
52  PathType = 1,
53  AreaType = 2,
54  };
55 
56  typedef std::vector<DtFeatureGeometry> GeometryVector;
57  typedef std::vector<DtPoint> PointVector;
58 
59  class Implementation;
61 
62  typedef boost::shared_ptr<Implementation> ImplPtr;
63  typedef boost::shared_ptr<const Implementation> ImplCPtr;
64 
65  typedef tbb::recursive_mutex Mutex;
66 
67  template <Type T> class Handle;
68 
76  typedef Handle<PointType> Point;
77  typedef Handle<PathType> Path;
78  typedef Handle<AreaType> Area;
80 
81  static std::string ToString(Type);
82 
84  static Area MakeBox(Point, double length, double width, double rotation);
85  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
86  static Area MakeBox(const DtProj::Bounds&);
87  static Area MakeArea(const DtProj&, std::vector<DtPoint> points);
88  static Area MakeArea(const DtProj&, std::vector<DtVector> points);
89 
90  static Path MakePath(const DtProj&, std::vector<DtPoint> points);
91  static Path MakePath(const DtProj&, std::vector<DtVector> points);
92 
95 
97  DtFeatureGeometry(const ImplPtr&);
99 
101  template <Type T>
102  DtFeatureGeometry(const Handle<T>&);
103 
105  {
106  myImpl = g.myImpl;
107  return *this;
108  }
109 
110  template <Type T>
111  DtFeatureGeometry& operator=(const Handle<T>& h)
112  {
113  myImpl = h.myImpl;
114  return *this;
115  }
116 
118  Type type() const;
119 
121  bool isEmpty() const;
122 
124  bool isUnknown() const;
125 
127  bool isPoint() const;
128 
130  bool isPath() const;
131 
133  bool isArea() const;
134 
136  ImplCPtr implementation() const;
137 
138  std::string debugPrint() const;
139 
142  template <typename T>
143  boost::shared_ptr<const T> cast() const;
144 
146  const DtProj& projection() const;
147 
149  DtFeatureGeometry clone() const;
150 
151  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
152 
153  void transform(TransformFunction func);
154 
156  void convert(const DtProj &p);
157 
159  unsigned numberOfPoints() const;
160 
162  std::auto_ptr<PointVector> points() const;
163 
165  unsigned numberOfSubGeometries() const;
166 
168  std::auto_ptr<GeometryVector> subGeometries() const;
169 
171  DtPoint centroid() const;
172 
174  bool intersects(DtFeatureGeometry g) const;
175 
176  bool overlaps(DtFeatureGeometry g) const;
177 
178  bool covers(DtFeatureGeometry g) const;
179 
180  bool within(DtFeatureGeometry g) const;
181 
183  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
184 
186  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
187 
189  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
190 
193  DtFeatureGeometry::Point closestPointTo(DtFeatureGeometry g, double* distanceTo = NULL) const;
194 
195  protected:
196  class Lock : boost::noncopyable
197  {
198  public:
199  Lock(const Implementation&);
200  Lock(const Implementation&, const Implementation&);
201  ~Lock();
202 
203  private:
206  };
207 
209  };
210 
211  template <DtFeatureGeometry::Type T>
212  DtFeatureGeometry::DtFeatureGeometry(const Handle<T>& handle)
213  : myImpl(handle.myImpl)
214  {
215  }
216 
217  template <typename T>
218  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
219  {
220  return boost::dynamic_pointer_cast<const T>(implementation());
221  }
222 
225  {
226  public:
229 
231  typedef std::vector<DtFeatureGeometry> GeometryVector;
232  typedef std::vector<DtPoint> PointVector;
233 
234  virtual ~Implementation();
235 
236  virtual Mutex& getMutex() const;
237 
239  virtual DtFeatureGeometry clone() const = 0;
240 
243  virtual bool unique() const;
244 
246  virtual const DtProj & projection() const = 0;
247 
248  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
249 
250  virtual void transform(TransformFunction) = 0;
251 
253  virtual void convert(const DtProj &) = 0;
254 
256  virtual Type type() const = 0;
257 
259  virtual unsigned numberOfPoints() const = 0;
260 
262  virtual std::auto_ptr<PointVector> points() const = 0;
263 
265  virtual unsigned numberOfSubGeometries() const = 0;
266 
268  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
269 
271  virtual DtPoint centroid() const = 0;
272 
274  virtual bool intersects(DtFeatureGeometry) const = 0;
275 
276  virtual bool overlaps(DtFeatureGeometry) const = 0;
277 
278  virtual bool covers(DtFeatureGeometry) const = 0;
279 
280  virtual bool within(DtFeatureGeometry) const = 0;
281 
283  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
284 
286  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
287 
289  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
290 
293  virtual DtFeatureGeometry::Point closestPointTo(DtFeatureGeometry, double* distanceTo = NULL) const = 0;
294  };
295 
299  class DtFeatureGeometry::EmptyImplementation : public DtFeatureGeometry::Implementation
300  {
301  public:
302  typedef boost::shared_ptr<EmptyImplementation> Ptr;
303 
305 
306  DtFeatureGeometry clone() const;
307 
308  const DtProj & projection() const;
310  void convert(const DtProj &);
311  Type type() const;
312 
313  unsigned numberOfPoints() const;
314  std::auto_ptr<PointVector> points() const;
315 
316  unsigned numberOfSubGeometries() const;
317  std::auto_ptr<GeometryVector> subGeometries() const;
318 
319  DtPoint centroid() const;
320  bool intersects(DtFeatureGeometry) const;
321  bool overlaps(DtFeatureGeometry) const;
322  bool covers(DtFeatureGeometry) const;
323  bool within(DtFeatureGeometry) const;
324  double distanceTo(DtFeatureGeometry, const DtProj&) const;
328 
329  private:
331  };
332 
333  template <>
334  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
335  : protected DtFeatureGeometry
336  {
337  public:
338  friend class DtFeatureGeometry;
339 
340  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
341 
342  Handle();
343  Handle(const DtFeatureGeometry&);
344  Handle(const Implementation::Ptr&);
345 
346  DtPoint point() const;
347 
361  };
362 
363  template <>
364  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
365  : protected DtFeatureGeometry
366  {
367  public:
368  friend class DtFeatureGeometry;
369 
370  Handle();
371  Handle(const DtFeatureGeometry&);
372  Handle(const Implementation::Ptr&);
373 
374  unsigned numberOfPoints() const;
375  std::auto_ptr<PointVector> points() const;
376 
391  };
392 
393  template <>
394  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
395  : protected DtFeatureGeometry
396  {
397  public:
398  friend class DtFeatureGeometry;
399 
400  Handle();
401  Handle(const DtFeatureGeometry&);
402  Handle(const Implementation::Ptr&);
403 
404  unsigned numberOfBoundaryPoints() const;
405  std::auto_ptr<PointVector> boundaryPoints() const;
406 
407  unsigned numberOfHoles() const;
408  std::auto_ptr<GeometryVector> holes() const;
409 
423  };
424 
425  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
426  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
427 
428  template <DtFeatureGeometry::Type T>
429  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
430  {
431  return str << DtFeatureGeometry(g);
432  }
433 }

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)