Exemple #1
0
  // delete all leaf nodes marked with DELETE_UPDATE and update the
  // bounds of the parents node
  BHNode deleteAndUpdateMarkedNodes() {

    if (this.mark == true) {
      if (this.nodeType == BH_TYPE_LEAF) {
        this.deleteFromParent();
        return null;

      } else {
        if (debug)
          if (((BHInternalNode) (this)).rChild == ((BHInternalNode) (this)).lChild)
            System.err.println(
                "rChild "
                    + ((BHInternalNode) (this)).rChild
                    + " lChild "
                    + ((BHInternalNode) (this)).lChild);

        if (((BHInternalNode) (this)).rChild != null)
          ((BHInternalNode) (this)).rChild =
              ((BHInternalNode) (this)).rChild.deleteAndUpdateMarkedNodes();
        if (((BHInternalNode) (this)).lChild != null)
          ((BHInternalNode) (this)).lChild =
              ((BHInternalNode) (this)).lChild.deleteAndUpdateMarkedNodes();

        if ((((BHInternalNode) (this)).rChild == null)
            && (((BHInternalNode) (this)).lChild == null)) {
          this.deleteFromParent();
          return null;
        } else {
          if (((BHInternalNode) this).rChild == null) {
            BHNode leftChild = ((BHInternalNode) this).lChild;
            leftChild.parent = this.parent;
            // delete self, return lChild
            this.deleteFromParent();
            return leftChild;
          } else if (((BHInternalNode) this).lChild == null) {
            BHNode rightChild = ((BHInternalNode) this).rChild;
            rightChild.parent = this.parent;
            // delete self, return rChild
            this.deleteFromParent();
            return rightChild;
          } else {
            // recompute your bounds and return yourself
            this.combineBHull(((BHInternalNode) this).rChild, ((BHInternalNode) this).lChild);
            // update the parent's pointers
            ((BHInternalNode) this).rChild.parent = this;
            ((BHInternalNode) this).lChild.parent = this;
            this.mark = false;
            return this;
          }
        }
      }
    } else {
      // mark is NOT set, simply return self
      return this;
    }
  }
Exemple #2
0
  // given two nodes determine the bHull surrounding them, ie. the parent hull
  void combineBHull(BHNode node1, BHNode node2) {
    BoundingBox bHull1 = null;
    BoundingBox bHull2 = null;

    bHull1 = node1.getBoundingHull();
    bHull2 = node2.getBoundingHull();

    if (this.bHull == null) this.bHull = new BoundingBox(bHull1);
    else this.bHull.set(bHull1);

    this.bHull.combine(bHull2);
  }