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

« back to all changes in this revision

Viewing changes to raster/r.mfilter/apply.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:
 
1
#include <grass/raster.h>
1
2
#include "filter.h"
2
3
 
3
4
/**************************************************************
6
7
 *  filter:    filter to be applied
7
8
 *  input:     input buffers
8
9
 **************************************************************/
9
 
CELL apply_filter(FILTER * filter, CELL ** input)
 
10
DCELL apply_filter(FILTER * filter, DCELL ** input)
10
11
{
11
 
    int **matrix;
12
 
    int size;
13
 
    int divisor;
14
 
    int round;
15
 
    register int r, c;
16
 
    register CELL v;
17
 
 
18
 
    size = filter->size;
19
 
    divisor = filter->divisor;
20
 
    matrix = filter->matrix;
 
12
    int size = filter->size;
 
13
    double **matrix = filter->matrix;
 
14
    double divisor = filter->divisor;
 
15
    int r, c;
 
16
    DCELL v;
21
17
 
22
18
    v = 0;
23
 
    for (r = 0; r < size; r++)
24
 
        for (c = 0; c < size; c++)
25
 
            v += input[r][c] * matrix[r][c];
26
 
    /* zero divisor means compute a divisor. this is done by adding the
27
 
       numbers is the divisor matrix where the corresponding cell value
28
 
       is not zero.
29
 
     */
 
19
 
30
20
    if (divisor == 0) {
31
 
        matrix = filter->dmatrix;
 
21
        int have_result = 0;
 
22
 
32
23
        for (r = 0; r < size; r++)
33
 
            for (c = 0; c < size; c++)
34
 
                if (input[r][c])
35
 
                    divisor += matrix[r][c];
 
24
            for (c = 0; c < size; c++) {
 
25
                if (Rast_is_d_null_value(&input[r][c]))
 
26
                    continue;
 
27
                v += input[r][c] * matrix[r][c];
 
28
                divisor += filter->dmatrix[r][c];
 
29
                have_result = 1;
 
30
            }
 
31
 
 
32
        if (have_result)
 
33
            v /= divisor;
 
34
        else
 
35
            Rast_set_d_null_value(&v, 1);
36
36
    }
 
37
    else {
 
38
        for (r = 0; r < size; r++)
 
39
            for (c = 0; c < size; c++) {
 
40
                if (Rast_is_d_null_value(&input[r][c])) {
 
41
                    Rast_set_d_null_value(&v, 1);
 
42
                    return v;
 
43
                }
 
44
                v += input[r][c] * matrix[r][c];
 
45
            }
37
46
 
38
 
    /* now round the result to nearest integer. negative numbers are rounded
39
 
       a little differently than non-negative numbers
40
 
     */
41
 
    if (divisor) {
42
 
        if (round = divisor / 2) {
43
 
            if ((round > 0 && v > 0) || (round < 0 && v < 0))
44
 
                v += round;
45
 
            else
46
 
                v -= round;
47
 
        }
48
47
        v /= divisor;
49
48
    }
50
 
    else
51
 
        v = 0;
52
49
 
53
50
    return v;
54
51
}