[GRASS-SVN] r39148 - grass/trunk/lib/vector/rtree
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Sep 12 11:40:07 EDT 2009
Author: mmetz
Date: 2009-09-12 11:40:06 -0400 (Sat, 12 Sep 2009)
New Revision: 39148
Modified:
grass/trunk/lib/vector/rtree/index.c
grass/trunk/lib/vector/rtree/node.c
grass/trunk/lib/vector/rtree/split.c
Log:
rtree minor bug fixes
Modified: grass/trunk/lib/vector/rtree/index.c
===================================================================
--- grass/trunk/lib/vector/rtree/index.c 2009-09-12 07:16:44 UTC (rev 39147)
+++ grass/trunk/lib/vector/rtree/index.c 2009-09-12 15:40:06 UTC (rev 39148)
@@ -189,7 +189,10 @@
/* child field of leaves contains tid of data record */
b.child = child;
/* add branch, may split node or remove branches */
- cover = &(s[top - 1].sn->branch[s[top - 1].branch_id].rect);
+ if (top)
+ cover = &(s[top - 1].sn->branch[s[top - 1].branch_id].rect);
+ else
+ cover = NULL;
result = RTreeAddBranch(&b, s[top].sn, &n2, ee, cover, overflow, t);
/* update node count */
if (result == 1) {
@@ -222,7 +225,10 @@
b.rect = RTreeNodeCover(b.child.ptr, t);
/* add branch, may split node or remove branches */
- cover = &(s[top - 1].sn->branch[s[top - 1].branch_id].rect);
+ if (top)
+ cover = &(s[top - 1].sn->branch[s[top - 1].branch_id].rect);
+ else
+ cover = NULL;
result =
RTreeAddBranch(&b, s[top].sn, &n2, ee, cover, overflow, t);
@@ -510,6 +516,7 @@
}
t->root = n->branch[i].child.ptr;
RTreeFreeNode(n);
+ t->n_levels--;
}
return 0;
}
Modified: grass/trunk/lib/vector/rtree/node.c
===================================================================
--- grass/trunk/lib/vector/rtree/node.c 2009-09-12 07:16:44 UTC (rev 39147)
+++ grass/trunk/lib/vector/rtree/node.c 2009-09-12 15:40:06 UTC (rev 39148)
@@ -22,7 +22,6 @@
#include "index.h"
#include "card.h"
-
/* rectangle distances for forced removal */
struct dist
{
@@ -433,7 +432,10 @@
RectReal center_n[NUMDIMS], center_r, delta;
struct Branch branchbuf[MAXCARD + 1];
struct dist rdist[MAXCARD + 1];
+ struct Rect new_cover;
+ assert(cover);
+
if ((n)->level > 0) {
maxkids = t->nodecard;
is_node = 1;
@@ -442,13 +444,14 @@
maxkids = t->leafcard;
is_node = 0;
}
- maxkids = (n)->level > 0 ? t->nodecard : t->leafcard;
assert(n->count == maxkids); /* must be full */
+ new_cover = RTreeCombineRect(cover, &(b->rect), t);
+
/* center coords of node cover */
for (j = 0; j < t->ndims; j++) {
- center_n[j] = (cover->boundary[j + NUMDIMS] + cover->boundary[j]) / 2;
+ center_n[j] = (new_cover.boundary[j + NUMDIMS] + new_cover.boundary[j]) / 2;
}
/* compute distances of child rectangle centers to node cover center */
@@ -458,8 +461,8 @@
rdist[i].id = i;
for (j = 0; j < t->ndims; j++) {
center_r =
- (n->branch[i].rect.boundary[j + NUMDIMS] +
- n->branch[i].rect.boundary[j]) / 2;
+ (branchbuf[i].rect.boundary[j + NUMDIMS] +
+ branchbuf[i].rect.boundary[j]) / 2;
delta = center_n[j] - center_r;
rdist[i].distance += delta * delta;
}
@@ -470,7 +473,14 @@
/* new branch */
branchbuf[maxkids] = *b;
rdist[maxkids].distance = 0;
- rdist[maxkids].id = i;
+ for (j = 0; j < t->ndims; j++) {
+ center_r =
+ (b->rect.boundary[j + NUMDIMS] +
+ b->rect.boundary[j]) / 2;
+ delta = center_n[j] - center_r;
+ rdist[maxkids].distance += delta * delta;
+ }
+ rdist[maxkids].id = maxkids;
/* quicksort dist */
RTreeQuicksortDist(rdist, maxkids);
Modified: grass/trunk/lib/vector/rtree/split.c
===================================================================
--- grass/trunk/lib/vector/rtree/split.c 2009-09-12 07:16:44 UTC (rev 39147)
+++ grass/trunk/lib/vector/rtree/split.c 2009-09-12 15:40:06 UTC (rev 39148)
@@ -464,7 +464,7 @@
static void RTreeMethodOne(struct PartitionVars *p, int minfill,
struct RTree *t)
{
- int i, j, k, l, s, maxkids, first_time = 1;
+ int i, j, k, l, s, maxkids;
int axis = 0, best_axis = 0, side = 0, best_side[NUMDIMS];
int best_cut[NUMDIMS];
RectReal margin, smallest_margin = 0;
@@ -530,7 +530,6 @@
if (margin <= smallest_margin) {
smallest_margin = margin;
best_axis = i;
- first_time = 0;
}
/* remember best distribution for this axis */
More information about the grass-commit
mailing list