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);
}
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());
}
}
Aggregations