~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to vector/v.voronoi/dt_main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*-s.delaunay
3
 
**
4
 
** Author: James Darrell McCauley (mccauley@ecn.purdue.edu)
5
 
**         USDA Fellow
6
 
**         Department of Agricultural Engineering
7
 
**         Purdue University
8
 
**         West Lafayette, Indiana 47907-1146 USA
9
 
**
10
 
** Permission to use, copy, modify, and distribute this software and its
11
 
** documentation for any purpose and without fee is hereby granted. This
12
 
** software is provided "as is" without express or implied warranty.
13
 
**
14
 
** Modification History:
15
 
** 06 Feb 93 - James Darrell McCauley <mccauley@ecn.purdue.edu> pieced
16
 
**             this together from stuff he found on netlib (see the manpage).
17
 
**
18
 
** 4 2008: Benjamin Ducke - 3D support + better memory management
19
 
**/
20
 
 
21
 
#define MAIN
22
 
#include <stdio.h>
23
 
#include <string.h>
24
 
#include <stdlib.h>
25
 
#include <unistd.h>
26
 
#include <math.h>
27
 
#include <grass/gis.h>
28
 
#include <grass/Vect.h>
29
 
#include <grass/glocale.h>
30
 
#include "sw_defs.h"
31
 
#include "defs.h"
32
 
 
33
 
int main(int argc, char **argv)
34
 
{
35
 
    char *mapset;
36
 
    struct Flag *reg_flag, *line_flag;
37
 
    struct Option *in_opt, *out_opt;
38
 
    struct GModule *module;
39
 
    struct line_pnts *Points;
40
 
    struct line_cats *Cats;
41
 
    int nareas, area;
42
 
 
43
 
    G_gisinit(argv[0]);
44
 
 
45
 
    module = G_define_module();
46
 
    module->keywords = _("vector, geometry, triangulation");
47
 
    module->description = _("Creates a Delaunay triangulation from an input "
48
 
                            "vector map containing points or centroids.");
49
 
 
50
 
    in_opt = G_define_standard_option(G_OPT_V_INPUT);
51
 
    out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
52
 
 
53
 
    reg_flag = G_define_flag();
54
 
    reg_flag->key = 'r';
55
 
    reg_flag->description = _("Use only points in current region");
56
 
 
57
 
    line_flag = G_define_flag();
58
 
    line_flag->key = 'l';
59
 
    line_flag->description =
60
 
        _("Output triangulation as a graph (lines), not areas");
61
 
 
62
 
    if (G_parser(argc, argv))
63
 
        exit(EXIT_FAILURE);
64
 
 
65
 
    if (line_flag->answer)
66
 
        Type = GV_LINE;
67
 
    else
68
 
        Type = GV_BOUNDARY;
69
 
 
70
 
    All = reg_flag->answer ? 0 : 1;
71
 
 
72
 
    Points = Vect_new_line_struct();
73
 
    Cats = Vect_new_cats_struct();
74
 
 
75
 
    /* open files */
76
 
    if ((mapset = G_find_vector2(in_opt->answer, "")) == NULL) {
77
 
        G_fatal_error(_("Vector map <%s> not found"), in_opt->answer);
78
 
    }
79
 
 
80
 
    Vect_set_open_level(2);
81
 
    Vect_open_old(&In, in_opt->answer, mapset);
82
 
 
83
 
    /* check if we have a 3D input points map */
84
 
    mode3d = 0;
85
 
    if (Vect_is_3d(&In)) {
86
 
        mode3d = 1;
87
 
    }
88
 
 
89
 
 
90
 
    if (mode3d) {
91
 
        if (0 > Vect_open_new(&Out, out_opt->answer, 1)) {
92
 
            G_fatal_error(_("Unable to create vector map <%s>"),
93
 
                          out_opt->answer);
94
 
        }
95
 
    }
96
 
    else {
97
 
        if (0 > Vect_open_new(&Out, out_opt->answer, 0)) {
98
 
            G_fatal_error(_("Unable to create vector map <%s>"),
99
 
                          out_opt->answer);
100
 
        }
101
 
 
102
 
    }
103
 
 
104
 
    Vect_hist_copy(&In, &Out);
105
 
    Vect_hist_command(&Out);
106
 
 
107
 
    Vect_build_partial(&Out, GV_BUILD_BASE);
108
 
 
109
 
    /* initialize working region */
110
 
    G_get_window(&Window);
111
 
    G_percent(0, 100, 1);
112
 
    Vect_region_box(&Window, &Box);
113
 
 
114
 
    freeinit(&sfl, sizeof *sites);
115
 
 
116
 
    readsites();
117
 
 
118
 
    siteidx = 0;
119
 
    geominit();
120
 
 
121
 
    triangulate = 1;
122
 
    plot = 0;
123
 
    debug = 0;
124
 
    voronoi(triangulate, nextone);
125
 
 
126
 
    Vect_close(&In);
127
 
 
128
 
    Vect_build_partial(&Out, GV_BUILD_ATTACH_ISLES);
129
 
 
130
 
    nareas = Vect_get_num_areas(&Out);
131
 
    G_debug(3, "nareas = %d", nareas);
132
 
    for (area = 1; area <= nareas; area++) {
133
 
        double x, y, z, angle, slope;
134
 
        int ret;
135
 
 
136
 
        G_percent(area, nareas, 2);
137
 
        Vect_reset_line(Points);
138
 
        Vect_reset_cats(Cats);
139
 
 
140
 
        ret = Vect_get_point_in_area(&Out, area, &x, &y);
141
 
        if (ret < 0) {
142
 
            G_warning(_("Cannot calculate area centroid"));
143
 
            continue;
144
 
        }
145
 
 
146
 
        ret = Vect_tin_get_z(&Out, x, y, &z, &angle, &slope);
147
 
        G_debug(3, "area centroid z: %f", z);
148
 
        if (ret < 0) {
149
 
            G_warning(_("Cannot calculate area centroid z coordinate"));
150
 
            continue;
151
 
        }
152
 
 
153
 
        Vect_append_point(Points, x, y, z);
154
 
        Vect_cat_set(Cats, 1, area);
155
 
 
156
 
        Vect_write_line(&Out, GV_CENTROID, Points, Cats);
157
 
    }
158
 
 
159
 
    Vect_build_partial(&Out, GV_BUILD_NONE);
160
 
    Vect_build(&Out);
161
 
    Vect_close(&Out);
162
 
 
163
 
    exit(EXIT_SUCCESS);
164
 
}