VR-Forces Development_Version 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 
91  static Area MakeBox(Point, double length, double width, double rotation);
92  static Area MakeBox(const DtProj&, double xmin, double ymin, double xmax, double ymax);
93  static Area MakeBox(const DtProj::Bounds&);
95 
97 
98  static Area MakeArea(const DtProj&, const std::vector<DtPoint>& points);
99  static Area MakeArea(const DtProj&, const std::vector<DtVector>& points);
100  static Path MakePath(const DtProj&, const std::vector<DtPoint>& points);
101  static Path MakePath(const DtProj&, const std::vector<DtVector>& points);
103 
105 
106  static DtFeatureGeometry MakeSet(const GeometryVector&, const DtProj&);
107  static DtFeatureGeometry MakeSet(const GeometryVector&);
108 
109  template <typename Container>
110  static DtFeatureGeometry MakeSet(const Container& cont)
111  {
112  return MakeSet(GeometryVector(cont.begin(), cont.end()));
113  }
114 
115  template <typename Iterator>
116  static DtFeatureGeometry MakeSet(Iterator i, Iterator end)
117  {
118  return MakeSet(GeometryVector(i,end));
119  }
121 
123  static GeometryVector Flatten(DtFeatureGeometry);
124 
128  static std::vector<Path> MergeLines(DtFeatureGeometry);
129 
133  static DtFeatureGeometry SimplifySet(const GeometryVector&, const DtProj&);
134  static DtFeatureGeometry SimplifySet(const GeometryVector&);
135 
138 
140  //DtFeatureGeometry(const ImplPtr&);
141  DtFeatureGeometry(const ImplCPtr&);
143 
145  template <Type T>
146  DtFeatureGeometry(const Handle<T>& h)
147  : myImpl(h.myImpl)
148  {
149  }
150 
151  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
152 
153  template <Type T>
154  DtFeatureGeometry& operator=(const Handle<T>& h)
155  {
156  myImpl = h.myImpl;
157  return *this;
158  }
159 
161  Type type() const;
162 
164  std::string description() const;
165 
167  bool isValid() const;
168 
170  bool isEmpty() const;
171 
173  bool isUnknown() const;
174 
176  bool isPoint() const;
177 
179  bool isPath() const;
180 
182  bool isArea() const;
183 
185  unsigned dimension() const;
186 
189  Area asArea() const;
190 
192  Hash hash() const;
193 
196  template <typename T>
197  boost::shared_ptr<T> cast();
198 
199  template <typename T>
200  boost::shared_ptr<const T> cast() const;
201 
203  const DtProj& projection() const;
204 
206  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
207 
209  void transform(const TransformFunction& func);
210 
212  void convert(const DtProj& p);
213 
215  void convertToLocalTopo();
216 
218  void prepare();
219 
220  DtFeatureGeometry simplify(double tolerance) const;
221 
223  unsigned numberOfPoints() const;
224 
227  std::auto_ptr<PointVector> points() const;
228 
230  std::auto_ptr<PointVector> pointsWithHeight() const;
231 
232  boost::optional<DtPoint> singlePointWithHeight() const;
233 
236  std::auto_ptr<PointVector> pointsWithoutHeight() const;
237 
239  unsigned numberOfSubGeometries() const;
240 
242  std::auto_ptr<GeometryVector> subGeometries() const;
243 
248  std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
249 
251  bool equals(DtFeatureGeometry g) const;
252 
254  bool intersects(DtFeatureGeometry g) const;
255 
256  bool overlaps(DtFeatureGeometry g) const;
257 
258  bool crosses(DtFeatureGeometry g) const;
259 
260  bool covers(DtFeatureGeometry g) const;
261 
262  bool within(DtFeatureGeometry g) const;
263 
264  bool touches(DtFeatureGeometry g) const;
265 
266  bool contains(DtFeatureGeometry g) const;
267 
269  DtProj::Bounds bounds() const;
270 
272  DtFeatureGeometry extent() const;
273 
275  double length() const;
276 
278  double area() const;
279 
281  Point centroid() const;
282 
284  double distanceTo(DtFeatureGeometry g, const DtProj& p) const;
285 
287  DtFeatureGeometry unionWith(DtFeatureGeometry g) const;
288 
290  DtFeatureGeometry intersectionWith(DtFeatureGeometry g) const;
291 
293  DtFeatureGeometry differenceWith(DtFeatureGeometry g) const;
294 
296  DtFeatureGeometry buffer(double width) const;
297 
300  DtFeatureGeometry buffer(double width, unsigned quadrantSegments) const;
301 
303  DtFeatureGeometry convexHull() const;
304 
306  DtFeatureGeometry boundary() const;
307 
310  DtFeatureGeometry::Point closestPointTo(
311  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
312 
313  DtFeatureGeometry::Point closestPointTo(
314  DtFeatureGeometry g, double* distanceTo = 0) const;
315 
317  ImplPtr implementation();
318  ImplCPtr implementation() const;
319 
321  {
322  public:
323  virtual ~Mutex();
324 
325  virtual void lock() = 0;
326  virtual void unlock() = 0;
327  };
328 
329  protected:
332  class DT_DLL_features Lock : boost::noncopyable
333  {
334  public:
336  explicit Lock(const Implementation&);
337 
339  explicit Lock(const Implementation&, const Implementation&);
340 
342  ~Lock();
343 
344  private:
347  };
348 
350  };
351 
352  template <typename T>
353  boost::shared_ptr<T> DtFeatureGeometry::cast()
354  {
355  return boost::dynamic_pointer_cast<T>(implementation());
356  }
357 
358  template <typename T>
359  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
360  {
361  return boost::dynamic_pointer_cast<const T>(implementation());
362  }
363 
366  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
367  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
368  {
369  public:
372 
374  typedef std::vector<DtFeatureGeometry> GeometryVector;
375  typedef std::vector<DtPoint> PointVector;
376 
377  virtual ~Implementation();
378 
379  virtual Mutex& getMutex() const;
380 
381  virtual std::string description() const;
382 
383  virtual bool isValid() const;
384 
385  virtual bool isEmpty() const;
386 
387  virtual unsigned dimension() const;
388 
389  virtual Hash hash() const;
390 
392  virtual DtFeatureGeometry clone() const = 0;
393 
396  virtual bool unique() const;
397 
399  virtual const DtProj & projection() const = 0;
400 
401  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
402 
403  virtual void transform(const TransformFunction&) = 0;
404 
406  virtual void convert(const DtProj &) = 0;
407 
409  virtual void prepare();
410 
411  virtual DtFeatureGeometry simplify(double tolerance) const;
412 
414  virtual Type type() const = 0;
415 
417  virtual unsigned numberOfPoints() const = 0;
418 
420  virtual std::auto_ptr<PointVector> points() const = 0;
421 
423  virtual boost::optional<DtPoint> singlePoint() const;
424 
426  virtual unsigned numberOfSubGeometries() const = 0;
427 
429  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
430 
431  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
432 
433  virtual bool equals(DtFeatureGeometry) const = 0;
434 
436  virtual bool intersects(DtFeatureGeometry) const = 0;
437 
438  virtual bool overlaps(DtFeatureGeometry) const = 0;
439 
440  virtual bool crosses(DtFeatureGeometry) const = 0;
441 
442  virtual bool covers(DtFeatureGeometry) const = 0;
443 
444  virtual bool within(DtFeatureGeometry) const = 0;
445 
446  virtual bool touches(DtFeatureGeometry) const = 0;
447 
448  virtual bool contains(DtFeatureGeometry) const = 0;
449 
451  virtual DtProj::Bounds bounds() const;
452 
454  virtual DtFeatureGeometry extent() const;
455 
456  virtual double length() const = 0;
457 
458  virtual double area() const = 0;
459 
461  virtual Point centroid() const = 0;
462 
464  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
465 
467  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
468 
470  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
471 
472  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
473 
475  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
476 
478  virtual DtFeatureGeometry convexHull() const = 0;
479 
480  virtual DtFeatureGeometry boundary() const = 0;
481 
484  virtual DtFeatureGeometry::Point closestPointTo(
485  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
486 
487  protected:
488  explicit Implementation();
489  explicit Implementation(const Implementation&);
490 
492  };
493 
499  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
500  {
501  public:
502  typedef boost::shared_ptr<EmptyImplementation> Ptr;
503 
505 
506  DtFeatureGeometry clone() const;
507 
508  const DtProj & projection() const;
509  void transform(const TransformFunction&);
510  void convert(const DtProj &);
511  Type type() const;
512  bool isValid() const;
513 
514  unsigned numberOfPoints() const;
515  std::auto_ptr<PointVector> points() const;
516  boost::optional<DtPoint> singlePoint() const;
517 
518  unsigned numberOfSubGeometries() const;
519  std::auto_ptr<GeometryVector> subGeometries() const;
520 
521  Point centroid() const;
522  bool equals(DtFeatureGeometry) const;
523  bool intersects(DtFeatureGeometry) const;
524  bool overlaps(DtFeatureGeometry) const;
525  bool crosses(DtFeatureGeometry) const;
526  bool covers(DtFeatureGeometry) const;
527  bool within(DtFeatureGeometry) const;
528  bool touches(DtFeatureGeometry) const;
529  bool contains(DtFeatureGeometry) const;
530  double length() const;
531  double area() const;
532  double distanceTo(DtFeatureGeometry, const DtProj&) const;
536  DtFeatureGeometry buffer(double width, unsigned segments) const;
538  DtFeatureGeometry boundary() const;
540  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
541 
542  private:
544  };
545 
546  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
547  : boost::noncopyable
548  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
549  {
550  public:
551  virtual ~RelationshipMatrix();
552 
553  virtual bool equals() const;
554  virtual bool intersects() const;
555  virtual bool disjoint() const;
556  virtual bool covers() const;
557  virtual bool coveredBy() const;
558  virtual bool within() const;
559  virtual bool touches() const;
560  virtual bool overlaps() const;
561  virtual bool crosses() const;
562  virtual bool contains() const;
563  };
564 
565  template <>
566  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
567  : public DtFeatureGeometry
568  {
569  public:
570  friend class DtFeatureGeometry;
571 
572  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
573  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
574 
575  Handle();
576  Handle(const DtFeatureGeometry&);
577  Handle(const Implementation::Ptr&);
578 
579  Handle(const DtPoint&, const DtProj& proj);
580  Handle(const DtVector&, const DtProj& proj);
581 
582  DtPoint point() const;
583  DtPoint pointWithHeight() const;
584  DtPoint pointWithoutHeight() const;
585  };
586 
587  template <>
588  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
589  : public DtFeatureGeometry
590  {
591  public:
592  friend class DtFeatureGeometry;
593 
594  typedef std::vector<DtFeatureGeometry::Path> Vector;
595 
596  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
597 
598  static DtFeatureGeometry::Path Make(
599  const DtPoint& p1, const DtPoint& p2,
600  const DtProj& proj);
601 
602  static DtFeatureGeometry::Path Make(
603  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
604  const DtProj& proj);
605 
606  template <typename Container>
607  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
608  {
609  return Make(PointVector(cont.begin(), cont.end()), proj);
610  }
611 
612  template <typename Iterator>
613  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
614  {
615  return Make(PointVector(i,end), proj);
616  }
617 
618  Handle();
619  Handle(const DtFeatureGeometry&);
620  Handle(const Implementation::Ptr&);
621 
622  Path reversed() const;
623  };
624 
625  template <>
626  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
627  : public DtFeatureGeometry
628  {
629  public:
630  friend class DtFeatureGeometry;
631 
632  typedef std::vector<DtFeatureGeometry::Area> Vector;
633 
634  Handle();
635  Handle(const DtFeatureGeometry&);
636  Handle(const Implementation::Ptr&);
637 
638  Path outerBoundary() const;
639 
640  unsigned numberOfHoles() const;
641  std::auto_ptr<GeometryVector> holes() const;
642 
643  Path findShortestPerimeter(Path) const;
644  };
645 
646  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
647  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
648 
649  template <DtFeatureGeometry::Type T>
650  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
651  {
652  return str << DtFeatureGeometry(g);
653  }
654 }
655 
658 DT_DEFINE_OBJECT_DEBUGGER_NAME(MAKVRinTerra::DtFeatureGeometry::RelationshipMatrix);

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)