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

« back to all changes in this revision

Viewing changes to lib/rst/interp_float/ressegm2d.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:
21
21
#include <stdio.h>
22
22
#include <stdlib.h>
23
23
#include <math.h>
 
24
 
24
25
#include <grass/gis.h>
 
26
#include <grass/raster.h>
25
27
#include <grass/interpf.h>
26
28
#include <grass/gmath.h>
27
29
 
28
30
static int input_data(struct interp_params *,
29
31
                      int, int, struct fcell_triple *, int, int, int, int,
30
32
                      double, double, double);
31
 
static int write_zeros(struct interp_params *, struct quaddata *, int);
 
33
static int write_zeros(struct interp_params *, struct quaddata *, off_t);
32
34
 
33
35
int IL_resample_interp_segments_2d(struct interp_params *params, struct BM *bitmask,    /* bitmask */
34
36
                                   double zmin, double zmax,    /* min and max input z-values */
36
38
                                   double *gmin, double *gmax,  /* min and max inperp. slope val. */
37
39
                                   double *c1min, double *c1max, double *c2min, double *c2max,  /* min and max interp. curv. val. */
38
40
                                   double *ertot,       /* total interplating func. error */
39
 
                                   int offset1, /* offset for temp file writing */
 
41
                                   off_t offset1,       /* offset for temp file writing */
40
42
                                   double *dnorm,
41
43
                                   int overlap,
42
44
                                   int inp_rows,
79
81
    double xmax, xmin, ymax, ymin;
80
82
    int totsegm;                /* total number of segments */
81
83
    int total_points = 0;
 
84
    struct triple triple;       /* contains garbage */
82
85
 
83
86
 
84
87
    xmin = params->x_orig;
168
171
                                                0, params->KMAX2);
169
172
        m1 = 0;
