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

« back to all changes in this revision

Viewing changes to raster/r.carve/enforce_ds.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:
20
20
#include <stdio.h>
21
21
#include <string.h>
22
22
#include <grass/gis.h>
 
23
#include <grass/raster.h>
23
24
#include <grass/glocale.h>
24
25
#include "enforce.h"
25
26
 
72
73
 
73
74
    /* allocate and clear memory for entire raster */
74
75
    rbuf =
75
 
        G_calloc(G_window_rows() * G_window_cols(),
76
 
                 G_raster_size(parm->raster_type));
 
76
        G_calloc(Rast_window_rows() * Rast_window_cols(),
 
77
                 Rast_cell_size(parm->raster_type));
77
78
 
78
79
    /* first read whole elevation file into buf */
79
80
    read_raster(rbuf, infd, parm->raster_type);
121
122
        return 0;
122
123
 
123
124
    if (!bm)
124
 
        bm = BM_create(G_window_cols(), G_window_rows());
 
125
        bm = BM_create(Rast_window_cols(), Rast_window_rows());
125
126
    clear_bitmap(bm);
126
127
 
127
128
    pg_init(&pg);
132
133
    for (i = 0; i < points->n_points; i++) {
133
134
        Point2 pt, ptxy;
134
135
        double elev;
135
 
        int row = G_northing_to_row(points->y[i], &wind);
136
 
        int col = G_easting_to_col(points->x[i], &wind);
 
136
        int row = Rast_northing_to_row(points->y[i], &wind);
 
137
        int col = Rast_easting_to_col(points->x[i], &wind);
137
138
 
138
139
        /* rough clipping */
139
 
        if (row < 0 || row > G_window_rows() - 1 ||
140
 
            col < 0 || col > G_window_cols() - 1) {
 
140
        if (row < 0 || row > Rast_window_rows() - 1 ||
 
141
            col < 0 || col > Rast_window_cols() - 1) {
141
142
            if (first_in != -1)
142
143
                in_out = 1;
143
144
 
209
210
{
210
211
    int i, j;
211
212
 
212
 
    for (i = 0; i < G_window_rows(); i++)
213
 
        for (j = 0; j < G_window_cols(); j++)
 
213
    for (i = 0; i < Rast_window_rows(); i++)
 
214
        for (j = 0; j < Rast_window_cols(); j++)
214
215
            BM_set(bm, i, j, 0);
215
216
}
216
217
 
277
278
        {
278
279
            CELL *cbuf = data;
279
280
 
280
 
            cbuf[row * G_window_cols() + col] =
281
 
                MIN(cbuf[row * G_window_cols() + col], elev) - (int)depth;
 
281
            cbuf[row * Rast_window_cols() + col] =
 
282
                MIN(cbuf[row * Rast_window_cols() + col], elev) - (int)depth;
282
283
        }
283
284
        break;
284
285
    case FCELL_TYPE:
285
286
        {
286
287
            FCELL *fbuf = data;
287
288
 
288
 
            fbuf[row * G_window_cols() + col] =
289
 
                MIN(fbuf[row * G_window_cols() + col], elev) - depth;
 
289
            fbuf[row * Rast_window_cols() + col] =
 
290
                MIN(fbuf[row * Rast_window_cols() + col], elev) - depth;
290
291
        }
291
292
        break;
292
293
    case DCELL_TYPE:
293
294
        {
294
295
            DCELL *dbuf = data;
295
296
 
296
 
            dbuf[row * G_window_cols() + col] =
297
 
                MIN(dbuf[row * G_window_cols() + col], elev) - depth;
 
297
            dbuf[row * Rast_window_cols() + col] =
 
298
                MIN(dbuf[row * Rast_window_cols() + col], elev) - depth;
298
299
        }
299
300
        break;
300
301
    }
312
313
    struct Cell_head wind;
313
314
 
314
315
    G_get_window(&wind);
315
 
    rastrows = G_window_rows();
316
 
    rastcols = G_window_cols();
 
316
    rastrows = Rast_window_rows();
 
317
    rastcols = Rast_window_cols();
317
318
 
318
 
    G_set_d_null_value(&min, 1);
 
319
    Rast_set_d_null_value(&min, 1);
319
320
 
320
321
    /* kludge - fix for lat_lon */
321
322
    rowoff = rad / wind.ns_res;
322
323
    coloff = rad / wind.ew_res;
323
324
 
324
 
    row = G_northing_to_row(py, &wind);
325
 
    col = G_easting_to_col(px, &wind);
 
325
    row = Rast_northing_to_row(py, &wind);
 
326
    col = Rast_easting_to_col(px, &wind);
326
327
 
327
328
    /* get bounding box of line segment */
328
329
    row1 = MAX(0, row - rowoff);
335
336
        {
336
337
            CELL *cbuf = data;
337
338
 
338
 
            if (!(G_is_c_null_value(&cbuf[row1 * rastcols + col1])))
 
339
            if (!(Rast_is_c_null_value(&cbuf[row1 * rastcols + col1])))
339
340
                min = cbuf[row1 * rastcols + col1];
340
341
        }
341
342
        break;
343
344
        {
344
345
            FCELL *fbuf = data;
345
346
 
346
 
            if (!(G_is_f_null_value(&fbuf[row1 * rastcols + col1])))
 
347
            if (!(Rast_is_f_null_value(&fbuf[row1 * rastcols + col1])))
347
348
                min = fbuf[row1 * rastcols + col1];
348
349
        }
349
350
        break;
351
352
        {
352
353
            DCELL *dbuf = data;
353
354
 
354
 
            if (!(G_is_d_null_value(&dbuf[row1 * rastcols + col1])))
 
355
            if (!(Rast_is_d_null_value(&dbuf[row1 * rastcols + col1])))
355
356
                min = dbuf[row1 * rastcols + col1];
356
357
        }
357
358
        break;
358
359
    }
359
360
 
360
361
    for (r = row1; r < row2; r++) {
361
 
        double cy = G_row_to_northing(r + 0.5, &wind);
 
362
        double cy = Rast_row_to_northing(r + 0.5, &wind);
362
363
        int c;
363
364
 
364
365
        for (c = col1; c < col2; c++) {
365
 
            double cx = G_col_to_easting(c + 0.5, &wind);
 
366
            double cx = Rast_col_to_easting(c + 0.5, &wind);
366
367
 
367
368
            if (G_distance(px, py, cx, cy) <= SQR(rad)) {
368
369
                switch (rtype) {
370
371
                    {
371
372
                        CELL *cbuf = data;
372
373
 
373
 
                        if (G_is_d_null_value(&min)) {
374
 
                            if (!(G_is_c_null_value(&cbuf[r * rastcols + c])))
 
374
                        if (Rast_is_d_null_value(&min)) {
 
375
                            if (!(Rast_is_c_null_value(&cbuf[r * rastcols + c])))
375
376
                                min = cbuf[r * rastcols + c];
376
377
                        }
377
378
                        else {
378
 
                            if (!(G_is_c_null_value(&cbuf[r * rastcols + c])))
 
379
                            if (!(Rast_is_c_null_value(&cbuf[r * rastcols + c])))
379
380
                                if (cbuf[r * rastcols + c] < min)
380
381
                                    min = cbuf[r * rastcols + c];
381
382
                        }
385
386
                    {
386
387
                        FCELL *fbuf = data;
387
388
 
388
 
                        if (G_is_d_null_value(&min)) {
389
 
                            if (!(G_is_f_null_value(&fbuf[r * rastcols + c])))
 
389
                        if (Rast_is_d_null_value(&min)) {
 
390
                            if (!(Rast_is_f_null_value(&fbuf[r * rastcols + c])))
390
391
                                min = fbuf[r * rastcols + c];
391
392
                        }
392
393
                        else {
393
 
                            if (!(G_is_f_null_value(&fbuf[r * rastcols + c])))
 
394
                            if (!(Rast_is_f_null_value(&fbuf[r * rastcols + c])))
394
395
                                if (fbuf[r * rastcols + c] < min)
395
396
                                    min = fbuf[r * rastcols + c];
396
397
                        }
400
401
                    {
401
402
                        DCELL *dbuf = data;
402
403
 
403
 
                        if (G_is_d_null_value(&min)) {
404
 
                            if (!(G_is_d_null_value(&dbuf[r * rastcols + c])))
 
404
                        if (Rast_is_d_null_value(&min)) {
 
405
                            if (!(Rast_is_d_null_value(&dbuf[r * rastcols + c])))
405
406
                                min = dbuf[r * rastcols + c];
406
407
                        }
407
408
                        else {
408
 
                            if (!(G_is_d_null_value(&dbuf[r * rastcols + c])))
 
409
                            if (!(Rast_is_d_null_value(&dbuf[r * rastcols + c])))
409
410
                                if (dbuf[r * rastcols + c] < min)
410
411
                                    min = dbuf[r * rastcols + c];
411
412
                        }
449
450
    coloff = parm->swidth / wind.ew_res;
450
451
 
451
452
    /* get prevrow and prevcol for iteration 0 of following loop */
452
 
    prevrow = G_northing_to_row(pgxypts[0][1], &wind);
453
 
    prevcol = G_easting_to_col(pgxypts[0][0], &wind);
 
453
    prevrow = Rast_northing_to_row(pgxypts[0][1], &wind);
 
454
    prevcol = Rast_easting_to_col(pgxypts[0][0], &wind);
454
455
 
455
456
    for (i = 1; i < (npts - 1); i++) {
456
457
        int c, r;
457
458
 
458
 
        int row = G_northing_to_row(pgxypts[i][1], &wind);
459
 
        int col = G_easting_to_col(pgxypts[i][0], &wind);
 
459
        int row = Rast_northing_to_row(pgxypts[i][1], &wind);
 
460
        int col = Rast_easting_to_col(pgxypts[i][0], &wind);
460
461
 
461
462
        /* get bounding box of line segment */
462
463
        row1 = MAX(0, MIN(row, prevrow) - rowoff);
463
 
        row2 = MIN(G_window_rows() - 1, MAX(row, prevrow) + rowoff);
 
464
        row2 = MIN(Rast_window_rows() - 1, MAX(row, prevrow) + rowoff);
464
465
        col1 = MAX(0, MIN(col, prevcol) - coloff);
465
 
        col2 = MIN(G_window_cols() - 1, MAX(col, prevcol) + coloff);
 
466
        col2 = MIN(Rast_window_cols() - 1, MAX(col, prevcol) + coloff);
466
467
 
467
468
        for (r = row1; r < row2; r++) {
468
 
            cy = G_row_to_northing(r + 0.5, &wind);
 
469
            cy = Rast_row_to_northing(r + 0.5, &wind);
469
470
 
470
471
            for (c = col1; c < col2; c++) {
471
 
                cellx = G_col_to_easting(c + 0.5, &wind);
 
472
                cellx = Rast_col_to_easting(c + 0.5, &wind);
472
473
                celly = cy;     /* gets written over in distance2... */
473
474
 
474
475
                /* Thought about not going past endpoints (use