LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BeachLine.h
Go to the documentation of this file.
1 
9 #ifndef BeachLine_h
10 #define BeachLine_h
11 
14 namespace dcel2d {
15  class Face;
16  class HalfEdge;
17 }
18 
19 // std includes
20 #include <list>
21 
22 //------------------------------------------------------------------------------------------------------------------------------------------
23 
24 namespace voronoi2d {
34  class BSTNode {
35  public:
40  : m_depth(0)
41  , m_event(NULL)
42  , m_parent(NULL)
43  , m_leftChild(NULL)
44  , m_rightChild(NULL)
45  , m_predecessor(NULL)
46  , m_successor(NULL)
47  , m_associated(NULL)
48  , m_halfEdge(NULL)
49  , m_face(NULL)
50  {}
51 
53  : m_depth(0)
54  , m_event(event)
55  , m_parent(NULL)
56  , m_leftChild(NULL)
57  , m_rightChild(NULL)
58  , m_predecessor(NULL)
59  , m_successor(NULL)
60  , m_associated(NULL)
61  , m_halfEdge(NULL)
62  , m_face(NULL)
63  {
64  if (m_event) m_event->setBSTNode(this);
65  }
66 
68 
72  int getDepth() const { return m_depth; }
73  IEvent* getEvent() const { return m_event; }
74  BSTNode* getParent() const { return m_parent; }
75  BSTNode* getLeftChild() const { return m_leftChild; }
76  BSTNode* getRightChild() const { return m_rightChild; }
77  BSTNode* getPredecessor() const { return m_predecessor; }
78  BSTNode* getSuccessor() const { return m_successor; }
79  BSTNode* getAssociated() const { return m_associated; }
80 
81  dcel2d::HalfEdge* getHalfEdge() const { return m_halfEdge; }
82  dcel2d::Face* getFace() const { return m_face; }
83 
87  void setParent(BSTNode* node) { m_parent = node; }
88  void setLeftChild(BSTNode* node) { m_leftChild = node; }
89  void setRightChild(BSTNode* node) { m_rightChild = node; }
90  void setPredecessor(BSTNode* node) { m_predecessor = node; }
91  void setSuccessor(BSTNode* node) { m_successor = node; }
92  void setAssociated(BSTNode* node) { m_associated = node; }
93 
94  void setHalfEdge(dcel2d::HalfEdge* half) { m_halfEdge = half; }
95  void setFace(dcel2d::Face* face) { m_face = face; }
96 
97  void setDepth(int depth) { m_depth = depth; }
98  void setDepth();
99 
103  bool operator<(const BSTNode&) const;
104 
105  private:
106  int m_depth; // Keep track of depth of nodes to this one
107  IEvent* m_event; // Pointer to the event object
108  BSTNode* m_parent; // Tree traversal - parent node
109  BSTNode* m_leftChild; // Tree traversal - left child node
110  BSTNode* m_rightChild; // Tree traversal - right child node
111  BSTNode* m_predecessor; // Beachline traversal - predecessor
112  BSTNode* m_successor; // Beachline traversal - successor
113  BSTNode* m_associated; // This allows handling of circle events
114  dcel2d::HalfEdge* m_halfEdge; // If a breakpoint then we associate halfedges
115  dcel2d::Face* m_face; // If a leaf then we associated faces
116  };
117 
118  using BSTNodeList = std::list<BSTNode>;
119 
125  class BeachLine {
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 
156  int getTreeDepth(const BSTNode*) const;
157 
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:125
IEvent * m_event
Definition: BeachLine.h:107
EventUtilities m_utilities
Definition: BeachLine.h:168
void setRightChild(BSTNode *node)
Definition: BeachLine.h:89
void setSuccessor(BSTNode *node)
Definition: BeachLine.h:91
BSTNode * m_associated
Definition: BeachLine.h:113
constexpr bool operator<(CryostatID const &a, CryostatID const &b)
Order cryostats with increasing ID.
Definition: geo_types.h:692
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:34
void setDepth(int depth)
Definition: BeachLine.h:97
BSTNode * getParent() const
Definition: BeachLine.h:74
std::list< BSTNode > BSTNodeList
Definition: BeachLine.h:118
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:79
dcel2d::Face * m_face
Definition: BeachLine.h:115
BSTNode * m_successor
Definition: BeachLine.h:112
BSTNode * m_predecessor
Definition: BeachLine.h:111
void setLeftChild(BSTNode *node)
Definition: BeachLine.h:88
void setParent(BSTNode *node)
Allow setting of the points.
Definition: BeachLine.h:87
BSTNode * getRightChild() const
Definition: BeachLine.h:76
BSTNodeList m_nodeVec
Definition: BeachLine.h:166
BSTNode * m_parent
Definition: BeachLine.h:108
void setAssociated(BSTNode *node)
Definition: BeachLine.h:92
const BSTNode * getTopNode() const
Definition: BeachLine.h:131
BSTNode()
Constructor.
Definition: BeachLine.h:39
int getDepth() const
recover the data members
Definition: BeachLine.h:72
BSTNode(IEvent *event)
Definition: BeachLine.h:52
BSTNode * getPredecessor() const
Definition: BeachLine.h:77
BSTNode * m_leftChild
Definition: BeachLine.h:109
dcel2d::Face * getFace() const
Definition: BeachLine.h:82
bool isEmpty() const
Definition: BeachLine.h:129
void setFace(dcel2d::Face *face)
Definition: BeachLine.h:95
dcel2d::HalfEdge * getHalfEdge() const
Definition: BeachLine.h:81
void setPredecessor(BSTNode *node)
Definition: BeachLine.h:90
IEvent * getEvent() const
Definition: BeachLine.h:73
dcel2d::HalfEdge * m_halfEdge
Definition: BeachLine.h:114
BSTNode * getSuccessor() const
Definition: BeachLine.h:78
BSTNode * m_rightChild
Definition: BeachLine.h:110
BSTNode * getLeftChild() const
Definition: BeachLine.h:75
Event finding and building.
void setHalfEdge(dcel2d::HalfEdge *half)
Definition: BeachLine.h:94