public ISpatialIndexNode <IExtents, TItem> SplitNode( ISpatialIndexNode <IExtents, TItem> node, IndexBalanceHeuristic heuristic) { if (node == null) { throw new ArgumentNullException("node"); } RTreeNode <TItem> rTreeNode = node as RTreeNode <TItem>; Debug.Assert(rTreeNode != null); DynamicRTreeBalanceHeuristic rTreeHueristic = heuristic as DynamicRTreeBalanceHeuristic; return(doSplit(rTreeNode, rTreeHueristic)); }
private void distribute(IList <IBoundable <IExtents> > entries, IBoundable <IExtents>[] group1, IBoundable <IExtents>[] group2, IndexBalanceHeuristic heuristic, ref Int32 group1Count, ref Int32 group2Count) { // recursion halting case #1 if (entries.Count == 0) { return; } // recursion halting case #2 if (group1Count == heuristic.TargetNodeCount || group2Count == heuristic.TargetNodeCount) { return; } IBoundable <IExtents> entry; ComputationExtents group1Bounds = computeBounds(group1, group1Count); ComputationExtents group2Bounds = computeBounds(group2, group2Count); GroupBoundsLeastEnlarged group = pickNext(entries, group1Bounds, group2Bounds, out entry); switch (group) { case GroupBoundsLeastEnlarged.Group1: group1[group1Count++] = entry; break; case GroupBoundsLeastEnlarged.Group2: group2[group2Count++] = entry; break; case GroupBoundsLeastEnlarged.Tie: Double group1BoundsArea = group1Bounds.Area; Double group2BoundsArea = group2Bounds.Area; if (group1BoundsArea < group2BoundsArea) { group1[group1Count++] = entry; } else if (group2BoundsArea < group1BoundsArea) { group2[group2Count++] = entry; } else if (group1Count < group2Count) { group1[group1Count++] = entry; } else if (group2Count < group1Count) { group2[group2Count++] = entry; } else if (_random.Next(0, 2) == 0) // generates 0 or 1 randomly { group1[group1Count++] = entry; } else { group2[group2Count++] = entry; } break; default: throw new InvalidOperationException("Unknown group."); } distribute(entries, group1, group2, heuristic, ref group1Count, ref group2Count); }
public void Insert(TBounds bounds, TItem entry, ISpatialIndexNode <TBounds, TItem> node, INodeSplitStrategy <TBounds, TItem> nodeSplitStrategy, IndexBalanceHeuristic heuristic, out ISpatialIndexNode <TBounds, TItem> newSiblingFromSplit) { newSiblingFromSplit = null; //TODO: handle null node.. // Terminating case if (node.IsLeaf) { node.Add(entry); // Handle node overflow if (node.ItemCount > heuristic.NodeItemMaximumCount) { // Split the node using the given strategy newSiblingFromSplit = nodeSplitStrategy.SplitNode(node, heuristic); //if (++_tempSplitCount % 100 == 0) //{ // Debug.Print("Node split # {0}", _tempSplitCount); //} } } else { // NOTE: Descending the tree recursively here // can make for a very expensive build of a tree, // even for moderate amounts of data. Double leastExpandedArea = Double.MaxValue; Double leastExpandedChildArea = Double.MaxValue; //TBounds currentBounds = new ComputationExtents(bounds); ISpatialIndexNode <TBounds, TItem> leastExpandedChild; leastExpandedChild = findLeastExpandedChild(node.SubNodes, bounds, leastExpandedArea, leastExpandedChildArea); Debug.Assert(leastExpandedChild != null); // Found least expanded child node - insert into it Insert(bounds, entry, leastExpandedChild, nodeSplitStrategy, heuristic, out newSiblingFromSplit); // Adjust this node... node.Bounds.ExpandToInclude(bounds); // Check for overflow and add to current node if it occured if (newSiblingFromSplit != null) { // Add new sibling node to the current node node.Add(newSiblingFromSplit); newSiblingFromSplit = null; // Split the current node, since the child count is too high, // and return the split to the caller if (node.ItemCount > heuristic.NodeItemMaximumCount) { newSiblingFromSplit = nodeSplitStrategy.SplitNode(node, heuristic); } } } }
public ISpatialIndexNode <TBounds, TItem> SplitNode(ISpatialIndexNode <TBounds, TItem> node, IndexBalanceHeuristic heuristic) { if (node == null) { throw new ArgumentNullException("node"); } DynamicRTreeBalanceHeuristic rTreeHueristic = heuristic as DynamicRTreeBalanceHeuristic; return(doSplit(node, rTreeHueristic)); }
private void insertEntryRecursive(QuadTreeNode <TItem> quadTreeNode, TItem entry, INodeSplitStrategy <IExtents, TItem> nodeSplitStrategy, IndexBalanceHeuristic heuristic, out ISpatialIndexNode <IExtents, TItem> newSiblingFromSplit) { throw new NotImplementedException(); }
public void Insert(IExtents bounds, TItem entry, ISpatialIndexNode <IExtents, TItem> node, INodeSplitStrategy <IExtents, TItem> nodeSplitStrategy, IndexBalanceHeuristic heuristic, out ISpatialIndexNode <IExtents, TItem> newSiblingFromSplit) { if (node == null) { throw new ArgumentNullException("node"); } if (!(node is QuadTreeNode <TItem>)) { throw new ArgumentException("Parameter 'node' must be of type QuadTreeNode<TItem>", "node"); } QuadTreeNode <TItem> quadTreeNode = node as QuadTreeNode <TItem>; insertEntryRecursive(quadTreeNode, entry, nodeSplitStrategy, heuristic, out newSiblingFromSplit); if (newSiblingFromSplit != null) { if (quadTreeNode.ItemCount == 4) { throw new QuadTreeIndexInsertOverflowException(); } quadTreeNode.Add(newSiblingFromSplit); } }
public ISpatialIndexNode <IExtents, TItem> SplitNode(ISpatialIndexNode <IExtents, TItem> node, IndexBalanceHeuristic heuristic) { if (node == null) { return(null); } QuadTreeNode <TItem> quadTreeNode = node as QuadTreeNode <TItem>; DynamicQuadTreeBalanceHeuristic quadTreeHeuristic = heuristic as DynamicQuadTreeBalanceHeuristic; throw new NotImplementedException(); }