[GRASS-SVN] r46956 - grass/trunk/lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 4 06:47:13 EDT 2011
Author: mmetz
Date: 2011-07-04 03:47:13 -0700 (Mon, 04 Jul 2011)
New Revision: 46956
Modified:
grass/trunk/lib/vector/Vlib/box.c
grass/trunk/lib/vector/Vlib/break_lines.c
grass/trunk/lib/vector/Vlib/build_nat.c
grass/trunk/lib/vector/Vlib/find.c
grass/trunk/lib/vector/Vlib/list.c
grass/trunk/lib/vector/Vlib/read_ogr.c
grass/trunk/lib/vector/Vlib/remove_duplicates.c
grass/trunk/lib/vector/Vlib/sindex.c
Log:
remove redundant code in vector lib: update Vlib
Modified: grass/trunk/lib/vector/Vlib/box.c
===================================================================
--- grass/trunk/lib/vector/Vlib/box.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/box.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -250,7 +250,7 @@
}
if (list == NULL) {
- list = Vect_new_boxlist();
+ list = Vect_new_boxlist(1);
}
Vect_reset_boxlist(list);
@@ -318,7 +318,7 @@
Node = Plus->Node[topo->N1];
if (list == NULL) {
- list = Vect_new_boxlist();
+ list = Vect_new_boxlist(1);
}
Vect_reset_boxlist(list);
@@ -384,7 +384,7 @@
Node = Plus->Node[topo->N1];
if (list == NULL) {
- list = Vect_new_boxlist();
+ list = Vect_new_boxlist(1);
}
Vect_reset_boxlist(list);
Modified: grass/trunk/lib/vector/Vlib/break_lines.c
===================================================================
--- grass/trunk/lib/vector/Vlib/break_lines.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/break_lines.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -70,7 +70,7 @@
int naxlines, nbxlines, nx;
double *xx = NULL, *yx = NULL, *zx = NULL;
struct bound_box ABox, BBox;
- struct ilist *List;
+ struct boxlist *List;
int nbreaks;
int touch1_n = 0, touch1_s = 0, touch1_e = 0, touch1_w = 0; /* other vertices except node1 touching box */
int touch2_n = 0, touch2_s = 0, touch2_e = 0, touch2_w = 0; /* other vertices except node2 touching box */
@@ -84,7 +84,7 @@
ACats = Vect_new_cats_struct();
BCats = Vect_new_cats_struct();
Cats = Vect_new_cats_struct();
- List = Vect_new_list();
+ List = Vect_new_boxlist(1);
is3d = Vect_is_3d(Map);
@@ -169,7 +169,7 @@
G_debug(3, " %d lines selected by box", List->n_values);
for (j = 0; j < List->n_values; j++) {
- bline = List->value[j];
+ bline = List->id[j];
if (List_break && !Vect_val_in_list(List_break, bline)) {
continue;
}
@@ -181,7 +181,7 @@
if (!is3d) {
Vect_get_line_nodes(Map, aline, &anode1, &anode2);
Vect_get_line_nodes(Map, bline, &bnode1, &bnode2);
- Vect_line_box(BPoints, &BBox);
+ BBox = List->box[j];
if (anode1 == bnode1 || anode1 == bnode2)
node = anode1;
@@ -381,7 +381,7 @@
Vect_destroy_cats_struct(ACats);
Vect_destroy_cats_struct(BCats);
Vect_destroy_cats_struct(Cats);
- Vect_destroy_list(List);
+ Vect_destroy_boxlist(List);
return nbreaks;
}
Modified: grass/trunk/lib/vector/Vlib/build_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_nat.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/build_nat.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -158,7 +158,7 @@
}
if (first_call) {
- List = Vect_new_boxlist();
+ List = Vect_new_boxlist(1);
APoints = Vect_new_line_struct();
first_call = 0;
}
@@ -176,7 +176,7 @@
box.S = Node->y;
box.T = PORT_DOUBLE_MAX;
box.B = -PORT_DOUBLE_MAX;
- Vect_select_areas_by_box_with_box(Map, &box, List);
+ Vect_select_areas_by_box(Map, &box, List);
G_debug(3, "%d areas overlap island boundary point", List->n_values);
sel_area = 0;
@@ -310,7 +310,7 @@
{
int i, isle;
static int first = 1;
- static struct ilist *List;
+ static struct boxlist *List;
struct Plus_head *plus;
G_debug(3, "Vect_attach_isles ()");
@@ -318,7 +318,7 @@
plus = &(Map->plus);
if (first) {
- List = Vect_new_list();
+ List = Vect_new_boxlist(0);
first = 0;
}
@@ -326,7 +326,7 @@
G_debug(3, " number of isles to attach = %d", List->n_values);
for (i = 0; i < List->n_values; i++) {
- isle = List->value[i];
+ isle = List->id[i];
/* only attach isles that are not yet attached, see Vect_attach_isle() */
if (plus->Isle[isle]->area == 0)
Vect_attach_isle(Map, isle);
@@ -346,7 +346,7 @@
{
int i, sel_area, centr;
static int first = 1;
- static struct ilist *List;
+ static struct boxlist *List;
static struct line_pnts *Points;
struct P_area *Area;
struct P_line *Line;
@@ -358,7 +358,7 @@
plus = &(Map->plus);
if (first) {
- List = Vect_new_list();
+ List = Vect_new_boxlist(0);
Points = Vect_new_line_struct();
first = 0;
}
@@ -394,7 +394,7 @@
for (i = 0; i < List->n_values; i++) {
int orig_area;
- centr = List->value[i];
+ centr = List->id[i];
Line = plus->Line[centr];
topo = (struct P_topo_c *)Line->topo;
Modified: grass/trunk/lib/vector/Vlib/find.c
===================================================================
--- grass/trunk/lib/vector/Vlib/find.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/find.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -174,7 +174,7 @@
static int first_time = 1;
const struct Plus_head *Plus;
struct bound_box box;
- struct ilist *List;
+ struct boxlist *List;
G_debug(3, "Vect_find_line_list() for %f %f %f type = %d maxdist = %f",
ux, uy, uz, type, maxdist);
@@ -202,14 +202,14 @@
box.B = -PORT_DOUBLE_MAX;
}
- List = Vect_new_list();
+ List = Vect_new_boxlist(0);
if (found)
Vect_reset_list(found);
Vect_select_lines_by_box(map, &box, type, List);
for (i = 0; i < List->n_values; i++) {
- line = List->value[i];
+ line = List->id[i];
if (Vect_val_in_list(exclude, line)) {
G_debug(3, " line = %d exclude", line);
continue;
@@ -248,7 +248,7 @@
if (cur_dist > maxdist)
choice = 0;
- Vect_destroy_list(List);
+ Vect_destroy_boxlist(List);
return (choice);
}
@@ -274,7 +274,7 @@
G_debug(3, "Vect_find_area() x = %f y = %f", x, y);
if (first) {
- List = Vect_new_boxlist();
+ List = Vect_new_boxlist(1);
first = 0;
alloc_size_list = 10;
size_list = G_malloc(alloc_size_list * sizeof(BOX_SIZE));
@@ -287,7 +287,7 @@
box.S = y;
box.T = PORT_DOUBLE_MAX;
box.B = -PORT_DOUBLE_MAX;
- Vect_select_areas_by_box_with_box(Map, &box, List);
+ Vect_select_areas_by_box(Map, &box, List);
G_debug(3, " %d areas selected by box", List->n_values);
/* sort areas by size, the smallest is likely to be the nearest */
@@ -345,7 +345,7 @@
G_debug(3, "Vect_find_island() x = %f y = %f", x, y);
if (first) {
- List = Vect_new_boxlist();
+ List = Vect_new_boxlist(1);
Points = Vect_new_line_struct();
first = 0;
}
@@ -357,7 +357,7 @@
box.S = y;
box.T = PORT_DOUBLE_MAX;
box.B = -PORT_DOUBLE_MAX;
- Vect_select_isles_by_box_with_box(Map, &box, List);
+ Vect_select_isles_by_box(Map, &box, List);
G_debug(3, " %d islands selected by box", List->n_values);
current_size = -1;
Modified: grass/trunk/lib/vector/Vlib/list.c
===================================================================
--- grass/trunk/lib/vector/Vlib/list.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/list.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -219,7 +219,7 @@
* \return pointer to struct boxlist
* \return NULL on error
*/
-struct boxlist *Vect_new_boxlist(void)
+struct boxlist *Vect_new_boxlist(int have_boxes)
{
struct boxlist *p;
@@ -228,6 +228,7 @@
if (p) {
p->id = NULL;
p->box = NULL;
+ p->have_boxes = have_boxes != 0;
p->n_values = 0;
p->alloc_values = 0;
}
@@ -263,7 +264,8 @@
if (list) { /* probably a moot test */
if (list->alloc_values) {
G_free((void *)list->id);
- G_free((void *)list->box);
+ if (list->box)
+ G_free((void *)list->box);
}
G_free((void *)list);
}
@@ -296,14 +298,17 @@
size = (list->n_values + 1000) * sizeof(int);
list->id = (int *)G_realloc((void *)list->id, size);
- size = (list->n_values + 1000) * sizeof(struct bound_box);
- list->box = (struct bound_box *)G_realloc((void *)list->box, size);
+ if (list->have_boxes) {
+ size = (list->n_values + 1000) * sizeof(struct bound_box);
+ list->box = (struct bound_box *)G_realloc((void *)list->box, size);
+ }
list->alloc_values = list->n_values + 1000;
}
list->id[list->n_values] = id;
- list->box[list->n_values] = box;
+ if (list->have_boxes)
+ list->box[list->n_values] = box;
list->n_values++;
return 0;
@@ -325,9 +330,18 @@
if (alist == NULL || blist == NULL)
return 1;
- for (i = 0; i < blist->n_values; i++)
- Vect_boxlist_append(alist, blist->id[i], blist->box[i]);
+ if (blist->have_boxes) {
+ for (i = 0; i < blist->n_values; i++)
+ Vect_boxlist_append(alist, blist->id[i], blist->box[i]);
+ }
+ else {
+ struct bound_box box;
+ box.E = box.N = box.N = box.S = box.T = box.B = 0;
+ for (i = 0; i < blist->n_values; i++)
+ Vect_boxlist_append(alist, blist->id[i], box);
+ }
+
return 0;
}
@@ -351,7 +365,8 @@
if (id == list->id[i]) {
for (j = i + 1; j < list->n_values; j++) {
list->id[j - 1] = list->id[j];
- list->box[j - 1] = list->box[j];
+ if (list->have_boxes)
+ list->box[j - 1] = list->box[j];
}
list->n_values--;
Modified: grass/trunk/lib/vector/Vlib/read_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_ogr.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/read_ogr.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -473,8 +473,8 @@
/* get area bbox */
Vect_get_area_box(Map, topo->area, &box);
/* search in spatial index for centroid with area bbox */
- dig_init_boxlist(&list);
- Vect_select_lines_by_box_with_box(Map, &box, Line->type, &list);
+ dig_init_boxlist(&list, 1);
+ Vect_select_lines_by_box(Map, &box, Line->type, &list);
found = 0;
for (i = 0; i < list.n_values; i++) {
Modified: grass/trunk/lib/vector/Vlib/remove_duplicates.c
===================================================================
--- grass/trunk/lib/vector/Vlib/remove_duplicates.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/remove_duplicates.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -39,7 +39,7 @@
int i, j, c, atype, btype, bline;
int nlines, nbcats_orig;
struct bound_box ABox;
- struct ilist *List;
+ struct boxlist *List;
int ndupl;
@@ -48,7 +48,7 @@
ACats = Vect_new_cats_struct();
BCats = Vect_new_cats_struct();
Cats = Vect_new_cats_struct();
- List = Vect_new_list();
+ List = Vect_new_boxlist(0);
nlines = Vect_get_num_lines(Map);
@@ -74,7 +74,7 @@
G_debug(3, " %d lines selected by box", List->n_values);
for (j = 0; j < List->n_values; j++) {
- bline = List->value[j];
+ bline = List->id[j];
G_debug(3, " j = %d bline = %d", j, bline);
if (i == bline)
continue;
Modified: grass/trunk/lib/vector/Vlib/sindex.c
===================================================================
--- grass/trunk/lib/vector/Vlib/sindex.c 2011-07-04 10:46:44 UTC (rev 46955)
+++ grass/trunk/lib/vector/Vlib/sindex.c 2011-07-04 10:47:13 UTC (rev 46956)
@@ -16,61 +16,7 @@
#include <stdlib.h>
#include <grass/vector.h>
-/*!
- \brief Select lines by box.
- Select lines whose boxes overlap specified box!!! It means that
- selected line may or may not overlap the box.
-
- \param Map vector map
- \param Box bounding box
- \param type line type
- \param[out] list output list, must be initialized
-
- \return number of lines
- */
-int
-Vect_select_lines_by_box(struct Map_info *Map, const struct bound_box * Box,
- int type, struct ilist *list)
-{
- int i, line, nlines;
- struct Plus_head *plus;
- struct P_line *Line;
- static struct ilist *LocList = NULL;
-
- G_debug(3, "Vect_select_lines_by_box()");
- G_debug(3, " Box(N,S,E,W,T,B): %e, %e, %e, %e, %e, %e", Box->N, Box->S,
- Box->E, Box->W, Box->T, Box->B);
- plus = &(Map->plus);
-
- if (!(plus->Spidx_built)) {
- G_debug(3, "Building spatial index.");
- Vect_build_sidx_from_topo(Map);
- }
-
- list->n_values = 0;
- if (!LocList)
- LocList = Vect_new_list();
-
- nlines = dig_select_lines(plus, Box, LocList);
- G_debug(3, " %d lines selected (all types)", nlines);
-
- /* Remove lines of not requested types */
- for (i = 0; i < nlines; i++) {
- line = LocList->value[i];
- if (plus->Line[line] == NULL)
- continue; /* Should not happen */
- Line = plus->Line[line];
- if (!(Line->type & type))
- continue;
- dig_list_add(list, line);
- }
-
- G_debug(3, " %d lines of requested type", list->n_values);
-
- return list->n_values;
-}
-
/*!
\brief Select lines with bounding boxes by box.
@@ -85,7 +31,7 @@
\return number of lines
*/
int
-Vect_select_lines_by_box_with_box(struct Map_info *Map, const struct bound_box *Box,
+Vect_select_lines_by_box(struct Map_info *Map, const struct bound_box *Box,
int type, struct boxlist *list)
{
int i, line, nlines;
@@ -98,18 +44,13 @@
Box->E, Box->W, Box->T, Box->B);
plus = &(Map->plus);
- if (!(plus->Spidx_built)) {
- G_debug(3, "Building spatial index.");
- Vect_build_sidx_from_topo(Map);
- }
-
list->n_values = 0;
if (!LocList) {
LocList = (struct boxlist *)G_malloc(sizeof(struct boxlist));
- dig_init_boxlist(LocList);
+ dig_init_boxlist(LocList, 1);
}
- nlines = dig_select_lines_with_box(plus, Box, LocList);
+ nlines = dig_select_lines(plus, Box, LocList);
G_debug(3, " %d lines selected (all types)", nlines);
/* Remove lines of not requested types */
@@ -128,58 +69,7 @@
return list->n_values;
}
-/*!
- \brief Select areas by box.
- Select areas whose boxes overlap specified box!!!
- It means that selected area may or may not overlap the box.
-
- \param Map vector map
- \param Box bounding box
- \param[out] output list, must be initialized
-
- \return number of areas
- */
-int
-Vect_select_areas_by_box(struct Map_info *Map, const struct bound_box * Box,
- struct ilist *list)
-{
- int i;
- static int debug_level = -1;
-
- if (debug_level == -1) {
- const char *dstr = G__getenv("DEBUG");
-
- if (dstr != NULL)
- debug_level = atoi(dstr);
- else
- debug_level = 0;
- }
-
- G_debug(3, "Vect_select_areas_by_box()");
- G_debug(3, "Box(N,S,E,W,T,B): %e, %e, %e, %e, %e, %e", Box->N, Box->S,
- Box->E, Box->W, Box->T, Box->B);
-
- if (!(Map->plus.Spidx_built)) {
- G_debug(3, "Building spatial index.");
- Vect_build_sidx_from_topo(Map);
- }
-
- dig_select_areas(&(Map->plus), Box, list);
- G_debug(3, " %d areas selected", list->n_values);
- /* avoid loop when not debugging */
- if (debug_level > 2) {
- for (i = 0; i < list->n_values; i++) {
- G_debug(3, " area = %d pointer to area structure = %lx",
- list->value[i],
- (unsigned long)Map->plus.Area[list->value[i]]);
- }
- }
-
- return list->n_values;
-}
-
-
/*!
\brief Select areas with bounding boxes by box.
@@ -193,7 +83,7 @@
\return number of areas
*/
int
-Vect_select_areas_by_box_with_box(struct Map_info *Map, const struct bound_box * Box,
+Vect_select_areas_by_box(struct Map_info *Map, const struct bound_box * Box,
struct boxlist *list)
{
int i;
@@ -212,7 +102,7 @@
G_debug(3, "Box(N,S,E,W,T,B): %e, %e, %e, %e, %e, %e", Box->N, Box->S,
Box->E, Box->W, Box->T, Box->B);
- dig_select_areas_with_box(&(Map->plus), Box, list);
+ dig_select_areas(&(Map->plus), Box, list);
G_debug(3, " %d areas selected", list->n_values);
/* avoid loop when not debugging */
if (debug_level > 2) {
@@ -228,7 +118,7 @@
/*!
- \brief Select isles by box.
+ \brief Select isles with bounding boxes by box.
Select isles whose boxes overlap specified box!!!
It means that selected isle may or may not overlap the box.
@@ -241,17 +131,12 @@
*/
int
Vect_select_isles_by_box(struct Map_info *Map, const struct bound_box * Box,
- struct ilist *list)
+ struct boxlist *list)
{
G_debug(3, "Vect_select_isles_by_box()");
G_debug(3, "Box(N,S,E,W,T,B): %e, %e, %e, %e, %e, %e", Box->N, Box->S,
Box->E, Box->W, Box->T, Box->B);
- if (!(Map->plus.Spidx_built)) {
- G_debug(3, "Building spatial index.");
- Vect_build_sidx_from_topo(Map);
- }
-
dig_select_isles(&(Map->plus), Box, list);
G_debug(3, " %d isles selected", list->n_values);
@@ -259,32 +144,6 @@
}
/*!
- \brief Select isles with bounding boxes by box.
-
- Select isles whose boxes overlap specified box!!!
- It means that selected isle may or may not overlap the box.
-
- \param Map vector map
- \param Box bounding box
- \param[out] list output list, must be initialized
-
- \return number of isles
- */
-int
-Vect_select_isles_by_box_with_box(struct Map_info *Map, const struct bound_box * Box,
- struct boxlist *list)
-{
- G_debug(3, "Vect_select_isles_by_box_with_box()");
- G_debug(3, "Box(N,S,E,W,T,B): %e, %e, %e, %e, %e, %e", Box->N, Box->S,
- Box->E, Box->W, Box->T, Box->B);
-
- dig_select_isles_with_box(&(Map->plus), Box, list);
- G_debug(3, " %d isles selected", list->n_values);
-
- return list->n_values;
-}
-
-/*!
\brief Select nodes by box.
\param Map vector map
@@ -305,11 +164,6 @@
plus = &(Map->plus);
- if (!(plus->Spidx_built)) {
- G_debug(3, "Building spatial index.");
- Vect_build_sidx_from_topo(Map);
- }
-
list->n_values = 0;
dig_select_nodes(plus, Box, list);
@@ -340,7 +194,7 @@
int i;
struct bound_box box;
static struct line_pnts *LPoints = NULL;
- static struct ilist *LocList = NULL;
+ static struct boxlist *LocList = NULL;
/* TODO: this function was not tested with isles */
G_debug(3, "Vect_select_lines_by_polygon() nisles = %d", nisles);
@@ -348,8 +202,9 @@
List->n_values = 0;
if (!LPoints)
LPoints = Vect_new_line_struct();
- if (!LocList)
- LocList = Vect_new_list();
+ if (!LocList) {
+ LocList = Vect_new_boxlist(0);
+ }
/* Select first all lines by box */
dig_line_box(Polygon, &box);
@@ -362,7 +217,7 @@
for (i = 0; i < LocList->n_values; i++) {
int j, line, intersect = 0;
- line = LocList->value[i];
+ line = LocList->id[i];
/* Read line points */
Vect_read_line(Map, LPoints, NULL, line);
More information about the grass-commit
mailing list