All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
voronoi2d::BeachLine Class Reference

This defines the actual beach line. The idea is to implement this as a self balancing binary search tree. More...

#include <BeachLine.h>

Public Member Functions

 BeachLine ()
 
bool isEmpty () const
 
void setEmpty ()
 
const BSTNodegetTopNode () const
 
BSTNodefindBestLeaf (const IEvent *event) const
 
BSTNodeinsertNewLeaf (IEvent *)
 
BSTNoderemoveLeaf (BSTNode *)
 
int getHeight () const
 
int countNodes () const
 
int countLeaves () const
 
int traverseBeach () const
 

Private Member Functions

BSTNodeinsertNewLeaf (IEvent *, BSTNode *)
 
BSTNodefindBestLeaf (const IEvent *, BSTNode *) const
 
void countNodes (const BSTNode *, int &) const
 
void countLeaves (const BSTNode *, int &) const
 
int traverseBeachLeft (BSTNode *) const
 
int traverseBeachRight (BSTNode *) const
 
void checkBeachLine (double) const
 
int getTreeDepth (const BSTNode *) const
 This recovers the depth of longest branch in the tree below input node. More...
 
void rebalance (BSTNode *)
 Tree balancing functions. More...
 
BSTNoderotateWithLeftChild (BSTNode *)
 
BSTNoderotateWithRightChild (BSTNode *)
 

Private Attributes

BSTNodem_root
 
BSTNodeList m_nodeVec
 
EventUtilities m_utilities
 

Detailed Description

This defines the actual beach line. The idea is to implement this as a self balancing binary search tree.

Definition at line 124 of file BeachLine.h.

Constructor & Destructor Documentation

voronoi2d::BeachLine::BeachLine ( )
inline

Definition at line 127 of file BeachLine.h.

127 : m_root(NULL) {m_nodeVec.clear();}
BSTNodeList m_nodeVec
Definition: BeachLine.h:166

Member Function Documentation

void voronoi2d::BeachLine::checkBeachLine ( double  beachLine) const
private

Definition at line 367 of file BeachLine.cxx.

