[GRASS-SVN] r35735 - grass/trunk/raster/r.proj
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 2 13:11:24 EST 2009
Author: kyngchaos
Date: 2009-02-02 13:11:24 -0500 (Mon, 02 Feb 2009)
New Revision: 35735
Added:
grass/trunk/raster/r.proj/bilinear_f.c
grass/trunk/raster/r.proj/cubic_f.c
Modified:
grass/trunk/raster/r.proj/main.c
grass/trunk/raster/r.proj/r.proj.h
grass/trunk/raster/r.proj/r.proj.html
Log:
add fallback methods for bilinear and cubic
Added: grass/trunk/raster/r.proj/bilinear_f.c
===================================================================
--- grass/trunk/raster/r.proj/bilinear_f.c (rev 0)
+++ grass/trunk/raster/r.proj/bilinear_f.c 2009-02-02 18:11:24 UTC (rev 35735)
@@ -0,0 +1,47 @@
+/*
+ * Name
+ * bilinear_f.c -- use bilinear interpolation with fallback for given row, col
+ *
+ * Description
+ * bilinear interpolation for the given row, column indices.
+ * If the interpolated value (but not the nearest) is null,
+ * it falls back to nearest neighbor.
+ */
+
+#include <grass/gis.h>
+#include "r.proj.h"
+
+void p_bilinear_f(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *col_idx, /* column index */
+ double *row_idx, /* row index */
+ struct Cell_head *cellhd /* cell header of input layer */
+ )
+{
+ /* start nearest neighbor to do some basic tests */
+ int row, col; /* row/col of nearest neighbor */
+ FCELL *cellp;
+
+ /* cut indices to integer */
+ row = (int)floor(*row_idx);
+ col = (int)floor(*col_idx);
+
+ /* check for out of bounds - if out of bounds set NULL value */
+ if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
+ G_set_null_value(obufptr, 1, cell_type);
+ return;
+ }
+
+ cellp = CPTR(ibuffer, row, col);
+ /* if nearest is null, all the other interps will be null */
+ if (G_is_f_null_value(cellp)) {
+ G_set_null_value(obufptr, 1, cell_type);
+ return;
+ }
+
+ p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
+ /* fallback to nearest if bilinear is null */
+ if (G_is_f_null_value(obufptr))
+ G_set_raster_value_f(obufptr, *cellp, cell_type);
+}
Added: grass/trunk/raster/r.proj/cubic_f.c
===================================================================
--- grass/trunk/raster/r.proj/cubic_f.c (rev 0)
+++ grass/trunk/raster/r.proj/cubic_f.c 2009-02-02 18:11:24 UTC (rev 35735)
@@ -0,0 +1,52 @@
+/*
+ * Name
+ * cubic_f.c -- use cubic interpolation with fallback for given row, col
+ *
+ * Description
+ * cubic interpolation for the given row, column indices.
+ * If the interpolated value (but not the nearest) is null,
+ * it falls back to bilinear. If that interp value is null,
+ * it falls back to nearest neighbor.
+ */
+
+#include <grass/gis.h>
+#include "r.proj.h"
+
+void p_cubic_f(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *col_idx, /* column index */
+ double *row_idx, /* row index */
+ struct Cell_head *cellhd /* cell header of input layer */
+ )
+{
+ /* start nearest neighbor to do some basic tests */
+ int row, col; /* row/col of nearest neighbor */
+ FCELL *cellp;
+
+ /* cut indices to integer */
+ row = (int)floor(*row_idx);
+ col = (int)floor(*col_idx);
+
+ /* check for out of bounds - if out of bounds set NULL value */
+ if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
+ G_set_null_value(obufptr, 1, cell_type);
+ return;
+ }
+
+ cellp = CPTR(ibuffer, row, col);
+ /* if nearest is null, all the other interps will be null */
+ if (G_is_f_null_value(cellp)) {
+ G_set_null_value(obufptr, 1, cell_type);
+ return;
+ }
+
+ p_cubic(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
+ /* fallback to bilinear if cubic is null */
+ if (G_is_f_null_value(obufptr)) {
+ p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
+ /* fallback to nearest if bilinear is null */
+ if (G_is_f_null_value(obufptr))
+ G_set_raster_value_f(obufptr, *cellp, cell_type);
+ }
+}
Modified: grass/trunk/raster/r.proj/main.c
===================================================================
--- grass/trunk/raster/r.proj/main.c 2009-02-02 18:07:10 UTC (rev 35734)
+++ grass/trunk/raster/r.proj/main.c 2009-02-02 18:11:24 UTC (rev 35735)
@@ -67,6 +67,8 @@
{p_nearest, "nearest", "nearest neighbor"},
{p_bilinear, "bilinear", "bilinear"},
{p_cubic, "cubic", "cubic convolution"},
+ {p_bilinear_f, "bilinear_f", "bilinear with fallback"},
+ {p_cubic_f, "cubic_f", "cubic convolution with fallback"},
{NULL, NULL, NULL}
};
Modified: grass/trunk/raster/r.proj/r.proj.h
===================================================================
--- grass/trunk/raster/r.proj/r.proj.h 2009-02-02 18:07:10 UTC (rev 35734)
+++ grass/trunk/raster/r.proj/r.proj.h 2009-02-02 18:11:24 UTC (rev 35735)
@@ -49,6 +49,12 @@
/* nearest.c */
extern void p_nearest(struct cache *, void *, int, double *, double *,
struct Cell_head *);
+/* bilinear_f.c */
+extern void p_bilinear_f(struct cache *, void *, int, double *, double *,
+ struct Cell_head *);
+/* cubic_f.c */
+extern void p_cubic_f(struct cache *, void *, int, double *, double *,
+ struct Cell_head *);
#if 1
Modified: grass/trunk/raster/r.proj/r.proj.html
===================================================================
--- grass/trunk/raster/r.proj/r.proj.html 2009-02-02 18:07:10 UTC (rev 35734)
+++ grass/trunk/raster/r.proj/r.proj.html 2009-02-02 18:11:24 UTC (rev 35735)
@@ -108,8 +108,16 @@
continuous data and cause some smoothing. Both options should not be used
with categorical data, since the cell values will be altered.
<p>
+In the bilinear and cubic methods, if any of the surrounding cells used to
+interpolate the new cell value are null, the resulting cell will be null, even if
+the nearest cell is not null. This will cause some thinning along null borders,
+such as the coasts of land areas in a DEM. The bilinear_f and cubic_f
+interpolation methods can be used if thinning along null edges is not desired.
+These methods "fall back" to simpler interpolation methods along null borders.
+That is, from cubic to bilinear to nearest.
+<p>
If nearest neighbor assignment is used, the output map has the same raster
-format as the input map. If any of the both interpolations is used, the
+format as the input map. If any of the interpolations is used, the
output map is written as floating point.
<p>
More information about the grass-commit
mailing list