~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to imagery/i.zc/main.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *
20
20
 *****************************************************************************/
21
21
 
22
 
#define MAIN
23
 
 
24
22
#include <stdlib.h>
25
23
#include <math.h>
26
24
#include <grass/gis.h>
 
25
#include <grass/raster.h>
27
26
#include <grass/gmath.h>
28
27
#include <grass/glocale.h>
29
28
 
34
33
    double Thresh;
35
34
    int NumOrients;
36
35
    int inputfd, zcfd;          /* the input and output file descriptors */
37
 
    char *inmapset;             /* the input mapset name */
38
36
    struct Cell_head window;
39
37
    CELL *cell_row;
40
38
    float Width;
45
43
    int size;                   /* the length of one side */
46
44
    long totsize;               /* the Total number of data points */
47
45
    double *data[2];            /* Data structure containing real & complex values of FFT */
48
 
    int save_args();            /* function to stash the command line arguments */
49
46
    struct GModule *module;
50
47
    struct Option *input_map, *output_map, *width, *threshold, *orientations;
51
 
    const char *me;
52
48
 
53
49
    G_gisinit(argv[0]);
54
 
    me = G_program_name();
55
50
 
56
51
    module = G_define_module();
57
 
    module->keywords = _("imagery");
 
52
    G_add_keyword(_("imagery"));
 
53
    G_add_keyword(_("edges"));
58
54
    module->description =
59
55
        _("Zero-crossing \"edge detection\" raster "
60
56
          "function for image processing.");
67
63
    input_map->multiple = NO;
68
64
    input_map->gisprompt = "old,cell,raster";
69
65
    input_map->description = _("Name of input raster map");
70
 
#define INPUT_MAP input_map->answer
71
66
 
72
67
    output_map = G_define_option();
73
68
    output_map->key = "output";
76
71
    output_map->multiple = NO;
77
72
    output_map->gisprompt = "new,cell,raster";
78
73
    output_map->description = _("Zero crossing raster map");
79
 
#define OUTPUT_MAP output_map->answer
80
74
 
81
75
    width = G_define_option();
82
76
    width->key = "width";
107
101
        exit(EXIT_FAILURE);
108
102
 
109
103
    /* open input cell map */
110
 
    if ((inmapset = G_find_cell(INPUT_MAP, "")) == NULL)
111
 
        G_fatal_error(_("Raster map <%s> not found"), INPUT_MAP);
112
 
 
113
 
    inputfd = G_open_cell_old(INPUT_MAP, inmapset);
114
 
    if (inputfd < 0)
115
 
        exit(EXIT_FAILURE);
116
 
 
117
 
    /* check command line args for validity */
118
 
    if (G_legal_filename(OUTPUT_MAP) < 0)
119
 
        G_fatal_error(_("<%s> is an illegal file name"), OUTPUT_MAP);
 
104
    inputfd = Rast_open_old(input_map->answer, "");
120
105
 
121
106
    sscanf(threshold->answer, "%1lf", &Thresh);
122
107
    if (Thresh <= 0.0)
137
122
    G_get_set_window(&window);
138
123
 
139
124
    /* get the rows and columns in the current window */
140
 
    or = G_window_rows();
141
 
    oc = G_window_cols();
 
125
    or = Rast_window_rows();
 
126
    oc = Rast_window_cols();
142
127
    rows = G_math_max_pow2((long)or);
143
128
    cols = G_math_max_pow2((long)oc);
144
129
    size = (rows > cols) ? rows : cols;
161
146
    }
162
147
 
163
148
    /* allocate the space for one row of cell map data */
164
 
    cell_row = G_allocate_cell_buf();
 
149
    cell_row = Rast_allocate_c_buf();
165
150
 
166
151
    /* Read in cell map values */
167
152
    G_message(_("Reading raster map..."));
168
153
    for (i = 0; i < or; i++) {
169
 
        if (G_get_map_row(inputfd, cell_row, i) < 0)
170
 
            G_fatal_error(_("Error while reading input raster map."));
 
154
        Rast_get_c_row(inputfd, cell_row, i);
171
155
 
172
156
        for (j = 0; j < oc; j++)
173
157
            *(data[0] + (i * size) + j) = (double)cell_row[j];
174
158
    }
175
159
    /* close input cell map and release the row buffer */
176
 
    G_close_cell(inputfd);
 
160
    Rast_close(inputfd);
177
161
    G_free(cell_row);
178
162
 
179
163
    /* take the del**2g of image */
186
170
 
187
171
    /* open the output cell maps and allocate cell row buffers */
188
172
    G_message(_("Writing transformed data to file..."));
189
 
    if ((zcfd = G_open_cell_new(OUTPUT_MAP)) < 0)
190
 
        exit(EXIT_FAILURE);
 
173
    zcfd = Rast_open_c_new(output_map->answer);
191
174
 
192
 
    cell_row = G_allocate_cell_buf();
 
175
    cell_row = Rast_allocate_c_buf();
193
176
 
194
177
    /* Write out result to a new cell map */
195
178
    for (i = 0; i < or; i++) {
196
179
        for (j = 0; j < oc; j++) {
197
180
            *(cell_row + j) = (CELL) (*(data[1] + i * cols + j));
198
181
        }
199
 
        G_put_raster_row(zcfd, cell_row, CELL_TYPE);
 
182
        Rast_put_row(zcfd, cell_row, CELL_TYPE);
200
183
    }
201
 
    G_close_cell(zcfd);
 
184
    Rast_close(zcfd);
202
185
 
203
186
    G_free(cell_row);
204
187