[GRASS-SVN] r52645 - in grass/trunk/lib/vector: Vlib diglib rtree

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 12 16:06:44 PDT 2012


Author: huhabla
Date: 2012-08-12 16:06:44 -0700 (Sun, 12 Aug 2012)
New Revision: 52645

Modified:
   grass/trunk/lib/vector/Vlib/break_polygons.c
   grass/trunk/lib/vector/Vlib/intersect.c
   grass/trunk/lib/vector/Vlib/select.c
   grass/trunk/lib/vector/Vlib/snap.c
   grass/trunk/lib/vector/diglib/spindex.c
   grass/trunk/lib/vector/diglib/spindex_rw.c
   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/indexm.c
   grass/trunk/lib/vector/rtree/node.c
   grass/trunk/lib/vector/rtree/rect.c
   grass/trunk/lib/vector/rtree/rtree.h
Log:
Added methods to modify rectangle boundary coordinates of different dimensions. Modified the names of several functions. Added doxygen style function descriptions.


Modified: grass/trunk/lib/vector/Vlib/break_polygons.c
===================================================================
--- grass/trunk/lib/vector/Vlib/break_polygons.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/Vlib/break_polygons.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -130,7 +130,7 @@
 
     filename = G_tempfile();
     fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-    RTree = RTreeNewIndex(fd, 0, 2);
+    RTree = RTreeCreateTree(fd, 0, 2);
     remove(filename);
 
     filename = G_tempfile();
@@ -389,7 +389,7 @@
     }
 
     close(RTree->fd);
-    RTreeFreeIndex(RTree);
+    RTreeDestroyTree(RTree);
     close(xpntfd);
     Vect_destroy_line_struct(Points);
     Vect_destroy_line_struct(BPoints);

Modified: grass/trunk/lib/vector/Vlib/intersect.c
===================================================================
--- grass/trunk/lib/vector/Vlib/intersect.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/Vlib/intersect.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -692,7 +692,7 @@
      *  in bound box */
 
     /* Create rtree for B line */
-    MyRTree = RTreeNewIndex(-1, 0, 2);
+    MyRTree = RTreeCreateTree(-1, 0, 2);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];
@@ -756,7 +756,7 @@
     }
 
     /* Free RTree */
-    RTreeFreeIndex(MyRTree);
+    RTreeDestroyTree(MyRTree);
 
     G_debug(2, "n_cross = %d", n_cross);
     /* Lines do not cross each other */
@@ -1239,7 +1239,7 @@
      *  in bound box */
 
     /* Create rtree for B line */
-    MyRTree = RTreeNewIndex(-1, 0, 2);
+    MyRTree = RTreeCreateTree(-1, 0, 2);
     for (i = 0; i < BPoints->n_points - 1; i++) {
 	if (BPoints->x[i] <= BPoints->x[i + 1]) {
 	    rect.boundary[0] = BPoints->x[i];
@@ -1309,7 +1309,7 @@
     }
 
     /* Free RTree */
-    RTreeFreeIndex(MyRTree);
+    RTreeDestroyTree(MyRTree);
 
     return cross_found;
 }

