| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include <grass/gis.h> |
| 16 |
#include <grass/raster.h> |
| 17 |
#include <math.h> |
| 18 |
#include "global.h" |
| 19 |
|
| 20 |
void p_lanczos(struct cache *ibuffer, |
| 21 |
void *obufptr, |
| 22 |
int cell_type, |
| 23 |
double *row_idx, |
| 24 |
double *col_idx, |
| 25 |
struct Cell_head *cellhd |
| 26 |
) |
| 27 |
{ |
| 28 |
int row; |
| 29 |
int col; |
| 30 |
int i, j, k; |
| 31 |
DCELL t, u; |
| 32 |
DCELL result; |
| 33 |
DCELL cell[25]; |
| 34 |
|
| 35 |
|
| 36 |
row = (int)floor(*row_idx); |
| 37 |
col = (int)floor(*col_idx); |
| 38 |
|
| 39 |
|
| 40 |
if (row - 2 < 0 || row + 2 >= cellhd->rows || col - 2 < 0 || |
| 41 |
col + 2 >= cellhd->cols) { |
| 42 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
k = 0; |
| 47 |
for (i = 0; i < 5; i++) { |
| 48 |
for (j = 0; j < 5; j++) { |
| 49 |
const DCELL *cellp = CPTR(ibuffer, row - 2 + i, col - 2 + j); |
| 50 |
|
| 51 |
if (Rast_is_d_null_value(cellp)) { |
| 52 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 53 |
return; |
| 54 |
} |
| 55 |
cell[k++] = *cellp; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
t = *col_idx - 0.5 - col; |
| 61 |
u = *row_idx - 0.5 - row; |
| 62 |
|
| 63 |
result = Rast_interp_lanczos(t, u, cell); |
| 64 |
|
| 65 |
Rast_set_d_value(obufptr, result, cell_type); |
| 66 |
} |
| 67 |
|
| 68 |
void p_lanczos_f(struct cache *ibuffer, |
| 69 |
void *obufptr, |
| 70 |
int cell_type, |
| 71 |
double *row_idx, |
| 72 |
double *col_idx, |
| 73 |
struct Cell_head *cellhd |
| 74 |
) |
| 75 |
{ |
| 76 |
int row; |
| 77 |
int col; |
| 78 |
DCELL *cellp, cell; |
| 79 |
|
| 80 |
|
| 81 |
row = (int)floor(*row_idx); |
| 82 |
col = (int)floor(*col_idx); |
| 83 |
|
| 84 |
|
| 85 |
if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) { |
| 86 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
cellp = CPTR(ibuffer, row, col); |
| 91 |
|
| 92 |
if (Rast_is_d_null_value(cellp)) { |
| 93 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 94 |
return; |
| 95 |
} |
| 96 |
cell = *cellp; |
| 97 |
|
| 98 |
p_lanczos(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd); |
| 99 |
|
| 100 |
if (Rast_is_d_null_value(obufptr)) { |
| 101 |
p_cubic(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd); |
| 102 |
|
| 103 |
if (Rast_is_d_null_value(obufptr)) { |
| 104 |
p_bilinear(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd); |
| 105 |
|
| 106 |
if (Rast_is_d_null_value(obufptr)) |
| 107 |
Rast_set_d_value(obufptr, cell, cell_type); |
| 108 |
} |
| 109 |
} |
| 110 |
} |