368 {
369  // Starting with the root, dive down until we find the leftmost leaf
370  BSTNode* node = m_root;
371 
372  if (!node) return;
373 
374  // Basically, follow the left branch down until we have no more children
375  while(node->getLeftChild()) node = node->getLeftChild();
376 
377  // Keep track of breakpoints
378  double lastBreakPointY = -std::numeric_limits<double>::max();
379  int nBadCompares(0);
380  int nNodes(0);
381  int nBreakPoints(0);
382  int nLeaves(0);
383  BSTNode* lastBreakPoint(NULL);
384 
385  const double tolerance(1.e-5);
386 
387  // This is the start of the beach line, we now traverse across and and check status
388  // of each breakpoint's position
389  while(node->getSuccessor())
390  {
391  // Is this a breakpoint?
392  if (node->getLeftChild() && node->getRightChild())
393  {
394  RootsPair roots;
395  double breakPoint = m_utilities.computeBreak(beachLine, node->getPredecessor()->getEvent(), node->getSuccessor()->getEvent(), roots);
396 
397  if (breakPoint + tolerance < lastBreakPointY)
398  {
399  std::cout << " #####>> Beach line check gets bad breakpoint, last: " << lastBreakPointY << ", new: " << breakPoint << ", roots: " << roots.first << "/" << roots.second << std::endl;
400  std::cout << " Current left arc x,y: " << node->getPredecessor()->getEvent()->xPos() << ", " << node->getPredecessor()->getEvent()->yPos() << ", right arc x,y: " << node->getSuccessor()->getEvent()->xPos() << ", " << node->getSuccessor()->getEvent()->yPos() << ", beachLine: " << beachLine;
401  if (node->getPredecessor()->getAssociated()) std::cout << ", left: " << node->getPredecessor()->getAssociated()->getEvent()->isValid();
402  if (node->getSuccessor()->getAssociated()) std::cout << ", right: " << node->getSuccessor()->getAssociated()->getEvent()->isValid();
403  std::cout << std::endl;
404  if (lastBreakPoint)
405  {
406  std::cout << " Previous left arc x,y: " << lastBreakPoint->getPredecessor()->getEvent()->xPos() << ", " << lastBreakPoint->getPredecessor()->getEvent()->yPos() << ", right arc x,y: " << lastBreakPoint->getSuccessor()->getEvent()->xPos() << ", " << lastBreakPoint->getSuccessor()->getEvent()->yPos();
407  if (lastBreakPoint->getPredecessor()->getAssociated()) std::cout << ", left: " << lastBreakPoint->getPredecessor()->getAssociated()->getEvent()->isValid();
408  if (lastBreakPoint->getSuccessor()->getAssociated()) std::cout << ", right: " << lastBreakPoint->getSuccessor()->getAssociated()->getEvent()->isValid();
409  std::cout << std::endl;
410  }
411  nBadCompares++;
412  }
413 
414  lastBreakPointY = breakPoint;
415  lastBreakPoint = node;
416  nBreakPoints++;
417  }
418  else
419  {
420  // Confirm that the next leaf in the beachline is the next according to the tree
421  if (node->getSuccessor())
422  {
423  BSTNode* temp = node;
424  while(temp->getParent() && temp != temp->getParent()->getLeftChild()) temp = temp->getParent();
425  if (temp->getParent()) temp = temp->getParent()->getRightChild();
426  while(temp->getLeftChild()) temp = temp->getLeftChild();
427 
428  if (node->getSuccessor()->getSuccessor() != temp || node != temp->getPredecessor()->getPredecessor())
429  {
430  std::cout << " --> Successor tree/beach mismatch, leaf # " << nLeaves << ", node: " << node << ", " << node->getEvent()->xPos() << "/" << node->getEvent()->yPos() << ", s: " << node->getSuccessor() << ", ss: " << node->getSuccessor()->getSuccessor() << std::endl;
431  std::cout << " temp: " << temp << ", " << temp->getEvent()->xPos() << "/" << temp->getEvent()->yPos() << ", p: " << temp->getPredecessor() << ", pp: " << temp->getPredecessor()->getPredecessor() << std::endl;
432  }
433  }
434 
435  if (node->getPredecessor())
436  {
437  BSTNode* temp = node;
438  while(temp->getParent() && temp != temp->getParent()->getRightChild()) temp = temp->getParent();
439  if (temp->getParent()) temp = temp->getParent()->getLeftChild();
440  while(temp->getRightChild()) temp = temp->getRightChild();
441 
442  if (node->getPredecessor()->getPredecessor() != temp || node != temp->getSuccessor()->getSuccessor())
443  {
444  std::cout << " --> Predecessor tree/beach mismatch, leaf # " << nLeaves << ", node: " << node << ", " << node->getEvent()->xPos() << "/" << node->getEvent()->yPos() << ", p: " << node->getPredecessor() << ", pp: " << node->getPredecessor()->getPredecessor() << std::endl;
445  std::cout << " temp: " << temp << ", " << temp->getEvent()->xPos() << "/" << temp->getEvent()->yPos() << ", s: " << temp->getSuccessor() << ", ss: " << temp->getSuccessor()->getSuccessor() << std::endl;
446  }
447  }
448 
449  nLeaves++;
450  }
451 
452  nNodes++;
453 
454  node = node->getSuccessor();
455  }
456 
457  if (nBadCompares > 0) std::cout << "=======>> Beach line check resulted in " << nBadCompares << " bad compares of " << nBreakPoints << " break points checked, with " << nLeaves << " leaves" << std::endl;
458 
459 // std::cout << "-------------------------------------------------------------------------------------------------------" << std::endl;
460 
461  return;
462 }
EventUtilities m_utilities
Definition: BeachLine.h:168
auto const tolerance
double computeBreak(const double, const IEvent *, const IEvent *, RootsPair &) const
do i e
std::pair< double, double > RootsPair
BEGIN_PROLOG could also be cout
BSTNode * getLeftChild() const
Definition: BeachLine.h:74
int voronoi2d::BeachLine::countLeaves ( ) const

Definition at line 303 of file BeachLine.cxx.

304 {
305  int leafCount(0);
306 
307  countLeaves(m_root, leafCount);
308 
309  return leafCount;
310 }
int countLeaves() const
Definition: BeachLine.cxx:303
void voronoi2d::BeachLine::countLeaves ( const BSTNode node,
int &  leafCount 
) const
private

