[GRASS-SVN] r31079 - grass/trunk/vector/v.voronoi
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Apr 22 19:00:38 EDT 2008
Author: neteler
Date: 2008-04-22 19:00:37 -0400 (Tue, 22 Apr 2008)
New Revision: 31079
Modified:
grass/trunk/vector/v.voronoi/dt_main.c
grass/trunk/vector/v.voronoi/dt_write.c
grass/trunk/vector/v.voronoi/sw_defs.h
grass/trunk/vector/v.voronoi/sw_main.c
grass/trunk/vector/v.voronoi/vo_main.c
Log:
Benjamin Ducke: patch for 3D support and better memory management. Added 3D centroids
Modified: grass/trunk/vector/v.voronoi/dt_main.c
===================================================================
--- grass/trunk/vector/v.voronoi/dt_main.c 2008-04-22 22:54:35 UTC (rev 31078)
+++ grass/trunk/vector/v.voronoi/dt_main.c 2008-04-22 23:00:37 UTC (rev 31079)
@@ -74,14 +74,28 @@
if ((mapset = G_find_vector2 (in_opt->answer, "")) == NULL) {
G_fatal_error(_("Vector map <%s> not found"), in_opt->answer);
}
-
+
Vect_set_open_level (2);
Vect_open_old (&In, in_opt->answer, mapset);
- if (0 > Vect_open_new (&Out, out_opt->answer, 0)) {
- G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
+ /* check if we have a 3D input points map */
+ mode3d = 0;
+ if ( Vect_is_3d ( &In ) ) {
+ mode3d = 1;
}
+
+ if ( mode3d ) {
+ if (0 > Vect_open_new (&Out, out_opt->answer, 1)) {
+ G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
+ }
+ } else {
+ if (0 > Vect_open_new (&Out, out_opt->answer, 0)) {
+ G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
+ }
+
+ }
+
Vect_hist_copy (&In, &Out);
Vect_hist_command ( &Out );
@@ -110,20 +124,26 @@
nareas = Vect_get_num_areas ( &Out );
G_debug ( 3, "nareas = %d", nareas );
for ( area = 1; area <= nareas; area++ ) {
- double x, y;
+ double x, y, z, angle, slope;
int ret;
Vect_reset_line ( Points );
Vect_reset_cats ( Cats );
ret = Vect_get_point_in_area ( &Out, area, &x, &y );
-
if ( ret < 0 ) {
G_warning ( _("Cannot calculate area centroid") );
continue;
}
+
+ ret = Vect_tin_get_z (&Out, x, y, &z, &angle, &slope);
+ G_debug(3, "area centroid z: %f",z);
+ if ( ret < 0 ) {
+ G_warning ( _("Cannot calculate area centroid z coordinate") );
+ continue;
+ }
- Vect_append_point ( Points, x, y, 0.0 );
+ Vect_append_point ( Points, x, y, z );
Vect_cat_set ( Cats, 1, area );
Vect_write_line ( &Out, GV_CENTROID, Points, Cats );
Modified: grass/trunk/vector/v.voronoi/dt_write.c
===================================================================
--- grass/trunk/vector/v.voronoi/dt_write.c 2008-04-22 22:54:35 UTC (rev 31078)
+++ grass/trunk/vector/v.voronoi/dt_write.c 2008-04-22 23:00:37 UTC (rev 31079)
@@ -46,7 +46,7 @@
if ( node > 0 ) { /* node found */
int j, nlines;
int found = 0;
- double x, y;
+ double x, y, z;
nlines = Vect_get_node_n_lines ( &Out, node );
@@ -60,7 +60,7 @@
else
Vect_get_line_nodes ( &Out, abs(line), &node2, NULL );
- Vect_get_node_coor ( &Out, node2, &x, &y, NULL );
+ Vect_get_node_coor ( &Out, node2, &x, &y, &z );
if ( x == sb->coord.x && y == sb->coord.y ) {
found = 1;
@@ -73,11 +73,18 @@
/* Not found, write it */
Vect_reset_line ( Points );
- Vect_append_point ( Points, sa->coord.x, sa->coord.y, 0.0 );
- Vect_append_point ( Points, sb->coord.x, sb->coord.y, 0.0 );
+ if ( mode3d ) {
+ G_debug(3, "sa->coord.z: %f", sa->coord.z );
+ Vect_append_point ( Points, sa->coord.x, sa->coord.y, sa->coord.z );
+ Vect_append_point ( Points, sb->coord.x, sb->coord.y, sb->coord.z );
+ } else {
+ Vect_append_point ( Points, sa->coord.x, sa->coord.y, 0.0 );
+ Vect_append_point ( Points, sb->coord.x, sb->coord.y, 0.0 );
+ }
Vect_write_line ( &Out, Type, Points, Cats );
}
}
return 0;
}
+
Modified: grass/trunk/vector/v.voronoi/sw_defs.h
===================================================================
--- grass/trunk/vector/v.voronoi/sw_defs.h 2008-04-22 22:54:35 UTC (rev 31078)
+++ grass/trunk/vector/v.voronoi/sw_defs.h 2008-04-22 23:00:37 UTC (rev 31079)
@@ -13,7 +13,7 @@
struct Point {
- double x,y;
+ double x,y,z;
};
/* structure used both for sites and for vertices */
@@ -41,7 +41,7 @@
};
#ifdef MAIN
-int triangulate, sorted, plot, debug;
+int triangulate, sorted, plot, debug, mode3d;
struct Site *sites;
int nsites;
int siteidx;
@@ -61,7 +61,7 @@
int PQcount;
int PQmin;
#else
-extern int triangulate, sorted, plot, debug;
+extern int triangulate, sorted, plot, debug, mode3d;
extern struct Site *sites;
extern int nsites;
extern int siteidx;
Modified: grass/trunk/vector/v.voronoi/sw_main.c
===================================================================
--- grass/trunk/vector/v.voronoi/sw_main.c 2008-04-22 22:54:35 UTC (rev 31078)
+++ grass/trunk/vector/v.voronoi/sw_main.c 2008-04-22 23:00:37 UTC (rev 31079)
@@ -42,12 +42,23 @@
i = j = 1;
foundDupe = 0;
while(i < nsites)
- if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y)
- i++;
- else
- {
- if(i != j) sites[j] = sites[i];
- i++; j++;;
+ if ( mode3d ) {
+ if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y
+ && sites[i].coord.z == sites[i-1].coord.z)
+ i++;
+ else
+ {
+ if(i != j) sites[j] = sites[i];
+ i++; j++;;
+ }
+ } else {
+ if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y)
+ i++;
+ else
+ {
+ if(i != j) sites[j] = sites[i];
+ i++; j++;;
+ }
}
if(j != nsites)
@@ -67,11 +78,11 @@
Points = Vect_new_line_struct ();
+ nlines = Vect_get_num_lines ( &In );
+
nsites = 0;
- sites = (struct Site *) myalloc(4000*sizeof(*sites));
+ sites = (struct Site *) myalloc(nlines * sizeof(*sites));
- nlines = Vect_get_num_lines ( &In );
-
for ( line = 1; line <= nlines; line++ ) {
int type;
@@ -84,6 +95,10 @@
sites[nsites].coord.x = Points->x[0];
sites[nsites].coord.y = Points->y[0];
+ if ( mode3d ) {
+ G_debug(3, "Points->z[0]: %f", Points->z[0]);
+ sites[nsites].coord.z = Points->z[0];
+ }
sites[nsites].sitenbr = nsites;
sites[nsites].refcnt = 0;
Modified: grass/trunk/vector/v.voronoi/vo_main.c
===================================================================
--- grass/trunk/vector/v.voronoi/vo_main.c 2008-04-22 22:54:35 UTC (rev 31078)
+++ grass/trunk/vector/v.voronoi/vo_main.c 2008-04-22 23:00:37 UTC (rev 31079)
@@ -321,7 +321,7 @@
Vect_map_add_dblink ( &Out, OFi->number, OFi->name, OFi->table,
IFi->key, OFi->database, OFi->driver);
}
- G_done_msg("");
+ G_done_msg(" ");
}
}
More information about the grass-commit
mailing list