[GRASS-SVN] r59131 - grass/trunk/raster/r.clump
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 24 01:17:27 PST 2014
Author: mmetz
Date: 2014-02-24 01:17:27 -0800 (Mon, 24 Feb 2014)
New Revision: 59131
Modified:
grass/trunk/raster/r.clump/clump.c
Log:
r.clump: reduce code duplication
Modified: grass/trunk/raster/r.clump/clump.c
===================================================================
--- grass/trunk/raster/r.clump/clump.c 2014-02-24 00:40:45 UTC (rev 59130)
+++ grass/trunk/raster/r.clump/clump.c 2014-02-24 09:17:27 UTC (rev 59131)
@@ -119,6 +119,8 @@
* clump and will have to be merged
*/
+ OLD = NEW = 0;
+
/* only one "if (diag)" for speed */
if (diag) {
temp_cell = prev_in + col - 1;
@@ -126,21 +128,6 @@
UP = *temp_cell++;
UR = *temp_cell;
- /* start a new clump */
- if (X != LEFT && X != UP && X != UL && X != UR) {
- label++;
- cur_clump[col] = label;
- if (label >= nalloc) {
- nalloc += INCR;
- index =
- (CELL *) G_realloc(index,
- nalloc * sizeof(CELL));
- }
- index[label] = label;
- continue;
- }
-
- OLD = NEW = 0;
/* same clump as to the left */
if (X == LEFT) {
OLD = cur_clump[col - 1];
@@ -170,21 +157,6 @@
else {
UP = prev_in[col];
- /* start a new clump */
- if (X != LEFT && X != UP) {
- label++;
- cur_clump[col] = label;
- if (label >= nalloc) {
- nalloc += INCR;
- index =
- (CELL *) G_realloc(index,
- nalloc * sizeof(CELL));
- }
- index[label] = label;
- continue;
- }
-
- OLD = NEW = 0;
/* same clump as to the left */
if (X == LEFT) {
OLD = cur_clump[col - 1];
@@ -204,6 +176,18 @@
}
if (NEW == 0 || OLD == NEW) { /* ok */
+ if (OLD == 0) {
+ /* start a new clump */
+ label++;
+ cur_clump[col] = label;
+ if (label >= nalloc) {
+ nalloc += INCR;
+ index =
+ (CELL *) G_realloc(index,
+ nalloc * sizeof(CELL));
+ }
+ index[label] = label;
+ }
continue;
}
@@ -259,7 +243,7 @@
/* generate a renumbering scheme */
G_message(_("Generating renumbering scheme..."));
- G_debug(0, "%d initial labels", label);
+ G_debug(1, "%d initial labels", label);
/* allocate final clump ID */
renumber = (CELL *) G_malloc((label + 1) * sizeof(CELL));
renumber[0] = 0;
More information about the grass-commit
mailing list