Definition at line 330 of file BeachLine.cxx.

331 {
332  // If not a leaf then still have children to search
333  if (node->getLeftChild() && node->getRightChild())
334  {
335  countLeaves(node->getLeftChild(), leafCount);
336  countLeaves(node->getRightChild(), leafCount);
337  }
338  else leafCount += 1;
339 
340  return;
341 }
int countLeaves() const
Definition: BeachLine.cxx:303
int voronoi2d::BeachLine::countNodes ( ) const

Definition at line 294 of file BeachLine.cxx.

295 {
296  int nodeCount(0);
297 
298  countNodes(m_root, nodeCount);
299 
300  return nodeCount;
301 }
int countNodes() const
Definition: BeachLine.cxx:294
void voronoi2d::BeachLine::countNodes ( const BSTNode node,
int &  nodeCount 
) const
private

Definition at line 312 of file BeachLine.cxx.

313 {
314  if (node)
315  {
316  if (node->getLeftChild()) countNodes(node->getLeftChild(), nodeCount);
317  if (node->getRightChild()) countNodes(node->getRightChild(), nodeCount);
318 
319  if ((node->getLeftChild() != NULL) != (node->getRightChild() != NULL))
320  {
321  std::cout << "****** Tree has one branch but not the other! *******" << std::endl;
322  }
323 
324  nodeCount++;
325  }
326 
327  return;
328 }
int countNodes() const
Definition: BeachLine.cxx:294
BEGIN_PROLOG could also be cout
BSTNode* voronoi2d::BeachLine::findBestLeaf ( const IEvent event) const
inline

Definition at line 132 of file BeachLine.h.

132 {return findBestLeaf(event, m_root);}
BSTNode * findBestLeaf(const IEvent *event) const
Definition: BeachLine.h:132
BSTNode * voronoi2d::BeachLine::findBestLeaf ( const IEvent event,
BSTNode topNode 
) const
private

Definition at line 72 of file BeachLine.cxx.

73 {
74  // Assumption: a leaf will have NULL child pointers so the idea is to
75  // follow the left or right child pointers until we get to a leaf
76  BSTNode* node = topNode;
77 
78  // A leaf is found when the node has no children
79  if (node && node->getLeftChild() && node->getRightChild())
80  {
81  // This node represents a breakpoint between two arcs and we can
82  // recover these immediately by getting the predecessor and successor leafs
83  BSTNode* rightLeaf = node->getSuccessor();
84  BSTNode* leftLeaf = node->getPredecessor();
85 
86  // Which path do we follow down the tree?
87  if (m_utilities.newSiteToLeft(event, leftLeaf->getEvent(), rightLeaf->getEvent()))
88  node = findBestLeaf(event, node->getLeftChild());
89  else
90  node = findBestLeaf(event, node->getRightChild());
91  }
92 
93  return node;
94 }
EventUtilities m_utilities
Definition: BeachLine.h:168
bool newSiteToLeft(const IEvent *, const IEvent *, const IEvent *) const
BSTNode * findBestLeaf(const IEvent *event) const
Definition: BeachLine.h:132
int voronoi2d::BeachLine::getHeight ( ) const
inline

Definition at line 135 of file BeachLine.h.

135 {return getTreeDepth(m_root);}
int getTreeDepth(const BSTNode *) const
This recovers the depth of longest branch in the tree below input node.
Definition: BeachLine.cxx:496
const BSTNode* voronoi2d::BeachLine::getTopNode ( ) const
inline

Definition at line 131 of file BeachLine.h.

131 {return m_root;}
int voronoi2d::BeachLine::getTreeDepth ( const BSTNode node) const
private

This recovers the depth of longest branch in the tree below input node.

Definition at line 496 of file BeachLine.cxx.

