Changeset 31079


Ignore:
Timestamp:
Apr 22, 2008, 4:00:37 PM (16 years ago)
Author:
neteler
Message:

Benjamin Ducke: patch for 3D support and better memory management. Added 3D centroids

Location:
grass/trunk/vector/v.voronoi
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/vector/v.voronoi/dt_main.c

    r25234 r31079  
    7575      G_fatal_error(_("Vector map <%s> not found"), in_opt->answer);
    7676  }
    77 
     77 
    7878  Vect_set_open_level (2);
    7979  Vect_open_old (&In, in_opt->answer, mapset);
    8080
    81   if (0 > Vect_open_new (&Out, out_opt->answer, 0)) {
    82     G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
     81  /* check if we have a 3D input points map */
     82  mode3d = 0;
     83  if ( Vect_is_3d ( &In ) ) {
     84        mode3d = 1;
     85  }
     86
     87
     88  if ( mode3d ) {
     89        if (0 > Vect_open_new (&Out, out_opt->answer, 1)) {
     90                G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
     91        }
     92  } else {
     93        if (0 > Vect_open_new (&Out, out_opt->answer, 0)) {
     94                G_fatal_error(_("Unable to create vector map <%s>"), out_opt->answer);
     95        }
     96 
    8397  }
    8498
     
    111125  G_debug ( 3, "nareas = %d", nareas );
    112126  for ( area = 1; area <= nareas; area++ ) {
    113       double x, y;
     127      double x, y, z, angle, slope;
    114128      int ret;
    115129
     
    118132     
    119133      ret = Vect_get_point_in_area ( &Out, area, &x, &y );
    120 
    121134      if ( ret < 0 ) {
    122135          G_warning ( _("Cannot calculate area centroid") );
    123136          continue;
    124137      }
     138
     139      ret = Vect_tin_get_z (&Out, x, y, &z, &angle, &slope);
     140      G_debug(3, "area centroid z: %f",z);
     141      if ( ret < 0 ) {
     142          G_warning ( _("Cannot calculate area centroid z coordinate") );
     143          continue;
     144      }
    125145     
    126       Vect_append_point ( Points, x, y, 0.0 );
     146      Vect_append_point ( Points, x, y, z );
    127147      Vect_cat_set ( Cats, 1, area );
    128148     
  • grass/trunk/vector/v.voronoi/dt_write.c

    r18934 r31079  
    4747                int j, nlines;
    4848                int found = 0;
    49                 double x, y;
     49                double x, y, z;
    5050               
    5151                nlines = Vect_get_node_n_lines ( &Out, node );
     
    6161                        Vect_get_line_nodes ( &Out, abs(line), &node2, NULL );
    6262               
    63                     Vect_get_node_coor ( &Out, node2, &x, &y, NULL );
     63                    Vect_get_node_coor ( &Out, node2, &x, &y, &z );
    6464                   
    6565                    if ( x == sb->coord.x && y == sb->coord.y ) {
     
    7474            /* Not found, write it */
    7575            Vect_reset_line ( Points );
    76             Vect_append_point ( Points, sa->coord.x, sa->coord.y, 0.0 );
    77             Vect_append_point ( Points, sb->coord.x, sb->coord.y, 0.0 );
     76            if ( mode3d ) {
     77                G_debug(3, "sa->coord.z: %f", sa->coord.z );
     78                Vect_append_point ( Points, sa->coord.x, sa->coord.y, sa->coord.z );
     79                Vect_append_point ( Points, sb->coord.x, sb->coord.y, sb->coord.z );       
     80            } else {
     81                Vect_append_point ( Points, sa->coord.x, sa->coord.y, 0.0 );
     82                Vect_append_point ( Points, sb->coord.x, sb->coord.y, 0.0 );
     83            }
    7884            Vect_write_line ( &Out, Type, Points, Cats );
    7985        }
     
    8288    return 0;
    8389}
     90
  • grass/trunk/vector/v.voronoi/sw_defs.h

    r13251 r31079  
    1414
    1515struct Point    {
    16     double x,y;
     16    double x,y,z;
    1717};
    1818
     
    4242
    4343#ifdef MAIN
    44 int triangulate, sorted, plot, debug;
     44int triangulate, sorted, plot, debug, mode3d;
    4545struct  Site    *sites;
    4646int             nsites;
     
    6262int PQmin;
    6363#else
    64 extern int triangulate, sorted, plot, debug;
     64extern int triangulate, sorted, plot, debug, mode3d;
    6565extern struct   Site    *sites;
    6666extern int              nsites;
  • grass/trunk/vector/v.voronoi/sw_main.c

    r25234 r31079  
    4343        foundDupe = 0;
    4444        while(i < nsites)
    45                 if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y)
    46                         i++;
    47                 else
    48                 {
    49                         if(i != j) sites[j] = sites[i];
    50                         i++; j++;;
     45                if ( mode3d ) {
     46                        if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y
     47                                                                  && sites[i].coord.z == sites[i-1].coord.z)
     48                                i++;
     49                        else
     50                        {
     51                                if(i != j) sites[j] = sites[i];
     52                                i++; j++;;
     53                        }               
     54                } else {
     55                        if(sites[i].coord.x == sites[i-1].coord.x && sites[i].coord.y == sites[i-1].coord.y)
     56                                i++;
     57                        else
     58                        {
     59                                if(i != j) sites[j] = sites[i];
     60                                i++; j++;;
     61                        }
    5162                }
    5263
     
    6879    Points = Vect_new_line_struct ();
    6980
     81    nlines = Vect_get_num_lines ( &In );
     82
    7083    nsites = 0;
    71     sites = (struct Site *) myalloc(4000*sizeof(*sites));
    72 
    73     nlines = Vect_get_num_lines ( &In );
     84    sites = (struct Site *) myalloc(nlines * sizeof(*sites));
    7485
    7586    for ( line = 1; line <= nlines; line++ ) {
     
    8596        sites[nsites].coord.x = Points->x[0];
    8697        sites[nsites].coord.y = Points->y[0];
     98        if ( mode3d ) {
     99                G_debug(3, "Points->z[0]: %f", Points->z[0]);
     100                sites[nsites].coord.z = Points->z[0];
     101        }
    87102
    88103        sites[nsites].sitenbr = nsites;
  • grass/trunk/vector/v.voronoi/vo_main.c

    r25234 r31079  
    322322                                      IFi->key, OFi->database, OFi->driver);
    323323            }
    324             G_done_msg("");
     324            G_done_msg(" ");
    325325        }
    326326  }
Note: See TracChangeset for help on using the changeset viewer.