Modified: grass/trunk/lib/vector/Vlib/select.c
===================================================================
--- grass/trunk/lib/vector/Vlib/select.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/Vlib/select.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -31,7 +31,7 @@
 {
     G_debug(1, "Vect_spatial_index_init()");
 
-    si->si_tree = RTreeNewIndex(-1, 0, 2 + (with_z != 0));
+    si->si_tree = RTreeCreateTree(-1, 0, 2 + (with_z != 0));
 }
 
 /*!
@@ -47,7 +47,7 @@
 {
     G_debug(1, "Vect_spatial_index_destroy()");
 
-    RTreeFreeIndex(si->si_tree);
+    RTreeDestroyTree(si->si_tree);
 }
 
 /*!

Modified: grass/trunk/lib/vector/Vlib/snap.c
===================================================================
--- grass/trunk/lib/vector/Vlib/snap.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/Vlib/snap.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -127,7 +127,7 @@
 	rtreefd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
 	remove(filename);
     }
-    RTree = RTreeNewIndex(rtreefd, 0, 2);
+    RTree = RTreeCreateTree(rtreefd, 0, 2);
 
     thresh2 = thresh * thresh;
 
@@ -438,7 +438,7 @@
     G_free(XPnts);
     G_free(Index);
     G_free(New);
-    RTreeFreeIndex(RTree);
+    RTreeDestroyTree(RTree);
     if (rtreefd >= 0)
 	close(rtreefd);
 

Modified: grass/trunk/lib/vector/diglib/spindex.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/diglib/spindex.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -47,22 +47,22 @@
 	
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Node_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Node_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
 
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Line_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Line_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
 
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Area_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Area_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
 
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Isle_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Isle_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
 
 	Plus->Face_spidx = NULL;
@@ -70,10 +70,10 @@
 	Plus->Hole_spidx = NULL;
     }
     else {
-	Plus->Node_spidx = RTreeNewIndex(-1, 0, ndims);
-	Plus->Line_spidx = RTreeNewIndex(-1, 0, ndims);
-	Plus->Area_spidx = RTreeNewIndex(-1, 0, ndims);
-	Plus->Isle_spidx = RTreeNewIndex(-1, 0, ndims);
+	Plus->Node_spidx = RTreeCreateTree(-1, 0, ndims);
+	Plus->Line_spidx = RTreeCreateTree(-1, 0, ndims);
+	Plus->Area_spidx = RTreeCreateTree(-1, 0, ndims);
+	Plus->Isle_spidx = RTreeCreateTree(-1, 0, ndims);
 	Plus->Face_spidx = NULL;
 	Plus->Volume_spidx = NULL;
 	Plus->Hole_spidx = NULL;
@@ -109,15 +109,15 @@
 	char *filename;
 	
 	close(Plus->Node_spidx->fd);
-	RTreeFreeIndex(Plus->Node_spidx);
+	RTreeDestroyTree(Plus->Node_spidx);
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Node_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Node_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
     }
     else {
-	RTreeFreeIndex(Plus->Node_spidx);
-	Plus->Node_spidx = RTreeNewIndex(-1, 0, ndims);
+	RTreeDestroyTree(Plus->Node_spidx);
+	Plus->Node_spidx = RTreeCreateTree(-1, 0, ndims);
     }
 }
 
@@ -138,15 +138,15 @@
 	char *filename;
 	
 	close(Plus->Line_spidx->fd);
-	RTreeFreeIndex(Plus->Line_spidx);
+	RTreeDestroyTree(Plus->Line_spidx);
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Line_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Line_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
     }
     else {
-	RTreeFreeIndex(Plus->Line_spidx);
-	Plus->Line_spidx = RTreeNewIndex(-1, 0, ndims);
+	RTreeDestroyTree(Plus->Line_spidx);
+	Plus->Line_spidx = RTreeCreateTree(-1, 0, ndims);
     }
 }
 
@@ -167,15 +167,15 @@
 	char *filename;
 	
 	close(Plus->Area_spidx->fd);
-	RTreeFreeIndex(Plus->Area_spidx);
+	RTreeDestroyTree(Plus->Area_spidx);
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Area_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Area_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
     }
     else {
-	RTreeFreeIndex(Plus->Area_spidx);
-	Plus->Area_spidx = RTreeNewIndex(-1, 0, ndims);
+	RTreeDestroyTree(Plus->Area_spidx);
+	Plus->Area_spidx = RTreeCreateTree(-1, 0, ndims);
     }
 }
 
@@ -196,15 +196,15 @@
 	char *filename;
 	
 	close(Plus->Isle_spidx->fd);
-	RTreeFreeIndex(Plus->Isle_spidx);
+	RTreeDestroyTree(Plus->Isle_spidx);
 	filename = G_tempfile();
 	fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-	Plus->Isle_spidx = RTreeNewIndex(fd, 0, ndims);
+	Plus->Isle_spidx = RTreeCreateTree(fd, 0, ndims);
 	remove(filename);
     }
     else {
-	RTreeFreeIndex(Plus->Isle_spidx);
-	Plus->Isle_spidx = RTreeNewIndex(-1, 0, ndims);
+	RTreeDestroyTree(Plus->Isle_spidx);
+	Plus->Isle_spidx = RTreeCreateTree(-1, 0, ndims);
     }
 }
 
@@ -218,22 +218,22 @@
     /* Node spidx */
     if (Plus->Node_spidx->fd > -1)
 	close(Plus->Node_spidx->fd);
