VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
149 
151  template <Type T>
152  DtFeatureGeometry(const Handle<T>& h)
153  : myImpl(h.myImpl)
154  {
155  }
156 
157  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
158 
159  template <Type T>
160  DtFeatureGeometry& operator=(const Handle<T>& h)
161  {
162  myImpl = h.myImpl;
163  return *this;
164  }
165 
167  Type type() const;
168 
170  std::string description() const;
171 
173  std::string toWKT() const;
174 
176  bool isValid() const;
177 
179  bool isEmpty() const;
180 
182  bool isUnknown() const;
183 
185  bool isPoint() const;
186 
188  bool isPath() const;
189 
191  bool isArea() const;
192 
194  unsigned dimension() const;
195 
198  Area asArea() const;
199 
201  Hash hash() const;
202 
205  template <typename T>
206  boost::shared_ptr<T> cast();
207 
208  template <typename T>
209  boost::shared_ptr<const T> cast() const;
210 
212  const DtProj& projection() const;
213 
215  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
216 
218  void transform(const TransformFunction& func);
219 
221  void convert(const DtProj& p);
222 
224  void convertToLocalTopo();
225 
227  void prepare();
228 
229  DtFeatureGeometry simplify(double tolerance) const;
230 
232  unsigned numberOfPoints() const;
233 
236  std::auto_ptr<PointVector> points() const;
237 
239  std::auto_ptr<PointVector> pointsWithHeight() const;
240 
241  boost::optional<DtPoint> singlePointWithHeight() const;
242 
245  std::auto_ptr<PointVector> pointsWithoutHeight() const;
246 
248  unsigned numberOfSubGeometries() const;
249 
251  std::auto_ptr<GeometryVector> subGeometries() const;
252 
257  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
258 
260  bool equals(DtFeatureGeometry g) const;
261 
263  bool intersects(DtFeatureGeometry g) const;
264 
265  bool overlaps(DtFeatureGeometry g) const;
266 
267  bool crosses(DtFeatureGeometry g) const;
268 
269  bool covers(DtFeatureGeometry g) const;
270 
271  bool within(DtFeatureGeometry g) const;
272 
273  bool touches(DtFeatureGeometry g) const;
274 
275  bool contains(DtFeatureGeometry g) const;
276 
278  DtProj::Bounds bounds() const;
279 
281  DtFeatureGeometry extent() const;
282 
284  double length() const;
285 
287  double area() const;
288 
290  Point centroid() const;
291 
293  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
294 
296  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
297 
299  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
300 
302  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
303 
305  DtFeatureGeometry buffer(double width) const;
306 
309  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
310 
313  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
314 
316  DtFeatureGeometry convexHull() const;
317 
319  DtFeatureGeometry boundary() const;
320 
323  DtFeatureGeometry::Point closestPointTo(
324  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
325 
326  DtFeatureGeometry::Point closestPointTo(
327  DtFeatureGeometry g, double* distanceTo = 0) const;
328 
330  ImplPtr implementation();
331  ImplCPtr implementation() const;
332 
334  {
335  public:
336  virtual ~Mutex();
337 
338  virtual void lock() = 0;
339  virtual void unlock() = 0;
340  };
341 
342  protected:
345  class DT_DLL_features Lock : boost::noncopyable
346  {
347  public:
349  explicit Lock(const Implementation&);
350 
352  explicit Lock(const Implementation&, const Implementation&);
353 
355  ~Lock();
356 
357  private:
360  };
361 
363  };
364 
365  template <typename T>
366  boost::shared_ptr<T> DtFeatureGeometry::cast()
367  {
368  return boost::dynamic_pointer_cast<T>(implementation());
369  }
370 
371  template <typename T>
372  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
373  {
374  return boost::dynamic_pointer_cast<const T>(implementation());
375  }
376 
379  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
380  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
381  {
382  public:
385 
387  typedef std::vector<DtFeatureGeometry> GeometryVector;
388  typedef std::vector<DtPoint> PointVector;
389 
390  virtual ~Implementation();
391 
392  virtual Mutex& getMutex() const;
393 
394  virtual std::string description() const;
395 
396  virtual std::string toWKT() const;
397 
398  virtual bool isValid() const;
399 
400  virtual bool isEmpty() const;
401 
402  virtual unsigned dimension() const;
403 
404  virtual Hash hash() const;
405 
407  virtual DtFeatureGeometry clone() const = 0;
408 
411  virtual bool unique() const;
412 
414  virtual const DtProj & projection() const = 0;
415 
416  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
417 
418  virtual void transform(const TransformFunction&) = 0;
419 
421  virtual void convert(const DtProj &) = 0;
422 
424  virtual void prepare();
425 
426  virtual DtFeatureGeometry simplify(double tolerance) const;
427 
429  virtual Type type() const = 0;
430 
432  virtual unsigned numberOfPoints() const = 0;
433 
435  virtual std::auto_ptr<PointVector> points() const = 0;
436 
438  virtual boost::optional<DtPoint> singlePoint() const;
439 
441  virtual unsigned numberOfSubGeometries() const = 0;
442 
444  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
445 
446  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
447 
448  virtual bool equals(DtFeatureGeometry) const = 0;
449 
451  virtual bool intersects(DtFeatureGeometry) const = 0;
452 
453  virtual bool overlaps(DtFeatureGeometry) const = 0;
454 
455  virtual bool crosses(DtFeatureGeometry) const = 0;
456 
457  virtual bool covers(DtFeatureGeometry) const = 0;
458 
459  virtual bool within(DtFeatureGeometry) const = 0;
460 
461  virtual bool touches(DtFeatureGeometry) const = 0;
462 
463  virtual bool contains(DtFeatureGeometry) const = 0;
464 
466  virtual DtProj::Bounds bounds() const;
467 
469  virtual DtFeatureGeometry extent() const;
470 
471  virtual double length() const = 0;
472 
473  virtual double area() const = 0;
474 
476  virtual Point centroid() const = 0;
477 
479  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
480 
482  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
483 
485  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
486 
487  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
488 
490  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
491 
493  virtual DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const = 0;
494 
496  virtual DtFeatureGeometry convexHull() const = 0;
497 
498  virtual DtFeatureGeometry boundary() const = 0;
499 
502  virtual DtFeatureGeometry::Point closestPointTo(
503  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
504 
505  protected:
506  explicit Implementation();
507  explicit Implementation(const Implementation&);
508 
510  };
511 
517  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
518  {
519  public:
520  typedef boost::shared_ptr<EmptyImplementation> Ptr;
521 
523 
524  DtFeatureGeometry clone() const;
525 
526  const DtProj & projection() const;
527  void transform(const TransformFunction&);
528  void convert(const DtProj &);
529  Type type() const;
530  bool isValid() const;
531 
532  unsigned numberOfPoints() const;
533  std::auto_ptr<PointVector> points() const;
534  boost::optional<DtPoint> singlePoint() const;
535 
536  unsigned numberOfSubGeometries() const;
537  std::auto_ptr<GeometryVector> subGeometries() const;
538 
539  Point centroid() const;
540  bool equals(DtFeatureGeometry) const;
541  bool intersects(DtFeatureGeometry) const;
542  bool overlaps(DtFeatureGeometry) const;
543  bool crosses(DtFeatureGeometry) const;
544  bool covers(DtFeatureGeometry) const;
545  bool within(DtFeatureGeometry) const;
546  bool touches(DtFeatureGeometry) const;
547  bool contains(DtFeatureGeometry) const;
548  double length() const;
549  double area() const;
550  double distanceTo(DtFeatureGeometry, const DtProj&) const;
554  DtFeatureGeometry buffer(double width, unsigned segments) const;
555  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
557  DtFeatureGeometry boundary() const;
559  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
560 
561  private:
563  };
564 
565  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
566  : boost::noncopyable
567  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
568  {
569  public:
570  virtual ~RelationshipMatrix();
571 
572  virtual bool equals() const;
573  virtual bool intersects() const;
574  virtual bool disjoint() const;
575  virtual bool covers() const;
576  virtual bool coveredBy() const;
577  virtual bool within() const;
578  virtual bool touches() const;
579  virtual bool overlaps() const;
580  virtual bool crosses() const;
581  virtual bool contains() const;
582  };
583 
584  template <>
585  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
586  : public DtFeatureGeometry
587  {
588  public:
589  friend class DtFeatureGeometry;
590 
591  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
592  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
593 
594  Handle();
595  Handle(const DtFeatureGeometry&);
596  Handle(const Implementation::Ptr&);
597 
598  Handle(const DtPoint&, const DtProj& proj);
599  Handle(const DtVector&, const DtProj& proj);
600 
601  DtPoint point() const;
602  DtPoint pointWithHeight() const;
603  DtPoint pointWithoutHeight() const;
604  };
605 
606  template <>
607  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
608  : public DtFeatureGeometry
609  {
610  public:
611  friend class DtFeatureGeometry;
612 
613  typedef std::vector<DtFeatureGeometry::Path> Vector;
614 
615  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
616 
617  static DtFeatureGeometry::Path Make(
618  const DtPoint& p1, const DtPoint& p2,
619  const DtProj& proj);
620 
621  static DtFeatureGeometry::Path Make(
622  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
623  const DtProj& proj);
624 
625  template <typename Container>
626  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
627  {
628  return Make(PointVector(cont.begin(), cont.end()), proj);
629  }
630 
631  template <typename Iterator>
632  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
633  {
634  return Make(PointVector(i,end), proj);
635  }
636 
637  Handle();
638  Handle(const DtFeatureGeometry&);
639  Handle(const Implementation::Ptr&);
640 
641  Path reversed() const;
642  };
643 
644  template <>
645  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
646  : public DtFeatureGeometry
647  {
648  public:
649  friend class DtFeatureGeometry;
650 
651  typedef std::vector<DtFeatureGeometry::Area> Vector;
652 
653  Handle();
654  Handle(const DtFeatureGeometry&);
655  Handle(const Implementation::Ptr&);
656 
657  static DtFeatureGeometry::Area Make(const PointVector& points, const DtProj& proj);
658 
659  Path outerBoundary() const;
660 
661  unsigned numberOfHoles() const;
662  std::auto_ptr<GeometryVector> holes() const;
663 
664  Path findShortestPerimeter(Path) const;
665  };
666 
667  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
668  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
669 
670  template <DtFeatureGeometry::Type T>
671  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
672  {
673  return str << DtFeatureGeometry(g);
674  }
675 }
676 
679 DT_DEFINE_OBJECT_DEBUGGER_NAME(MAKVRinTerra::DtFeatureGeometry::RelationshipMatrix);

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)