497 {
498  int depth(0);
499 
500  // Node exists and its not a leaf
501  if (node && node->getLeftChild() && node->getRightChild())
502  {
503  depth = std::max(getTreeDepth(node->getLeftChild()),getTreeDepth(node->getRightChild()));
504 
505  depth++;
506  }
507  else if (node && (node->getLeftChild() || node->getRightChild()))
508  {
509  std::cout << "****** Found a node which only one child: " << node << ", L/R: " << node->getLeftChild() << "/" << node->getRightChild() << std::endl;
510  }
511 
512  return depth;
513 }
int getTreeDepth(const BSTNode *) const
This recovers the depth of longest branch in the tree below input node.
Definition: BeachLine.cxx:496
BEGIN_PROLOG could also be cout
BSTNode * voronoi2d::BeachLine::insertNewLeaf ( IEvent event)

Definition at line 55 of file BeachLine.cxx.

56 {
57  // Find the insertion point for the new event
58  BSTNode* node = findBestLeaf(event, m_root);
59 
60  // Insert it
61  node = insertNewLeaf(event, node);
62 
63  // Now rebalance starting at this node
64  rebalance(node);
65 
66  // Check beach line integrity
67 // checkBeachLine(event->xPos() - 0.000001);
68 
69  return node;
70 }
void rebalance(BSTNode *)
Tree balancing functions.
Definition: BeachLine.cxx:515
BSTNode * findBestLeaf(const IEvent *event) const
Definition: BeachLine.h:132
BSTNode * insertNewLeaf(IEvent *)
Definition: BeachLine.cxx:55
BSTNode * voronoi2d::BeachLine::insertNewLeaf ( IEvent event,
BSTNode node 
)
private

Definition at line 96 of file BeachLine.cxx.

97 {
98  // The idea of this function is to insert a new Site Event into the beach line
99  // where it is assumed that the input node is the matched arc into which we
100  // insert the new site event.
101  // The function then returns the new leaf created which represents the new arc
102 
103  // Have we found a null pointer?
104  if (node == NULL)
105  {
106  m_nodeVec.push_back(BSTNode(event));
107  node = &m_nodeVec.back();
108  return node;
109  }
110 
111  // Check if a circle event had been definied for the node we are splitting,
112  // if so then we need to invalidate that circle event
113  if (node->getAssociated())
114  {
115  node->getAssociated()->getEvent()->setInvalid();
116  node->getAssociated()->setAssociated(NULL);
117  node->setAssociated(NULL);
118  }
119 
120  // Right now assume that the input node is the leaf at which we want to insert the new data
121  // For the beachline, this means we are inserting a new arc into the beachline by dividing the
122  // current arc. So we are going to replace the input leaf with a subtree having three leaves
123  // (two breakpoints)...
124  // Start by creating a node for the new arc
125  m_nodeVec.push_back(BSTNode(event)); // This will be the new site point
126 
127  BSTNode* newLeaf = &m_nodeVec.back();
128 
129  m_nodeVec.push_back(BSTNode(*node)); // This will be the new left leaf (the original arc)
130 
131  BSTNode* leftLeaf = &m_nodeVec.back();
132 
133  m_nodeVec.push_back(BSTNode(event)); // This will be the breakpoint between the left and new leaves
134 
135  BSTNode* breakNode = &m_nodeVec.back();
136 
137  m_nodeVec.push_back(BSTNode(event)); // Finally, this is the breakpoint between new and right leaves
138 
139  BSTNode* topNode = &m_nodeVec.back();
140 
141  // Set this to be the king of the local world
142  topNode->setParent(node->getParent());
143 
144  // Make sure the parent points to this new node
145  if (node->getParent())
146  {
147  if (node->getParent()->getLeftChild() == node) node->getParent()->setLeftChild(topNode);
148  else node->getParent()->setRightChild(topNode);
149  }
150  // But if there is no parent then the topnode is the new root
151  else m_root = topNode;
152 
153  // Set our children
154  topNode->setLeftChild(breakNode);
155  topNode->setRightChild(node);
156 
157  // Original node is now child of the top node
158  node->setParent(topNode);
159 
160  // If there was an associated circle event to this node, invalidate it
161  if (node->getAssociated())
162  {
163  node->getAssociated()->setAssociated(NULL);
164  node->getAssociated()->getEvent()->setInvalid();
165  node->setAssociated(NULL);
166  leftLeaf->setAssociated(NULL);
167  }
168 
169  // Now set the parent and children of the left breakpoint node
170  breakNode->setParent(topNode);
171  breakNode->setLeftChild(leftLeaf);
172  breakNode->setRightChild(newLeaf);
173 
174  // Finally set the leaves parents
175  leftLeaf->setParent(breakNode);
176  newLeaf->setParent(breakNode);
177 
178  // Now we wire up traversal chain, going left to right
179  leftLeaf->setPredecessor(node->getPredecessor());
180  leftLeaf->setSuccessor(breakNode);
181 
182  if (node->getPredecessor()) node->getPredecessor()->setSuccessor(leftLeaf);
183 
184  breakNode->setPredecessor(leftLeaf);
185  breakNode->setSuccessor(newLeaf);
186 
187  newLeaf->setPredecessor(breakNode);
188  newLeaf->setSuccessor(topNode);
189 
190  topNode->setPredecessor(newLeaf);
191  topNode->setSuccessor(node);
192  node->setPredecessor(topNode);
193 
194  // Finally, reset the depths
195  // By definition the break node will have depth of 1
196  breakNode->setDepth();
197 
198  // Check the beachline integrity
199  checkBeachLine(newLeaf->getEvent()->xPos()-0.00000001);
200 
201  return newLeaf;
202 }
void checkBeachLine(double) const
Definition: BeachLine.cxx:367
void setLeftChild(BSTNode *node)
Definition: BeachLine.h:87
BSTNodeList m_nodeVec
Definition: BeachLine.h:166
bool voronoi2d::BeachLine::isEmpty ( ) const
inline

