VR-Forces 4.8 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  typedef int Type;
48 
49  static const int UnknownType = -1;
50  static const int PointType = 0;
51  static const int PathType = 1;
52  static const int AreaType = 2;
53 
54  template <Type T> class Handle;
55 
67 
68  typedef std::vector<DtFeatureGeometry> GeometryVector;
69  typedef std::vector<DtPoint> PointVector;
70 
71  class Implementation;
72  class EmptyImplementation;
73  class RelationshipMatrix;
74 
76  typedef boost::shared_ptr<Implementation> ImplPtr;
77 
79  typedef boost::shared_ptr<const Implementation> ImplCPtr;
80 
83  typedef std::string Hash;
84 
86  static std::string ToString(Type);
87 
89  static DtFeatureGeometry FromWKT(const std::string&, const DtProj&);
90 
92 
93  static Area MakeBox(Point, double length, double width, double rotation);
94  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
95  static Area MakeBox(const DtProj::Bounds&);
97 
99 
100  static Area MakeArea(const DtProj&, const std::vector<DtPoint>& points);
101  static Area MakeArea(const DtProj&, const std::vector<DtVector>& points);
102  static Path MakePath(const DtProj&, const std::vector<DtPoint>& points);
103  static Path MakePath(const DtProj&, const std::vector<DtVector>& points);
105 
107 
108  static DtFeatureGeometry MakeSet(const GeometryVector&, const DtProj&);
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&, const DtProj&);
136  static DtFeatureGeometry SimplifySet(const GeometryVector&);
137 
140 
142  //DtFeatureGeometry(const ImplPtr&);
143  DtFeatureGeometry(const ImplCPtr&);
144  DtFeatureGeometry(Implementation*);
145 
148 
150  template <Type T>
152  : myImpl(h.myImpl)
153  {
154  }
155 
156  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
157 
158  template <Type T>
160  {
161  myImpl = h.myImpl;
162  return *this;
163  }
164 
166  Type type() const;
167 
169  std::string description() const;
170 
172  std::string toWKT() const;
173 
175  bool isValid() const;
176 
178  bool isEmpty() const;
179 
181  bool isUnknown() const;
182 
184  bool isPoint() const;
185 
187  bool isPath() const;
188 
190  bool isArea() const;
191 
193  unsigned dimension() const;
194 
197  Area asArea() const;
198 
200  Hash hash() const;
201 
204  template <typename T>
205  boost::shared_ptr<T> cast();
206 
207  template <typename T>
208  boost::shared_ptr<const T> cast() const;
209 
211  const DtProj& projection() const;
212 
214  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
215 
217  void transform(const TransformFunction& func);
218 
220  void convert(const DtProj& p);
221 
223  void convertToLocalTopo();
224 
226  void prepare();
227 
228  DtFeatureGeometry simplify(double tolerance) const;
229 
231  unsigned numberOfPoints() const;
232 
235  std::auto_ptr<PointVector> points() const;
236 
238  std::auto_ptr<PointVector> pointsWithHeight() const;
239 
240  boost::optional<DtPoint> singlePointWithHeight() const;
241 
244  std::auto_ptr<PointVector> pointsWithoutHeight() const;
245 
247  unsigned numberOfSubGeometries() const;
248 
250  std::auto_ptr<GeometryVector> subGeometries() const;
251 
256  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
257 
259  bool equals(DtFeatureGeometry g) const;
260 
262  bool intersects(DtFeatureGeometry g) const;
263 
264  bool overlaps(DtFeatureGeometry g) const;
265 
266  bool crosses(DtFeatureGeometry g) const;
267 
268  bool covers(DtFeatureGeometry g) const;
269 
270  bool within(DtFeatureGeometry g) const;
271 
272  bool touches(DtFeatureGeometry g) const;
273 
274  bool contains(DtFeatureGeometry g) const;
275 
277  DtProj::Bounds bounds() const;
278 
280  DtFeatureGeometry extent() const;
281 
283  double length() const;
284 
286  double area() const;
287 
289  Point centroid() const;
290 
292  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
293 
295  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
296 
298  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
299 
301  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
302 
304  DtFeatureGeometry buffer(double width) const;
305 
308  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
309 
312  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
313 
315  DtFeatureGeometry convexHull() const;
316 
318  DtFeatureGeometry boundary() const;
319 
322  DtFeatureGeometry::Point closestPointTo(
323  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
324 
325  DtFeatureGeometry::Point closestPointTo(
326  DtFeatureGeometry g, double* distanceTo = 0) const;
327 
329  ImplPtr implementation();
330  ImplCPtr implementation() const;
331 
333  {
334  public:
335  virtual ~Mutex();
336 
337  virtual void lock() = 0;
338  virtual void unlock() = 0;
339  };
340 
341  protected:
344  class DT_DLL_features Lock : boost::noncopyable
345  {
346  public:
348  explicit Lock(const Implementation&);
349 
351  explicit Lock(const Implementation&, const Implementation&);
352 
354  ~Lock();
355 
356  private:
359  };
360 
362  };
363 
364  template <typename T>
365  boost::shared_ptr<T> DtFeatureGeometry::cast()
366  {
367  return boost::dynamic_pointer_cast<T>(implementation());
368  }
369 
370  template <typename T>
371  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
372  {
373  return boost::dynamic_pointer_cast<const T>(implementation());
374  }
375 
377  class DT_DLL_features DtFeatureGeometry::Implementation
378  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
379  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
380  {
381  public:
384 
386  typedef std::vector<DtFeatureGeometry> GeometryVector;
387  typedef std::vector<DtPoint> PointVector;
388 
389  virtual ~Implementation();
390 
391  virtual Mutex& getMutex() const;
392 
393  virtual std::string description() const;
394 
395  virtual std::string toWKT() const;
396 
397  virtual bool isValid() const;
398 
399  virtual bool isEmpty() const;
400 
401  virtual unsigned dimension() const;
402 
403  virtual Hash hash() const;
404 
406  virtual DtFeatureGeometry clone() const = 0;
407 
410  virtual bool unique() const;
411 
413  virtual const DtProj & projection() const = 0;
414 
415  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
416 
417  virtual void transform(const TransformFunction&) = 0;
418 
420  virtual void convert(const DtProj &) = 0;
421 
423  virtual void prepare();
424 
425  virtual DtFeatureGeometry simplify(double tolerance) const;
426 
428  virtual Type type() const = 0;
429 
431  virtual unsigned numberOfPoints() const = 0;
432 
434  virtual std::auto_ptr<PointVector> points() const = 0;
435 
437  virtual boost::optional<DtPoint> singlePoint() const;
438 
440  virtual unsigned numberOfSubGeometries() const = 0;
441 
443  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
444 
445  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
446 
447  virtual bool equals(DtFeatureGeometry) const = 0;
448 
450  virtual bool intersects(DtFeatureGeometry) const = 0;
451 
452  virtual bool overlaps(DtFeatureGeometry) const = 0;
453 
454  virtual bool crosses(DtFeatureGeometry) const = 0;
455 
456  virtual bool covers(DtFeatureGeometry) const = 0;
457 
458  virtual bool within(DtFeatureGeometry) const = 0;
459 
460  virtual bool touches(DtFeatureGeometry) const = 0;
461 
462  virtual bool contains(DtFeatureGeometry) const = 0;
463 
465  virtual DtProj::Bounds bounds() const;
466 
468  virtual DtFeatureGeometry extent() const;
469 
470  virtual double length() const = 0;
471 
472  virtual double area() const = 0;
473 
475  virtual Point centroid() const = 0;
476 
478  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
479 
481  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
482 
484  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
485 
486  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
487 
489  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
490 
492  virtual DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const = 0;
493 
495  virtual DtFeatureGeometry convexHull() const = 0;
496 
497  virtual DtFeatureGeometry boundary() const = 0;
498 
501  virtual DtFeatureGeometry::Point closestPointTo(
502  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
503 
504  protected:
505  explicit Implementation();
506  explicit Implementation(const Implementation&);
507 
509  };
510 
516  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
517  {
518  public:
519  typedef boost::shared_ptr<EmptyImplementation> Ptr;
520 
522 
523  DtFeatureGeometry clone() const;
524 
525  const DtProj & projection() const;
526  void transform(const TransformFunction&);
527  void convert(const DtProj &);
528  Type type() const;
529  bool isValid() const;
530 
531  unsigned numberOfPoints() const;
532  std::auto_ptr<PointVector> points() const;
533  boost::optional<DtPoint> singlePoint() const;
534 
535  unsigned numberOfSubGeometries() const;
536  std::auto_ptr<GeometryVector> subGeometries() const;
537 
538  Point centroid() const;
539  bool equals(DtFeatureGeometry) const;
540  bool intersects(DtFeatureGeometry) const;
541  bool overlaps(DtFeatureGeometry) const;
542  bool crosses(DtFeatureGeometry) const;
543  bool covers(DtFeatureGeometry) const;
544  bool within(DtFeatureGeometry) const;
545  bool touches(DtFeatureGeometry) const;
546  bool contains(DtFeatureGeometry) const;
547  double length() const;
548  double area() const;
549  double distanceTo(DtFeatureGeometry, const DtProj&) const;
553  DtFeatureGeometry buffer(double width, unsigned segments) const;
554  DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const;
556  DtFeatureGeometry boundary() const;
558  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
559 
560  private:
562  };
563 
564  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
565  : boost::noncopyable
566  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
567  {
568  public:
569  virtual ~RelationshipMatrix();
570 
571  virtual bool equals() const;
572  virtual bool intersects() const;
573  virtual bool disjoint() const;
574  virtual bool covers() const;
575  virtual bool coveredBy() const;
576  virtual bool within() const;
577  virtual bool touches() const;
578  virtual bool overlaps() const;
579  virtual bool crosses() const;
580  virtual bool contains() const;
581  };
582 
583  template <>
584  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
585  : public DtFeatureGeometry
586  {
587  public:
588  friend class DtFeatureGeometry;
589 
590  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
591  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
592 
593  Handle();
594  Handle(const DtFeatureGeometry&);
595  Handle(const Implementation::Ptr&);
596 
597  Handle(const DtPoint&, const DtProj& proj);
598  Handle(const DtVector&, const DtProj& proj);
599 
600  DtPoint point() const;
601  DtPoint pointWithHeight() const;
602  DtPoint pointWithoutHeight() const;
603  };
604 
605  template <>
606  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
607  : public DtFeatureGeometry
608  {
609  public:
610  friend class DtFeatureGeometry;
611 
612  typedef std::vector<DtFeatureGeometry::Path> Vector;
613 
614  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
615 
616  static DtFeatureGeometry::Path Make(
617  const DtPoint& p1, const DtPoint& p2,
618  const DtProj& proj);
619 
620  static DtFeatureGeometry::Path Make(
621  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
622  const DtProj& proj);
623 
624  template <typename Container>
625  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
626  {
627  return Make(PointVector(cont.begin(), cont.end()), proj);
628  }
629 
630  template <typename Iterator>
631  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
632  {
633  return Make(PointVector(i,end), proj);
634  }
635 
636  Handle();
637  Handle(const DtFeatureGeometry&);
638  Handle(const Implementation::Ptr&);
639 
640  Path reversed() const;
641  };
642 
643  template <>
644  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
645  : public DtFeatureGeometry
646  {
647  public:
648  friend class DtFeatureGeometry;
649 
650  typedef std::vector<DtFeatureGeometry::Area> Vector;
651 
652  Handle();
653  Handle(const DtFeatureGeometry&);
654  Handle(const Implementation::Ptr&);
655 
656  static DtFeatureGeometry::Area Make(const PointVector& points, const DtProj& proj);
657 
658  Path outerBoundary() const;
659 
660  unsigned numberOfHoles() const;
661  std::auto_ptr<GeometryVector> holes() const;
662 
663  Path findShortestPerimeter(Path) const;
664  };
665 
666  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
667 }
668 
671 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:36
std::vector< DtPoint > PointVector
Definition: featureGeometry.h:69
DtTaggedException< struct InvalidGeometryTag > InvalidGeometry
Definition: featureGeometry.h:39
int Type
Type of geometry represented.
Definition: featureGeometry.h:47
boost::shared_ptr< const Implementation > ImplCPtr
Shared pointer to const Implementation.
Definition: featureGeometry.h:79
Mutex * mutex2
Definition: featureGeometry.h:358
DtFeatureGeometry::Type Type
Definition: featureGeometry.h:385
DtFeatureGeometry(const Handle< T > &h)
Create a geometry from a handle.
Definition: featureGeometry.h:151
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:612
std::string Hash
DtFeatureGeometry caches the hashes for the geometries can be differentiated quickly.
Definition: featureGeometry.h:83
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:54
DT_DLL_features std::ostream & operator<<(std::ostream &, const DtFeatureTransform &)
std::ostream output.
Definition: proj.h:68
Handle< AreaType > Area
Definition: featureGeometry.h:65
static DtFeatureGeometry MakeSet(const Container &cont)
Definition: featureGeometry.h:112
Definition: featureGeometry.h:332
boost::shared_ptr< EmptyImplementation > Ptr
Definition: featureGeometry.h:519
DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const
ImplPtr myImpl
Definition: featureGeometry.h:361
DtFeatureGeometry::ImplCPtr CPtr
Definition: featureGeometry.h:383
DtTaggedException< struct BadGeometryCastTag > BadGeometryCast
Definition: featureGeometry.h:40
Handle< PointType > Point
Definition: featureGeometry.h:63
Represents some coordinate system.
Definition: proj.h:44
std::auto_ptr< PointVector > points() const
Mutex * mutex1
Definition: featureGeometry.h:357
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:344
Handle< PathType > Path
Definition: featureGeometry.h:64
DtFeatureGeometry unionWith(DtFeatureGeometry g) const
std::vector< DtFeatureGeometry::Area > Vector
Definition: featureGeometry.h:650
boost::function< DtPoint(const DtPoint &)> TransformFunction
Callback for transform().
Definition: featureGeometry.h:214
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:631
std::auto_ptr< GeometryVector > subGeometries() const
DtFeatureGeometry Unknown
Definition: featureGeometry.h:62
std::vector< DtFeatureGeometry > GeometryVector
Definition: featureGeometry.h:68
DtProj::CPtr myProjection
Definition: featureGeometry.h:561
Implementation which represents an empty geometry.
Definition: featureGeometry.h:514
DtFeatureGeometry bufferWithFlatCap(double width, unsigned segments) const
static DtFeatureGeometry::Path Make(const Container &cont, const DtProj &proj)
Definition: featureGeometry.h:625
double distanceTo(DtFeatureGeometry, const DtProj &) const
Hash myHash
Definition: featureGeometry.h:508
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:73
DtFeatureGeometry::ImplPtr Ptr
Definition: featureGeometry.h:382
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:365
Represents a feature geometry.
Definition: featureGeometry.h:35
Definition: point.h:34
DtFeatureGeometry & operator=(const Handle< T > &h)
Definition: featureGeometry.h:159
static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
Definition: featureGeometry.h:118

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)