BeachLine.h
Go to the documentation of this file.
1 /**
2  * @file BeachLine.h
3  *
4  * @brief Represents the beachline implemented as a self balancing binary search tree
5  *
6  * @author usher@slac.stanford.edu
7  *
8  */
9 #ifndef BeachLine_h
10 #define BeachLine_h
11 
14 namespace dcel2d { class Face; class HalfEdge; }
15 
16 // std includes
17 #include <list>
18 
19 //------------------------------------------------------------------------------------------------------------------------------------------
20 
21 namespace voronoi2d
22 {
23 /**
24  * @brief BSTNode class definiton specifically for use in constructing
25  * Voronoi diagrams. We are trying to follow the prescription
26  * described in "Computational Geometry" by Mark de Berg, et al.
27  *
28  * Note that in this implementation the internal nodes of the tree
29  * will describe the breakpoints in the beach line and the leaves of
30  * the tree will describe the arcs (site points).
31  */
32 class BSTNode
33 {
34 public:
35  /**
36  * @brief Constructor
37  */
38  BSTNode() :
39  m_depth(0),
40  m_event(NULL),
41  m_parent(NULL),
42  m_leftChild(NULL),
43  m_rightChild(NULL),
44  m_predecessor(NULL),
45  m_successor(NULL),
46  m_associated(NULL),
47  m_halfEdge(NULL),
48  m_face(NULL)
49  {}
50 
52  m_depth(0),
53  m_event(event),
54  m_parent(NULL),
55  m_leftChild(NULL),
56  m_rightChild(NULL),
57  m_predecessor(NULL),
58  m_successor(NULL),
59  m_associated(NULL),
60  m_halfEdge(NULL),
61  m_face(NULL)
62  {
63  if (m_event) m_event->setBSTNode(this);
64  }
65 
67 
68  /**
69  * @brief recover the data members
70  */
71  int getDepth() const {return m_depth;}
72  IEvent* getEvent() const {return m_event;}
73  BSTNode* getParent() const {return m_parent;}
74  BSTNode* getLeftChild() const {return m_leftChild;}
75  BSTNode* getRightChild() const {return m_rightChild;}
76  BSTNode* getPredecessor() const {return m_predecessor;}
77  BSTNode* getSuccessor() const {return m_successor;}
78  BSTNode* getAssociated() const {return m_associated;}
79 
80  dcel2d::HalfEdge* getHalfEdge() const {return m_halfEdge;}
81  dcel2d::Face* getFace() const {return m_face;}
82 
83  /**
84  * @brief Allow setting of the points
85  */
86  void setParent(BSTNode* node) {m_parent = node;}
87  void setLeftChild(BSTNode* node) {m_leftChild = node;}
88  void setRightChild(BSTNode* node) {m_rightChild = node;}
89  void setPredecessor(BSTNode* node) {m_predecessor = node;}
90  void setSuccessor(BSTNode* node) {m_successor = node;}
91  void setAssociated(BSTNode* node) {m_associated = node;}
92 
93  void setHalfEdge(dcel2d::HalfEdge* half) {m_halfEdge = half;}
94  void setFace(dcel2d::Face* face) {m_face = face;}
95 
96  void setDepth(int depth) {m_depth = depth;}
97  void setDepth();
98 
99  /**
100  * @brief Provide override definition for ordering
101  */
102  bool operator<(const BSTNode&) const;
103 
104 private:
105  int m_depth; // Keep track of depth of nodes to this one
106  IEvent* m_event; // Pointer to the event object
107  BSTNode* m_parent; // Tree traversal - parent node
108  BSTNode* m_leftChild; // Tree traversal - left child node
109  BSTNode* m_rightChild; // Tree traversal - right child node
110  BSTNode* m_predecessor; // Beachline traversal - predecessor
111  BSTNode* m_successor; // Beachline traversal - successor
112  BSTNode* m_associated; // This allows handling of circle events
113  dcel2d::HalfEdge* m_halfEdge; // If a breakpoint then we associate halfedges
114  dcel2d::Face* m_face; // If a leaf then we associated faces
115 };
116 
117 using BSTNodeList = std::list<BSTNode>;
118 
119 /**
120  * @brief This defines the actual beach line. The idea is to implement this as a
121  * self balancing binary search tree.
122  */
123 
125 {
126 public:
127  BeachLine() : m_root(NULL) {m_nodeVec.clear();}
128 
129  bool isEmpty() const {return m_root == NULL;}
130  void setEmpty() {m_root = NULL;}
131  const BSTNode* getTopNode() const {return m_root;}
132  BSTNode* findBestLeaf(const IEvent* event) const {return findBestLeaf(event, m_root);}
133  BSTNode* insertNewLeaf(IEvent*);
134  BSTNode* removeLeaf(BSTNode*);
135  int getHeight() const {return getTreeDepth(m_root);}
136  int countNodes() const;
137  int countLeaves() const;
138  int traverseBeach() const;
139 
140 private:
141  BSTNode* insertNewLeaf(IEvent*, BSTNode*);
142 
143  BSTNode* findBestLeaf(const IEvent*, BSTNode*) const;
144 
145  void countNodes(const BSTNode*, int&) const;
146  void countLeaves(const BSTNode*, int&) const;
147 
148  int traverseBeachLeft(BSTNode*) const;
149  int traverseBeachRight(BSTNode*) const;
150 
151  void checkBeachLine(double) const;
152 
153  /**
154  * @brief This recovers the depth of longest branch in the tree below input node
155  */
156  int getTreeDepth(const BSTNode*) const;
157 
158  /**
159  * @brief Tree balancing functions
160  */
161  void rebalance(BSTNode*);
162  BSTNode* rotateWithLeftChild(BSTNode*);
163  BSTNode* rotateWithRightChild(BSTNode*);
164 
165  BSTNode* m_root; // the root of all evil, er, the top node
166  BSTNodeList m_nodeVec; // Use this to keep track of the nodes
167 
169 };
170 
171 } // namespace lar_cluster3d
172 #endif
This defines the actual beach line. The idea is to implement this as a self balancing binary search t...
Definition: BeachLine.h:124
IEvent * m_event
Definition: BeachLine.h:106
EventUtilities m_utilities
Definition: BeachLine.h:168
void setRightChild(BSTNode *node)
Definition: BeachLine.h:88
void setSuccessor(BSTNode *node)
Definition: BeachLine.h:90
BSTNode * m_associated
Definition: BeachLine.h:112
Provides some basic functions operating in IEvent class objects.
BSTNode class definiton specifically for use in constructing Voronoi diagrams. We are trying to follo...
Definition: BeachLine.h:32
void setDepth(int depth)
Definition: BeachLine.h:96
BSTNode * getParent() const
Definition: BeachLine.h:73
std::list< BSTNode > BSTNodeList
Definition: BeachLine.h:117
int getHeight() const
Definition: BeachLine.h:135
Internal class definitions to facilitate construction of diagram.
BSTNode * findBestLeaf(const IEvent *event) const
Definition: BeachLine.h:132
BSTNode * getAssociated() const
Definition: BeachLine.h:78
bool operator<(ProductInfo const &a, ProductInfo const &b)
Definition: ProductInfo.cc:51
dcel2d::Face * m_face
Definition: BeachLine.h:114
BSTNode * m_successor
Definition: BeachLine.h:111
BSTNode * m_predecessor
Definition: BeachLine.h:110
void setLeftChild(BSTNode *node)
Definition: BeachLine.h:87
void setParent(BSTNode *node)
Allow setting of the points.
Definition: BeachLine.h:86
BSTNode * getRightChild() const
Definition: BeachLine.h:75
BSTNodeList m_nodeVec
Definition: BeachLine.h:166
BSTNode * m_parent
Definition: BeachLine.h:107
void setAssociated(BSTNode *node)
Definition: BeachLine.h:91
const BSTNode * getTopNode() const
Definition: BeachLine.h:131
BSTNode()
Constructor.
Definition: BeachLine.h:38
int getDepth() const
recover the data members
Definition: BeachLine.h:71
BSTNode(IEvent *event)
Definition: BeachLine.h:51
BSTNode * getPredecessor() const
Definition: BeachLine.h:76
BSTNode * m_leftChild
Definition: BeachLine.h:108
dcel2d::Face * getFace() const
Definition: BeachLine.h:81
bool isEmpty() const
Definition: BeachLine.h:129
void setFace(dcel2d::Face *face)
Definition: BeachLine.h:94
dcel2d::HalfEdge * getHalfEdge() const
Definition: BeachLine.h:80
void setPredecessor(BSTNode *node)
Definition: BeachLine.h:89
IEvent * getEvent() const
Definition: BeachLine.h:72
dcel2d::HalfEdge * m_halfEdge
Definition: BeachLine.h:113
BSTNode * getSuccessor() const
Definition: BeachLine.h:77
BSTNode * m_rightChild
Definition: BeachLine.h:109
BSTNode * getLeftChild() const
Definition: BeachLine.h:74
Event finding and building.
void setHalfEdge(dcel2d::HalfEdge *half)
Definition: BeachLine.h:93