Definition at line 129 of file BeachLine.h.

129 {return m_root == NULL;}
void voronoi2d::BeachLine::rebalance ( BSTNode node)
private

Tree balancing functions.

Definition at line 515 of file BeachLine.cxx.

516 {
517  // The idea is to rebalance starting with the current node and the walking back up the branch
518  // until we reach the ultimate parent.
519  // First, if at internal node then check depth down either branch
520  if (node->getLeftChild() && node->getRightChild())
521  {
522  int depthLeft = getTreeDepth(node->getLeftChild());
523  int depthRight = getTreeDepth(node->getRightChild());
524 
525  if (depthLeft != node->getLeftChild()->getDepth() || depthRight != node->getRightChild()->getDepth())
526  {
527  std::cout << " --> node depth: " << getTreeDepth(node) << ", left/right: " << depthLeft << "/" << node->getLeftChild()->getDepth() << ", " << depthRight << "/" << node->getRightChild()->getDepth() << ", parent/depth " << node->getParent() << "/" << getTreeDepth(node->getParent()) << std::endl;
528  }
529 
530  // If left branch is longer then we rotate with the left child
531  if (depthLeft - depthRight > 2) node = rotateWithLeftChild(node);
532  else if (depthRight - depthLeft > 2) node = rotateWithRightChild(node);
533  }
534 
535  // Ok now rebalance the parent unless we are the root
536  if (node->getParent()) rebalance(node->getParent());
537  // In which case update the internal root node pointer
538  else m_root = node;
539 
540  return;
541 }
BSTNode * rotateWithLeftChild(BSTNode *)
Definition: BeachLine.cxx:543
void rebalance(BSTNode *)
Tree balancing functions.
Definition: BeachLine.cxx:515
int getTreeDepth(const BSTNode *) const
This recovers the depth of longest branch in the tree below input node.
Definition: BeachLine.cxx:496
BSTNode * rotateWithRightChild(BSTNode *)
Definition: BeachLine.cxx:575
BEGIN_PROLOG could also be cout
BSTNode * voronoi2d::BeachLine::removeLeaf ( BSTNode node)

Definition at line 204 of file BeachLine.cxx.

