OGS
GeoLib::SimplePolygonTree Class Reference

Detailed Description

This class computes and stores the topological relations between polygons. Every node of the SimplePolygonTree represents a polygon. A child node c of a parent node p mean that the polygon represented by c is contained in the polygon represented by p.

Definition at line 30 of file SimplePolygonTree.h.

#include <SimplePolygonTree.h>

Inheritance diagram for GeoLib::SimplePolygonTree:
[legend]
Collaboration diagram for GeoLib::SimplePolygonTree:
[legend]

Public Member Functions

 SimplePolygonTree (Polygon *polygon, SimplePolygonTree *parent)
 
virtual ~SimplePolygonTree ()
 
bool isRoot () const
 
bool isPolygonInside (const SimplePolygonTree *polygon_hierarchy) const
 
void insertSimplePolygonTree (SimplePolygonTree *polygon_hierarchy)
 
Polygon const & polygon () const
 
Polygonpolygon ()
 
const SimplePolygonTreeparent () const
 
std::size_t getNumberOfChildren () const
 
decltype(_children) ::iterator begin ()
 
decltype(_children) ::iterator end ()
 
decltype(_children) ::const_iterator begin () const
 
decltype(_children) ::const_iterator end () const
 

Private Attributes

Polygon_node_polygon
 
std::list< SimplePolygonTree * > _children
 
SimplePolygonTree_parent
 

Constructor & Destructor Documentation

◆ SimplePolygonTree()

GeoLib::SimplePolygonTree::SimplePolygonTree ( Polygon polygon,
SimplePolygonTree parent 
)

Creates a node of a tree containing a simple polygon.

Parameters
polygonthe polygon represented by this tree node
parentpointer to the parent node within the tree or nullptr (if SimplePolygonTree node is the root node of the tree)

Definition at line 19 of file SimplePolygonTree.cpp.

22 {
23 }
const SimplePolygonTree * parent() const
Polygon const & polygon() const
SimplePolygonTree * _parent

◆ ~SimplePolygonTree()

GeoLib::SimplePolygonTree::~SimplePolygonTree ( )
virtual

Destructor: Attention: does not destroy the polygon!

Definition at line 25 of file SimplePolygonTree.cpp.

26 {
27  for (auto* child : _children)
28  {
29  delete child;
30  }
31 }
std::list< SimplePolygonTree * > _children

References _children.

Member Function Documentation

◆ begin() [1/2]

decltype(_children) ::iterator GeoLib::SimplePolygonTree::begin ( )
inline

Definition at line 79 of file SimplePolygonTree.h.

79 { return _children.begin(); }

References _children.

◆ begin() [2/2]

decltype(_children) ::const_iterator GeoLib::SimplePolygonTree::begin ( ) const
inline

Definition at line 82 of file SimplePolygonTree.h.

83  {
84  return _children.begin();
85  }

References _children.

◆ end() [1/2]

decltype(_children) ::iterator GeoLib::SimplePolygonTree::end ( )
inline

Definition at line 80 of file SimplePolygonTree.h.

80 { return _children.end(); }

References _children.

◆ end() [2/2]

decltype(_children) ::const_iterator GeoLib::SimplePolygonTree::end ( ) const
inline

Definition at line 86 of file SimplePolygonTree.h.

87  {
88  return _children.end();
89  }

References _children.

◆ getNumberOfChildren()

std::size_t GeoLib::SimplePolygonTree::getNumberOfChildren ( ) const
inline

returns the number of children

Definition at line 59 of file SimplePolygonTree.h.

59 { return _children.size(); }

References _children.

◆ insertSimplePolygonTree()

void GeoLib::SimplePolygonTree::insertSimplePolygonTree ( SimplePolygonTree polygon_hierarchy)

Either insert the given SimplePolygonTree in one of the existing children or as a new child.

Definition at line 49 of file SimplePolygonTree.cpp.

51 {
52  Polygon const& polygon = polygon_hierarchy->polygon();
53  bool nfound(true);
54  for (auto* child : _children)
55  {
56  if (child->polygon().isPolylineInPolygon(polygon))
57  {
58  child->insertSimplePolygonTree(polygon_hierarchy);
59  nfound = false;
60  break;
61  }
62  }
63  if (nfound)
64  {
65  _children.push_back(polygon_hierarchy);
66  polygon_hierarchy->_parent = this;
67  }
68 }

References _children, _parent, and polygon().

◆ isPolygonInside()

bool GeoLib::SimplePolygonTree::isPolygonInside ( const SimplePolygonTree polygon_hierarchy) const

Definition at line 38 of file SimplePolygonTree.cpp.

40 {
41  return _node_polygon->isPolylineInPolygon(polygon_hierarchy->polygon());
42 }
bool isPolylineInPolygon(const Polyline &ply) const
Definition: Polygon.cpp:215

References _node_polygon, GeoLib::Polygon::isPolylineInPolygon(), and polygon().

◆ isRoot()

bool GeoLib::SimplePolygonTree::isRoot ( ) const

Checks if the polygon represented by the given polygon tree node is inside this node polygon.

Definition at line 33 of file SimplePolygonTree.cpp.

34 {
35  return _parent == nullptr;
36 }

References _parent.

Referenced by FileIO::GMSH::GMSHPolygonTree::~GMSHPolygonTree(), FileIO::GMSH::GMSHPolygonTree::markSharedSegments(), and FileIO::GMSH::GMSHPolygonTree::writeSubPolygonsAsLineConstraints().

◆ parent()

const SimplePolygonTree * GeoLib::SimplePolygonTree::parent ( ) const

Definition at line 44 of file SimplePolygonTree.cpp.

45 {
46  return _parent;
47 }

References _parent.

Referenced by FileIO::GMSH::GMSHPolygonTree::markSharedSegments().

◆ polygon() [1/2]

Polygon & GeoLib::SimplePolygonTree::polygon ( )

Definition at line 70 of file SimplePolygonTree.cpp.

71 {
72  return *_node_polygon;
73 }

References _node_polygon.

◆ polygon() [2/2]

Member Data Documentation

◆ _children

std::list<SimplePolygonTree*> GeoLib::SimplePolygonTree::_children
private

list of polygons (represented by SimplePolygonTree nodes) contained in the _node_polygon

Definition at line 71 of file SimplePolygonTree.h.

Referenced by ~SimplePolygonTree(), begin(), end(), getNumberOfChildren(), and insertSimplePolygonTree().

◆ _node_polygon

Polygon* GeoLib::SimplePolygonTree::_node_polygon
private

the polygon this node stands for

Definition at line 65 of file SimplePolygonTree.h.

Referenced by isPolygonInside(), and polygon().

◆ _parent

SimplePolygonTree* GeoLib::SimplePolygonTree::_parent
private

the polygon represented by this node is contained in the polygon represented by the parent node in the tree

Definition at line 76 of file SimplePolygonTree.h.

Referenced by insertSimplePolygonTree(), isRoot(), and parent().


The documentation for this class was generated from the following files: