Example #1
0
  OcNode(ID3BoundingBox box, int maxNodeSize) {
    super(new ArrayList<>(maxNodeSize), maxNodeSize);
    this.box = box;
    // Split into up and down.
    ID3BoundingBox[] split = box.splitMidY();

    ID3BoundingBox[] uxsplit = split[0].splitMidX();
    ID3BoundingBox[] uyupsplit = uxsplit[0].splitMidY();
    ID3BoundingBox[] uydownsplit = uxsplit[1].splitMidY();
    ID3BoundingBox unw = uyupsplit[0];
    ID3BoundingBox usw = uyupsplit[1];
    ID3BoundingBox une = uydownsplit[0];
    ID3BoundingBox use = uydownsplit[1];

    ID3BoundingBox[] dxsplit = split[0].splitMidX();
    ID3BoundingBox[] dyupsplit = dxsplit[0].splitMidY();
    ID3BoundingBox[] dydownsplit = dxsplit[1].splitMidY();
    ID3BoundingBox dnw = dyupsplit[0];
    ID3BoundingBox dsw = dyupsplit[1];
    ID3BoundingBox dne = dydownsplit[0];
    ID3BoundingBox dse = dydownsplit[1];

    subboxes.put(unw, Quadrant.UNW);
    subboxes.put(usw, Quadrant.USW);
    subboxes.put(une, Quadrant.UNE);
    subboxes.put(use, Quadrant.USE);

    subboxes.put(dnw, Quadrant.DNW);
    subboxes.put(dsw, Quadrant.DSW);
    subboxes.put(dne, Quadrant.DNE);
    subboxes.put(dse, Quadrant.DSE);
  }
Example #2
0
  @Override
  void add(Pair<K, V> newpair) {
    assert box.contains(newpair.getKey()) : "Not contained: " + box + " - " + newpair.getKey();
    OcNode<K, V> child = getChild(newpair.getKey());

    if (child == this) {
      super.add(newpair);
    } else {
      child.add(newpair);
    }
  }
Example #3
0
  /**
   * True if this nodes integrity (all conditions that are required for a quadnode) are true.
   *
   * @return True if this nodes integrity (all conditions that are required for a quadnode) are
   *     true.
   */
  boolean checkIntegrity() {
    assert getMaxNodeSize() >= 1;
    assert subboxes != null;
    assert subboxes.size() == 8;
    assert subboxes.keySet().stream().noneMatch((b) -> b == null);
    //        assert values.size() <= parent.getMaxNodeSize();
    assert getValues().stream().noneMatch((p) -> p == null);
    assert getValues().stream().allMatch((p) -> box.contains(p.getKey()));

    assert getChildren().values().stream().distinct().count()
        == getChildren().values().stream().filter((n) -> n != null).count();
    return true;
  }
Example #4
0
  /**
   * Returns the child that contains the key, or this node if no child contains the key.
   *
   * @param key Key to query for child containment.
   * @return A child node if the key fits into a child node or this node, if the key doesn't fit
   *     within any child node.
   */
  OcNode<K, V> getChild(K key) {
    assert box.contains(key);

    if (isSplit()) {
      for (Map.Entry<ID3BoundingBox, Quadrant> entry : subboxes.entrySet()) {
        if (entry.getKey().contains(key)) {
          if (!hasChild(entry.getValue())) {
            setChild(entry.getValue(), new OcNode<>(entry.getKey(), getMaxNodeSize()));
          }

          return getChild(entry.getValue());
        }
      }
    }

    return this;
  }