VR-Forces 4.2 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  template <Type T> class Handle;
57 
65  typedef Handle<PointType> Point;
66  typedef Handle<PathType> Path;
67  typedef Handle<AreaType> Area;
69 
70  typedef std::vector<DtFeatureGeometry> GeometryVector;
71  typedef std::vector<DtPoint> PointVector;
72 
73  class Implementation;
74  class EmptyImplementation;
75  class RelationshipMatrix;
76 
78  typedef boost::shared_ptr<Implementation> ImplPtr;
79 
81  typedef boost::shared_ptr<const Implementation> ImplCPtr;
82 
85  typedef std::string Hash;
86 
87  typedef tbb::recursive_mutex Mutex;
88 
90  static std::string ToString(Type);
91 
93 
94  static Area MakeBox(Point, double length, double width, double rotation);
95  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
96  static Area MakeBox(const DtProj::Bounds&);
98 
100 
101  static Area MakeArea(const DtProj&, std::vector<DtPoint> points);
102  static Area MakeArea(const DtProj&, std::vector<DtVector> points);
103  static Path MakePath(const DtProj&, std::vector<DtPoint> points);
104  static Path MakePath(const DtProj&, std::vector<DtVector> points);
106 
108 
109  static DtFeatureGeometry MakeSet(const GeometryVector&);
110 
111  template <typename Container>
112  static DtFeatureGeometry MakeSet(const Container& cont)
113  {
114  return MakeSet(GeometryVector(cont.begin(), cont.end()));
115  }
116 
117  template <typename Iterator>
118  static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
119  {
120  return MakeSet(GeometryVector(i,end));
121  }
123 
125  static GeometryVector Flatten(DtFeatureGeometry);
126 
130  static std::vector<Path> MergeLines(DtFeatureGeometry);
131 
135  static DtFeatureGeometry SimplifySet(const GeometryVector&);
136 
139 
141  //DtFeatureGeometry(const ImplPtr&);
142  DtFeatureGeometry(const ImplCPtr&);
144 
146  template <Type T>
147  DtFeatureGeometry(const Handle<T>&);
148 
150  {
151  myImpl = g.myImpl;
152  myHash = g.myHash;
153  return *this;
154  }
155 
156  template <Type T>
157  DtFeatureGeometry& operator=(const Handle<T>& h)
158  {
159  myImpl = h.myImpl;
160  myHash = h.myHash;
161  return *this;
162  }
163 
165  Type type() const;
166 
168  std::string description() const;
169 
171  bool isValid() const;
172 
174  bool isEmpty() const;
175 
177  bool isUnknown() const;
178 
180  bool isPoint() const;
181 
183  bool isPath() const;
184 
186  bool isArea() const;
187 
189  unsigned dimension() const;
190 
193  Area asArea() const;
194 
196  Hash hash() const;
197 
199  ImplCPtr implementation() const;
200 
203  template <typename T>
204  boost::shared_ptr<const T> cast() const;
205 
207  const DtProj& projection() const;
208 
210  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
211 
213  void transform(TransformFunction func);
214 
216  void convert(const DtProj &p);
217 
219  unsigned numberOfPoints() const;
220 
223  std::auto_ptr<PointVector> points() const;
224 
226  std::auto_ptr<PointVector> pointsWithHeight() const;
227 
229  unsigned numberOfSubGeometries() const;
230 
232  std::auto_ptr<GeometryVector> subGeometries() const;
233 
238  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
239 
241  bool equals(DtFeatureGeometry g) const;
242 
244  bool intersects(DtFeatureGeometry g) const;
245 
246  bool overlaps(DtFeatureGeometry g) const;
247 
248  bool covers(DtFeatureGeometry g) const;
249 
250  bool within(DtFeatureGeometry g) const;
251 
252  bool touches(DtFeatureGeometry g) const;
253 
255  DtProj::Bounds bounds() const;
256 
258  DtFeatureGeometry extent() const;
259 
261  double length() const;
262 
264  double area() const;
265 
267  Point centroid() const;
268 
270  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
271 
273  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
274 
276  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
277 
279  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
280 
282  DtFeatureGeometry buffer(double width) const;
283 
286  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
287 
289  DtFeatureGeometry convexHull() const;
290 
292  DtFeatureGeometry boundary() const;
293 
296  DtFeatureGeometry::Point closestPointTo(DtFeatureGeometry g, double* distanceTo = NULL) const;
297 
298  protected:
301  class Lock : boost::noncopyable
302  {
303  public:
305  Lock(const Implementation&);
306 
308  Lock(const Implementation&, const Implementation&);
309 
311  ~Lock();
312 
313  private:
316  };
317 
320  };
321 
322  template <DtFeatureGeometry::Type T>
323  DtFeatureGeometry::DtFeatureGeometry(const Handle<T>& handle)
324  : myImpl(handle.myImpl)
325  {
326  }
327 
328  template <typename T>
329  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
330  {
331  return boost::dynamic_pointer_cast<const T>(implementation());
332  }
333 
336  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
337  {
338  public:
341 
343  typedef std::vector<DtFeatureGeometry> GeometryVector;
344  typedef std::vector<DtPoint> PointVector;
345 
346  virtual ~Implementation();
347 
348  virtual Mutex& getMutex() const;
349 
350  virtual std::string description() const;
351 
352  virtual bool isValid() const;
353 
354  virtual bool isEmpty() const;
355 
356  virtual unsigned dimension() const;
357 
359  virtual DtFeatureGeometry clone() const = 0;
360 
363  virtual bool unique() const;
364 
366  virtual const DtProj & projection() const = 0;
367 
368  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
369 
370  virtual void transform(TransformFunction) = 0;
371 
373  virtual void convert(const DtProj &) = 0;
374 
376  virtual Type type() const = 0;
377 
379  virtual unsigned numberOfPoints() const = 0;
380 
382  virtual std::auto_ptr<PointVector> points() const = 0;
383 
385  virtual unsigned numberOfSubGeometries() const = 0;
386 
388  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
389 
390  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
391 
392  virtual bool equals(DtFeatureGeometry) const = 0;
393 
395  virtual bool intersects(DtFeatureGeometry) const = 0;
396 
397  virtual bool overlaps(DtFeatureGeometry) const = 0;
398 
399  virtual bool covers(DtFeatureGeometry) const = 0;
400 
401  virtual bool within(DtFeatureGeometry) const = 0;
402 
403  virtual bool touches(DtFeatureGeometry) const = 0;
404 
406  virtual DtProj::Bounds bounds() const;
407 
409  virtual DtFeatureGeometry extent() const;
410 
411  virtual double length() const = 0;
412 
413  virtual double area() const = 0;
414 
416  virtual Point centroid() const = 0;
417 
419  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
420 
422  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
423 
425  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
426 
427  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
428 
430  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
431 
433  virtual DtFeatureGeometry convexHull() const = 0;
434 
435  virtual DtFeatureGeometry boundary() const = 0;
436 
439  virtual DtFeatureGeometry::Point closestPointTo(DtFeatureGeometry, double* distanceTo = NULL) const = 0;
440  };
441 
445  class DtFeatureGeometry::EmptyImplementation : public DtFeatureGeometry::Implementation
446  {
447  public:
448  typedef boost::shared_ptr<EmptyImplementation> Ptr;
449 
451 
452  DtFeatureGeometry clone() const;
453 
454  const DtProj & projection() const;
456  void convert(const DtProj &);
457  Type type() const;
458  bool isValid() const;
459 
460  unsigned numberOfPoints() const;
461  std::auto_ptr<PointVector> points() const;
462 
463  unsigned numberOfSubGeometries() const;
464  std::auto_ptr<GeometryVector> subGeometries() const;
465 
466  Point centroid() const;
467  bool equals(DtFeatureGeometry) const;
468  bool intersects(DtFeatureGeometry) const;
469  bool overlaps(DtFeatureGeometry) const;
470  bool covers(DtFeatureGeometry) const;
471  bool within(DtFeatureGeometry) const;
472  bool touches(DtFeatureGeometry) const;
473  double length() const;
474  double area() const;
475  double distanceTo(DtFeatureGeometry, const DtProj&) const;
479  DtFeatureGeometry buffer(double width, unsigned segments) const;
481  DtFeatureGeometry boundary() const;
483 
484  private:
486  };
487 
488  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix : boost::noncopyable
489  {
490  public:
491  virtual ~RelationshipMatrix();
492 
493  virtual bool intersects() const;
494  virtual bool covers() const;
495  virtual bool within() const;
496  virtual bool touches() const;
497  };
498 
499  template <>
500  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
501  : protected DtFeatureGeometry
502  {
503  public:
504  friend class DtFeatureGeometry;
505 
506  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
507 
508  Handle();
509  Handle(const DtFeatureGeometry&);
510  Handle(const Implementation::Ptr&);
511 
512  DtPoint point() const;
513  DtPoint pointWithHeight() const;
514 
537  };
538 
539  template <>
540  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
541  : protected DtFeatureGeometry
542  {
543  public:
544  friend class DtFeatureGeometry;
545 
546  typedef std::vector<DtFeatureGeometry::Path> Vector;
547 
548  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
549 
550  template <typename Container>
551  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
552  {
553  return Make(PointVector(cont.begin(), cont.end()), proj);
554  }
555 
556  template <typename Iterator>
557  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
558  {
559  return Make(PointVector(i,end), proj);
560  }
561 
562  Handle();
563  Handle(const DtFeatureGeometry&);
564  Handle(const Implementation::Ptr&);
565 
566  Path reversed() const;
567 
594  };
595 
596  template <>
597  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
598  : protected DtFeatureGeometry
599  {
600  public:
601  friend class DtFeatureGeometry;
602 
603  typedef std::vector<DtFeatureGeometry::Area> Vector;
604 
605  Handle();
606  Handle(const DtFeatureGeometry&);
607  Handle(const Implementation::Ptr&);
608 
609  Path outerBoundary() const;
610 
611  unsigned numberOfHoles() const;
612  std::auto_ptr<GeometryVector> holes() const;
613 
614  Path findShortestPerimeter(Path) const;
615 
638  };
639 
640  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
641  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
642 
643  template <DtFeatureGeometry::Type T>
644  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
645  {
646  return str << DtFeatureGeometry(g);
647  }
648 }

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)