Search in sources :

Example 1 with NonLeafElement

use of rtree.NonLeafElement in project OsmAnd-tools by osmandapp.

the class SdTree method seedRec.

/**
 *     @param sdingNode The seeding node from which to copy (source).
 *     @param level The height at which this node falls in the tree.
 */
private // sd
void seedRec(// sd
Node sdingNode, // sd
Node sdNode, // sd
int level) throws Exception {
    if (sdingNode.getElementType() == Node.LEAF_NODE)
        throw new IllegalArgumentException("SdTree.seedRec : Cannot seed a leaf node");
    // make the child nodes before hand so that we know their indices in file
    // sd
    Node[] chNodes = null;
    if (// we do not need to alocate new nodes if we are at slot level
    level != slotLvl)
        // sd
        chNodes = new Node[sdingNode.getTotalElements()];
    Element[] elmts = sdingNode.getAllElements();
    // elements for non-slot levels
    Element[] newElmts;
    if (level != slotLvl)
        // non slots have multiple elements
        newElmts = new Element[sdingNode.getTotalElements()];
    else {
        // slot has only one element
        newElmts = new Element[1];
        // element for slot level
        newElmts[0] = new NonLeafElement(new Rect(), Node.NOT_DEFINED);
    }
    for (int i = 0; i < sdingNode.getTotalElements(); i++) {
        if (level != slotLvl) {
            // we do not seed leaf elements
            newElmts[i] = (NonLeafElement) ((NonLeafElement) elmts[i]).clone();
            chNodes[i] = // sd
            chdNodes.getNode(// sd
            fileHdr.getFile(), // sd
            fileName, // sd
            sdNode.getNodeIndex(), sdingNode.getElementType(), fileHdr);
            // update the child pointers for new node
            newElmts[i].setPtr(chNodes[i].getNodeIndex());
            seedRec(sdingTree.getReadNode(elmts[i].getPtr()), chNodes[i], level + 1);
        } else {
            // this is the slot level
            /*What we do here is that we put only one element into the slot node instead of all the elements.
          This would result in a single element in the node which represents all the seding node elements
          with a null pointer.
        */
            newElmts[0].getRect().expandToInclude(elmts[i].getRect());
        }
    // else
    }
    // for
    // copy the non-slot elements now //sd
    sdNode.insertElement(newElmts, false);
}
Also used : Rect(rtree.Rect) Node(rtree.Node) Element(rtree.Element) NonLeafElement(rtree.NonLeafElement) NonLeafElement(rtree.NonLeafElement)

Aggregations

Element (rtree.Element)1 Node (rtree.Node)1 NonLeafElement (rtree.NonLeafElement)1 Rect (rtree.Rect)1