-    RTreeFreeIndex(Plus->Node_spidx);
+    RTreeDestroyTree(Plus->Node_spidx);
 
     /* Line spidx */
     if (Plus->Line_spidx->fd > -1)
 	close(Plus->Line_spidx->fd);
-    RTreeFreeIndex(Plus->Line_spidx);
+    RTreeDestroyTree(Plus->Line_spidx);
 
     /* Area spidx */
     if (Plus->Area_spidx->fd > -1)
 	close(Plus->Area_spidx->fd);
-    RTreeFreeIndex(Plus->Area_spidx);
+    RTreeDestroyTree(Plus->Area_spidx);
 
     /* Isle spidx */
     if (Plus->Isle_spidx->fd > -1)
 	close(Plus->Isle_spidx->fd);
-    RTreeFreeIndex(Plus->Isle_spidx);
+    RTreeDestroyTree(Plus->Isle_spidx);
 
     /* 3D future : */
     /* Face spidx */

Modified: grass/trunk/lib/vector/diglib/spindex_rw.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex_rw.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/diglib/spindex_rw.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -617,7 +617,7 @@
     
     if (!node_init) {
 	for (i = 0; i < MAXCARD; i++)
-	    RTreeNewRect(&(n.branch[i].rect), t);
+	    RTreeAllocBoundary(&(n.branch[i].rect), t);
     }
 
     /* recursive nearly-but-a-bit-messy depth-first pre-order traversal
@@ -998,7 +998,7 @@
 	if (loadnode) {
 	    /* ready to load node to memory */
 
-	    newnode = RTreeNewNode(t, s[top].sn.level);
+	    newnode = RTreeAllocNode(t, s[top].sn.level);
 	    /* copy from stack node */
 	    RTreeCopyNode(newnode, &(s[top].sn), t);
 

Modified: grass/trunk/lib/vector/rtree/index.c
===================================================================
--- grass/trunk/lib/vector/rtree/index.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/index.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -31,7 +31,7 @@
  * ndims number of dimensions
  * returns pointer to RTree structure
  */
-struct RTree *RTreeNewIndex(int fd, off_t rootpos, int ndims)
+struct RTree *RTreeCreateTree(int fd, off_t rootpos, int ndims)
 {
     struct RTree *new_rtree;
     struct RTree_Node *n;
@@ -65,7 +65,7 @@
                             sizeof(RectReal *) + new_rtree->rectsize;
     
     /* create empty root node */
-    n = RTreeNewNode(new_rtree, 0);
+    n = RTreeAllocNode(new_rtree, 0);
     new_rtree->rootlevel = n->level = 0;       /* leaf */
     new_rtree->root = NULL;
 
@@ -89,11 +89,11 @@
 
 	    /* alloc memory for rectangles */
 	    for (j = 0; j < MAXCARD; j++) {
-		RTreeNewRect(&(new_rtree->nb[i][0].n.branch[j].rect), new_rtree);
-		RTreeNewRect(&(new_rtree->nb[i][1].n.branch[j].rect), new_rtree);
-		RTreeNewRect(&(new_rtree->nb[i][2].n.branch[j].rect), new_rtree);
+		RTreeAllocBoundary(&(new_rtree->nb[i][0].n.branch[j].rect), new_rtree);
+		RTreeAllocBoundary(&(new_rtree->nb[i][1].n.branch[j].rect), new_rtree);
+		RTreeAllocBoundary(&(new_rtree->nb[i][2].n.branch[j].rect), new_rtree);
 
-		RTreeNewRect(&(new_rtree->fs[i].sn.branch[j].rect), new_rtree);
+		RTreeAllocBoundary(&(new_rtree->fs[i].sn.branch[j].rect), new_rtree);
 	    }
 	}
 
