OGS
SimplePolygonTree.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <list>
7
8// GeoLib
9#include "Polygon.h"
10
11namespace GeoLib
12{
20{
21public:
29 virtual ~SimplePolygonTree();
33
34 bool isRoot() const;
35
36 bool isPolygonInside(const SimplePolygonTree* polygon_hierarchy) const;
40 void insertSimplePolygonTree(SimplePolygonTree* polygon_hierarchy);
41
42 Polygon const& polygon() const;
44
45 const SimplePolygonTree* parent() const;
46
48 std::size_t getNumberOfChildren() const { return _children.size(); }
49
50private:
55
60 std::list<SimplePolygonTree*> _children;
66
67public:
68 decltype(_children)::const_iterator begin() const
69 {
70 return _children.begin();
71 }
72 decltype(_children)::const_iterator end() const { return _children.end(); }
73};
74
78template <typename POLYGONTREETYPE>
80 std::list<POLYGONTREETYPE*>& list_of_simple_polygon_hierarchies)
81{
82 for (auto it0 = list_of_simple_polygon_hierarchies.begin();
83 it0 != list_of_simple_polygon_hierarchies.end();
84 ++it0)
85 {
86 auto it1 = list_of_simple_polygon_hierarchies.begin();
87 while (it1 != list_of_simple_polygon_hierarchies.end())
88 {
89 if (it0 == it1)
90 { // don't check same polygons
91 ++it1;
92 // skip test if it1 points to the end after increment
93 if (it1 == list_of_simple_polygon_hierarchies.end())
94 {
95 break;
96 }
97 }
98 if ((*it0)->isPolygonInside(*it1))
99 {
100 (*it0)->insertSimplePolygonTree(*it1);
101 it1 = list_of_simple_polygon_hierarchies.erase(it1);
102 }
103 else
104 {
105 ++it1;
106 }
107 }
108 }
109}
110
111} // end namespace GeoLib
std::list< SimplePolygonTree * > _children
decltype(_children) ::const_iterator end() const
bool isPolygonInside(const SimplePolygonTree *polygon_hierarchy) const
SimplePolygonTree(Polygon *polygon, SimplePolygonTree *parent)
const SimplePolygonTree * parent() const
void insertSimplePolygonTree(SimplePolygonTree *polygon_hierarchy)
decltype(_children) ::const_iterator begin() const
std::size_t getNumberOfChildren() const
Polygon const & polygon() const
SimplePolygonTree * _parent
void createPolygonTrees(std::list< POLYGONTREETYPE * > &list_of_simple_polygon_hierarchies)