Search in sources :

Example 6 with Node

use of rtree.Node 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)

Example 7 with Node

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

the class SdTree method chooseLeaf.

/**
 *     This method is a copy of <code>RTree.chooseLeaf</code> with minor modifications.
 *     In fact there are number of changes , most important is that this method will just not get the new
 *     Node, but also change the parent's (slot node) child pointer.
 *     Remeber that if there are no leaf node associated with a slot selected, this method creates one
 *     returns this new Node after doing the process described above.
 *     but if there is a leaf node present then that node is returned just as in simple rtrees.
 */
private // sd
Node chooseLeaf(// sd
Element elmt, // sd
LongWraper slotIndex) throws RTreeException, IOException {
    /*TODO : we may also have to traverse non seed node, i.e grown nodes.*/
    try {
        // get the root node
        long root = fileHdr.getRootIndex();
        int level = 0;
        // sd
        Node sltNode = chdNodes.getNode(fileHdr.getFile(), fileName, root, fileHdr);
        // repeat till you reach a slot node
        while (sltNode.getElementType() != Node.LEAF_NODE) {
            // (level != slotLvl){
            // get the best fitting rect from the node
            Element nextElmt = sltNode.getLeastEnlargement(elmt);
            if (level == slotLvl) {
                slotIndex.val = sltNode.getNodeIndex();
                if (nextElmt.getPtr() == Node.NOT_DEFINED) {
                    // the first leaf node for this slot node
                    Node rtNode = // sd
                    chdNodes.getNode(// sd
                    fileHdr.getFile(), // sd
                    fileName, // sd
                    sltNode.getNodeIndex(), Node.LEAF_NODE, fileHdr);
                    sltNode.modifyElement(0, rtNode.getNodeIndex());
                    nextElmt.setPtr(rtNode.getNodeIndex());
                    return rtNode;
                }
            }
            // if are here then we are not at a slot that has no childs
            // sd
            sltNode = chdNodes.getNode(fileHdr.getFile(), fileName, nextElmt.getPtr(), fileHdr);
            level++;
        }
        // if we are here then we reached a proper leaf node rather than a slot node
        return sltNode;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RTreeException(e.getMessage());
    }
}
Also used : RTreeException(rtree.RTreeException) Node(rtree.Node) Element(rtree.Element) NonLeafElement(rtree.NonLeafElement) RTreeException(rtree.RTreeException) NodeFullException(rtree.NodeFullException) IOException(java.io.IOException) NodeReadException(rtree.NodeReadException) FileNotFoundException(java.io.FileNotFoundException) IllegalValueException(rtree.IllegalValueException) NodeWriteException(rtree.NodeWriteException)

Aggregations

Node (rtree.Node)7 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 IllegalValueException (rtree.IllegalValueException)4 NodeFullException (rtree.NodeFullException)4 NodeReadException (rtree.NodeReadException)4 NodeWriteException (rtree.NodeWriteException)4 RTreeException (rtree.RTreeException)4 Element (rtree.Element)3 NonLeafElement (rtree.NonLeafElement)3 Rect (rtree.Rect)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)1 MapData (net.osmand.binary.OsmandOdb.MapData)1 MapDataBlock (net.osmand.binary.OsmandOdb.MapDataBlock)1 BinaryFileReference (net.osmand.data.preparation.BinaryFileReference)1 Element (org.w3c.dom.Element)1 LeafElement (rtree.LeafElement)1