@@ -136,25 +136,25 @@
     new_rtree->n_leafs = 0;
 
     /* initialize temp variables */
-    RTreeNewRect(&(new_rtree->p.cover[0]), new_rtree);
-    RTreeNewRect(&(new_rtree->p.cover[1]), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->p.cover[0]), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->p.cover[1]), new_rtree);
     
-    RTreeNewRect(&(new_rtree->tmpb1.rect), new_rtree);
-    RTreeNewRect(&(new_rtree->tmpb2.rect), new_rtree);
-    RTreeNewRect(&(new_rtree->c.rect), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->tmpb1.rect), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->tmpb2.rect), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->c.rect), new_rtree);
     for (i = 0; i <= MAXCARD; i++) {
-	RTreeNewRect(&(new_rtree->BranchBuf[i].rect), new_rtree);
+	RTreeAllocBoundary(&(new_rtree->BranchBuf[i].rect), new_rtree);
     }
-    RTreeNewRect(&(new_rtree->rect_0), new_rtree);
-    RTreeNewRect(&(new_rtree->rect_1), new_rtree);
-    RTreeNewRect(&(new_rtree->upperrect), new_rtree);
-    RTreeNewRect(&(new_rtree->orect), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->rect_0), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->rect_1), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->upperrect), new_rtree);
+    RTreeAllocBoundary(&(new_rtree->orect), new_rtree);
     new_rtree->center_n = (RectReal *)malloc(new_rtree->ndims_alloc * sizeof(RectReal));
 
     return new_rtree;
 }
 
-void RTreeFreeIndex(struct RTree *t)
+void RTreeDestroyTree(struct RTree *t)
 {
     int i, j;
 
@@ -173,29 +173,28 @@
 
 	    /* free memory for rectangles */
 	    for (j = 0; j < MAXCARD; j++) {
-		free(t->nb[i][0].n.branch[j].rect.boundary);
-		free(t->nb[i][1].n.branch[j].rect.boundary);
-		free(t->nb[i][2].n.branch[j].rect.boundary);
-
-		free(t->fs[i].sn.branch[j].rect.boundary);
+		RTreeFreeBoundary(&(t->nb[i][0].n.branch[j].rect));
+		RTreeFreeBoundary(&(t->nb[i][1].n.branch[j].rect));
+		RTreeFreeBoundary(&(t->nb[i][2].n.branch[j].rect));
+		RTreeFreeBoundary(&(t->fs[i].sn.branch[j].rect));
 	    }
 	}
     }
 
     /* free temp variables */
-    free(t->p.cover[0].boundary);
-    free(t->p.cover[1].boundary);
+    RTreeFreeBoundary(&(t->p.cover[0]));
+    RTreeFreeBoundary(&(t->p.cover[1]));
     
-    free(t->tmpb1.rect.boundary);
-    free(t->tmpb2.rect.boundary);
-    free(t->c.rect.boundary);
+    RTreeFreeBoundary(&(t->tmpb1.rect));
+    RTreeFreeBoundary(&(t->tmpb2.rect));
+    RTreeFreeBoundary(&(t->c.rect));
     for (i = 0; i <= MAXCARD; i++) {
-	free(t->BranchBuf[i].rect.boundary);
+        RTreeFreeBoundary(&(t->BranchBuf[i].rect));
     }
-    free(t->rect_0.boundary);
-    free(t->rect_1.boundary);
-    free(t->upperrect.boundary);
-    free(t->orect.boundary);
+    RTreeFreeBoundary(&(t->rect_0));
+    RTreeFreeBoundary(&(t->rect_1));
+    RTreeFreeBoundary(&(t->upperrect));
+    RTreeFreeBoundary(&(t->orect));
     free(t->center_n);
 
     free(t);
