Browse Source

r.grow: move the C version of r.grow to addons as r.grow.shrink since it supports shrinking

 * remove C version of r.grow in release branch 7.0
 * see also https://trac.osgeo.org/grass/ticket/2368 and https://trac.osgeo.org/grass/ticket/1024
 * note: trunk and 7.0 now contains Python version of r.grow which is using r.grow.distance and does not support shrinking


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62819 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 10 years ago
parent
commit
c3d304cb69
4 changed files with 0 additions and 436 deletions
  1. 0 2
      raster/r.grow/DEPRECATED
  2. 0 10
      raster/r.grow/Makefile
  3. 0 327
      raster/r.grow/main.c
  4. 0 97
      raster/r.grow/r.grow.html

+ 0 - 2
raster/r.grow/DEPRECATED

@@ -1,2 +0,0 @@
-no longer maintained.
-Continued in ../r.grow.distance/

+ 0 - 10
raster/r.grow/Makefile

@@ -1,10 +0,0 @@
-MODULE_TOPDIR = ../..
-
-PGM = r.grow
-
-LIBES = $(GISLIB) $(RASTERLIB)
-DEPENDENCIES = $(GISDEP) $(RASTERDEP)
-
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-default: cmd

+ 0 - 327
raster/r.grow/main.c

@@ -1,327 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r.grow2
- *
- * AUTHOR(S):    Marjorie Larson - CERL
- *               Glynn Clements
- *
- * PURPOSE:      Generates a raster map layer with contiguous areas 
- *               grown by one cell.
- *
- * COPYRIGHT:    (C) 2006 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- ***************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-
-#ifdef MAX
-#undef MAX
-#endif
-#define MAX(a, b)	((a) > (b) ? (a) : (b))
-
-static int size;
-static int count;
-static int (*neighbors)[2];
-
-typedef int metric_fn(int, int);
-
-
-static int distance_euclidean_squared(int dx, int dy)
-{
-    return dx * dx + dy * dy;
-}
-
-static int distance_maximum(int dx, int dy)
-{
-    return MAX(abs(dx), abs(dy));
-}
-
-static int distance_manhattan(int dx, int dy)
-{
-    return abs(dx) + abs(dy);
-}
-
-static void setup_neighbors(double radius, int limit, metric_fn * dist)
-{
-    int i, dx, dy;
-    int n;
-
-    size = (int)radius;
-
-    n = size * 2 + 1;
-
-    neighbors = G_malloc(n * n * 2 * sizeof(int));
-
-    count = 0;
-
-    for (i = 1; i <= limit; i++) {
-	for (dy = -size; dy <= size; dy++) {
-	    for (dx = -size; dx <= size; dx++) {
-		if ((*dist) (dx, dy) != i)
-		    continue;
-
-		neighbors[count][0] = dx;
-		neighbors[count][1] = dy;
-		count++;
-	    }
-	}
-    }
-}
-
-static void setup_neighbors_euclidean(double radius)
-{
-    int r2 = (int)(radius * radius);
-
-    setup_neighbors(radius, r2, distance_euclidean_squared);
-}
-
-static void setup_neighbors_maximum(double radius)
-{
-    setup_neighbors(radius, (int)radius, distance_maximum);
-}
-
-static void setup_neighbors_manhattan(double radius)
-{
-    setup_neighbors(radius, (int)radius, distance_manhattan);
-}
-
-int main(int argc, char **argv)
-{
-    struct GModule *module;
-    struct
-    {
-	struct Option *in, *out, *rad, *met, *old, *new;
-    } opt;
-    struct Colors colr;
-    struct Categories cats;
-    struct History history;
-    int colrfile;
-    char *in_name;
-    char *out_name;
-    double radius;
-    int oldval = 0;
-    int newval = 0;
-    RASTER_MAP_TYPE type;
-    int in_fd;
-    int out_fd;
-    DCELL **in_rows;
-    DCELL *out_row;
-    int nrows, row;
-    int ncols, col;
-    int shrink;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    G_add_keyword(_("raster"));
-    G_add_keyword(_("distance"));
-    module->description =
-	_("Generates a raster map layer "
-	  "with contiguous areas grown by one cell.");
-
-    opt.in = G_define_standard_option(G_OPT_R_INPUT);
-
-    opt.out = G_define_standard_option(G_OPT_R_OUTPUT);
-
-    opt.rad = G_define_option();
-    opt.rad->key = "radius";
-    opt.rad->type = TYPE_DOUBLE;
-    opt.rad->required = NO;
-    opt.rad->description = _("Radius of buffer in raster cells");
-    opt.rad->answer = "1.01";
-
-    opt.met = G_define_option();
-    opt.met->key = "metric";
-    opt.met->type = TYPE_STRING;
-    opt.met->required = NO;
-    opt.met->description = _("Metric");
-    opt.met->options = "euclidean,maximum,manhattan";
-    opt.met->answer = "euclidean";
-
-    opt.old = G_define_option();
-    opt.old->key = "old";
-    opt.old->type = TYPE_INTEGER;
-    opt.old->required = NO;
-    opt.old->description =
-	_("Value to write for input cells which are non-NULL (-1 => NULL)");
-
-    opt.new = G_define_option();
-    opt.new->key = "new";
-    opt.new->type = TYPE_INTEGER;
-    opt.new->required = NO;
-    opt.new->description = _("Value to write for \"grown\" cells");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-    in_name = opt.in->answer;
-    out_name = opt.out->answer;
-
-    shrink = 0;
-
-    radius = atof(opt.rad->answer);
-    if (radius < 0) {
-	shrink = 1;
-	radius = -radius;
-    }
-
-    if (opt.old->answer)
-	oldval = atoi(opt.old->answer);
-
-    if (opt.new->answer)
-	newval = atoi(opt.new->answer);
-
-    nrows = Rast_window_rows();
-    ncols = Rast_window_cols();
-
-    if (strcmp(opt.met->answer, "euclidean") == 0)
-	setup_neighbors_euclidean(radius);
-    else if (strcmp(opt.met->answer, "maximum") == 0)
-	setup_neighbors_maximum(radius);
-    else if (strcmp(opt.met->answer, "manhattan") == 0)
-	setup_neighbors_manhattan(radius);
-    else
-	G_fatal_error(_("Unknown metric: [%s]."), opt.met->answer);
-
-    in_fd = Rast_open_old(in_name, "");
-
-    type = Rast_get_map_type(in_fd);
-
-    out_fd = Rast_open_new(out_name, type);
-
-    if (Rast_read_cats(in_name, "", &cats) == -1) {
-	G_warning(_("Error reading category file for <%s>"), in_name);
-	Rast_init_cats("", &cats);
-    }
-
-    if (Rast_read_colors(in_name, "", &colr) == -1) {
-	G_warning(_("Error in reading color file for <%s>"), in_name);
-	colrfile = 0;
-    }
-    else
-	colrfile = 1;
-
-    if (opt.old->answer && oldval >= 0)
-	Rast_set_c_cat(&oldval, &oldval, "original cells", &cats);
-
-    if (opt.new->answer)
-	Rast_set_c_cat(&newval, &newval,"grown cells", &cats);
-
-    in_rows = G_malloc((size * 2 + 1) * sizeof(DCELL *));
-
-    for (row = 0; row <= size * 2; row++)
-	in_rows[row] = Rast_allocate_d_buf();
-
-    out_row = Rast_allocate_d_buf();
-
-    for (row = 0; row < size; row++)
-	Rast_get_d_row(in_fd, in_rows[size + row], row);
-
-    for (row = 0; row < nrows; row++) {
-	DCELL *tmp;
-	int i;
-
-	if (row + size < nrows)
-	    Rast_get_d_row(in_fd, in_rows[size * 2], row + size);
-
-	for (col = 0; col < ncols; col++) {
-	    DCELL *c = &in_rows[size][col];
-
-	    if (shrink) {
-		if (Rast_is_d_null_value(c)) {
-		    Rast_set_d_null_value(&out_row[col], 1);
-		    continue;
-		}
-
-		for (i = 0; i < count; i++) {
-		    int dx = neighbors[i][0];
-		    int dy = neighbors[i][1];
-		    int x = col + dx;
-		    int y = row + dy;
-
-		    if (x < 0 || x >= ncols || y < 0 || y >= nrows)
-			continue;
-
-		    c = &in_rows[size + dy][x];
-
-		    if (Rast_is_d_null_value(c)) {
-			Rast_set_d_null_value(&out_row[col], 1);
-			break;
-		    }
-		}
-
-		if (i == count)
-		    out_row[col] = *c;
-	    }
-	    else {
-		if (!Rast_is_d_null_value(c)) {
-		    if (opt.old->answer) {
-			if (oldval < 0)
-			    Rast_set_d_null_value(&out_row[col], 1);
-			else
-			    out_row[col] = oldval;
-		    }
-		    else
-			out_row[col] = *c;
-
-		    continue;
-		}
-
-		for (i = 0; i < count; i++) {
-		    int dx = neighbors[i][0];
-		    int dy = neighbors[i][1];
-		    int x = col + dx;
-		    int y = row + dy;
-
-		    if (x < 0 || x >= ncols || y < 0 || y >= nrows)
-			continue;
-
-		    c = &in_rows[size + dy][x];
-
-		    if (!Rast_is_d_null_value(c)) {
-			out_row[col] = opt.new->answer ? newval : *c;
-			break;
-		    }
-		}
-
-		if (i == count)
-		    Rast_set_d_null_value(&out_row[col], 1);
-	    }
-	}
-
-	Rast_put_d_row(out_fd, out_row);
-
-	G_percent(row, nrows, 2);
-
-	tmp = in_rows[0];
-	for (i = 0; i < size * 2; i++)
-	    in_rows[i] = in_rows[i + 1];
-	in_rows[size * 2] = tmp;
-    }
-
-    G_percent(row, nrows, 2);
-
-    Rast_close(in_fd);
-    Rast_close(out_fd);
-
-    Rast_write_cats(out_name, &cats);
-
-    if (colrfile)
-	Rast_write_colors(out_name, G_mapset(), &colr);
-
-    Rast_short_history(out_name, "raster", &history);
-    Rast_command_history(&history);
-    Rast_write_history(out_name, &history);
-
-    return EXIT_SUCCESS;
-}