170
173
        for (k = 1; k <= p_size; k++) {
171
 
            if (!G_is_f_null_value(&(in_points[k - 1].z))) {
 
174
            if (!Rast_is_f_null_value(&(in_points[k - 1].z))) {
172
175
                data->points[m1].x = in_points[k - 1].x / (*dnorm);
173
176
                data->points[m1].y = in_points[k - 1].y / (*dnorm);
174
177
                /*        data->points[m1].z = (double) (in_points[k - 1].z) / (*dnorm); */
200
203
        b[0] = 0.;
201
204
        G_lubksb(matrix, m1 + 1, indx, b);
202
205
 
203
 
        params->check_points(params, data, b, ertot, zmin, *dnorm);
 
206
        params->check_points(params, data, b, ertot, zmin, *dnorm, triple);
204
207
 
205
208
        if (params->grid_calc(params, data, bitmask,
206
209
                              zmin, zmax, zminac, zmaxac, gmin, gmax,
316
319
            for (k = 0; k <= last_row - first_row; k++) {
317
320
                for (l = first_col - 1; l < last_col; l++) {
318
321
                    index = k * inp_cols + l;
319
 
                    if (!G_is_f_null_value(&(in_points[index].z))) {
 
322
                    if (!Rast_is_f_null_value(&(in_points[index].z))) {
320
323
                        /* if the point is inside the segment (not overlapping) */
321
324
                        if ((in_points[index].x - x_or >= 0) &&
322
325
                            (in_points[index].y - y_or >= 0) &&
397
400
                    G_lubksb(new_matrix, data->n_points + 1, new_indx, b);
398
401
 
399
402
                    params->check_points(params, data, b, ertot, zmin,
400
 
                                         *dnorm);
 
403
                                         *dnorm, triple);
401
404
 
402
405
                    if (params->grid_calc(params, data, bitmask,
403
406
                                          zmin, zmax, zminac, zmaxac, gmin,
443
446
                    G_lubksb(matrix, data->n_points + 1, indx, b);
444
447
 
445
448
                    params->check_points(params, data, b, ertot, zmin,
446
 
                                         *dnorm);
 
449
                                         *dnorm, triple);
447
450
 
448
451
                    if (params->grid_calc(params, data, bitmask,
449
452
                                          zmin, zmax, zminac, zmaxac, gmin,
491
494
{
492
495
    double x, y, sm;            /* input data and smoothing */
493
496
    int m1, m2;                 /* loop counters */
494
 
    int ret_val, ret_val1;      /* return values of G_get_map_row */
495
497
    static FCELL *cellinp = NULL;       /* cell buffer for input data */
496
498
    static FCELL *cellsmooth = NULL;    /* cell buffer for smoothing */
497
499
 
498
500
 
499
501
    if (!cellinp)
500
 
        cellinp = G_allocate_f_raster_buf();
 
502
        cellinp = Rast_allocate_f_buf();
501
503
    if (!cellsmooth)
502
 
        cellsmooth = G_allocate_f_raster_buf();
 
504
        cellsmooth = Rast_allocate_f_buf();
503
505
 
504
506
    for (m1 = 0; m1 <= last_row - first_row; m1++) {
505
 
        ret_val =
506
 
            G_get_f_raster_row(fdinp, cellinp, inp_rows - m1 - first_row);
507
 
        if (ret_val < 0) {
508
 
            fprintf(stderr, "Cannot get row %d (return value = %d)\n", m1,
509
 
                    ret_val);
510
 
            return -1;
511
 
        }
512
 
        if (fdsmooth >= 0) {
513
 
            ret_val1 =
514
 
                G_get_f_raster_row(fdsmooth, cellsmooth,
515
 
                                   inp_rows - m1 - first_row);
516
 
            if (ret_val1 < 0) {
517
 
                fprintf(stderr, "Cannot get smoothing row\n");
518
 
            }
519
 
        }
 
507
        Rast_get_f_row(fdinp, cellinp, inp_rows - m1 - first_row);
 
508
        if (fdsmooth >= 0)
 
509
            Rast_get_f_row(fdsmooth, cellsmooth, inp_rows - m1 - first_row);
 
510
 
520
511
        y = params->y_orig + (m1 + first_row - 1 + 0.5) * inp_ns_res;
521
512
        for (m2 = 0; m2 < inp_cols; m2++) {
522
513
            x = params->x_orig + (m2 + 0.5) * inp_ew_res;
530
521
 
531
522
            points[m1 * inp_cols + m2].x = x - params->x_orig;
532
523
            points[m1 * inp_cols + m2].y = y - params->y_orig;
533
 
            if (!G_is_f_null_value(cellinp + m2)) {
 
524
            if (!Rast_is_f_null_value(cellinp + m2)) {
534
525
                points[m1 * inp_cols + m2].z =
535
526
                    cellinp[m2] * params->zmult - zmin;
536
527
            }
537
528
            else {
538
 
                G_set_f_null_value(&(points[m1 * inp_cols + m2].z), 1);
 
529
                Rast_set_f_null_value(&(points[m1 * inp_cols + m2].z), 1);
539
530
            }
540
531
 
541
532
            /*              fprintf (stdout,"sm: %f\n",sm); */
546
537
    return 1;
547
538
}
548
539
 
549
 
static int write_zeros(struct interp_params *params, struct quaddata *data,     /* given segment */
550
 
                       int offset1      /* offset for temp file writing */
 
540
static int write_zeros(struct interp_params *params,
 
541
                       struct quaddata *data,   /* given segment */
 
542
                       off_t offset1            /* offset for temp file writing */
551
543
    )
552
544
{
553
545
 
562
554
    int cond1, cond2;
563
555
    int k, l;
564
556
    int ngstc, nszc, ngstr, nszr;
565
 
    int offset, offset2;
 
557
    off_t offset, offset2;
566
558
    double ns_res, ew_res;
567
559
 
568
560
    ns_res = (((struct quaddata *)(data))->ymax -
585
577
            /*
586
578
             * params->az[l] = 0.;
587
579
             */
588
 
            G_set_d_null_value(params->az + l, 1);
 
580
            Rast_set_d_null_value(params->az + l, 1);
589
581
            if (cond1) {
590
582
                /*
591
583
                 * params->adx[l] = (FCELL)0.; params->ady[l] = (FCELL)0.;
592
584
                 */
593
 
                G_set_d_null_value(params->adx + l, 1);
594
 
                G_set_d_null_value(params->ady + l, 1);
 
585
                Rast_set_d_null_value(params->adx + l, 1);
 
586
                Rast_set_d_null_value(params->ady + l, 1);
595
587
                if (cond2) {
596
 
                    G_set_d_null_value(params->adxx + l, 1);
597
 
                    G_set_d_null_value(params->adyy + l, 1);
598
 
                    G_set_d_null_value(params->adxy + l, 1);
 
588
                    Rast_set_d_null_value(params->adxx + l, 1);
 
589
                    Rast_set_d_null_value(params->adyy + l, 1);
 
590
                    Rast_set_d_null_value(params->adxy + l, 1);
599
591
                    /*
600
592
                     * params->adxx[l] = (FCELL)0.; params->adyy[l] = (FCELL)0.;
601
593
                     * params->adxy[l] = (FCELL)0.;