@@ -295,7 +294,7 @@
  */
 void RTreeFreeListBranch(struct RTree_ListBranch *p)
 {
-    free(p->b.rect.boundary);
+    RTreeFreeBoundary(&(p->b.rect));
     free(p);
 }
 

Modified: grass/trunk/lib/vector/rtree/index.h
===================================================================
--- grass/trunk/lib/vector/rtree/index.h	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/index.h	2012-08-12 23:06:44 UTC (rev 52645)
@@ -92,7 +92,6 @@
 void RTreeCombineRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
 void RTreeExpandRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
 int RTreeCompareRect(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
-void RTreePrintRect(struct RTree_Rect *, int, struct RTree *);
 
 /*-----------------------------------------------------------------------------
 | Copy second rectangle to first rectangle.

Modified: grass/trunk/lib/vector/rtree/indexf.c
===================================================================
--- grass/trunk/lib/vector/rtree/indexf.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/indexf.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -126,9 +126,9 @@
     
     if (!rect_init) {
 	for (i = 0; i < MAXCARD; i++) {
-	    RTreeNewRect(&(nn.branch[i].rect), t);
+	    RTreeAllocBoundary(&(nn.branch[i].rect), t);
 	}
-	RTreeNewRect(&nr, t);
+	RTreeAllocBoundary(&nr, t);
 	rect_init = t->ndims_alloc;
     }
 
@@ -240,9 +240,9 @@
     
     if (!rect_init) {
 	for (i = 0; i < MAXCARD; i++) {
-	    RTreeNewRect(&(oldroot.branch[i].rect), t);
-	    RTreeNewRect(&(newroot.branch[i].rect), t);
-	    RTreeNewRect(&(newnode.branch[i].rect), t);
+	    RTreeAllocBoundary(&(oldroot.branch[i].rect), t);
+	    RTreeAllocBoundary(&(newroot.branch[i].rect), t);
+	    RTreeAllocBoundary(&(newnode.branch[i].rect), t);
 	}
 	rect_init = t->ndims_alloc;
     }
@@ -336,7 +336,7 @@
     assert(ee);
     
     if (!rect_init) {
-	RTreeNewRect(&(nr), t);
+	RTreeAllocBoundary(&(nr), t);
 	rect_init = 1;
     }
 
@@ -409,7 +409,7 @@
 	else {
 	    /* not enough entries in child, eliminate child node */
 	    assert(s[top].sn.branch[i].child.pos == s[down].pos);
-	    n = RTreeNewNode(t, s[down].sn.level);
+	    n = RTreeAllocNode(t, s[down].sn.level);
 	    /* copy node */
 	    RTreeCopyNode(n, &(s[down].sn), t);
 	    RTreeAddNodePos(s[top].sn.branch[i].child.pos, s[down].sn.level, t);
@@ -442,7 +442,7 @@
     
     if (!rect_init) {
 	for (i = 0; i < MAXCARD; i++) {
-	    RTreeNewRect(&(rn.branch[i].rect), t);
+	    RTreeAllocBoundary(&(rn.branch[i].rect), t);
 	}
 	rect_init = 1;
     }

Modified: grass/trunk/lib/vector/rtree/indexm.c
===================================================================
--- grass/trunk/lib/vector/rtree/indexm.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/indexm.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -204,7 +204,7 @@
     if (result == 1) {		/* root split */
 	/* grow a new root, & tree taller */
 	t->rootlevel++;
-	newroot = RTreeNewNode(t, t->rootlevel);
+	newroot = RTreeAllocNode(t, t->rootlevel);
 	newroot->level = t->rootlevel;
 	/* branch for old root */
 	RTreeNodeCover(t->root, &(b->rect), t);
@@ -237,7 +237,7 @@
 	    if (result == 1) {	/* root split */
 		/* grow a new root, & tree taller */
 		t->rootlevel++;
-		newroot = RTreeNewNode(t, t->rootlevel);
+		newroot = RTreeAllocNode(t, t->rootlevel);
 		newroot->level = t->rootlevel;
 		/* branch for old root */
 		RTreeNodeCover(t->root, &(b->rect), t);

Modified: grass/trunk/lib/vector/rtree/node.c
===================================================================
--- grass/trunk/lib/vector/rtree/node.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/node.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -71,7 +71,7 @@
 }
 
 /* Make a new node and initialize to have all branch cells empty. */
-struct RTree_Node *RTreeNewNode(struct RTree *t, int level)
+struct RTree_Node *RTreeAllocNode(struct RTree *t, int level)
 {
     int i;
     struct RTree_Node *n;
@@ -83,7 +83,7 @@
     n->level = level;
 
     for (i = 0; i < MAXCARD; i++) {
-	RTreeNewRect(&(n->branch[i].rect), t);
+	RTreeAllocBoundary(&(n->branch[i].rect), t);
 	RTreeInitBranch[NODETYPE(level, t->fd)](&(n->branch[i]), t);
     }
 
@@ -97,7 +97,7 @@
     assert(n);
 
     for (i = 0; i < MAXCARD; i++)
-	free(n->branch[i].rect.boundary);
+	RTreeFreeBoundary(&(n->branch[i].rect));
 
     free(n);
 }
@@ -433,7 +433,7 @@
        (struct RTree_ListBranch *)malloc(sizeof(struct RTree_ListBranch));
 
     assert(p);
-    RTreeNewRect(&(p->b.rect), t);
+    RTreeAllocBoundary(&(p->b.rect), t);
 
     return p;
 }
@@ -578,7 +578,7 @@
 	    if (t->fd > -1)
 		RTreeInitNode(t, *newnode, NODETYPE(n->level, t->fd));
 	    else
-		*newnode = RTreeNewNode(t, (n)->level);
+		*newnode = RTreeAllocNode(t, (n)->level);
 	    RTreeSplitNode(n, b, *newnode, t);
 	    return 1;
 	}

