VR-Forces 4.3 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 
17 #include <boost/function.hpp>
18 
19 #include <iosfwd>
20 
21 #include <vrfutil/objectCounter.h>
22 
23 namespace tbb
24 {
25  class recursive_mutex;
26 }
27 
28 namespace MAKVRinTerra
29 {
42  : public DtObjectDebugger<DtFeatureGeometry>
43  {
44  public:
47 
53  enum Type
54  {
55  UnknownType = -1,
56  PointType = 0,
57  PathType = 1,
58  AreaType = 2,
59  };
60 
61  template <Type T> class Handle;
62 
70  typedef Handle<PointType> Point;
71  typedef Handle<PathType> Path;
72  typedef Handle<AreaType> Area;
74 
75  typedef std::vector<DtFeatureGeometry> GeometryVector;
76  typedef std::vector<DtPoint> PointVector;
77 
78  class Implementation;
79  class EmptyImplementation;
80  class RelationshipMatrix;
81 
83  typedef boost::shared_ptr<Implementation> ImplPtr;
84 
86  typedef boost::shared_ptr<const Implementation> ImplCPtr;
87 
90  typedef std::string Hash;
91 
92  typedef tbb::recursive_mutex Mutex;
93 
95  static std::string ToString(Type);
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&);
151 
153  template <Type T>
154  DtFeatureGeometry(const Handle<T>& h)
155  : myImpl(h.myImpl)
156  {
157  }
158 
159  DtFeatureGeometry& operator=(const DtFeatureGeometry&);
160 
161  template <Type T>
162  DtFeatureGeometry& operator=(const Handle<T>& h)
163  {
164  myImpl = h.myImpl;
165  return *this;
166  }
167 
169  Type type() const;
170 
172  std::string description() 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 
311  DtFeatureGeometry convexHull() const;
312 
314  DtFeatureGeometry boundary() const;
315 
318  DtFeatureGeometry::Point closestPointTo(
319  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
320 
321  DtFeatureGeometry::Point closestPointTo(
322  DtFeatureGeometry g, double* distanceTo = 0) const;
323 
325  ImplPtr implementation();
326  ImplCPtr implementation() const;
327 
328  protected:
331  class Lock : boost::noncopyable
332  {
333  public:
335  Lock(const Implementation&);
336 
338  Lock(const Implementation&, const Implementation&);
339 
341  ~Lock();
342 
343  private:
346  };
347 
349  };
350 
351  template <typename T>
352  boost::shared_ptr<T> DtFeatureGeometry::cast()
353  {
354  return boost::dynamic_pointer_cast<T>(implementation());
355  }
356 
357  template <typename T>
358  boost::shared_ptr<const T> DtFeatureGeometry::cast() const
359  {
360  return boost::dynamic_pointer_cast<const T>(implementation());
361  }
362 
365  : public boost::enable_shared_from_this<DtFeatureGeometry::Implementation>
366  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
367  {
368  public:
371 
373  typedef std::vector<DtFeatureGeometry> GeometryVector;
374  typedef std::vector<DtPoint> PointVector;
375 
376  virtual ~Implementation();
377 
378  virtual Mutex& getMutex() const;
379 
380  virtual std::string description() const;
381 
382  virtual bool isValid() const;
383 
384  virtual bool isEmpty() const;
385 
386  virtual unsigned dimension() const;
387 
388  virtual Hash hash() const;
389 
391  virtual DtFeatureGeometry clone() const = 0;
392 
395  virtual bool unique() const;
396 
398  virtual const DtProj & projection() const = 0;
399 
400  typedef boost::function<DtPoint (const DtPoint&)> TransformFunction;
401 
402  virtual void transform(const TransformFunction&) = 0;
403 
405  virtual void convert(const DtProj &) = 0;
406 
408  virtual void prepare();
409 
410  virtual DtFeatureGeometry simplify(double tolerance) const;
411 
413  virtual Type type() const = 0;
414 
416  virtual unsigned numberOfPoints() const = 0;
417 
419  virtual std::auto_ptr<PointVector> points() const = 0;
420 
422  virtual boost::optional<DtPoint> singlePoint() const;
423 
425  virtual unsigned numberOfSubGeometries() const = 0;
426 
428  virtual std::auto_ptr<GeometryVector> subGeometries() const = 0;
429 
430  virtual std::auto_ptr<RelationshipMatrix> relate(DtFeatureGeometry) const;
431 
432  virtual bool equals(DtFeatureGeometry) const = 0;
433 
435  virtual bool intersects(DtFeatureGeometry) const = 0;
436 
437  virtual bool overlaps(DtFeatureGeometry) const = 0;
438 
439  virtual bool crosses(DtFeatureGeometry) const = 0;
440 
441  virtual bool covers(DtFeatureGeometry) const = 0;
442 
443  virtual bool within(DtFeatureGeometry) const = 0;
444 
445  virtual bool touches(DtFeatureGeometry) const = 0;
446 
447  virtual bool contains(DtFeatureGeometry) const = 0;
448 
450  virtual DtProj::Bounds bounds() const;
451 
453  virtual DtFeatureGeometry extent() const;
454 
455  virtual double length() const = 0;
456 
457  virtual double area() const = 0;
458 
460  virtual Point centroid() const = 0;
461 
463  virtual double distanceTo(DtFeatureGeometry, const DtProj &) const = 0;
464 
466  virtual DtFeatureGeometry unionWith(DtFeatureGeometry) const = 0;
467 
469  virtual DtFeatureGeometry intersectionWith(DtFeatureGeometry) const = 0;
470 
471  virtual DtFeatureGeometry differenceWith(DtFeatureGeometry) const = 0;
472 
474  virtual DtFeatureGeometry buffer(double width, unsigned segments) const = 0;
475 
477  virtual DtFeatureGeometry convexHull() const = 0;
478 
479  virtual DtFeatureGeometry boundary() const = 0;
480 
483  virtual DtFeatureGeometry::Point closestPointTo(
484  DtFeatureGeometry, const DtProj&, double* distanceTo = 0) const = 0;
485 
486  protected:
487  explicit Implementation();
488  explicit Implementation(const Implementation&);
489 
491  };
492 
498  , public DtObjectDebugger<DtFeatureGeometry::Implementation>
499  {
500  public:
501  typedef boost::shared_ptr<EmptyImplementation> Ptr;
502 
504 
505  DtFeatureGeometry clone() const;
506 
507  const DtProj & projection() const;
508  void transform(const TransformFunction&);
509  void convert(const DtProj &);
510  Type type() const;
511  bool isValid() const;
512 
513  unsigned numberOfPoints() const;
514  std::auto_ptr<PointVector> points() const;
515  boost::optional<DtPoint> singlePoint() const;
516 
517  unsigned numberOfSubGeometries() const;
518  std::auto_ptr<GeometryVector> subGeometries() const;
519 
520  Point centroid() const;
521  bool equals(DtFeatureGeometry) const;
522  bool intersects(DtFeatureGeometry) const;
523  bool overlaps(DtFeatureGeometry) const;
524  bool crosses(DtFeatureGeometry) const;
525  bool covers(DtFeatureGeometry) const;
526  bool within(DtFeatureGeometry) const;
527  bool touches(DtFeatureGeometry) const;
528  bool contains(DtFeatureGeometry) const;
529  double length() const;
530  double area() const;
531  double distanceTo(DtFeatureGeometry, const DtProj&) const;
535  DtFeatureGeometry buffer(double width, unsigned segments) const;
537  DtFeatureGeometry boundary() const;
539  DtFeatureGeometry g, const DtProj&, double* distanceTo = 0) const;
540 
541  private:
543  };
544 
545  class DT_DLL_features DtFeatureGeometry::RelationshipMatrix
546  : boost::noncopyable
547  , public DtObjectDebugger<DtFeatureGeometry::RelationshipMatrix>
548  {
549  public:
550  virtual ~RelationshipMatrix();
551 
552  virtual bool equals() const;
553  virtual bool intersects() const;
554  virtual bool disjoint() const;
555  virtual bool covers() const;
556  virtual bool coveredBy() const;
557  virtual bool within() const;
558  virtual bool touches() const;
559  virtual bool overlaps() const;
560  virtual bool crosses() const;
561  virtual bool contains() const;
562  };
563 
564  template <>
565  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PointType>
566  : public DtFeatureGeometry
567  {
568  public:
569  friend class DtFeatureGeometry;
570 
571  static DtFeatureGeometry::Point Make(const DtPoint& p, const DtProj& proj);
572  static DtFeatureGeometry::Point Make(const DtVector& v, const DtProj& proj);
573 
574  Handle();
575  Handle(const DtFeatureGeometry&);
576  Handle(const Implementation::Ptr&);
577 
578  Handle(const DtPoint&, const DtProj& proj);
579  Handle(const DtVector&, const DtProj& proj);
580 
581  DtPoint point() const;
582  DtPoint pointWithHeight() const;
583  DtPoint pointWithoutHeight() const;
584  };
585 
586  template <>
587  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::PathType>
588  : public DtFeatureGeometry
589  {
590  public:
591  friend class DtFeatureGeometry;
592 
593  typedef std::vector<DtFeatureGeometry::Path> Vector;
594 
595  static DtFeatureGeometry::Path Make(const PointVector& points, const DtProj& proj);
596 
597  static DtFeatureGeometry::Path Make(
598  const DtPoint& p1, const DtPoint& p2,
599  const DtProj& proj);
600 
601  static DtFeatureGeometry::Path Make(
602  const DtPoint& p1, const DtPoint& p2, const DtPoint& p3,
603  const DtProj& proj);
604 
605  template <typename Container>
606  static DtFeatureGeometry::Path Make(const Container& cont, const DtProj& proj)
607  {
608  return Make(PointVector(cont.begin(), cont.end()), proj);
609  }
610 
611  template <typename Iterator>
612  static DtFeatureGeometry::Path Make(Iterator i, Iterator end, const DtProj& proj)
613  {
614  return Make(PointVector(i,end), proj);
615  }
616 
617  Handle();
618  Handle(const DtFeatureGeometry&);
619  Handle(const Implementation::Ptr&);
620 
621  Path reversed() const;
622  };
623 
624  template <>
625  class DT_DLL_features DtFeatureGeometry::Handle<DtFeatureGeometry::AreaType>
626  : public DtFeatureGeometry
627  {
628  public:
629  friend class DtFeatureGeometry;
630 
631  typedef std::vector<DtFeatureGeometry::Area> Vector;
632 
633  Handle();
634  Handle(const DtFeatureGeometry&);
635  Handle(const Implementation::Ptr&);
636 
637  Path outerBoundary() const;
638 
639  unsigned numberOfHoles() const;
640  std::auto_ptr<GeometryVector> holes() const;
641 
642  Path findShortestPerimeter(Path) const;
643  };
644 
645  DT_DLL_features std::ostream& operator<< (std::ostream&, DtFeatureGeometry::Type);
646  DT_DLL_features std::ostream& operator<< (std::ostream&, const DtFeatureGeometry&);
647 
648  template <DtFeatureGeometry::Type T>
649  std::ostream& operator<< (std::ostream& str, const DtFeatureGeometry::Handle<T>& g)
650  {
651  return str << DtFeatureGeometry(g);
652  }
653 }
654 
657 DT_DEFINE_OBJECT_DEBUGGER_NAME(MAKVRinTerra::DtFeatureGeometry::RelationshipMatrix);

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)