VR-Forces 4.10 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) 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 {
36 #ifdef DtObjectDebugger_Enable
37  : public DtObjectDebugger<DtFeatureGeometry>
38 #endif
39  {
40  public:
43 
49  typedef int Type;
50 
51  static const int UnknownType = -1;
52  static const int PointType = 0;
53  static const int PathType = 1;
54  static const int AreaType = 2;
55 
56  template <Type T> class Handle;
57 
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 
88  static std::string ToString(Type);
89 
91  static DtFeatureGeometry FromWKT(const std::string&, const DtProj&);
92 
94 
95  static Area MakeBox(Point, double length, double width, double rotation);
96  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
97  static Area MakeBox(const DtProj::Bounds&);
99 
101 
102  static Area MakeArea(const DtProj&, const std::vector<DtPoint>& points);
103  static Area MakeArea(const DtProj&, const std::vector<DtVector>& points);
104  static Path MakePath(const DtProj&, const std::vector<DtPoint>& points);
105  static Path MakePath(const DtProj&, const std::vector<DtVector>& points);
107 
109 
110  static DtFeatureGeometry MakeSet(const GeometryVector&, const DtProj&);
111  static DtFeatureGeometry MakeSet(const GeometryVector&);
112 
113  template <typename Container>
114  static DtFeatureGeometry MakeSet(const Container& cont)
115  {
116  return MakeSet(GeometryVector(cont.begin(), cont.end()));
117  }
118 
119  template <typename Iterator>
120  static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
121  {
122  return MakeSet(GeometryVector(i,end));
123  }
125 
127  static GeometryVector Flatten(DtFeatureGeometry);
128 
132  static std::vector<Path> MergeLines(DtFeatureGeometry);
133 
137  static DtFeatureGeometry SimplifySet(const GeometryVector&, const DtProj&);
138  static DtFeatureGeometry SimplifySet(const GeometryVector&);
139 
142 
144  //DtFeatureGeometry(const ImplPtr&);
145  DtFeatureGeometry(const ImplCPtr&);
146  DtFeatureGeometry(Implementation*);
147 
150 
152  template <Type T>
154  : myImpl(h.myImpl)
155  {
156  }
157 
158  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
159 
160  template <Type T>
162  {
163  myImpl = h.myImpl;
164  return *this;
165  }
166 
168  Type type() const;
169 
171  std::string description() const;
172 
174  std::string toWKT() const;
175 
177  bool isValid() const;
178 
180  bool isEmpty() const;
181 
183  bool isUnknown() const;
184 
186  bool isPoint() const;
187 
189  bool isPath() const;
190 
192  bool isArea() const;
193 
195  unsigned dimension() const;
196 
199  Area asArea() const;
200 
202  Hash hash() const;
203 
206  template <typename T>
207  boost::shared_ptr<T> cast();
208 
209  template <typename T>
210  boost::shared_ptr<const T> cast() const;
211 
213  const DtProj& projection() const;
214 
216  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
217 
219  void transform(const TransformFunction& func);
220 
222  void convert(const DtProj& p);
223 
225  void convertToLocalTopo();
226 
228  void prepare();
229 
230  DtFeatureGeometry simplify(double tolerance) const;
231 
233  unsigned numberOfPoints() const;
234 
237  std::auto_ptr<PointVector> points() const;
238 
240  std::auto_ptr<PointVector> pointsWithHeight() const;
241 
242  boost::optional<DtPoint> singlePointWithHeight() const;
243 
246  std::auto_ptr<PointVector> pointsWithoutHeight() const;
247 
249  unsigned numberOfSubGeometries() const;
250 
252  std::auto_ptr<GeometryVector> subGeometries() const;
253 
258  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
259 
261  bool equals(DtFeatureGeometry g) const;
262 
264  bool intersects(DtFeatureGeometry g) const;
265 
266  bool overlaps(DtFeatureGeometry g) const;
267 
268  bool crosses(DtFeatureGeometry g) const;
269 
270  bool covers(DtFeatureGeometry g) const;
271 
272  bool within(DtFeatureGeometry g) const;
273 
274  bool touches(DtFeatureGeometry g) const;
275 
276  bool contains(DtFeatureGeometry g) const;
277 
279  DtProj::Bounds bounds() const;
280 
282  DtFeatureGeometry extent() const;
283 
285  double length() const;
286 
288  double area() const;
289 
291  Point centroid() const;
292 
294  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
295 
297  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
298 
300  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
301 
303  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
304 
306  DtFeatureGeometry buffer(double width) const;
307 
310  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
311 
314  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
315 
317  DtFeatureGeometry convexHull() const;
318 
320  DtFeatureGeometry boundary() const;
321 
324  DtFeatureGeometry::Point closestPointTo(
325  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
326 
327  DtFeatureGeometry::Point closestPointTo(
328  DtFeatureGeometry g, double* distanceTo = 0) const;
329 
331  ImplPtr implementation();
332  ImplCPtr implementation() const;
333 
335  {
336  public:
337  virtual ~Mutex();
338 
339  virtual void lock() = 0;
340  virtual void unlock() = 0;
341  };
342 
343  protected:
346  class DT_DLL_features Lock : boost::noncopyable
347  {
348  public:
350  explicit Lock(const Implementation&);
351 
353  explicit Lock(const Implementation&, const Implementation&);
354 
356  ~Lock();
357 
358  private:
361  };
362 
364  };
365 
366  template <typename T>
367  boost::shared_ptr<T> DtFeatureGeometry::cast()
368  {
369  return boost::dynamic_pointer_cast<T>(implementation());
370  }
371 
372  template <typename T>
373  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
374  {
375  return boost::dynamic_pointer_cast<const T>(implementation());
376  }
377 
379  class DT_DLL_features DtFeatureGeometry::Implementation
380  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
381 #ifdef DtObjectDebugger_Enable
382  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
383 #endif
384  {
385  public:
388 
390  typedef std::vector<DtFeatureGeometry> GeometryVector;
391  typedef std::vector<DtPoint> PointVector;
392 
393  virtual ~Implementation();
394 
395  virtual Mutex& getMutex() const;
396 
397  virtual std::string description() const;
398 
399  virtual std::string toWKT() const;
400 
401  virtual bool isValid() const;
402 
403  virtual bool isEmpty() const;
404 
405  virtual unsigned dimension() const;
406 
407  virtual Hash hash() const;
408 
410  virtual DtFeatureGeometry clone() const = 0;
411 
414  virtual bool unique() const;
415 
417  virtual const DtProj & projection() const = 0;
418 
419  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
420 
421  virtual void transform(const TransformFunction&) = 0;
422 
424  virtual void convert(const DtProj &) = 0;
425 
427  virtual void prepare();
428 
429  virtual DtFeatureGeometry simplify(double tolerance) const;
430 
432  virtual Type type() const = 0;
433 
435  virtual unsigned numberOfPoints() const = 0;
436 
438  virtual std::auto_ptr<PointVector> points() const = 0;
439 
441  virtual boost::optional<DtPoint> singlePoint() const;
442 
444  virtual unsigned numberOfSubGeometries() const = 0;
445 
447  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
448 
449  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
450 
451  virtual bool equals(DtFeatureGeometry) const = 0;
452 
454  virtual bool intersects(DtFeatureGeometry) const = 0;
455 
456  virtual bool overlaps(DtFeatureGeometry) const = 0;
457 
458  virtual bool crosses(DtFeatureGeometry) const = 0;
459 
460  virtual bool covers(DtFeatureGeometry) const = 0;
461 
462  virtual bool within(DtFeatureGeometry) const = 0;
463 
464  virtual bool touches(DtFeatureGeometry) const = 0;
465 
466  virtual bool contains(DtFeatureGeometry) const = 0;
467 
469  virtual DtProj::Bounds bounds() const;
470 
472  virtual DtFeatureGeometry extent() const;
473 
474  virtual double length() const = 0;
475 
476  virtual double area() const = 0;
477 
479  virtual Point centroid() const = 0;
480 
482  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
483 
485  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
486 
488  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
489 
490  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
491 
493  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
494 
496  virtual DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const = 0;
497 
499  virtual DtFeatureGeometry convexHull() const = 0;
500 
501  virtual DtFeatureGeometry boundary() const = 0;
502 
505  virtual DtFeatureGeometry::Point closestPointTo(
506  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
507 
508  protected:
509  explicit Implementation();
510  explicit Implementation(const Implementation&);
511 
513  };
514 
520 #ifdef DtObjectDebugger_Enable
521  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
522 #endif
523  {
524  public:
525  typedef boost::shared_ptr<EmptyImplementation> Ptr;
526 
528 
529  DtFeatureGeometry clone() const;
530 
531  const DtProj & projection() const;
532  void transform(const TransformFunction&);
533  void convert(const DtProj &);
534  Type type() const;
535  bool isValid() const;
536 
537  unsigned numberOfPoints() const;
538  std::auto_ptr<PointVector> points() const;
539  boost::optional<DtPoint> singlePoint() const;
540 
541  unsigned numberOfSubGeometries() const;
542  std::auto_ptr<GeometryVector> subGeometries() const;
543 
544  Point centroid() const;
545  bool equals(DtFeatureGeometry) const;
546  bool intersects(DtFeatureGeometry) const;
547  bool overlaps(DtFeatureGeometry) const;
548  bool crosses(DtFeatureGeometry) const;
549  bool covers(DtFeatureGeometry) const;
550  bool within(DtFeatureGeometry) const;
551  bool touches(DtFeatureGeometry) const;
552  bool contains(DtFeatureGeometry) const;
553  double length() const;
554  double area() const;
555  double distanceTo(DtFeatureGeometry, const DtProj&) const;
559  DtFeatureGeometry buffer(double width, unsigned segments) const;
560  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
562  DtFeatureGeometry boundary() const;
564  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
565 
566  private:
568  };
569 
570  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
571  : boost::noncopyable
572 #ifdef DtObjectDebugger_Enable
573  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
574 #endif
575  {
576  public:
577  virtual ~RelationshipMatrix();
578 
579  virtual bool equals() const;
580  virtual bool intersects() const;
581  virtual bool disjoint() const;
582  virtual bool covers() const;
583  virtual bool coveredBy() const;
584  virtual bool within() const;
585  virtual bool touches() const;
586  virtual bool overlaps() const;
587  virtual bool crosses() const;
588  virtual bool contains() const;
589  };
590 
591  template <>
592  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
593  : public DtFeatureGeometry
594  {
595  public:
596  friend class DtFeatureGeometry;
597 
598  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
599  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
600 
601  Handle();
602  Handle(const DtFeatureGeometry&);
606  Handle(const DtFeatureGeometry&, bool fastCreation);
607  Handle(const Implementation::Ptr&);
608 
609  Handle(const DtPoint&, const DtProj& proj);
610  Handle(const DtVector&, const DtProj& proj);
611 
612  DtPoint point() const;
613  DtPoint pointWithHeight() const;
614  DtPoint pointWithoutHeight() const;
615  };
616 
617  template <>
618  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
619  : public DtFeatureGeometry
620  {
621  public:
622  friend class DtFeatureGeometry;
623 
624  typedef std::vector<DtFeatureGeometry::Path> Vector;
625 
626  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
627 
628  static DtFeatureGeometry::Path Make(
629  const DtPoint& p1, const DtPoint& p2,
630  const DtProj& proj);
631 
632  static DtFeatureGeometry::Path Make(
633  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
634  const DtProj& proj);
635 
636  template <typename Container>
637  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
638  {
639  return Make(PointVector(cont.begin(), cont.end()), proj);
640  }
641 
642  template <typename Iterator>
643  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
644  {
645  return Make(PointVector(i,end), proj);
646  }
647 
648  Handle();
649  Handle(const DtFeatureGeometry&);
650  Handle(const Implementation::Ptr&);
651 
652  Path reversed() const;
653  };
654 
655  template <>
656  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
657  : public DtFeatureGeometry
658  {
659  public:
660  friend class DtFeatureGeometry;
661 
662  typedef std::vector<DtFeatureGeometry::Area> Vector;
663 
664  Handle();
665  Handle(const DtFeatureGeometry&);
666  Handle(const Implementation::Ptr&);
667 
668  static DtFeatureGeometry::Area Make(const PointVector& points, const DtProj& proj);
669 
670  Path outerBoundary() const;
671 
672  unsigned numberOfHoles() const;
673  std::auto_ptr<GeometryVector> holes() const;
674 
675  Path findShortestPerimeter(Path) const;
676  };
677 
678  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
679 }
680 
683 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:71
DtTaggedException< struct InvalidGeometryTag > InvalidGeometry
Definition: featureGeometry.h:41
int Type
Type of geometry represented.
Definition: featureGeometry.h:49
boost::shared_ptr< const Implementation > ImplCPtr
Shared pointer to const Implementation.
Definition: featureGeometry.h:81
Mutex * mutex2
Definition: featureGeometry.h:360
DtFeatureGeometry::Type Type
Definition: featureGeometry.h:389
DtFeatureGeometry(const Handle< T > &h)
Create a geometry from a handle.
Definition: featureGeometry.h:153
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:624
std::string Hash
DtFeatureGeometry caches the hashes for the geometries can be differentiated quickly.
Definition: featureGeometry.h:85
ImplPtr implementation()
Get implementation of this geometry.
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
Default on in debug, off in release.
Definition: objectCounter.h:31
Definition: featureGeometry.h:56
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
Definition: proj.h:68
Handle< AreaType > Area
Definition: featureGeometry.h:67
static DtFeatureGeometry MakeSet(const Container &cont)
Definition: featureGeometry.h:114
Definition: featureGeometry.h:334
boost::shared_ptr< EmptyImplementation > Ptr
Definition: featureGeometry.h:525
DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const
ImplPtr myImpl
Definition: featureGeometry.h:363
DtFeatureGeometry::ImplCPtr CPtr
Definition: featureGeometry.h:387
DtTaggedException< struct BadGeometryCastTag > BadGeometryCast
Definition: featureGeometry.h:42
Handle< PointType > Point
Definition: featureGeometry.h:65
Represents some coordinate system.
Definition: proj.h:44
std::auto_ptr< PointVector > points() const
Mutex * mutex1
Definition: featureGeometry.h:359
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:346
Handle< PathType > Path
Definition: featureGeometry.h:66
DtFeatureGeometry unionWith(DtFeatureGeometry g) const
std::vector< DtFeatureGeometry::Area > Vector
Definition: featureGeometry.h:662
boost::function< DtPoint(const DtPoint &)> TransformFunction
Callback for transform().
Definition: featureGeometry.h:216
Create a new MAK exception type that inherits from boost::exception.
Definition: taggedException.h:15
static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj &proj)
Definition: featureGeometry.h:643
std::auto_ptr< GeometryVector > subGeometries() const
DtFeatureGeometry Unknown
Definition: featureGeometry.h:64
std::vector< DtFeatureGeometry > GeometryVector
Definition: featureGeometry.h:70
DtProj::CPtr myProjection
Definition: featureGeometry.h:567
Implementation which represents an empty geometry.
Definition: featureGeometry.h:518
DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const
static DtFeatureGeometry::Path Make(const Container &cont, const DtProj &proj)
Definition: featureGeometry.h:637
double distanceTo(DtFeatureGeometry, const DtProj &) const
Hash myHash
Definition: featureGeometry.h:512
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.
boost::shared_ptr< Implementation > ImplPtr
Shared pointer to Implementation.
Definition: featureGeometry.h:75
DtFeatureGeometry::ImplPtr Ptr
Definition: featureGeometry.h:386
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:367
Represents a feature geometry.
Definition: featureGeometry.h:35
Definition: point.h:34
DtFeatureGeometry & operator=(const Handle< T > &h)
Definition: featureGeometry.h:161
static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
Definition: featureGeometry.h:120

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)