Modified: grass/trunk/lib/vector/rtree/rect.c
===================================================================
--- grass/trunk/lib/vector/rtree/rect.c	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/rect.c	2012-08-12 23:06:44 UTC (rev 52645)
@@ -31,19 +31,82 @@
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 
+/**-----------------------------------------------------------------------------
+ \brief Create a new rectangle for a given tree
 
-/*-----------------------------------------------------------------------------
-| Create a new rectangle for a given tree
+ This method allocates a new rectangle and initializes
+ the internal boundary coordinates based on the tree dimension.
+
+ Hence a call to RTreeNewBoundary() is not necessary.
+
+ \param t: The pointer to a RTree struct
+ \return A new allocated RTree_Rect struct
 -----------------------------------------------------------------------------*/
-void RTreeNewRect(struct RTree_Rect *r, struct RTree *t)
+struct RTree_Rect *RTreeAllocRect(struct RTree *t)
 {
+    struct RTree_Rect *r;
+
+    assert(t);
+
+    r = (struct RTree_Rect *)malloc(sizeof(struct RTree_Rect));
+
+    assert(r);
+
+    RTreeAllocBoundary(r, t);
+    return r;
+}
+
+/**----------------------------------------------------------------------------
+ \brief Delete a rectangle
+
+ This method deletes (free) the allocated memory of a rectangle.
+
+ \param r: The pointer to the rectangle to be deleted
+-----------------------------------------------------------------------------*/
+void RTreeFreeRect(struct RTree_Rect *r)
+{
+    assert(r);
+    RTreeFreeBoundary(r);
+    free(r);
+}
+
+/**----------------------------------------------------------------------------
+ \brief Allocate the boundary array of a rectangle for a given tree
+
+ This method allocated the boundary coordinates array in
+ provided rectangle. It does not release previously allocated memory.
+
+ \param r: The  pointer to rectangle to initialize the boundary coordinates.
+           This is usually a rectangle that was created on the stack or
+           self allocated.
+ \param t: The pointer to a RTree struct
+-----------------------------------------------------------------------------*/
+void RTreeAllocBoundary(struct RTree_Rect *r, struct RTree *t)
+{
+    assert(r && t);
     r->boundary = (RectReal *)malloc(t->rectsize);
     assert(r->boundary);
 }
 