+ 0 - 97
raster/r.grow/r.grow.html

@@ -1,97 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>r.grow</em> adds cells around the perimeters of all areas
-in a user-specified raster map layer and stores the output in
-a new raster map layer. The user can use it to grow by one or
-more than one cell (by varying the size of the <b>radius</b>
-parameter), or like <em>r.buffer</em>, but with the
-option of preserving the original cells (similar to combining
-<em>r.buffer</em> and <em>r.patch</em>).
-<p>
-A negative <b>radius</b> shrinks inwards instead of growing outwards.
-
-
-<h2>NOTES</h2>
-The user has the option of specifying three different metrics which
-control the geometry in which grown cells are created, (controlled by
-the <b>metric</b> parameter): <i>Euclidean</i>, <i>Manhattan</i>, and 
-<i>Maximum</i>. 
-
-<p>
-The <i>Euclidean distance</i> or <i>Euclidean metric</i> is the "ordinary" distance 
-between two points that one would measure with a ruler, which can be 
-proven by repeated application of the Pythagorean theorem. 
-The formula is given by: 
-
-<div class="code"><pre>d(dx,dy) = sqrt(dx^2 + dy^2)</pre></div>
-
-Cells grown using this metric would form isolines of distance that are
-circular from a given point, with the distance given by the <b>radius</b>.
-
-<p>
-The <i>Manhattan metric</i>, or <i>Taxicab geometry</i>, is a form of geometry in 
-which the usual metric of Euclidean geometry is replaced by a new 
-metric in which the distance between two points is the sum of the (absolute) 
-differences of their coordinates. The name alludes to the grid layout of 
-most streets on the island of Manhattan, which causes the shortest path a 
-car could take between two points in the city to have length equal to the
-points' distance in taxicab geometry.
-The formula is given by:
-
-<div class="code"><pre>d(dx,dy) = abs(dx) + abs(dy)</pre></div>
-
-where cells grown using this metric would form isolines of distance that are
-rhombus-shaped from a given point. 
-
-<p>
-The <i>Maximum metric</i> is given by the formula
-
-<div class="code"><pre>d(dx,dy) = max(abs(dx),abs(dy))</pre></div>
-
-where the isolines of distance from a point are squares.
-
-<p>
-If there are two cells which are equal candidates to grow into an empty space, 
-<em>r.grow</em> will choose the northernmost candidate; if there are multiple 
-candidates with the same northing, the westernmost is chosen. 
-
-
-<h2>EXAMPLE</h2>
-
-You can shrink inwards by using a negative radius. For example:
-<div class="code"><pre>
-# North Carolina sample dataset
-
-g.region rast=lakes
-r.grow in=lakes out=lakes.shrunken radius=-2.01
-r.colors lakes.shrunken rast=lakes
-</pre></div>
-
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="r.buffer.html">r.buffer</a>,
-<a href="r.grow.distance.html">r.grow.distance</a>
-</em>
-
-<p>
-<em>
-<a href="r.distance.html">r.distance</a>,
-<a href="r.patch.html">r.patch</a>
-</em>
-
-<p>
-<em><a href="http://en.wikipedia.org/wiki/Euclidean_metric">Wikipedia Entry: Euclidean Metric</a></em><br>
-<em><a href="http://en.wikipedia.org/wiki/Manhattan_metric">Wikipedia Entry: Manhattan Metric</a></em>
-
-
-<h2>AUTHORS</h2>
-
-Marjorie Larson, 
-U.S. Army Construction Engineering Research Laboratory
-<p>
-Glynn Clements
-
-<p>
-<i>Last changed: $Date$</i>