VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <geometry/point.h>
16 #include <vrfutil/objectCounter.h>
17 
18 #include <boost/function.hpp>
19 
20 #include <iosfwd>
21 
22 namespace MAKVRinTerra
23 {
36  : public DtObjectDebugger<DtFeatureGeometry>
37  {
38  public:
41 
47  enum Type
48  {
49  UnknownType = -1,
50  PointType = 0,
51  PathType = 1,
52  AreaType = 2,
53  };
54 
55  template <Type T> class Handle;
56 
64  typedef Handle<PointType> Point;
65  typedef Handle<PathType> Path;
66  typedef Handle<AreaType> Area;
68 
69  typedef std::vector<DtFeatureGeometry> GeometryVector;
70  typedef std::vector<DtPoint> PointVector;
71 
72  class Implementation;
73  class EmptyImplementation;
74  class RelationshipMatrix;
75 
77  typedef boost::shared_ptr<Implementation> ImplPtr;
78 
80  typedef boost::shared_ptr<const Implementation> ImplCPtr;
81 
84  typedef std::string Hash;
85 
87  static std::string ToString(Type);
88 
90  static DtFeatureGeometry FromWKT(const std::string&, const DtProj&);
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&, const std::vector<DtPoint>& points);
102  static Area MakeArea(const DtProj&, const std::vector<DtVector>& points);
103  static Path MakePath(const DtProj&, const std::vector<DtPoint>& points);
104  static Path MakePath(const DtProj&, const std::vector<DtVector>& points);
106 
108 
109  static DtFeatureGeometry MakeSet(const GeometryVector&, const DtProj&);
110  static DtFeatureGeometry MakeSet(const GeometryVector&);
111 
112  template <typename Container>
113  static DtFeatureGeometry MakeSet(const Container& cont)
114  {
115  return MakeSet(GeometryVector(cont.begin(), cont.end()));
116  }
117 
118  template <typename Iterator>
119  static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
120  {
121  return MakeSet(GeometryVector(i,end));
122  }
124 
126  static GeometryVector Flatten(DtFeatureGeometry);
127 
131  static std::vector<Path> MergeLines(DtFeatureGeometry);
132 
136  static DtFeatureGeometry SimplifySet(const GeometryVector&, const DtProj&);
137  static DtFeatureGeometry SimplifySet(const GeometryVector&);
138 
141 
143  //DtFeatureGeometry(const ImplPtr&);
144  DtFeatureGeometry(const ImplCPtr&);
146 
148  template <Type T>
149  DtFeatureGeometry(const Handle<T>& h)
150  : myImpl(h.myImpl)
151  {
152  }
153 
154  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
155 
156  template <Type T>
157  DtFeatureGeometry& operator=(const Handle<T>& h)
158  {
159  myImpl = h.myImpl;
160  return *this;
161  }
162 
164  Type type() const;
165 
167  std::string description() const;
168 
170  std::string toWKT() const;
171 
173  bool isValid() const;
174 
176  bool isEmpty() const;
177 
179  bool isUnknown() const;
180 
182  bool isPoint() const;
183 
185  bool isPath() const;
186 
188  bool isArea() const;
189 
191  unsigned dimension() const;
192 
195  Area asArea() const;
196 
198  Hash hash() const;
199 
202  template <typename T>
203  boost::shared_ptr<T> cast();
204 
205  template <typename T>
206  boost::shared_ptr<const T> cast() const;
207 
209  const DtProj& projection() const;
210 
212  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
213 
215  void transform(const TransformFunction& func);
216 
218  void convert(const DtProj& p);
219 
221  void convertToLocalTopo();
222 
224  void prepare();
225 
226  DtFeatureGeometry simplify(double tolerance) const;
227 
229  unsigned numberOfPoints() const;
230 
233  std::auto_ptr<PointVector> points() const;
234 
236  std::auto_ptr<PointVector> pointsWithHeight() const;
237 
238  boost::optional<DtPoint> singlePointWithHeight() const;
239 
242  std::auto_ptr<PointVector> pointsWithoutHeight() const;
243 
245  unsigned numberOfSubGeometries() const;
246 
248  std::auto_ptr<GeometryVector> subGeometries() const;
249 
254  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
255 
257  bool equals(DtFeatureGeometry g) const;
258 
260  bool intersects(DtFeatureGeometry g) const;
261 
262  bool overlaps(DtFeatureGeometry g) const;
263 
264  bool crosses(DtFeatureGeometry g) const;
265 
266  bool covers(DtFeatureGeometry g) const;
267 
268  bool within(DtFeatureGeometry g) const;
269 
270  bool touches(DtFeatureGeometry g) const;
271 
272  bool contains(DtFeatureGeometry g) const;
273 
275  DtProj::Bounds bounds() const;
276 
278  DtFeatureGeometry extent() const;
279 
281  double length() const;
282 
284  double area() const;
285 
287  Point centroid() const;
288 
290  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
291 
293  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
294 
296  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
297 
299  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
300 
302  DtFeatureGeometry buffer(double width) const;
303 
306  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
307 
310  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
311 
313  DtFeatureGeometry convexHull() const;
314 
316  DtFeatureGeometry boundary() const;
317 
320  DtFeatureGeometry::Point closestPointTo(
321  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
322 
323  DtFeatureGeometry::Point closestPointTo(
324  DtFeatureGeometry g, double* distanceTo = 0) const;
325 
327  ImplPtr implementation();
328  ImplCPtr implementation() const;
329 
331  {
332  public:
333  virtual ~Mutex();
334 
335  virtual void lock() = 0;
336  virtual void unlock() = 0;
337  };
338 
339  protected:
342  class DT_DLL_features Lock : boost::noncopyable
343  {
344  public:
346  explicit Lock(const Implementation&);
347 
349  explicit Lock(const Implementation&, const Implementation&);
350 
352  ~Lock();
353 
354  private:
357  };
358 
360  };
361 
362  template <typename T>
363  boost::shared_ptr<T> DtFeatureGeometry::cast()
364  {
365  return boost::dynamic_pointer_cast<T>(implementation());
366  }
367 
368  template <typename T>
369  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
370  {
371  return boost::dynamic_pointer_cast<const T>(implementation());
372  }
373 
376  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
377  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
378  {
379  public:
382 
384  typedef std::vector<DtFeatureGeometry> GeometryVector;
385  typedef std::vector<DtPoint> PointVector;
386 
387  virtual ~Implementation();
388 
389  virtual Mutex& getMutex() const;
390 
391  virtual std::string description() const;
392 
393  virtual std::string toWKT() const;
394 
395  virtual bool isValid() const;
396 
397  virtual bool isEmpty() const;
398 
399  virtual unsigned dimension() const;
400 
401  virtual Hash hash() const;
402 
404  virtual DtFeatureGeometry clone() const = 0;
405 
408  virtual bool unique() const;
409 
411  virtual const DtProj & projection() const = 0;
412 
413  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
414 
415  virtual void transform(const TransformFunction&) = 0;
416 
418  virtual void convert(const DtProj &) = 0;
419 
421  virtual void prepare();
422 
423  virtual DtFeatureGeometry simplify(double tolerance) const;
424 
426  virtual Type type() const = 0;
427 
429  virtual unsigned numberOfPoints() const = 0;
430 
432  virtual std::auto_ptr<PointVector> points() const = 0;
433 
435  virtual boost::optional<DtPoint> singlePoint() const;
436 
438  virtual unsigned numberOfSubGeometries() const = 0;
439 
441  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
442 
443  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
444 
445  virtual bool equals(DtFeatureGeometry) const = 0;
446 
448  virtual bool intersects(DtFeatureGeometry) const = 0;
449 
450  virtual bool overlaps(DtFeatureGeometry) const = 0;
451 
452  virtual bool crosses(DtFeatureGeometry) const = 0;
453 
454  virtual bool covers(DtFeatureGeometry) const = 0;
455 
456  virtual bool within(DtFeatureGeometry) const = 0;
457 
458  virtual bool touches(DtFeatureGeometry) const = 0;
459 
460  virtual bool contains(DtFeatureGeometry) const = 0;
461 
463  virtual DtProj::Bounds bounds() const;
464 
466  virtual DtFeatureGeometry extent() const;
467 
468  virtual double length() const = 0;
469 
470  virtual double area() const = 0;
471 
473  virtual Point centroid() const = 0;
474 
476  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
477 
479  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
480 
482  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
483 
484  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
485 
487  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
488 
490  virtual DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const = 0;
491 
493  virtual DtFeatureGeometry convexHull() const = 0;
494 
495  virtual DtFeatureGeometry boundary() const = 0;
496 
499  virtual DtFeatureGeometry::Point closestPointTo(
500  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
501 
502  protected:
503  explicit Implementation();
504  explicit Implementation(const Implementation&);
505 
507  };
508 
514  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
515  {
516  public:
517  typedef boost::shared_ptr<EmptyImplementation> Ptr;
518 
520 
521  DtFeatureGeometry clone() const;
522 
523  const DtProj & projection() const;
524  void transform(const TransformFunction&);
525  void convert(const DtProj &);
526  Type type() const;
527  bool isValid() const;
528 
529  unsigned numberOfPoints() const;
530  std::auto_ptr<PointVector> points() const;
531  boost::optional<DtPoint> singlePoint() const;
532 
533  unsigned numberOfSubGeometries() const;
534  std::auto_ptr<GeometryVector> subGeometries() const;
535 
536  Point centroid() const;
537  bool equals(DtFeatureGeometry) const;
538  bool intersects(DtFeatureGeometry) const;
539  bool overlaps(DtFeatureGeometry) const;
540  bool crosses(DtFeatureGeometry) const;
541  bool covers(DtFeatureGeometry) const;
542  bool within(DtFeatureGeometry) const;
543  bool touches(DtFeatureGeometry) const;
544  bool contains(DtFeatureGeometry) const;
545  double length() const;
546  double area() const;
547  double distanceTo(DtFeatureGeometry, const DtProj&) const;
551  DtFeatureGeometry buffer(double width, unsigned segments) const;
552  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
554  DtFeatureGeometry boundary() const;
556  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
557 
558  private:
560  };
561 
562  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
563  : boost::noncopyable
564  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
565  {
566  public:
567  virtual ~RelationshipMatrix();
568 
569  virtual bool equals() const;
570  virtual bool intersects() const;
571  virtual bool disjoint() const;
572  virtual bool covers() const;
573  virtual bool coveredBy() const;
574  virtual bool within() const;
575  virtual bool touches() const;
576  virtual bool overlaps() const;
577  virtual bool crosses() const;
578  virtual bool contains() const;
579  };
580 
581  template <>
582  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
583  : public DtFeatureGeometry
584  {
585  public:
586  friend class DtFeatureGeometry;
587 
588  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
589  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
590 
591  Handle();
592  Handle(const DtFeatureGeometry&);
593  Handle(const Implementation::Ptr&);
594 
595  Handle(const DtPoint&, const DtProj& proj);
596  Handle(const DtVector&, const DtProj& proj);
597 
598  DtPoint point() const;
599  DtPoint pointWithHeight() const;
600  DtPoint pointWithoutHeight() const;
601  };
602 
603  template <>
604  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
605  : public DtFeatureGeometry
606  {
607  public:
608  friend class DtFeatureGeometry;
609 
610  typedef std::vector<DtFeatureGeometry::Path> Vector;
611 
612  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
613 
614  static DtFeatureGeometry::Path Make(
615  const DtPoint& p1, const DtPoint& p2,
616  const DtProj& proj);
617 
618  static DtFeatureGeometry::Path Make(
619  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
620  const DtProj& proj);
621 
622  template <typename Container>
623  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
624  {
625  return Make(PointVector(cont.begin(), cont.end()), proj);
626  }
627 
628  template <typename Iterator>
629  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
630  {
631  return Make(PointVector(i,end), proj);
632  }
633 
634  Handle();
635  Handle(const DtFeatureGeometry&);
636  Handle(const Implementation::Ptr&);
637 
638  Path reversed() const;
639  };
640 
641  template <>
642  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
643  : public DtFeatureGeometry
644  {
645  public:
646  friend class DtFeatureGeometry;
647 
648  typedef std::vector<DtFeatureGeometry::Area> Vector;
649 
650  Handle();
651  Handle(const DtFeatureGeometry&);
652  Handle(const Implementation::Ptr&);
653 
654  Path outerBoundary() const;
655 
656  unsigned numberOfHoles() const;
657  std::auto_ptr<GeometryVector> holes() const;
658 
659  Path findShortestPerimeter(Path) const;
660  };
661 
662  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
663  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
664 
665  template <DtFeatureGeometry::Type T>
666  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
667  {
668  return str << DtFeatureGeometry(g);
669  }
670 }
671 
674 DT_DEFINE_OBJECT_DEBUGGER_NAME(MAKVRinTerra::DtFeatureGeometry::RelationshipMatrix);

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)