OGS
SimplePolygonTree.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <list>
18 
19 // GeoLib
20 #include "Polygon.h"
21 
22 namespace GeoLib
23 {
31 {
32 public:
40  virtual ~SimplePolygonTree();
45  bool isRoot() const;
46 
47  bool isPolygonInside(const SimplePolygonTree* polygon_hierarchy) const;
51  void insertSimplePolygonTree(SimplePolygonTree* polygon_hierarchy);
52 
53  Polygon const& polygon() const;
54  Polygon& polygon();
55 
56  const SimplePolygonTree* parent() const;
57 
59  std::size_t getNumberOfChildren() const { return _children.size(); }
60 
61 private:
66 
71  std::list<SimplePolygonTree*> _children;
77 
78 public:
79  decltype(_children)::iterator begin() { return _children.begin(); }
80  decltype(_children)::iterator end() { return _children.end(); }
81 
82  decltype(_children)::const_iterator begin() const
83  {
84  return _children.begin();
85  }
86  decltype(_children)::const_iterator end() const
87  {
88  return _children.end();
89  }
90 
91 };
92 
96 template <typename POLYGONTREETYPE>
97 void createPolygonTrees (std::list<POLYGONTREETYPE*>& list_of_simple_polygon_hierarchies)
98 {
99  for (auto it0 = list_of_simple_polygon_hierarchies.begin();
100  it0 != list_of_simple_polygon_hierarchies.end();
101  ++it0)
102  {
103  auto it1 = list_of_simple_polygon_hierarchies.begin();
104  while (it1 != list_of_simple_polygon_hierarchies.end()) {
105  if (it0 == it1) { // don't check same polygons
106  ++it1;
107  // skip test if it1 points to the end after increment
108  if (it1 == list_of_simple_polygon_hierarchies.end())
109  {
110  break;
111  }
112  }
113  if ((*it0)->isPolygonInside(*it1)) {
114  (*it0)->insertSimplePolygonTree(*it1);
115  it1 = list_of_simple_polygon_hierarchies.erase(it1);
116  } else {
117  ++it1;
118  }
119  }
120  }
121 }
122 
123 
124 } // end namespace GeoLib
Definition of the Polygon class.
This class computes and stores the topological relations between polygons. Every node of the SimplePo...
decltype(_children) ::iterator end()
std::list< SimplePolygonTree * > _children
bool isPolygonInside(const SimplePolygonTree *polygon_hierarchy) const
SimplePolygonTree(Polygon *polygon, SimplePolygonTree *parent)
const SimplePolygonTree * parent() const
void insertSimplePolygonTree(SimplePolygonTree *polygon_hierarchy)
std::size_t getNumberOfChildren() const
decltype(_children) ::iterator begin()
Polygon const & polygon() const
SimplePolygonTree * _parent
void createPolygonTrees(std::list< POLYGONTREETYPE * > &list_of_simple_polygon_hierarchies)