[GRASS-SVN] r51800 - grass/trunk/lib/vector/diglib
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 26 11:21:35 EDT 2012
Author: mmetz
Date: 2012-05-26 08:21:35 -0700 (Sat, 26 May 2012)
New Revision: 51800
Modified:
grass/trunk/lib/vector/diglib/spindex.c
grass/trunk/lib/vector/diglib/spindex_rw.c
Log:
adjust diglib to changed rtree
Modified: grass/trunk/lib/vector/diglib/spindex.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex.c 2012-05-26 15:20:58 UTC (rev 51799)
+++ grass/trunk/lib/vector/diglib/spindex.c 2012-05-26 15:21:35 UTC (rev 51800)
@@ -38,7 +38,9 @@
ndims = (Plus->with_z != 0) ? 3 : 2;
Plus->spidx_with_z = (Plus->with_z != 0);
-
+
+ G_debug(1, "dig_spidx_init(), %d dims", ndims);
+
if (Plus->Spidx_file) {
int fd;
char *filename;
@@ -253,8 +255,15 @@
dig_spidx_add_node(struct Plus_head *Plus, int node,
double x, double y, double z)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_add_node(): node = %d, x,y,z = %f, %f, %f", node, x,
y, z);
@@ -280,8 +289,15 @@
*/
int dig_spidx_add_line(struct Plus_head *Plus, int line, struct bound_box * box)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_add_line(): line = %d", line);
rect.boundary[0] = box->W;
@@ -306,8 +322,15 @@
*/
int dig_spidx_add_area(struct Plus_head *Plus, int area, struct bound_box * box)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_add_area(): area = %d", area);
rect.boundary[0] = box->W;
@@ -333,8 +356,15 @@
int dig_spidx_add_isle(struct Plus_head *Plus, int isle, struct bound_box * box)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_add_isle(): isle = %d", isle);
rect.boundary[0] = box->W;
@@ -362,8 +392,15 @@
{
int ret;
struct P_node *Node;
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_del_node(): node = %d", node);
Node = Plus->Node[node];
@@ -395,10 +432,17 @@
*/
int dig_spidx_del_line(struct Plus_head *Plus, int line, double x, double y, double z)
{
+ int ret;
struct P_line *Line;
- struct RTree_Rect rect;
- int ret;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_del_line(): line = %d", line);
Line = Plus->Line[line];
@@ -437,8 +481,15 @@
struct P_line *Line;
struct P_node *Node;
struct P_topo_b *topo;
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_del_area(): area = %d", area);
Area = Plus->Area[area];
@@ -483,8 +534,15 @@
struct P_line *Line;
struct P_node *Node;
struct P_topo_b *topo;
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_spidx_del_isle(): isle = %d", isle);
Isle = Plus->Isle[isle];
@@ -565,8 +623,15 @@
dig_select_nodes(struct Plus_head *Plus, const struct bound_box * box,
struct ilist *list)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_select_nodes()");
list->n_values = 0;
@@ -604,9 +669,16 @@
*/
int dig_find_node(struct Plus_head *Plus, double x, double y, double z)
{
- struct RTree_Rect rect;
int node;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_find_node()");
rect.boundary[0] = x;
@@ -638,8 +710,15 @@
int dig_select_lines(struct Plus_head *Plus, const struct bound_box *box,
struct boxlist *list)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_select_lines_with_box()");
list->n_values = 0;
@@ -670,9 +749,16 @@
*/
int dig_find_line_box(struct Plus_head *Plus, struct boxlist *list)
{
- struct RTree_Rect rect;
int ret;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_find_line_box()");
if (list->n_values < 1)
@@ -706,8 +792,15 @@
dig_select_areas(struct Plus_head *Plus, const struct bound_box * box,
struct boxlist *list)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_select_areas_with_box()");
list->n_values = 0;
@@ -738,9 +831,16 @@
*/
int dig_find_area_box(struct Plus_head *Plus, struct boxlist *list)
{
- struct RTree_Rect rect;
int ret;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_find_line_box()");
if (list->n_values < 1)
@@ -774,8 +874,15 @@
dig_select_isles(struct Plus_head *Plus, const struct bound_box * box,
struct boxlist *list)
{
- struct RTree_Rect rect;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_select_areas_with_box()");
list->n_values = 0;
@@ -806,9 +913,16 @@
*/
int dig_find_isle_box(struct Plus_head *Plus, struct boxlist *list)
{
- struct RTree_Rect rect;
int ret;
+ static struct RTree_Rect rect;
+ static int rect_init = 0;
+ if (!rect_init) {
+ /* always 6 sides for 3D */
+ rect.boundary = G_malloc(6 * sizeof(RectReal));
+ rect_init = 6;
+ }
+
G_debug(3, "dig_find_line_box()");
if (list->n_values < 1)
Modified: grass/trunk/lib/vector/diglib/spindex_rw.c
===================================================================
--- grass/trunk/lib/vector/diglib/spindex_rw.c 2012-05-26 15:20:58 UTC (rev 51799)
+++ grass/trunk/lib/vector/diglib/spindex_rw.c 2012-05-26 15:21:35 UTC (rev 51800)
@@ -22,6 +22,26 @@
#include <grass/vector.h>
#include <grass/glocale.h>
+/* TODO: only write out actually used sides */
+#ifndef NUMSIDES
+#define NUMSIDES 6
+#endif
+
+/* TODO: merge these two */
+struct spidxstack
+{
+ off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
+ struct RTree_Node sn; /* stack node */
+ int branch_id; /* branch no to follow down */
+};
+
+struct spidxpstack
+{
+ off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
+ struct RTree_Node *sn; /* stack node pointer */
+ int branch_id; /* branch no to follow down */
+};
+
/*!
\brief Write spatial index header to file
@@ -590,7 +610,13 @@
int rtree_dump_node_file(FILE * fp, off_t pos, int with_z, struct RTree *t)
{
int i;
- struct RTree_Node n;
+ static struct RTree_Node n;
+ static int node_init = 0;
+
+ if (!node_init) {
+ for (i = 0; i < MAXCARD; i++)
+ RTreeNewRect(&(n.branch[i].rect), t);
+ }
/* recursive nearly-but-a-bit-messy depth-first pre-order traversal
* potentially filling up memory */
@@ -660,12 +686,7 @@
int sidx_nodesize, sidx_leafsize;
struct RTree_Node *n;
int i, j, writeout, maxcard;
- struct spidxstack
- {
- off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
- struct RTree_Node *sn; /* stack node */
- int branch_id; /* branch no to follow down */
- } s[50];
+ struct spidxpstack s[MAXLEVEL];
int top = 0;
/* should be foolproof */
@@ -765,14 +786,21 @@
int sidx_nodesize, sidx_leafsize;
struct RTree_Node *n;
int i, j, writeout, maxcard;
- struct spidxstack
- {
- off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
- struct RTree_Node sn; /* stack node */
- int branch_id; /* branch no to follow down */
- } s[MAXLEVEL];
+ static struct spidxstack s[MAXLEVEL];
+ static int stack_init = 0;
int top = 0;
+ if (!stack_init) {
+ for (i = 0; i < MAXLEVEL; i++) {
+ for (j = 0; j < MAXCARD; j++) {
+ s[i].sn.branch[j].rect.boundary = G_malloc(6 * sizeof(RectReal));
+ }
+ }
+ stack_init = 1;
+ }
+
+
+
/* write pending changes to file */
RTreeFlushBuffer(t);
@@ -879,14 +907,20 @@
{
struct RTree_Node *newnode = NULL;
int i, j, loadnode, maxcard;
- struct spidxstack
- {
- off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
- struct RTree_Node sn; /* stack node */
- int branch_id; /* branch no to follow down */
- } s[50], *last;
+ struct spidxstack *last;
+ static struct spidxstack s[MAXLEVEL];
+ static int stack_init = 0;
int top = 0;
+ if (!stack_init) {
+ for (i = 0; i < MAXLEVEL; i++) {
+ for (j = 0; j < MAXCARD; j++) {
+ s[i].sn.branch[j].rect.boundary = G_malloc(6 * sizeof(RectReal));
+ }
+ }
+ stack_init = 1;
+ }
+
/* stack size of t->rootlevel + 1 would be enough because of
* depth-first postorder traversal:
* only one node per level on stack at any given time */
@@ -1005,14 +1039,20 @@
struct RTree_Node newnode;
off_t newnode_pos = -1;
int i, j, loadnode, maxcard;
- struct spidxstack
- {
- off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
- struct RTree_Node sn; /* stack node */
- int branch_id; /* branch no to follow down */
- } s[MAXLEVEL], *last;
+ struct spidxstack *last;
+ static struct spidxstack s[MAXLEVEL];
+ static int stack_init = 0;
int top = 0;
+ if (!stack_init) {
+ for (i = 0; i < MAXLEVEL; i++) {
+ for (j = 0; j < MAXCARD; j++) {
+ s[i].sn.branch[j].rect.boundary = G_malloc(6 * sizeof(RectReal));
+ }
+ }
+ stack_init = 1;
+ }
+
/* stack size of t->rootlevel + 1 would be enough because of
* depth-first postorder traversal:
* only one node per level on stack at any given time */
@@ -1284,17 +1324,25 @@
{
int hitCount = 0, found, maxcard;
int i, j;
- struct spidxstack
- {
- off_t pos[MAXCARD]; /* file position of child node, object ID on level 0 */
- struct RTree_Node sn; /* stack node */
- int branch_id; /* branch no to follow down */
- } s[50], *last;
+ struct spidxstack *last;
+ static struct spidxstack s[MAXLEVEL];
+ static int stack_init = 0;
int top = 0;
assert(r);
assert(t);
+ if (!stack_init) {
+ struct Rect_Real *r;
+
+ for (i = 0; i < MAXLEVEL; i++) {
+ for (j = 0; j < MAXCARD; j++) {
+ s[i].sn.branch[j].rect.boundary = G_malloc(6 * sizeof(RectReal));
+ }
+ }
+ stack_init = 1;
+ }
+
/* stack size of t->rootlevel + 1 is enough because of depth first search */
/* only one node per level on stack at any given time */
More information about the grass-commit
mailing list