-/*-----------------------------------------------------------------------------
-| Initialize a rectangle to have all 0 coordinates.
+/**----------------------------------------------------------------------------
+ \brief Delete the boundary of a rectangle
+
+ This method deletes (free) the memory of the boundary of a rectangle
+ and sets the boundary pointer to NULL.
+
+ \param r: The pointer to the rectangle to delete the boundary from.
 -----------------------------------------------------------------------------*/
+void RTreeFreeBoundary(struct RTree_Rect *r)
+{
+    assert(r);
+    if(r->boundary)
+        free(r->boundary);
+    r->boundary = NULL;
+}
+
+/**-----------------------------------------------------------------------------
+ \brief Initialize a rectangle to have all 0 coordinates.
+-----------------------------------------------------------------------------*/
 void RTreeInitRect(struct RTree_Rect *r, struct RTree *t)
 {
     register int i;
@@ -52,6 +115,109 @@
 	r->boundary[i] = r->boundary[i + t->ndims_alloc] = (RectReal) 0;
 }
 
+/**-----------------------------------------------------------------------------
+ \brief Set one dimensional coordinates of a rectangle for a given tree.
+
+ All coordinates of the rectangle will be initialized to 0 before
+ the x coordinates are set.
+
+ \param r: The pointer to the rectangle
+ \param t: The pointer to the RTree
+ \param x_min: The lower x coordinate
+ \param x_max: The higher x coordinate
+-----------------------------------------------------------------------------*/
+void RTreeSetRect1D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max)
+{
+    RTreeInitRect(r, t);
+    r->boundary[0] = (RectReal)x_min;
+    r->boundary[t->ndims_alloc] = (RectReal)x_max;
+}
+
+/**-----------------------------------------------------------------------------
+ \brief Set two dimensional coordinates of a rectangle for a given tree.
+
+ All coordinates of the rectangle will be initialized to 0 before
+ the x and y coordinates are set.
+
+ \param r: The pointer to the rectangle
+ \param t: The pointer to the RTree
+ \param x_min: The lower x coordinate
+ \param x_max: The higher x coordinate
+ \param y_min: The lower y coordinate
+ \param y_max: The higher y coordinate
+-----------------------------------------------------------------------------*/
+void RTreeSetRect2D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max)
+{
+    RTreeInitRect(r, t);
+    r->boundary[0] = (RectReal)x_min;
+    r->boundary[t->ndims_alloc] = (RectReal)x_max;
+    r->boundary[1] = (RectReal)y_min;
+    r->boundary[1 + t->ndims_alloc] = (RectReal)y_max;
+}
+
+/**-----------------------------------------------------------------------------
+ \brief Set three dimensional coordinates of a rectangle for a given tree.
+
+ All coordinates of the rectangle will be initialized to 0 before
+ the x,y and z coordinates are set.
+
+ \param r: The pointer to the rectangle
+ \param t: The pointer to the RTree
+ \param x_min: The lower x coordinate
+ \param x_max: The higher x coordinate
+ \param y_min: The lower y coordinate
+ \param y_max: The higher y coordinate
+ \param z_min: The lower z coordinate
+ \param z_max: The higher z coordinate
+-----------------------------------------------------------------------------*/
+void RTreeSetRect3D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max, double z_min,
+                   double z_max)
+{
+    RTreeInitRect(r, t);
+    r->boundary[0] = (RectReal)x_min;
+    r->boundary[t->ndims_alloc] = (RectReal)x_max;
+    r->boundary[1] = (RectReal)y_min;
+    r->boundary[1 + t->ndims_alloc] = (RectReal)y_max;
+    r->boundary[2] = (RectReal)z_min;
+    r->boundary[2 + t->ndims_alloc] = (RectReal)z_max;
+}
+
+/**-----------------------------------------------------------------------------
+ \brief Set 4 dimensional coordinates of a rectangle for a given tree.
+
+ All coordinates of the rectangle will be initialized to 0 before
+ the x,y,z and t coordinates are set.
+
+ \param r: The pointer to the rectangle
+ \param t: The pointer to the RTree
+ \param x_min: The lower x coordinate
+ \param x_max: The higher x coordinate
+ \param y_min: The lower y coordinate
+ \param y_max: The higher y coordinate
+ \param z_min: The lower z coordinate
+ \param z_max: The higher z coordinate
+ \param t_min: The lower t coordinate
+ \param t_max: The higher t coordinate
+-----------------------------------------------------------------------------*/
+void RTreeSetRect4D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max, double z_min,
+                   double z_max, double t_min, double t_max)
+{
+    assert(t->ndims >= 4);
+
+    RTreeInitRect(r, t);
+    r->boundary[0] = (RectReal)x_min;
+    r->boundary[t->ndims_alloc] = (RectReal)x_max;
+    r->boundary[1] = (RectReal)y_min;
+    r->boundary[1 + t->ndims_alloc] = (RectReal)y_max;
+    r->boundary[2] = (RectReal)z_min;
+    r->boundary[2 + t->ndims_alloc] = (RectReal)z_max;
+    r->boundary[3] = (RectReal)t_min;
+    r->boundary[3 + t->ndims_alloc] = (RectReal)t_max;
+}
 /*-----------------------------------------------------------------------------
 | Return a rect whose first low side is higher than its opposite side -
 | interpreted as an undefined rect.

Modified: grass/trunk/lib/vector/rtree/rtree.h
===================================================================
--- grass/trunk/lib/vector/rtree/rtree.h	2012-08-12 20:28:13 UTC (rev 52644)
+++ grass/trunk/lib/vector/rtree/rtree.h	2012-08-12 23:06:44 UTC (rev 52645)
@@ -198,21 +198,36 @@
 int RTreeSearch(struct RTree *, struct RTree_Rect *,
                 SearchHitCallback *, void *);
 int RTreeInsertRect(struct RTree_Rect *, int, struct RTree *);
+void RTreeSetRect1D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max);
+void RTreeSetRect2D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max);
+void RTreeSetRect3D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max, double z_min,
+                   double z_max);
+void RTreeSetRect4D(struct RTree_Rect *r, struct RTree *t, double x_min,
+                   double x_max, double y_min, double y_max, double z_min,
+                   double z_max, double t_min, double t_max);
 int RTreeDeleteRect(struct RTree_Rect *, int, struct RTree *);
-struct RTree *RTreeNewIndex(int, off_t, int);
-void RTreeFreeIndex(struct RTree *);
+void RTreePrintRect(struct RTree_Rect *, int, struct RTree *);
+struct RTree *RTreeCreateTree(int, off_t, int);
+void RTreeDestroyTree(struct RTree *);
 int RTreeOverlap(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
 int RTreeContained(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
 int RTreeContains(struct RTree_Rect *, struct RTree_Rect *, struct RTree *);
 
 /* RTree node management */
-struct RTree_Node *RTreeNewNode(struct RTree *, int);
+struct RTree_Node *RTreeAllocNode(struct RTree *, int);
 void RTreeInitNode(struct RTree *, struct RTree_Node *, int);
 void RTreeCopyNode(struct RTree_Node *, struct RTree_Node *, struct RTree *);
 void RTreeFreeNode(struct RTree_Node *);
 void RTreeDestroyNode(struct RTree_Node *, int);
 
-void RTreeNewRect(struct RTree_Rect *, struct RTree *);
+/* RTree rectangle allocation and deletion */
+struct RTree_Rect *RTreeAllocRect(struct RTree *t);
+void RTreeFreeRect(struct RTree_Rect *r);
+void RTreeAllocBoundary(struct RTree_Rect *r, struct RTree *t);
+void RTreeFreeBoundary(struct RTree_Rect *r);
 
 /* RTree IO */
 size_t RTreeReadNode(struct RTree_Node *, off_t, struct RTree *);



More information about the grass-commit mailing list