205 {
206  // The input node is assumed to be a leaf (arc) and is the disappearing arc
207  // between a leaf (arc) to the left and one to the right. There are breakpoints
208  // between the arcs.
209  // One of the intervening breakpoints is the parent of the leaf to remove
210  BSTNode* nodeParent = node->getParent();
211 
212  // parent of the parent
213  BSTNode* grandParent = nodeParent->getParent();
214 
215  // Parent is either left or right child, node is left or right child.... my brain is dizzy
216  BSTNode* sibling = nodeParent->getRightChild();
217 
218  if (node == sibling) sibling = nodeParent->getLeftChild();
219 
220  if (nodeParent == grandParent->getLeftChild()) grandParent->setLeftChild(sibling);
221  else grandParent->setRightChild(sibling);
222 
223  sibling->setParent(grandParent);
224 
225  // Now we need to deal with the predecessor/successor chain.
226  // This should be straightforward, we are removing the middle arc and the immediate parent
227  // breakpoint with the grandparent becoming the new breakpoint. It should be that we simply
228  // set the left arc's successor, the right arc's predecessor and make sure the grandparent points
229  // to the right objects.
230  // Also note that if here there MUST be a left and right arc
231  BSTNode* arcLeft = node->getPredecessor()->getPredecessor();
232  BSTNode* arcRight = node->getSuccessor()->getSuccessor();
233 
234  // Note as well that any circle events for those arcs are now invalid
235  if (arcLeft->getAssociated())
236  {
237  arcLeft->getAssociated()->getEvent()->setInvalid();
238  arcLeft->getAssociated()->setAssociated(NULL);
239  arcLeft->setAssociated(NULL);
240  }
241 
242  if (arcRight->getAssociated())
243  {
244  arcRight->getAssociated()->getEvent()->setInvalid();
245  arcRight->getAssociated()->setAssociated(NULL);
246  arcRight->setAssociated(NULL);
247  }
248 
249  // Basically, we need to connect the left and right arcs to their common break point
250  // What breakpoint that is will be determined by weather the arc we are removing is a
251  // left or right child
252  if (node == nodeParent->getLeftChild())
253  {
254  // In this case, the right arc's predecessor becomes the node's predecessor
255  // The left arc is all set
256  arcRight->setPredecessor(node->getPredecessor());
257  node->getPredecessor()->setSuccessor(arcRight);
258  }
259  else
260  {
261  // Here the left arc's successor is what needs to be changed
262  arcLeft->setSuccessor(node->getSuccessor());
263  node->getSuccessor()->setPredecessor(arcLeft);
264  }
265 
266  // zap the pointers for the removed nodes
267  node->setParent(NULL);
268  nodeParent->setLeftChild(NULL);
269  nodeParent->setRightChild(NULL);
270  nodeParent->setParent(NULL);
271  nodeParent->setSuccessor(NULL);
272  nodeParent->setPredecessor(NULL);
273  node->setSuccessor(NULL);
274  node->setPredecessor(NULL);
275  node->setHalfEdge(NULL);
276  node->setFace(NULL);
277 
278  // Reset the depth
279  grandParent->setDepth();
280 
281  // Check beach line integrity
282 // checkBeachLine(node->getAssociated()->getEvent()->xPos()-0.000001);
283 
284  // Rebalance
285  rebalance(grandParent);
286 
287  // Check beach line integrity
288  checkBeachLine(node->getAssociated()->getEvent()->xPos()-0.00000001);
289 
290  // Return the new breakpoint
291  return arcLeft->getSuccessor();
292 }
void checkBeachLine(double) const
Definition: BeachLine.cxx:367
void rebalance(BSTNode *)
Tree balancing functions.
Definition: BeachLine.cxx:515
BSTNode * voronoi2d::BeachLine::rotateWithLeftChild ( BSTNode node)
private

Definition at line 543 of file BeachLine.cxx.

544 {
545  // Here we rebalance by rotating the root node with its left child
546  BSTNode* newTopNode = node->getLeftChild();
547  BSTNode* parent = node->getParent();
548 
549  // Check if there is a parent and if so make sure it points at the new node
550  if (parent)
551  {
552  if (parent->getLeftChild() == node) parent->setLeftChild(newTopNode);
553  else parent->setRightChild(newTopNode);
554  }
555  // if no parent this the new root
556  else m_root = newTopNode;
557 
558  // Swap parents (for the root node the parent is null)
559  newTopNode->setParent(parent);
560  node->setParent(newTopNode);
561 
562  // Reset the children
563  BSTNode* childToSwitch = newTopNode->getRightChild();
564 
565  childToSwitch->setParent(node);
566  node->setLeftChild(childToSwitch);
567  newTopNode->setRightChild(node);
568 
569  // Reset node depth
570  node->getLeftChild()->setDepth();
571 
572  return newTopNode;
573 }
void setParent(BSTNode *node)
Allow setting of the points.
Definition: BeachLine.h:86
BSTNode * voronoi2d::BeachLine::rotateWithRightChild ( BSTNode node)
private

