VR-Forces Developer's Guide
 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) 2020 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 {
40 #ifdef DtObjectDebugger_Enable
41  : public DtObjectDebugger<DtFeatureGeometry>
42 #endif
43  {
44  public:
47 
53  typedef int Type;
54 
55  static const int UnknownType = -1;
56  static const int PointType = 0;
57  static const int PathType = 1;
58  static const int AreaType = 2;
59 
60  template <Type T> class Handle;
61 
73 
74  typedef std::vector<DtFeatureGeometry> GeometryVector;
75  typedef std::vector<DtPoint> PointVector;
76 
77  class Implementation;
78  class EmptyImplementation;
79  class RelationshipMatrix;
80 
82  typedef boost::shared_ptr<Implementation> ImplPtr;
83 
85  typedef boost::shared_ptr<const Implementation> ImplCPtr;
86 
89  typedef std::string Hash;
90 
92  static std::string ToString(Type);
93 
95  static DtFeatureGeometry FromWKT(const std::string&, const DtProj&);
96 
98 
99  static Area MakeBox(Point, double length, double width, double rotation);
100  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
101  static Area MakeBox(const DtProj::Bounds&);
103 
105 
106  static Area MakeArea(const DtProj&, const std::vector<DtPoint>& points);
107  static Area MakeArea(const DtProj&, const std::vector<DtVector>& points);
108  static Path MakePath(const DtProj&, const std::vector<DtPoint>& points);
109  static Path MakePath(const DtProj&, const std::vector<DtVector>& points);
111 
113 
114  static DtFeatureGeometry MakeSet(const GeometryVector&, const DtProj&);
115  static DtFeatureGeometry MakeSet(const GeometryVector&);
116 
117  template <typename Container>
118  static DtFeatureGeometry MakeSet(const Container& cont)
119  {
120  return MakeSet(GeometryVector(cont.begin(), cont.end()));
121  }
122 
123  template <typename Iterator>
124  static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
125  {
126  return MakeSet(GeometryVector(i,end));
127  }
129 
131  static GeometryVector Flatten(DtFeatureGeometry);
132 
136  static std::vector<Path> MergeLines(DtFeatureGeometry);
137 
141  static DtFeatureGeometry SimplifySet(const GeometryVector&, const DtProj&);
142  static DtFeatureGeometry SimplifySet(const GeometryVector&);
143 
146 
148  //DtFeatureGeometry(const ImplPtr&);
149  DtFeatureGeometry(const ImplCPtr&);
150  DtFeatureGeometry(Implementation*);
151 
154 
156  template <Type T>
158  : myImpl(h.myImpl)
159  {
160  }
161 
162  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
163 
164  template <Type T>
166  {
167  myImpl = h.myImpl;
168  return *this;
169  }
170 
172  Type type() const;
173 
175  std::string description() const;
176 
178  std::string toWKT() const;
179 
181  bool isValid() const;
182 
184  bool isEmpty() const;
185 
187  bool isUnknown() const;
188 
190  bool isPoint() const;
191 
193  bool isPath() const;
194 
196  bool isArea() const;
197 
199  unsigned dimension() const;
200 
203  Area asArea() const;
204 
206  Hash hash() const;
207 
210  template <typename T>
211  boost::shared_ptr<T> cast();
212 
213  template <typename T>
214  boost::shared_ptr<const T> cast() const;
215 
217  const DtProj& projection() const;
218 
220  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
221 
223  void transform(const TransformFunction& func);
224 
226  void convert(const DtProj& p);
227 
229  void convertToLocalTopo();
230 
232  void prepare();
233 
234  DtFeatureGeometry simplify(double tolerance) const;
235 
237  unsigned numberOfPoints() const;
238 
241  std::auto_ptr<PointVector> points() const;
242 
244  std::auto_ptr<PointVector> pointsWithHeight() const;
245 
246  boost::optional<DtPoint> singlePointWithHeight() const;
247 
250  std::auto_ptr<PointVector> pointsWithoutHeight() const;
251 
253  unsigned numberOfSubGeometries() const;
254 
256  std::auto_ptr<GeometryVector> subGeometries() const;
257 
262  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
263 
265  bool equals(DtFeatureGeometry g) const;
266 
268  bool intersects(DtFeatureGeometry g) const;
269 
270  bool overlaps(DtFeatureGeometry g) const;
271 
272  bool crosses(DtFeatureGeometry g) const;
273 
274  bool covers(DtFeatureGeometry g) const;
275 
276  bool within(DtFeatureGeometry g) const;
277 
278  bool touches(DtFeatureGeometry g) const;
279 
280  bool contains(DtFeatureGeometry g) const;
281 
283  DtProj::Bounds bounds() const;
284 
286  DtFeatureGeometry extent() const;
287 
289  double length() const;
290 
292  double area() const;
293 
295  Point centroid() const;
296 
298  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
299 
301  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
302 
304  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
305 
307  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
308 
310  DtFeatureGeometry buffer(double width) const;
311 
314  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
315 
318  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
319 
321  DtFeatureGeometry convexHull() const;
322 
324  DtFeatureGeometry boundary() const;
325 
328  DtFeatureGeometry::Point closestPointTo(
329  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
330 
331  DtFeatureGeometry::Point closestPointTo(
332  DtFeatureGeometry g, double* distanceTo = 0) const;
333 
335  ImplPtr implementation();
336  ImplCPtr implementation() const;
337 
339  {
340  public:
341  virtual ~Mutex();
342 
343  virtual void lock() = 0;
344  virtual void unlock() = 0;
345  };
346 
347  protected:
350  class DT_DLL_features Lock : boost::noncopyable
351  {
352  public:
354  explicit Lock(const Implementation&);
355 
357  explicit Lock(const Implementation&, const Implementation&);
358 
360  ~Lock();
361 
362  private:
365  };
366 
368  };
369 
370  template <typename T>
371  boost::shared_ptr<T> DtFeatureGeometry::cast()
372  {
373  return boost::dynamic_pointer_cast<T>(implementation());
374  }
375 
376  template <typename T>
377  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
378  {
379  return boost::dynamic_pointer_cast<const T>(implementation());
380  }
381 
383  class DT_DLL_features DtFeatureGeometry::Implementation
384  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
385 #ifdef DtObjectDebugger_Enable
386  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
387 #endif
388  {
389  public:
392 
394  typedef std::vector<DtFeatureGeometry> GeometryVector;
395  typedef std::vector<DtPoint> PointVector;
396 
397  virtual ~Implementation();
398 
399  virtual Mutex& getMutex() const;
400 
401  virtual std::string description() const;
402 
403  virtual std::string toWKT() const;
404 
405  virtual bool isValid() const;
406 
407  virtual bool isEmpty() const;
408 
409  virtual unsigned dimension() const;
410 
411  virtual Hash hash() const;
412 
414  virtual DtFeatureGeometry clone() const = 0;
415 
418  virtual bool unique() const;
419 
421  virtual const DtProj & projection() const = 0;
422 
423  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
424 
425  virtual void transform(const TransformFunction&) = 0;
426 
428  virtual void convert(const DtProj &) = 0;
429 
431  virtual void prepare();
432 
433  virtual DtFeatureGeometry simplify(double tolerance) const;
434 
436  virtual Type type() const = 0;
437 
439  virtual unsigned numberOfPoints() const = 0;
440 
442  virtual std::auto_ptr<PointVector> points() const = 0;
443 
445  virtual boost::optional<DtPoint> singlePoint() const;
446 
448  virtual unsigned numberOfSubGeometries() const = 0;
449 
451  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
452 
453  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
454 
455  virtual bool equals(DtFeatureGeometry) const = 0;
456 
458  virtual bool intersects(DtFeatureGeometry) const = 0;
459 
460  virtual bool overlaps(DtFeatureGeometry) const = 0;
461 
462  virtual bool crosses(DtFeatureGeometry) const = 0;
463 
464  virtual bool covers(DtFeatureGeometry) const = 0;
465 
466  virtual bool within(DtFeatureGeometry) const = 0;
467 
468  virtual bool touches(DtFeatureGeometry) const = 0;
469 
470  virtual bool contains(DtFeatureGeometry) const = 0;
471 
473  virtual DtProj::Bounds bounds() const;
474 
476  virtual DtFeatureGeometry extent() const;
477 
478  virtual double length() const = 0;
479 
480  virtual double area() const = 0;
481 
483  virtual Point centroid() const = 0;
484 
486  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
487 
489  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
490 
492  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
493 
494  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
495 
497  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
498 
500  virtual DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const = 0;
501 
503  virtual DtFeatureGeometry convexHull() const = 0;
504 
505  virtual DtFeatureGeometry boundary() const = 0;
506 
509  virtual DtFeatureGeometry::Point closestPointTo(
510  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
511 
512  protected:
513  explicit Implementation();
514  explicit Implementation(const Implementation&);
515 
517  };
518 
524 #ifdef DtObjectDebugger_Enable
525  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
526 #endif
527  {
528  public:
529  typedef boost::shared_ptr<EmptyImplementation> Ptr;
530 
532 
533  DtFeatureGeometry clone() const;
534 
535  const DtProj & projection() const;
536  void transform(const TransformFunction&);
537  void convert(const DtProj &);
538  Type type() const;
539  bool isValid() const;
540 
541  unsigned numberOfPoints() const;
542  std::auto_ptr<PointVector> points() const;
543  boost::optional<DtPoint> singlePoint() const;
544 
545  unsigned numberOfSubGeometries() const;
546  std::auto_ptr<GeometryVector> subGeometries() const;
547 
548  Point centroid() const;
549  bool equals(DtFeatureGeometry) const;
550  bool intersects(DtFeatureGeometry) const;
551  bool overlaps(DtFeatureGeometry) const;
552  bool crosses(DtFeatureGeometry) const;
553  bool covers(DtFeatureGeometry) const;
554  bool within(DtFeatureGeometry) const;
555  bool touches(DtFeatureGeometry) const;
556  bool contains(DtFeatureGeometry) const;
557  double length() const;
558  double area() const;
559  double distanceTo(DtFeatureGeometry, const DtProj&) const;
563  DtFeatureGeometry buffer(double width, unsigned segments) const;
564  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
566  DtFeatureGeometry boundary() const;
568  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
569 
570  private:
572  };
573 
574  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
575  : boost::noncopyable
576 #ifdef DtObjectDebugger_Enable
577  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
578 #endif
579  {
580  public:
581  virtual ~RelationshipMatrix();
582 
583  virtual bool equals() const;
584  virtual bool intersects() const;
585  virtual bool disjoint() const;
586  virtual bool covers() const;
587  virtual bool coveredBy() const;
588  virtual bool within() const;
589  virtual bool touches() const;
590  virtual bool overlaps() const;
591  virtual bool crosses() const;
592  virtual bool contains() const;
593  };
594 
595  template <>
596  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
597  : public DtFeatureGeometry
598  {
599  public:
600  friend class DtFeatureGeometry;
601 
602  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
603  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
604 
605  Handle();
606  Handle(const DtFeatureGeometry&);
610  Handle(const DtFeatureGeometry&, bool fastCreation);
611  Handle(const Implementation::Ptr&);
612 
613  Handle(const DtPoint&, const DtProj& proj);
614  Handle(const DtVector&, const DtProj& proj);
615 
616  DtPoint point() const;
617  DtPoint pointWithHeight() const;
618  DtPoint pointWithoutHeight() const;
619  };
620 
621  template <>
622  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
623  : public DtFeatureGeometry
624  {
625  public:
626  friend class DtFeatureGeometry;
627 
628  typedef std::vector<DtFeatureGeometry::Path> Vector;
629 
630  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
631 
632  static DtFeatureGeometry::Path Make(
633  const DtPoint& p1, const DtPoint& p2,
634  const DtProj& proj);
635 
636  static DtFeatureGeometry::Path Make(
637  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
638  const DtProj& proj);
639 
640  template <typename Container>
641  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
642  {
643  return Make(PointVector(cont.begin(), cont.end()), proj);
644  }
645 
646  template <typename Iterator>
647  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
648  {
649  return Make(PointVector(i,end), proj);
650  }
651 
652  Handle();
653  Handle(const DtFeatureGeometry&);
654  Handle(const Implementation::Ptr&);
655 
656  Path reversed() const;
657  };
658 
659  template <>
660  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
661  : public DtFeatureGeometry
662  {
663  public:
664  friend class DtFeatureGeometry;
665 
666  typedef std::vector<DtFeatureGeometry::Area> Vector;
667 
668  Handle();
669  Handle(const DtFeatureGeometry&);
670  Handle(const Implementation::Ptr&);
671 
672  static DtFeatureGeometry::Area Make(const PointVector& points, const DtProj& proj);
673 
674  Path outerBoundary() const;
675 
676  unsigned numberOfHoles() const;
677  std::auto_ptr<GeometryVector> holes() const;
678 
679  Path findShortestPerimeter(Path) const;
680  };
681 
682  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
683 }
684 
687 DT_DEFINE_OBJECT_DEBUGGER_NAME(MAKVRinTerra::DtFeatureGeometry::RelationshipMatrix);
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
std::vector< DtPoint > PointVector
Definition: featureGeometry.h:75
DtTaggedException< struct InvalidGeometryTag > InvalidGeometry
Definition: featureGeometry.h:45
int Type
Type of geometry represented.
Definition: featureGeometry.h:53
boost::shared_ptr< const Implementation > ImplCPtr
Shared pointer to const Implementation.
Definition: featureGeometry.h:85
Mutex * mutex2
Definition: featureGeometry.h:364
DtFeatureGeometry::Type Type
Definition: featureGeometry.h:393
DtFeatureGeometry(const Handle< T > &h)
Create a geometry from a handle.
Definition: featureGeometry.h:157
DtFeatureGeometry buffer(double width, unsigned segments) const
DtFeatureGeometry differenceWith(DtFeatureGeometry g) const
boost::optional< DtPoint > singlePoint() const
std::vector< DtFeatureGeometry::Path > Vector
Definition: featureGeometry.h:628
std::string Hash
DtFeatureGeometry caches the hashes for the geometries can be differentiated quickly.
Definition: featureGeometry.h:89
ImplPtr implementation()
Get implementation of this geometry.
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
Default on in debug, off in release.
Definition: objectCounter.h:27
Definition: featureGeometry.h:60
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
Definition: proj.h:68
Handle< AreaType > Area
Definition: featureGeometry.h:71
static DtFeatureGeometry MakeSet(const Container &cont)
Functions for creating set or collection geometries.
Definition: featureGeometry.h:118
Definition: featureGeometry.h:338
boost::shared_ptr< EmptyImplementation > Ptr
Definition: featureGeometry.h:529
DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const
ImplPtr myImpl
Definition: featureGeometry.h:367
DtFeatureGeometry::ImplCPtr CPtr
Definition: featureGeometry.h:391
DtTaggedException< struct BadGeometryCastTag > BadGeometryCast
Definition: featureGeometry.h:46
Handle< PointType > Point
Definition: featureGeometry.h:69
Represents some coordinate system. The terms &quot;coordinate system&quot;, &quot;projection&quot;, &quot;spatial reference&quot;...
Definition: proj.h:44
std::auto_ptr< PointVector > points() const
Mutex * mutex1
Definition: featureGeometry.h:363
boost::shared_ptr< const DtProj > CPtr
Definition: proj.h:48
Scoped lock which will lock two Implementation mutexes in a predefined order to avoid deadlock...
Definition: featureGeometry.h:350
Handle< PathType > Path
Definition: featureGeometry.h:70
DtFeatureGeometry unionWith(DtFeatureGeometry g) const
std::vector< DtFeatureGeometry::Area > Vector
Definition: featureGeometry.h:666
boost::function< DtPoint(const DtPoint &)> TransformFunction
Callback for transform().
Definition: featureGeometry.h:220
Create a new MAK exception type that inherits from boost::exception. Tag is what differentiates this ...
Definition: taggedException.h:15
static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj &proj)
Definition: featureGeometry.h:647
std::auto_ptr< GeometryVector > subGeometries() const
DtFeatureGeometry Unknown
Definition: featureGeometry.h:68
std::vector< DtFeatureGeometry > GeometryVector
Definition: featureGeometry.h:74
DtProj::CPtr myProjection
Definition: featureGeometry.h:571
Implementation which represents an empty geometry. Empty geometry do have 0 points, do not intersect with any other geometries, and are infinitely far away from all other geometries.
Definition: featureGeometry.h:522
DT_DLL_VRVCORE double length(const makVrv::DtCoordinateSystem &, const std::vector< DtVector > &vertices)
Returns the total distance of a segmented line defined by the provided vector of vertices. Coordinates are in local database coordinates. The coordinate system is used to convert between the local database coordinates and geocentric. All distance is in 2D – the Z value is ignored.
DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const
static DtFeatureGeometry::Path Make(const Container &cont, const DtProj &proj)
Definition: featureGeometry.h:641
double distanceTo(DtFeatureGeometry, const DtProj &) const
Hash myHash
Definition: featureGeometry.h:516
DT_DLL_vrfutil bool intersects(const DtVector &localPoint1, const DtVector &localPoint2, const DtLocalVertexList &localVertexList, const Coordinate_System &coordinateSystem)
Returns true if the line segment localPoint1-localPoint2 intersects any line segment in localVert...
boost::shared_ptr< Implementation > ImplPtr
Shared pointer to Implementation.
Definition: featureGeometry.h:79
DtFeatureGeometry::ImplPtr Ptr
Definition: featureGeometry.h:390
DtFeatureGeometry::Point closestPointTo(DtFeatureGeometry g, const DtProj &, double *distanceTo=0) const
boost::shared_ptr< T > cast()
Get implementation as a specific type.
Definition: featureGeometry.h:371
Represents a feature geometry.
Definition: featureGeometry.h:39
Definition: point.h:34
DtFeatureGeometry & operator=(const Handle< T > &h)
Definition: featureGeometry.h:165
static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
Functions for creating set or collection geometries.
Definition: featureGeometry.h:124

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)