[GRASS-SVN] r51673 - grass/trunk/lib/vector/rtree
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 23 08:56:04 EDT 2012
Author: mmetz
Date: 2012-05-23 05:56:03 -0700 (Wed, 23 May 2012)
New Revision: 51673
Modified:
grass/trunk/lib/vector/rtree/index.c
grass/trunk/lib/vector/rtree/index.h
grass/trunk/lib/vector/rtree/indexf.c
grass/trunk/lib/vector/rtree/node.c
grass/trunk/lib/vector/rtree/rect.c
grass/trunk/lib/vector/rtree/rtree.h
grass/trunk/lib/vector/rtree/split.c
Log:
rtreelib: update header, change node init
Modified: grass/trunk/lib/vector/rtree/index.c
===================================================================
--- grass/trunk/lib/vector/rtree/index.c 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/index.c 2012-05-23 12:56:03 UTC (rev 51673)
@@ -43,6 +43,11 @@
new_rtree->rootpos = rootpos;
new_rtree->ndims = ndims;
new_rtree->nsides = 2 * ndims;
+ /* hack to keep compatibility */
+ if (ndims < 3)
+ new_rtree->nsides_alloc = 6;
+ else
+ new_rtree->nsides_alloc = 2 * ndims;
new_rtree->rectsize = sizeof(struct RTree_Rect);
Modified: grass/trunk/lib/vector/rtree/index.h
===================================================================
--- grass/trunk/lib/vector/rtree/index.h 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/index.h 2012-05-23 12:56:03 UTC (rev 51673)
@@ -80,7 +80,8 @@
void RTreeTabIn(int);
/* rect.c */
-void RTreeInitRect(struct RTree_Rect *);
+void RTreeNewRect(struct RTree_Rect *, struct RTree *);
+void RTreeInitRect(struct RTree_Rect *, struct RTree *);
struct RTree_Rect RTreeNullRect(void);
RectReal RTreeRectArea(struct RTree_Rect *, struct RTree *);
RectReal RTreeRectSphericalVolume(struct RTree_Rect *, struct RTree *);
@@ -88,7 +89,6 @@
RectReal RTreeRectMargin(struct RTree_Rect *, struct RTree *);
struct RTree_Rect RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
int RTreeCompareRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
-int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
void RTreePrintRect(struct RTree_Rect *, int);
/* split.c */
Modified: grass/trunk/lib/vector/rtree/indexf.c
===================================================================
--- grass/trunk/lib/vector/rtree/indexf.c 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/indexf.c 2012-05-23 12:56:03 UTC (rev 51673)
@@ -252,7 +252,7 @@
RTreeGetNode(&oldroot, t->rootpos, t->rootlevel, t);
/* grow a new root, & tree taller */
t->rootlevel++;
- RTreeInitNode(&newroot, NODETYPE(t->rootlevel, t->fd));
+ RTreeInitNode(t, &newroot, NODETYPE(t->rootlevel, t->fd));
newroot.level = t->rootlevel;
/* branch for old root */
b.rect = RTreeNodeCover(&oldroot, t);
@@ -284,7 +284,7 @@
RTreeGetNode(&oldroot, t->rootpos, t->rootlevel, t);
/* grow a new root, & tree taller */
t->rootlevel++;
- RTreeInitNode(&newroot, NODETYPE(t->rootlevel, t->fd));
+ RTreeInitNode(t, &newroot, NODETYPE(t->rootlevel, t->fd));
newroot.level = t->rootlevel;
/* branch for old root */
b.rect = RTreeNodeCover(&oldroot, t);
Modified: grass/trunk/lib/vector/rtree/node.c
===================================================================
--- grass/trunk/lib/vector/rtree/node.c 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/node.c 2012-05-23 12:56:03 UTC (rev 51673)
@@ -31,23 +31,23 @@
};
/* Initialize one branch cell in an internal node. */
-static void RTreeInitNodeBranchM(struct RTree_Branch *b)
+static void RTreeInitNodeBranchM(struct RTree *t, struct RTree_Branch *b)
{
- RTreeInitRect(&(b->rect));
+ RTreeInitRect(&(b->rect), t);
b->child.ptr = NULL;
}
/* Initialize one branch cell in an internal node. */
-static void RTreeInitNodeBranchF(struct RTree_Branch *b)
+static void RTreeInitNodeBranchF(struct RTree *t, struct RTree_Branch *b)
{
- RTreeInitRect(&(b->rect));
+ RTreeInitRect(&(b->rect), t);
b->child.pos = -1;
}
/* Initialize one branch cell in a leaf node. */
-static void RTreeInitLeafBranch(struct RTree_Branch *b)
+static void RTreeInitLeafBranch(struct RTree *t, struct RTree_Branch *b)
{
- RTreeInitRect(&(b->rect));
+ RTreeInitRect(&(b->rect), t);
b->child.id = 0;
}
@@ -57,7 +57,7 @@
/* Initialize a Node structure. */
/* type = 1: leaf, type = 2: internal, memory, type = 3: internal, file */
-void RTreeInitNode(struct RTree_Node *n, int type)
+void RTreeInitNode(struct RTree *t, struct RTree_Node *n, int type)
{
int i;
@@ -65,7 +65,7 @@
n->level = -1;
for (i = 0; i < MAXCARD; i++)
- RTreeInitBranch[type](&(n->branch[i]));
+ RTreeInitBranch[type](&(n->branch[i]), t);
}
/* Make a new node and initialize to have all branch cells empty. */
@@ -75,7 +75,7 @@
n = (struct RTree_Node *)malloc((size_t) t->nodesize);
assert(n);
- RTreeInitNode(n, NODETYPE(level, t->fd));
+ RTreeInitNode(t, n, NODETYPE(level, t->fd));
return n;
}
@@ -94,7 +94,7 @@
int i, first_time = 1;
struct RTree_Rect r;
- RTreeInitRect(&r);
+ RTreeInitRect(&r, t);
if ((n)->level > 0) { /* internal node */
for (i = 0; i < t->nodecard; i++) {
if (t->valid_child(&(n->branch[i].child))) {
@@ -234,14 +234,14 @@
assert(n && i >= 0 && i < t->nodecard);
assert(t->valid_child(&(n->branch[i].child)));
if (t->fd < 0)
- RTreeInitNodeBranchM(&(n->branch[i]));
+ RTreeInitNodeBranchM(t, &(n->branch[i]));
else
- RTreeInitNodeBranchF(&(n->branch[i]));
+ RTreeInitNodeBranchF(t, &(n->branch[i]));
}
else {
assert(n && i >= 0 && i < t->leafcard);
assert(n->branch[i].child.id);
- RTreeInitLeafBranch(&(n->branch[i]));
+ RTreeInitLeafBranch(t, &(n->branch[i]));
}
n->count--;
@@ -536,7 +536,7 @@
}
else {
if (t->fd > -1)
- RTreeInitNode(*newnode, NODETYPE(n->level, t->fd));
+ RTreeInitNode(t, *newnode, NODETYPE(n->level, t->fd));
else
*newnode = RTreeNewNode(t, (n)->level);
RTreeSplitNode(n, b, *newnode, t);
Modified: grass/trunk/lib/vector/rtree/rect.c
===================================================================
--- grass/trunk/lib/vector/rtree/rect.c 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/rect.c 2012-05-23 12:56:03 UTC (rev 51673)
@@ -32,15 +32,27 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#if 0
/*-----------------------------------------------------------------------------
+| Create a new rectangle for a given tree
+-----------------------------------------------------------------------------*/
+void RTreeNewRect(struct RTree_Rect *r, struct RTree *t)
+{
+ r->boundary = (struct RTree_Rect *)malloc((size_t) t->nsides_alloc);
+ assert(r->boundary);
+
+ RTreeInitRect(r, t);
+}
+#endif
+
+/*-----------------------------------------------------------------------------
| Initialize a rectangle to have all 0 coordinates.
-----------------------------------------------------------------------------*/
-void RTreeInitRect(struct RTree_Rect *R)
+void RTreeInitRect(struct RTree_Rect *r, struct RTree *t)
{
- register struct RTree_Rect *r = R;
register int i;
- for (i = 0; i < NUMSIDES; i++)
+ for (i = 0; i < t->nsides; i++)
r->boundary[i] = (RectReal) 0;
}
Modified: grass/trunk/lib/vector/rtree/rtree.h
===================================================================
--- grass/trunk/lib/vector/rtree/rtree.h 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/rtree.h 2012-05-23 12:56:03 UTC (rev 51673)
@@ -24,6 +24,7 @@
#define NUMDIMS 3 /* maximum number of dimensions */
+#define NUMSIDES 2*NUMDIMS
typedef double RectReal;
@@ -38,8 +39,6 @@
#define FALSE 0
#endif
-#define NUMSIDES 2*NUMDIMS
-
/* max branching factor of a node */
/* was (PGSIZE-(2 * sizeof(int))) / sizeof(struct Branch)
* this is LFS dependent, not good
@@ -100,12 +99,13 @@
struct RTree
{
/* RTree setup info */
- int fd; /* file descriptor */
- unsigned char ndims; /* number of dimensions */
- unsigned char nsides; /* number of sides = 2 * ndims */
- int nodesize; /* node size in bytes */
- int branchsize; /* branch size in bytes */
- int rectsize; /* rectangle size in bytes */
+ int fd; /* file descriptor */
+ unsigned char ndims; /* number of dimensions */
+ unsigned char nsides; /* number of sides = 2 * ndims */
+ unsigned char nsides_alloc; /* number of sides = 2 * ndims */
+ int nodesize; /* node size in bytes */
+ int branchsize; /* branch size in bytes */
+ int rectsize; /* rectangle size in bytes */
/* RTree info, useful to calculate space requirements */
int n_nodes; /* number of nodes */
@@ -159,10 +159,11 @@
int RTreeDeleteRect(struct RTree_Rect *, int, struct RTree *);
struct RTree *RTreeNewIndex(int, off_t, int);
void RTreeFreeIndex(struct RTree *);
+int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
/* RTree node management */
struct RTree_Node *RTreeNewNode(struct RTree *, int);
-void RTreeInitNode(struct RTree_Node *, int);
+void RTreeInitNode(struct RTree *, struct RTree_Node *, int);
void RTreeFreeNode(struct RTree_Node *);
void RTreeDestroyNode(struct RTree_Node *, int);
Modified: grass/trunk/lib/vector/rtree/split.c
===================================================================
--- grass/trunk/lib/vector/rtree/split.c 2012-05-23 12:29:50 UTC (rev 51672)
+++ grass/trunk/lib/vector/rtree/split.c 2012-05-23 12:56:03 UTC (rev 51673)
@@ -73,7 +73,7 @@
CoverSplitArea = RTreeRectSphericalVolume(&CoverSplit, t);
}
- RTreeInitNode(n, NODETYPE(n->level, t->fd));
+ RTreeInitNode(t, n, NODETYPE(n->level, t->fd));
}
/*----------------------------------------------------------------------
More information about the grass-commit
mailing list