Definition at line 575 of file BeachLine.cxx.

576 {
577  // Here we rebalance by rotating the root node with its left child
578  BSTNode* newTopNode = node->getRightChild();
579  BSTNode* parent = node->getParent();
580 
581  // Check if there is a parent and if so make sure it points at the new node
582  if (parent)
583  {
584  if (parent->getLeftChild() == node) parent->setLeftChild(newTopNode);
585  else parent->setRightChild(newTopNode);
586  }
587  // if no parent this the new root
588  else m_root = newTopNode;
589 
590  // Swap parents (for the root node the parent is null)
591  newTopNode->setParent(parent);
592  node->setParent(newTopNode);
593 
594  // Reset the children
595  BSTNode* childToSwitch = newTopNode->getLeftChild();
596 
597  childToSwitch->setParent(node);
598  node->setRightChild(childToSwitch);
599  newTopNode->setLeftChild(node);
600 
601  // Reset node depths
602  node->getRightChild()->setDepth();
603 
604  return newTopNode;
605 }
void setParent(BSTNode *node)
Allow setting of the points.
Definition: BeachLine.h:86
void voronoi2d::BeachLine::setEmpty ( )
inline

Definition at line 130 of file BeachLine.h.

130 {m_root = NULL;}
int voronoi2d::BeachLine::traverseBeach ( ) const

Definition at line 343 of file BeachLine.cxx.

344 {
345  int leafCount(0);
346 
347  // Starting with the root, dive down until we find a leaf
348  BSTNode* node = m_root;
349 
350  // Basically, follow the left branch down until we have no more children
351  while(node->getLeftChild()) node = node->getLeftChild();
352 
353  // Note that construction we should be a leaf, now we traverse across
354  // the beach line in both directions to get the leaf count
355  if (node)
356  {
357  leafCount += traverseBeachLeft(node->getPredecessor());
358  leafCount += traverseBeachRight(node->getSuccessor());
359 
360  // just to be sure...
361  if (!node->getLeftChild() && !node->getRightChild()) leafCount++;
362  }
363 
364  return leafCount;
365 }
int traverseBeachLeft(BSTNode *) const
Definition: BeachLine.cxx:464
int traverseBeachRight(BSTNode *) const
Definition: BeachLine.cxx:480
BSTNode * getLeftChild() const
Definition: BeachLine.h:74
int voronoi2d::BeachLine::traverseBeachLeft ( BSTNode node) const
private

Definition at line 464 of file BeachLine.cxx.

465 {
466  int leafCount(0);
467 
468  if (node)
469  {
470  // Keep traversing
471  if (node->getPredecessor()) leafCount += traverseBeachLeft(node->getPredecessor());
472 
473  // Are we also a leaf?
474  if (!node->getLeftChild() && !node->getRightChild()) leafCount++;
475  }
476 
477  return leafCount;
478 }
int traverseBeachLeft(BSTNode *) const
Definition: BeachLine.cxx:464
int voronoi2d::BeachLine::traverseBeachRight ( BSTNode node) const
private

Definition at line 480 of file BeachLine.cxx.

481 {
482  int leafCount(0);
483 
484  if (node)
485  {
486  // Keep traversing
487  if (node->getSuccessor()) leafCount += traverseBeachRight(node->getSuccessor());
488 
489  // Are we also a leaf?
490  if (!node->getLeftChild() && !node->getRightChild()) leafCount++;
491  }
492 
493  return leafCount;
494 }
int traverseBeachRight(BSTNode *) const
Definition: BeachLine.cxx:480

Member Data Documentation

BSTNodeList voronoi2d::BeachLine::m_nodeVec
private

Definition at line 166 of file BeachLine.h.

BSTNode* voronoi2d::BeachLine::m_root
private

Definition at line 165 of file BeachLine.h.

EventUtilities voronoi2d::BeachLine::m_utilities
private

Definition at line 168 of file BeachLine.h.


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