[GRASS-SVN] r70852 - in grass-addons/grass7/raster/r.pi: . r.pi.corearea r.pi.csr.mw r.pi.energy r.pi.energy.iter r.pi.enn r.pi.enn.iter r.pi.export r.pi.fnn r.pi.graph r.pi.graph.dec r.pi.graph.iter r.pi.graph.red r.pi.import r.pi.index r.pi.library r.pi.neigh r.pi.nlm.stats r.pi.odc r.pi.prob.mw r.pi.prox r.pi.searchtime r.pi.searchtime.iter r.pi.searchtime.mw
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 8 13:05:19 PDT 2017
Author: mmetz
Date: 2017-04-08 13:05:19 -0700 (Sat, 08 Apr 2017)
New Revision: 70852
Added:
grass-addons/grass7/raster/r.pi/r.pi.library/frag.c
Removed:
grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c
grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c
grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c
grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c
grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c
grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c
grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c
grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c
grass-addons/grass7/raster/r.pi/r.pi.import/frag.c
grass-addons/grass7/raster/r.pi/r.pi.index/frag.c
grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c
grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c
grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c
grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c
Modified:
grass-addons/grass7/raster/r.pi/TODO.txt
grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c
grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c
grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.energy/main.c
grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c
grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
grass-addons/grass7/raster/r.pi/r.pi.export/frag.c
grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.export/main.c
grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c
grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c
grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c
grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c
grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c
grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c
grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c
grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.graph/main.c
grass-addons/grass7/raster/r.pi/r.pi.import/Makefile
grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.import/main.c
grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.index/main.c
grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h
grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c
grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c
grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.odc/main.c
grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c
grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c
grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.prox/main.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c
grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h
grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c
Log:
r.pi: move frag.c to library
Modified: grass-addons/grass7/raster/r.pi/TODO.txt
===================================================================
--- grass-addons/grass7/raster/r.pi/TODO.txt 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/TODO.txt 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,14 +1,6 @@
#####################################
C-code:
-r.pi.corrwin and r.pi.corrwindow seem to be duplicates, the main.c version
-are slightly different, but r.pi.corrwin seems to be newer - correct?
-
-- r.pi.energy,r.pi.energy.iter,r.pi.searchtime have "overwrite" as default, need to be changed to option "--o"
-
-- remmove custom 'quiet' flag
-- convert C++ style comments
-- code must conform to C89 (variable declarations)
- fix all the unused variables
- fix compiler warnings
- there are LOTs of cloned files, put them into a r.pi library (example:
@@ -28,7 +20,35 @@
ls -l */$i
done
+ frag.c, writeFrag()
+ outside is neighbor
+ r.pi.energy (keep in sync with search.c)
+ r.pi.energy.iter (keep in sync with search.c)
+ r.pi.export
+ r.pi.graph.dec
+ r.pi.graph.iter
+ r.pi.graph.red
+ r.pi.import
+ r.pi.prob.mw
+ r.pi.searchtime (keep in sync with search.c)
+ r.pi.searchtime.iter (keep in sync with search.c)
+ r.pi.searchtime.mw (keep in sync with search.c)
+ outside is NOT neighbor
+ r.pi.corearea
+ r.pi.enn
+ r.pi.enn.iter
+ r.pi.fnn
+ r.pi.graph
+ r.pi.index
+ r.pi.neigh
+ r.pi.nlm.stats
+ r.pi.odc
+ r.pi.prox
+
+- some modules allow to choose between 4 or 8 neighbors,
+ but hardcode neighbors to 4 (e.g. r.pi.energy)
+
- fix SVN propsets with this helper script when uploading to Addons (Markus will do):
grass-addons/tools/module_svn_propset.sh
Deleted: grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,157 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
-
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -19,11 +19,6 @@
typedef struct
{
- int x, y;
-} Position;
-
-typedef struct
-{
double x, y;
} Vector2;
@@ -37,9 +32,6 @@
typedef DCELL(f_statmethod) (DCELL *, int);
typedef DCELL(f_propmethod) (DCELL, DCELL);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* func.c */
void find_borders(int *flagbuf, int nrows, int ncols, int fragcount);
void init_border_values(double distance, double angle, int buffer,
Modified: grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.corearea/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -352,7 +352,7 @@
} */
/* find fragments */
- fragcount = writeFragments(flagbuf, nrows, ncols, nbr_count);
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
/* create a patch map */
for (i = 0; i < fragcount; i++) {
Deleted: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,140 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, double distance);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- double distance);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- double distance)
-{
- int left, right, top, bottom;
- int i, j;
- double dist_q = distance * distance;
- int cnt = 0;
-
- left = x - distance < 0 ? 0 : Round(x - distance);
- right = x + distance > nx - 1 ? nx - 1 : Round(x + distance);
- top = y - distance < 0 ? 0 : Round(y - distance);
- bottom = y + distance > ny - 1 ? ny - 1 : Round(y + distance);
-
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- int dx = i - x;
- int dy = j - y;
- int q_sum = dx * dx + dy * dy;
-
- if (q_sum <= dist_q) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, double distance)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- int neighb_max_count = Round(4 * distance * distance);
- Position *nbr_list =
- (Position *) G_malloc(neighb_max_count * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, distance);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
-
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, double distance)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, distance);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.csr.mw/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -18,11 +18,6 @@
#define GLOBAL extern
#endif
-typedef struct
-{
- int x, y;
-} Position;
-
typedef DCELL(f_statmethod) (DCELL *, int);
typedef void (f_method) (DCELL * values, int *map, int *mask, int n,
int size);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -21,11 +21,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
double dir;
DCELL energy;
int finished;
@@ -48,9 +43,6 @@
typedef DCELL(f_statmethod) (DCELL *, int);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* search.c */
void perform_search(int *map, DCELL * costmap, int n, int fragcount, int sx, int sy);
Modified: grass-addons/grass7/raster/r.pi/r.pi.energy/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -449,7 +449,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, neighb_count);
/* test output */
/* print_fragments(); */
Deleted: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,11 +20,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
double dir;
DCELL energy;
int finished;
@@ -47,9 +42,6 @@
typedef DCELL(f_statmethod) (DCELL *, int);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* search.c */
void perform_search(int *map, DCELL * costmap, int remove_indi, int n, int fragcount, int sx, int sy);
Modified: grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.energy.iter/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -479,7 +479,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, neighb_count);
/* test output */
/* print_fragments(); */
Deleted: grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,139 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/stats.h>
-#include <math.h>
-#include "local_proto.h"
-
-typedef struct
-{
- int x, y;
-} Position;
-
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-void writeFrag(int row, int col, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,8 +20,6 @@
typedef DCELL(f_statmethod) (DCELL *, int);
typedef int (f_func) (DCELL *, int, int *, int, f_statmethod);
-void writeFrag(int row, int col, int nbr_cnt);
-
DCELL value(DCELL * vals, int count);
int get_dist_matrix(int count);
Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -300,7 +300,7 @@
for (col = 0; col < ncols; col++) {
if (flagbuf[row * ncols + col] == 1) {
fragcount++;
- writeFrag(row, col, neighb_count);
+ writeFrag(flagbuf, actpos, row, col, nrows, ncols, neighb_count);
fragments[fragcount] = actpos;
}
}
Deleted: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,157 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- fragments[0] = cells;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -21,19 +21,11 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
} Point;
typedef DCELL(f_statmethod) (DCELL *, int);
typedef void (f_func) (DCELL *, Coords **, int, f_statmethod);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* func.c */
void f_distance(DCELL * vals, Coords ** frags, int count,
f_statmethod statmethod);
Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.iter/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -239,7 +239,7 @@
}
Rast_close(in_fd);
- fragcount = writeFragments(flagbuf, nrows, ncols, neighb_count);
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, neighb_count);
/* perform actual function on the patches */
values = (DCELL *) G_malloc(3 * fragcount * sizeof(DCELL));
Modified: grass-addons/grass7/raster/r.pi/r.pi.export/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,6 +1,6 @@
#include "local_proto.h"
-Coords *writeFrag(DCELL * flagbuf, Coords * actpos, int row, int col,
+Coords *writeFrag_DCELL(DCELL * flagbuf, Coords * actpos, int row, int col,
int nrows, int ncols, int nbr_cnt, int fragcount);
int getNeighbors(Position * res, DCELL * flagbuf, int x, int y, int nx,
int ny, int nbr_cnt);
@@ -56,7 +56,7 @@
return cnt;
}
-Coords *writeFrag(DCELL * flagbuf, Coords * actpos, int row, int col,
+Coords *writeFrag_DCELL(DCELL * flagbuf, Coords * actpos, int row, int col,
int nrows, int ncols, int nbr_cnt, int fragcount)
{
int x, y, i;
@@ -151,7 +151,7 @@
return actpos;
}
-int writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt)
+int writeFragments_DCELL(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt)
{
int row, col;
int fragcount = 0;
@@ -163,7 +163,7 @@
fragcount++;
fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
+ writeFrag_DCELL(flagbuf, fragments[fragcount - 1], row, col,
nrows, ncols, nbr_cnt, fragcount);
}
}
Modified: grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -21,18 +21,13 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
int patch;
} PatchPoint;
typedef DCELL(f_statmethod) (DCELL *, int);
/* frag.c */
-int writeFragments(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt);
+int writeFragments_DCELL(DCELL * flagbuf, int nrows, int ncols, int nbr_cnt);
/* global variables */
GLOBAL Coords **fragments;
Modified: grass-addons/grass7/raster/r.pi/r.pi.export/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.export/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.export/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -231,7 +231,7 @@
Rast_close(in_fd);
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments_DCELL(map, sy, sx, neighb_count);
G_message("Writing output...");
Deleted: grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,139 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/stats.h>
-#include <math.h>
-#include "local_proto.h"
-
-typedef struct
-{
- int x, y;
-} Position;
-
-int getNeighbors(Position * res, int x, int y, int nx, int ny, int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-void writeFrag(int row, int col, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt = getNeighbors(nbr_list, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -25,7 +25,7 @@
typedef DCELL(f_statmethod) (DCELL *, int);
typedef int (f_func) (DCELL *, int, int *, int, f_statmethod);
-void writeFrag(int row, int col, int nbr_cnt);
+void writeFrag_local(int row, int col, int nbr_cnt);
DCELL value(DCELL * vals, int count);
Modified: grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.fnn/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -83,7 +83,7 @@
char *p;
/* neighbors count */
- int neighb_count;
+ int nbr_count;
int row, col, i, j, m;
int method_count;
@@ -291,7 +291,7 @@
compute_stat = statmethods[statmethod].method;
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* allocate the cell buffers */
costmap = (DCELL *) G_malloc(nrows * ncols * sizeof(DCELL));
@@ -330,18 +330,11 @@
G_percent(row, nrows, 2);
}
Rast_close(in_fd);
-
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
- writeFrag(row, col, neighb_count);
- fragments[fragcount] = actpos;
- }
- }
- }
G_percent(nrows, nrows, 2);
+ /* find fragments */
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+
/* generate the distance matrix */
get_dist_matrix(fragcount);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -16,17 +16,9 @@
#define GLOBAL extern
#endif
-typedef struct
-{
- int x, y;
-} Position;
-
typedef void (f_neighborhood) (DCELL max_dist, int fragcount);
typedef void (f_index) (DCELL * values, int fragcount);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* func.c */
int get_dist_matrix(int fragcount);
void f_nearest_neighbor(DCELL max_dist, int fragcount);
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -269,7 +269,7 @@
} */
/* find fragments */
- fragcount = writeFragments(flagbuf, nrows, ncols, nbr_count);
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
/* allocate distance matrix */
distmatrix = (DCELL *) G_malloc(fragcount * fragcount * sizeof(DCELL));
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,11 +1,6 @@
#include "local_proto.h"
-typedef struct
-{
- int x, y;
-} Position;
-
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt);
int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
int nbr_cnt);
@@ -60,7 +55,7 @@
return cnt;
}
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt)
{
int x, y, i;
@@ -72,13 +67,13 @@
/* count neighbors */
int neighbors = 0;
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
+ if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
+ if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
+ if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
+ if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
neighbors++;
/* write first cell */
@@ -115,13 +110,13 @@
/* count neighbors */
neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
neighbors++;
/* set values */
@@ -139,7 +134,7 @@
return curpos;
}
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt)
{
int row, col;
@@ -154,6 +149,7 @@
fragments[fragcount].first_cell =
writeFrag(flagbuf, fragments[fragcount - 1].first_cell,
row, col, nrows, ncols, nbr_cnt);
+ /* divide by sizeof(Patch *) ? */
fragments[fragcount - 1].count =
fragments[fragcount].first_cell - fragments[fragcount -
1].first_cell;
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -41,9 +41,8 @@
DCELL * distmatrix);
/* frag.c */
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt);
-
/* func.c */
int get_dist_matrix(DCELL * distmatrix, Patch * fragments, int fragcount);
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.dec/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -354,7 +354,7 @@
/* find fragments */
fragcount =
- writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+ writeFragments_local(fragments, flagbuf, nrows, ncols, nbr_count);
/* allocate distance matrix */
distmatrix =
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,11 +1,6 @@
#include "local_proto.h"
-typedef struct
-{
- int x, y;
-} Position;
-
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt);
int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
int nbr_cnt);
@@ -60,7 +55,7 @@
return cnt;
}
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt)
{
int x, y, i;
@@ -72,13 +67,13 @@
/* count neighbors */
int neighbors = 0;
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
+ if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
+ if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
+ if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
+ if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
neighbors++;
/* write first cell */
@@ -115,13 +110,13 @@
/* count neighbors */
neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
neighbors++;
/* set values */
@@ -139,7 +134,7 @@
return curpos;
}
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt)
{
int row, col;
@@ -154,6 +149,7 @@
fragments[fragcount].first_cell =
writeFrag(flagbuf, fragments[fragcount - 1].first_cell,
row, col, nrows, ncols, nbr_cnt);
+ /* divide by sizeof(Patch *) ? */
fragments[fragcount - 1].count =
fragments[fragcount].first_cell - fragments[fragcount -
1].first_cell;
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -36,7 +36,7 @@
DCELL * distmatrix);
/* frag.c */
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt);
/* func.c */
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.iter/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -288,7 +288,7 @@
/* find fragments */
fragcount =
- writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+ writeFragments_local(fragments, flagbuf, nrows, ncols, nbr_count);
/* allocate distance matrix */
distmatrix =
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,11 +1,7 @@
#include "local_proto.h"
-typedef struct
-{
- int x, y;
-} Position;
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt);
int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
int nbr_cnt);
@@ -60,7 +56,7 @@
return cnt;
}
-Coords *writeFrag(int *flagbuf, Coords * curpos, int row, int col, int nrows,
+Coords *writeFrag_local(int *flagbuf, Coords * curpos, int row, int col, int nrows,
int ncols, int nbr_cnt)
{
int x, y, i;
@@ -72,13 +68,13 @@
/* count neighbors */
int neighbors = 0;
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
neighbors++;
/* write first cell */
@@ -115,13 +111,13 @@
/* count neighbors */
neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
neighbors++;
/* set values */
@@ -139,7 +135,7 @@
return curpos;
}
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt)
{
int row, col;
@@ -154,6 +150,7 @@
fragments[fragcount].first_cell =
writeFrag(flagbuf, fragments[fragcount - 1].first_cell,
row, col, nrows, ncols, nbr_cnt);
+ /* divide by sizeof(Patch *) ? */
fragments[fragcount - 1].count =
fragments[fragcount].first_cell - fragments[fragcount -
1].first_cell;
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -38,7 +38,7 @@
/* frag.c */
-int writeFragments(Patch * fragments, int *flagbuf, int nrows, int ncols,
+int writeFragments_local(Patch * fragments, int *flagbuf, int nrows, int ncols,
int nbr_cnt);
/* func.c */
Modified: grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.graph.red/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -338,7 +338,7 @@
/* find fragments */
fragcount =
- writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+ writeFragments_local(fragments, flagbuf, nrows, ncols, nbr_count);
/* allocate distance matrix */
distmatrix =
Modified: grass-addons/grass7/raster/r.pi/r.pi.import/Makefile
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/Makefile 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/Makefile 2017-04-08 20:05:19 UTC (rev 70852)
@@ -2,7 +2,10 @@
PGM = r.pi.import
-LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB)
+LIB_NAME = grass_rpi
+RPI_LIB = -l$(LIB_NAME)
+
+LIBES = $(STATSLIB) $(RASTERLIB) $(GISLIB) $(RPI_LIB)
DEPENDENCIES = $(STATSDEP) $(RASTERDEP) $(GISDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Deleted: grass-addons/grass7/raster/r.pi/r.pi.import/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -22,16 +22,8 @@
#define GLOBAL extern
#endif
-typedef struct
-{
- int x, y;
-} Position;
-
typedef DCELL(f_statmethod) (DCELL *, int);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* parse.c */
void parse(DCELL * values, char *file_name, int id_col, int val_col, int fragcount);
Modified: grass-addons/grass7/raster/r.pi/r.pi.import/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.import/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.import/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -177,7 +177,7 @@
Rast_close(in_fd);
/* find fragment values */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, neighb_count);
/* parse input */
parse(values, parm.input->answer, id_col, val_col, fragcount);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.index/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,139 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/stats.h>
-#include <math.h>
-#include "local_proto.h"
-
-typedef struct
-{
- int x, y;
-} Position;
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt = getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -9,8 +9,6 @@
#define GLOBAL extern
#endif
-extern void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt);
-
extern int f_area(DCELL * vals, Coords ** frags, int);
extern int f_perim(DCELL * vals, Coords ** frags, int);
extern int f_shapeindex(DCELL *, Coords **, int);
Modified: grass-addons/grass7/raster/r.pi/r.pi.index/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.index/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.index/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -68,7 +68,7 @@
f_func *compute_values;
/* neighbors count */
- int neighb_count;
+ int nbr_count;
char *p;
@@ -187,7 +187,7 @@
compute_values = menu[method].method;
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* allocate the cell buffers */
cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
@@ -220,18 +220,11 @@
G_percent(row, nrows, 2);
}
-
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
- writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
- fragments[fragcount] = actpos;
- }
- }
- }
G_percent(nrows, nrows, 2);
+ /* find fragments */
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+
/* perform actual function on the patches */
G_message("Performing operation...");
values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
Copied: grass-addons/grass7/raster/r.pi/r.pi.library/frag.c (from rev 70847, grass-addons/grass7/raster/r.pi/r.pi.corearea/frag.c)
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.library/frag.c (rev 0)
+++ grass-addons/grass7/raster/r.pi/r.pi.library/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -0,0 +1,160 @@
+#include "r_pi.h"
+
+int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
+ int nbr_cnt);
+
+int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
+ int nbr_cnt)
+{
+ int left, right, top, bottom;
+ int i, j;
+ int cnt = 0;
+
+ switch (nbr_cnt) {
+ case 4: /* von Neumann neighborhood */
+ if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
+ res[cnt].x = x - 1;
+ res[cnt].y = y;
+ cnt++;
+ }
+ if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
+ res[cnt].x = x;
+ res[cnt].y = y - 1;
+ cnt++;
+ }
+ if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
+ res[cnt].x = x + 1;
+ res[cnt].y = y;
+ cnt++;
+ }
+ if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
+ res[cnt].x = x;
+ res[cnt].y = y + 1;
+ cnt++;
+ }
+ break;
+ case 8: /* Moore neighborhood */
+ left = x > 0 ? x - 1 : 0;
+ top = y > 0 ? y - 1 : 0;
+ right = x < nx - 1 ? x + 1 : nx - 1;
+ bottom = y < ny - 1 ? y + 1 : ny - 1;
+ for (i = left; i <= right; i++) {
+ for (j = top; j <= bottom; j++) {
+ if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
+ res[cnt].x = i;
+ res[cnt].y = j;
+ cnt++;
+ }
+ }
+ }
+ break;
+ }
+
+ return cnt;
+}
+
+Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
+ int ncols, int nbr_cnt)
+{
+ int x, y, i;
+ Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
+ Position *first = list;
+ Position *last = list;
+ Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
+
+ /* count neighbors */
+ int neighbors = 0;
+
+ /* cells outside the current region are treated as background,
+ * as in fragstats:
+ * "The distinction among nodata, background, border, and boundary
+ * and how they affect the landscape analysis and the calculations
+ * of various metrics is a source of great confusion and thus
+ * great importance." */
+ if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
+ neighbors++;
+ if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
+ neighbors++;
+ if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
+ neighbors++;
+ if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
+ neighbors++;
+
+ /* write first cell */
+ actpos->x = col;
+ actpos->y = row;
+ actpos->neighbors = neighbors;
+ actpos++;
+ flagbuf[row * ncols + col] = -1;
+
+ /* push position on fifo-list */
+ last->x = col;
+ last->y = row;
+ last++;
+
+ while (first < last) {
+ /* get position from fifo-list */
+ int r = first->y;
+ int c = first->x;
+
+ /* add neighbors to fifo-list */
+ int cnt =
+ getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
+
+ first++;
+
+ for (i = 0; i < cnt; i++) {
+ x = nbr_list[i].x;
+ y = nbr_list[i].y;
+
+ /* add position to fifo-list */
+ last->x = x;
+ last->y = y;
+ last++;
+
+ /* count neighbors */
+ neighbors = 0;
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
+ neighbors++;
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
+ neighbors++;
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
+ neighbors++;
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
+ neighbors++;
+
+ /* set values */
+ actpos->x = x;
+ actpos->y = y;
+ actpos->neighbors = neighbors;
+ actpos++;
+ flagbuf[y * ncols + x] = -1;
+ }
+ }
+
+ G_free(list);
+ G_free(nbr_list);
+
+ return actpos;
+}
+
+int writeFragments(Coords **fragments, int *flagbuf, int nrows, int ncols, int nbr_cnt)
+{
+ int row, col;
+ int fragcount = 0;
+
+ /* find fragments */
+ for (row = 0; row < nrows; row++) {
+ for (col = 0; col < ncols; col++) {
+ if (flagbuf[row * ncols + col] == 1) {
+ fragcount++;
+
+ fragments[fragcount] =
+ writeFrag(flagbuf, fragments[fragcount - 1], row, col,
+ nrows, ncols, nbr_cnt);
+ }
+ }
+ }
+
+ return fragcount;
+}
Modified: grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.library/r_pi.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -22,6 +22,11 @@
typedef struct
{
int x, y;
+} Position;
+
+typedef struct
+{
+ int x, y;
int neighbors;
double value;
} Coords;
@@ -31,6 +36,11 @@
void draw_line(int *map, int val, int x1, int y1, int x2, int y2, int sx,
int sy, int width);
+/* frag.c */
+Coords *writeFrag(int *flagbuf, Coords *actpos, int row, int col, int nrows,
+ int ncols, int nbr_cnt);
+int writeFragments(Coords **fragments, int *flagbuf, int nrows, int ncols, int nbr_cnt);
+
/* helpers.c */
int Round(double d);
int Random(int max);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,139 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/stats.h>
-#include <math.h>
-#include "local_proto.h"
-
-typedef struct
-{
- int x, y;
-} Position;
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny, int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt = getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -15,9 +15,6 @@
typedef DCELL(f_func) (DCELL * values, int count);
-/* frag.c */
-void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols, int nbr_cnt);
-
/* func.c */
void compute_values(DCELL * vals, int fragcount, int min, int max, f_func stat_method);
Modified: grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.neigh/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -57,7 +57,7 @@
char *p;
/* neighbors count */
- int neighb_count;
+ int nbr_count;
int nrows, ncols;
int row, col, i;
@@ -206,7 +206,7 @@
stat_method = menu[method].method;
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* allocate the cell buffers */
cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
@@ -250,22 +250,8 @@
Rast_close(in_fd);
/* find fragments */
- fragcount = 0;
- for (row = 0; row < nrows; row++) {
- /* display progress */
- G_percent(row, nrows, 2);
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
- writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
- fragments[fragcount] = actpos;
- }
- }
- }
-
- G_percent(1, 1, 2);
-
/* open patch-values file */
in_fd = Rast_open_old(vals_name, vals_mapset);
if (in_fd < 0)
Deleted: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,11 +20,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
} Point;
typedef DCELL(f_statmethod) (DCELL *, int);
@@ -52,9 +47,6 @@
/* fractal.c */
void create_map(int *res, int size);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* global parameters */
GLOBAL int *buffer;
GLOBAL double *bigbuf;
Modified: grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.nlm.stats/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -70,7 +70,7 @@
int rand_seed;
int methods[GNAME_MAX];
int statmethods[GNAME_MAX];
- int neighb_count;
+ int nbr_count;
/* helper variables */
int i, j;
@@ -270,7 +270,7 @@
}
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* scan all method answers */
for (method_count = 0; parm.method->answers[method_count] != NULL;
@@ -389,7 +389,7 @@
}
/* apply methods to real landscape */
- fragcount = writeFragments(real_landscape, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, real_landscape, sy, sx, nbr_count);
/* allocate memory for result */
res = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
@@ -431,7 +431,7 @@
create_map(resmap, size);
- fragcount = writeFragments(resmap, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, resmap, sy, sx, nbr_count);
/* save fragcount */
fragcounts[i] = fragcount;
Deleted: grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,157 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
-
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,11 +20,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
} Point;
typedef struct
@@ -42,9 +37,6 @@
void print_array(DCELL * buffer, int size);
void print_fragments();
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* voronoi.c */
void voronoi(DCELL * values, int *map, int sx, int sy, int diag_move, int fragcount);
void calc_neighbors(DCELL * res, DCELL * focals, f_statmethod **methods,
Modified: grass-addons/grass7/raster/r.pi/r.pi.odc/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.odc/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.odc/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -85,7 +85,7 @@
DCELL *d_res;
DCELL *values;
DCELL *neighb_values;
- int neighb_count;
+ int nbr_count;
int i, n;
int x, y;
int sx, sy;
@@ -220,7 +220,7 @@
sscanf(parm.keyval->answer, "%d", &keyval);
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* get neighbor level */
if (parm.neighbor_level->answer) {
@@ -314,7 +314,7 @@
Rast_close(in_fd);
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, nbr_count);
G_message("Found %d patches", fragcount);
Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,6 +1,6 @@
#include "local_proto.h"
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
+Coords *writeFrag_dist(int *flagbuf, Coords * actpos, int row, int col, int nrows,
int ncols, double distance);
int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
double distance);
@@ -37,7 +37,7 @@
return cnt;
}
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
+Coords *writeFrag_dist(int *flagbuf, Coords * actpos, int row, int col, int nrows,
int ncols, double distance)
{
int x, y, i;
@@ -51,13 +51,13 @@
/* count neighbors */
int neighbors = 0;
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
+ if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
+ if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
+ if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
+ if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
neighbors++;
/* write first cell */
@@ -94,13 +94,13 @@
/* count neighbors */
neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
+ if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
+ if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
+ if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
+ if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
neighbors++;
/* set values */
@@ -119,7 +119,7 @@
return actpos;
}
-int writeFragments(int *flagbuf, int nrows, int ncols, double distance)
+int writeFragments_dist(int *flagbuf, int nrows, int ncols, double distance)
{
int row, col;
int fragcount = 0;
@@ -131,7 +131,7 @@
fragcount++;
fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
+ writeFrag_dist(flagbuf, fragments[fragcount - 1], row, col,
nrows, ncols, distance);
}
}
Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -17,11 +17,6 @@
#define GLOBAL extern
#endif
-typedef struct
-{
- int x, y;
-} Position;
-
typedef DCELL(f_statmethod) (DCELL *, int);
void print_buffer(int *buffer, int sx, int sy);
@@ -33,8 +28,8 @@
/* analysis.c */
void perform_analysis(DCELL * values, int *map, int *mask, int n, int size, int patch_only, int sx, int sy);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, double distance);
+/* frag.c*/
+int writeFragments_dist(int *flagbuf, int nrows, int ncols, double distance);
/* global variables */
GLOBAL Coords **fragments;
Modified: grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prob.mw/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -266,7 +266,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, distance);
+ fragcount = writeFragments_dist(map, sy, sx, distance);
/* test output */
/* G_message("fragcount = %d", fragcount);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,139 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <grass/gis.h>
-#include <grass/glocale.h>
-#include <grass/stats.h>
-#include <math.h>
-#include "local_proto.h"
-
-typedef struct
-{
- int x, y;
-} Position;
-
-int getNeighbors(int *flagbuf, Position * res, int x, int y, int nx, int ny, int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols,int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col > 0 && flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row > 0 && flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col < ncols - 1 && flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row < nrows - 1 && flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt = getNeighbors(flagbuf, nbr_list, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x > 0 && flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y > 0 && flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x < ncols - 1 && flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y < nrows - 1 && flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -17,9 +17,6 @@
#define GLOBAL extern
#endif
-/* frag.c */
-void writeFrag(int *flagbuf, int row, int col, int nrows, int ncols,int nbr_cnt);
-
/* func.c */
int f_proximity(DCELL *, Coords **, int, int, int);
int f_modified_prox(DCELL * vals, Coords ** frags, int count, int min,
Modified: grass-addons/grass7/raster/r.pi/r.pi.prox/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.prox/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.prox/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -68,7 +68,7 @@
char *p;
/* neighbors count */
- int neighb_count;
+ int nbr_count;
int row, col, i;
int nrows, ncols;
@@ -206,7 +206,7 @@
compute_values = menu[method].method;
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* allocate the cell buffers */
cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
@@ -245,21 +245,11 @@
flagbuf[row * ncols + col] = 1;
}
}
-
- for (row = 0; row < nrows; row++) {
- /* display progress */
- G_percent(row, nrows, 2);
-
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
- writeFrag(flagbuf, row, col, nrows, ncols, neighb_count);
- fragments[fragcount] = actpos;
- }
- }
- }
Rast_close(in_fd);
+ /* find fragments */
+ fragcount = writeFragments(fragments, flagbuf, nrows, ncols, nbr_count);
+
/* perform actual function on the patches */
values = (DCELL *) G_malloc(fragcount * sizeof(DCELL));
compute_values(values, fragments, fragcount, min, max);
Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -21,11 +21,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
double dir;
DCELL path;
int finished;
@@ -51,9 +46,6 @@
void print_array(DCELL * buffer, int size);
void print_fragments();
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* search.c */
void perform_search(DCELL * values, int *map, DCELL * costmap,
f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -66,7 +66,7 @@
CELL *result;
DCELL *d_res;
DCELL *values;
- int neighb_count;
+ int nbr_count;
int i, j;
Coords *p;
char *str;
@@ -325,7 +325,7 @@
}
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* get include_cost */
include_cost = flag.cost->answer;
@@ -464,7 +464,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, nbr_count);
/* test output */
/* print_fragments(); */
Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,156 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
-
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,11 +20,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
double dir;
DCELL path;
int finished;
@@ -50,9 +45,6 @@
void print_array(DCELL * buffer, int size);
void print_fragments();
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* search.c */
void perform_search(DCELL * values, int *map, DCELL * costmap,
f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.iter/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -70,7 +70,7 @@
DCELL *values;
DCELL *output_values;
DCELL *dummy;
- int neighb_count;
+ int nbr_count;
int i, j;
Coords *p;
char *str;
@@ -288,7 +288,7 @@
sscanf(parm.percent->answer, "%lf", &percent);
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* get include_cost */
include_cost = flag.cost->answer;
@@ -451,7 +451,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, nbr_count);
/* test output */
/* print_fragments(); */
Deleted: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/frag.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -1,155 +0,0 @@
-#include "local_proto.h"
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt);
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt);
-
-int getNeighbors(Position * res, int *flagbuf, int x, int y, int nx, int ny,
- int nbr_cnt)
-{
- int left, right, top, bottom;
- int i, j;
- int cnt = 0;
-
- switch (nbr_cnt) {
- case 4: /* von Neumann neighborhood */
- if (x > 0 && flagbuf[y * nx + x - 1] == 1) {
- res[cnt].x = x - 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y > 0 && flagbuf[(y - 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y - 1;
- cnt++;
- }
- if (x < nx - 1 && flagbuf[y * nx + x + 1] == 1) {
- res[cnt].x = x + 1;
- res[cnt].y = y;
- cnt++;
- }
- if (y < ny - 1 && flagbuf[(y + 1) * nx + x] == 1) {
- res[cnt].x = x;
- res[cnt].y = y + 1;
- cnt++;
- }
- break;
- case 8: /* Moore neighborhood */
- left = x > 0 ? x - 1 : 0;
- top = y > 0 ? y - 1 : 0;
- right = x < nx - 1 ? x + 1 : nx - 1;
- bottom = y < ny - 1 ? y + 1 : ny - 1;
- for (i = left; i <= right; i++) {
- for (j = top; j <= bottom; j++) {
- if (!(i == x && j == y) && flagbuf[j * nx + i] == 1) {
- res[cnt].x = i;
- res[cnt].y = j;
- cnt++;
- }
- }
- }
- break;
- }
-
- return cnt;
-}
-
-Coords *writeFrag(int *flagbuf, Coords * actpos, int row, int col, int nrows,
- int ncols, int nbr_cnt)
-{
- int x, y, i;
- Position *list = (Position *) G_malloc(nrows * ncols * sizeof(Position));
- Position *first = list;
- Position *last = list;
- Position *nbr_list = (Position *) G_malloc(8 * sizeof(Position));
-
- /* count neighbors */
- int neighbors = 0;
-
- if (col <= 0 || flagbuf[row * ncols + col - 1] != 0)
- neighbors++;
- if (row <= 0 || flagbuf[(row - 1) * ncols + col] != 0)
- neighbors++;
- if (col >= ncols - 1 || flagbuf[row * ncols + col + 1] != 0)
- neighbors++;
- if (row >= nrows - 1 || flagbuf[(row + 1) * ncols + col] != 0)
- neighbors++;
-
- /* write first cell */
- actpos->x = col;
- actpos->y = row;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[row * ncols + col] = -1;
-
- /* push position on fifo-list */
- last->x = col;
- last->y = row;
- last++;
-
- while (first < last) {
- /* get position from fifo-list */
- int r = first->y;
- int c = first->x;
-
- /* add neighbors to fifo-list */
- int cnt =
- getNeighbors(nbr_list, flagbuf, c, r, ncols, nrows, nbr_cnt);
-
- first++;
-
- for (i = 0; i < cnt; i++) {
- x = nbr_list[i].x;
- y = nbr_list[i].y;
-
- /* add position to fifo-list */
- last->x = x;
- last->y = y;
- last++;
-
- /* count neighbors */
- neighbors = 0;
- if (x <= 0 || flagbuf[y * ncols + x - 1] != 0)
- neighbors++;
- if (y <= 0 || flagbuf[(y - 1) * ncols + x] != 0)
- neighbors++;
- if (x >= ncols - 1 || flagbuf[y * ncols + x + 1] != 0)
- neighbors++;
- if (y >= nrows - 1 || flagbuf[(y + 1) * ncols + x] != 0)
- neighbors++;
-
- /* set values */
- actpos->x = x;
- actpos->y = y;
- actpos->neighbors = neighbors;
- actpos++;
- flagbuf[y * ncols + x] = -1;
- }
- }
-
- G_free(list);
- G_free(nbr_list);
- return actpos;
-}
-
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt)
-{
- int row, col;
- int fragcount = 0;
-
- /* find fragments */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (flagbuf[row * ncols + col] == 1) {
- fragcount++;
-
- fragments[fragcount] =
- writeFrag(flagbuf, fragments[fragcount - 1], row, col,
- nrows, ncols, nbr_cnt);
- }
- }
- }
-
- return fragcount;
-}
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/local_proto.h 2017-04-08 20:05:19 UTC (rev 70852)
@@ -20,11 +20,6 @@
typedef struct
{
int x, y;
-} Position;
-
-typedef struct
-{
- int x, y;
double dir;
DCELL path;
int finished;
@@ -44,9 +39,6 @@
typedef DCELL(f_statmethod) (DCELL *, int);
-/* frag.c */
-int writeFragments(int *flagbuf, int nrows, int ncols, int nbr_cnt);
-
/* search.c */
void perform_search(DCELL * values, int *map, DCELL * costmap, int size,
f_statmethod **stats, int stat_count, int n, int fragcount, int sx, int sy);
Modified: grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c 2017-04-07 16:41:10 UTC (rev 70851)
+++ grass-addons/grass7/raster/r.pi/r.pi.searchtime.mw/main.c 2017-04-08 20:05:19 UTC (rev 70852)
@@ -71,7 +71,7 @@
CELL *result;
DCELL *d_res;
DCELL *values;
- int neighb_count;
+ int nbr_count;
int i;
Coords *p;
char *str;
@@ -278,7 +278,7 @@
sscanf(parm.percent->answer, "%lf", &percent);
/* get number of cell-neighbors */
- neighb_count = flag.adjacent->answer ? 8 : 4;
+ nbr_count = flag.adjacent->answer ? 8 : 4;
/* get include_cost */
include_cost = flag.cost->answer;
@@ -412,7 +412,7 @@
print_d_buffer(costmap, sx, sy); */
/* find fragments */
- fragcount = writeFragments(map, sy, sx, neighb_count);
+ fragcount = writeFragments(fragments, map, sy, sx, nbr_count);
/* test output */
/* print_fragments(); */
More information about the grass-commit
mailing list