[GRASS-SVN] r35801 - grass/trunk/raster/r.surf.contour
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 8 03:08:41 EST 2009
Author: glynn
Date: 2009-02-08 03:08:41 -0500 (Sun, 08 Feb 2009)
New Revision: 35801
Added:
grass/trunk/raster/r.surf.contour/read_cell.c
Removed:
grass/trunk/raster/r.surf.contour/bseg_close.c
grass/trunk/raster/r.surf.contour/bseg_get.c
grass/trunk/raster/r.surf.contour/bseg_open.c
grass/trunk/raster/r.surf.contour/bseg_put.c
grass/trunk/raster/r.surf.contour/bseg_read.c
grass/trunk/raster/r.surf.contour/bseg_write.c
grass/trunk/raster/r.surf.contour/cseg.h
grass/trunk/raster/r.surf.contour/cseg_close.c
grass/trunk/raster/r.surf.contour/cseg_get.c
grass/trunk/raster/r.surf.contour/cseg_open.c
grass/trunk/raster/r.surf.contour/cseg_put.c
grass/trunk/raster/r.surf.contour/cseg_read.c
grass/trunk/raster/r.surf.contour/cseg_write.c
Modified:
grass/trunk/raster/r.surf.contour/add_in.c
grass/trunk/raster/r.surf.contour/addpts.c
grass/trunk/raster/r.surf.contour/contour.h
grass/trunk/raster/r.surf.contour/find_con.c
grass/trunk/raster/r.surf.contour/main.c
Log:
Eliminate segmentation; read input into RAM
Modified: grass/trunk/raster/r.surf.contour/add_in.c
===================================================================
--- grass/trunk/raster/r.surf.contour/add_in.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/add_in.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,32 +1,5 @@
#include "contour.h"
-NODE *add_in_slow(int r, int c, int rr, int cc, NODE * zero, int *node_ct)
-{
- int dor, doc;
-
- bseg_put(&bseen, &on, rr, cc);
- if (rr < minr)
- minr = rr;
- if (rr > maxr)
- maxr = rr;
- if (cc < minc)
- minc = cc;
- if (cc > maxc)
- maxc = cc;
- if (*node_ct == array_size) {
- zero = (NODE *) G_realloc(zero, (array_size + AR_INCR) *
- sizeof(NODE));
- array_size += AR_INCR;
- }
- dor = ABS(rr - r);
- doc = ABS(cc - c);
- zero[*node_ct].r = rr;
- zero[*node_ct].c = cc;
- zero[*node_ct].d = MIN(dor, doc) * 1.414 + ABS(dor - doc);
- *node_ct = *node_ct + 1;
- return (zero);
-}
-
NODE *add_in(int r, int c, int rr, int cc, NODE * zero, int *node_ct)
{
int dor, doc;
Modified: grass/trunk/raster/r.surf.contour/addpts.c
===================================================================
--- grass/trunk/raster/r.surf.contour/addpts.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/addpts.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,33 +1,5 @@
#include "contour.h"
-NODE *addpts_slow(NODE * zero, int r, int c, int rr, int cc, int *node_ct)
-{
- NODE *add_in_slow();
- CELL value;
-
- if (rr < nrows - 1) {
- bseg_get(&bseen, &value, rr + 1, cc);
- if (!value)
- zero = add_in_slow(r, c, rr + 1, cc, zero, node_ct);
- }
- if (cc < ncols - 1) {
- bseg_get(&bseen, &value, rr, cc + 1);
- if (!value)
- zero = add_in_slow(r, c, rr, cc + 1, zero, node_ct);
- }
- if (rr > 0) {
- bseg_get(&bseen, &value, rr - 1, cc);
- if (!value)
- zero = add_in_slow(r, c, rr - 1, cc, zero, node_ct);
- }
- if (cc > 0) {
- bseg_get(&bseen, &value, rr, cc - 1);
- if (!value)
- zero = add_in_slow(r, c, rr, cc - 1, zero, node_ct);
- }
- return (zero);
-}
-
NODE *addpts(NODE * zero, int r, int c, int rr, int cc, int *node_ct)
{
NODE *add_in();
Deleted: grass/trunk/raster/r.surf.contour/bseg_close.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_close.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_close.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,19 +0,0 @@
-#include <unistd.h>
-#include <grass/gis.h>
-#include "cseg.h"
-
-int bseg_close(BSEG * bseg)
-{
- segment_release(&(bseg->seg));
- close(bseg->fd);
- unlink(bseg->filename);
- if (bseg->name) {
- G_free(bseg->name);
- bseg->name = NULL;
- }
- if (bseg->mapset) {
- G_free(bseg->mapset);
- bseg->mapset = NULL;
- }
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/bseg_get.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_get.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_get.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,18 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int bseg_get(BSEG * bseg, CELL * value, int row, int col)
-{
- unsigned char x;
- char errmsg[200];
-
- if (segment_get(&(bseg->seg), (int *)&x, row, col >> 3) < 0) {
- sprintf(errmsg,
- "bseg_get(): could not read segment file at r:%d c:%d",
- (int)row, (int)col);
- G_warning(errmsg);
- return -1;
- }
- *value = (CELL) ((x & (1 << (col & 7))) ? 1 : 0);
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/bseg_open.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_open.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_open.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,60 +0,0 @@
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <grass/gis.h>
-#include "cseg.h"
-
-int bseg_open(BSEG * bseg, int srows, int scols, int nsegs_in_memory)
-{
- char *filename;
- int errflag;
- int fd;
-
- bseg->filename = NULL;
- bseg->fd = -1;
- bseg->name = NULL;
- bseg->mapset = NULL;
-
- filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("bseg_open(): unable to create segment file");
- return -2;
- }
- if (0 >
- (errflag =
- segment_format(fd, G_window_rows(), (G_window_cols() + 7) / 8, srows,
- scols, sizeof(char)))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("bseg_open(): could not write segment file");
- return -1;
- }
- else {
- G_warning("bseg_open(): illegal configuration parameter(s)");
- return -3;
- }
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("bseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = segment_init(&(bseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("bseg_open(): could not read segment file");
- return -5;
- }
- else {
- G_warning("bseg_open(): out of memory");
- return -6;
- }
- }
- bseg->filename = filename;
- bseg->fd = fd;
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/bseg_put.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_put.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_put.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,28 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int bseg_put(BSEG * bseg, CELL * value, int row, int col)
-{
- unsigned char old_value;
- char errmsg[200];
-
- if (segment_get(&(bseg->seg), (int *)&old_value, row, col >> 3) < 0) {
- sprintf(errmsg,
- "bseg_put(): could not read segment file at r:%d c:%d",
- (int)row, (int)col);
- G_warning(errmsg);
- return -1;
- }
- if (*value)
- old_value |= (1 << (col & 7));
- else
- old_value &= ~(1 << (col & 7));
- if (segment_put(&(bseg->seg), (int *)&old_value, row, col >> 3) < 0) {
- sprintf(errmsg,
- "bseg_put(): could not write segment file at r:%d c:%d",
- (int)row, (int)col);
- G_warning(errmsg);
- return -2;
- }
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/bseg_read.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_read.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_read.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,49 +0,0 @@
-#include <unistd.h>
-#include <grass/gis.h>
-#include "cseg.h"
-
-static char *me = "bseg_read_cell";
-
-int bseg_read_cell(BSEG * bseg, const char *map_name, const char *mapset)
-{
- int row, nrows;
- int col, ncols;
- int map_fd;
- char msg[100];
- CELL *buffer;
-
- bseg->name = NULL;
- bseg->mapset = NULL;
-
- map_fd = G_open_cell_old(map_name, mapset);
- if (map_fd < 0) {
- sprintf(msg, "%s(): unable to open file [%s] in [%s], %d",
- me, map_name, mapset, map_fd);
- G_warning(msg);
- return -3;
- }
- nrows = G_window_rows();
- ncols = G_window_cols();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- if (G_get_map_row(map_fd, buffer, row) < 0) {
- G_free(buffer);
- G_close_cell(map_fd);
- sprintf(msg, "%s(): unable to read file [%s] in [%s], %d %d",
- me, map_name, mapset, row, nrows);
- G_warning(msg);
- return -2;
- }
- for (col = ncols; col >= 0; col--) {
- bseg_put(bseg, &(buffer[col]), row, col);
- }
- }
-
- G_close_cell(map_fd);
- G_free(buffer);
-
- bseg->name = G_store(map_name);
- bseg->mapset = G_store(mapset);
-
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/bseg_write.c
===================================================================
--- grass/trunk/raster/r.surf.contour/bseg_write.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/bseg_write.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,38 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-static char *me = "bseg_write_cell";
-
-int bseg_write_cellfile(BSEG * bseg, const char *map_name)
-{
- int map_fd;
- int row, nrows;
- int col, ncols;
- CELL *buffer;
- CELL value;
-
- map_fd = G_open_cell_new(map_name);
- if (map_fd < 0) {
- G_warning("%s(): unable to open new map layer [%s]", me, map_name);
- return -1;
- }
- nrows = G_window_rows();
- ncols = G_window_cols();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- bseg_get(bseg, &value, row, col);
- buffer[col] = value;
- }
- if (G_put_raster_row(map_fd, buffer, CELL_TYPE) < 0) {
- G_free(buffer);
- G_unopen_cell(map_fd);
- G_warning("%s(): unable to write new map layer [%s], row %d",
- me, map_name, row);
- return -2;
- }
- }
- G_free(buffer);
- G_close_cell(map_fd);
- return 0;
-}
Modified: grass/trunk/raster/r.surf.contour/contour.h
===================================================================
--- grass/trunk/raster/r.surf.contour/contour.h 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/contour.h 2009-02-08 08:08:41 UTC (rev 35801)
@@ -2,7 +2,6 @@
#include <math.h>
#include <grass/gis.h>
#include "flag.h"
-#include "cseg.h"
#define NODE struct _n_o_d_e_
#define INIT_AR 64
@@ -25,20 +24,20 @@
extern int maxr;
extern int array_size;
extern double i_val_l_f;
-extern CSEG con;
+extern CELL **con;
extern FLAG *seen, *mask;
-extern BSEG bseen, bmask;
extern NODE *zero;
extern CELL on, off;
/* add_in.c */
-NODE *add_in_slow(int, int, int, int, NODE *, int *);
NODE *add_in(int, int, int, int, NODE *, int *);
/* addpts.c */
-NODE *addpts_slow(NODE *, int, int, int, int, int *);
NODE *addpts(NODE *, int, int, int, int, int *);
/* find_con.c */
-int find_con_slow(int, int, double *, double *, CELL *, CELL *);
int find_con(int, int, double *, double *, CELL *, CELL *);
+
+/* read_cell.c */
+CELL **read_cell(const char *, const char *);
+void free_cell(CELL **);
Deleted: grass/trunk/raster/r.surf.contour/cseg.h
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg.h 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg.h 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,64 +0,0 @@
-#include <grass/segment.h>
-
-#define CSEG struct _c_s_e_g_
-CSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-#define DSEG struct _d_s_e_g_
-DSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-#define BSEG struct _b_s_e_g_
-BSEG {
- SEGMENT seg; /* segment structure */
- int fd; /* fd for reading/writing segment file */
- char *filename; /* name of segment file */
- char *name; /* raster map read into segment file */
- char *mapset;
-};
-
-/* bseg_close.c */
-int bseg_close(BSEG *);
-
-/* bseg_get.c */
-int bseg_get(BSEG *, CELL *, int, int);
-
-/* bseg_open.c */
-int bseg_open(BSEG *, int, int, int);
-
-/* bseg_put.c */
-int bseg_put(BSEG *, CELL *, int, int);
-
-/* bseg_read.c */
-int bseg_read_cell(BSEG *, const char *, const char *);
-
-/* bseg_write.c */
-int bseg_write_cellfile(BSEG *, const char *);
-
-/* cseg_close.c */
-int cseg_close(CSEG *);
-
-/* cseg_get.c */
-int cseg_get(CSEG *, int, int, CELL *);
-
-/* cseg_open.c */
-int cseg_open(CSEG *, int, int, int);
-
-/* cseg_put.c */
-int cseg_put(CSEG *, int, int, CELL);
-
-/* cseg_read.c */
-int cseg_read_cell(CSEG *, const char *, const char *);
-
-/* cseg_write.c */
-int cseg_write_cellfile(CSEG *, const char *);
Deleted: grass/trunk/raster/r.surf.contour/cseg_close.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_close.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_close.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,19 +0,0 @@
-#include <grass/gis.h>
-#include <unistd.h>
-#include "cseg.h"
-
-int cseg_close(CSEG * cseg)
-{
- segment_release(&(cseg->seg));
- close(cseg->fd);
- unlink(cseg->filename);
- if (cseg->name) {
- G_free(cseg->name);
- cseg->name = NULL;
- }
- if (cseg->mapset) {
- G_free(cseg->mapset);
- cseg->mapset = NULL;
- }
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/cseg_get.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_get.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_get.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,11 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_get(CSEG * cseg, int row, int col, CELL * value)
-{
- if (segment_get(&(cseg->seg), value, row, col) < 0) {
- G_warning("cseg_get(): could not read segment file");
- return -1;
- }
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/cseg_open.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_open.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_open.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,60 +0,0 @@
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_open(CSEG * cseg, int srows, int scols, int nsegs_in_memory)
-{
- char *filename;
- int errflag;
- int fd;
-
- cseg->filename = NULL;
- cseg->fd = -1;
- cseg->name = NULL;
- cseg->mapset = NULL;
-
- filename = G_tempfile();
- if (-1 == (fd = creat(filename, 0666))) {
- G_warning("cseg_open(): unable to create segment file");
- return -2;
- }
- if (0 >
- (errflag =
- segment_format(fd, G_window_rows(), G_window_cols(), srows, scols,
- sizeof(CELL)))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("cseg_open(): could not write segment file");
- return -1;
- }
- else {
- G_warning("cseg_open(): illegal configuration parameter(s)");
- return -3;
- }
- }
- close(fd);
- if (-1 == (fd = open(filename, 2))) {
- unlink(filename);
- G_warning("cseg_open(): unable to re-open segment file");
- return -4;
- }
- if (0 > (errflag = segment_init(&(cseg->seg), fd, nsegs_in_memory))) {
- close(fd);
- unlink(filename);
- if (errflag == -1) {
- G_warning("cseg_open(): could not read segment file");
- return -5;
- }
- else {
- G_warning("cseg_open(): out of memory");
- return -6;
- }
- }
- cseg->filename = filename;
- cseg->fd = fd;
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/cseg_put.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_put.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_put.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,11 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-int cseg_put(CSEG * cseg, int row, int col, CELL value)
-{
- if (segment_put(&(cseg->seg), &value, row, col) < 0) {
- G_warning("cseg_put(): could not write segment file");
- return -1;
- }
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/cseg_read.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_read.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_read.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,51 +0,0 @@
-#include <grass/gis.h>
-#include <unistd.h>
-#include "cseg.h"
-
-static char *me = "cseg_read_cell";
-
-int cseg_read_cell(CSEG * cseg, const char *map_name, const char *mapset)
-{
- int row, nrows;
- int map_fd;
- char msg[100];
- CELL *buffer;
-
- cseg->name = NULL;
- cseg->mapset = NULL;
-
- if ((map_fd = G_open_cell_old(map_name, mapset)) < 0) {
- sprintf(msg, "%s(): unable to open file [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return -3;
- }
- nrows = G_window_rows();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- if (G_get_map_row(map_fd, buffer, row) < 0) {
- G_free(buffer);
- G_close_cell(map_fd);
- sprintf(msg, "%s(): unable to read file [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return -2;
- }
- if (segment_put_row(&(cseg->seg), buffer, row) < 0) {
- G_free(buffer);
- G_close_cell(map_fd);
- sprintf(msg, "%s(): unable to segment put row for [%s] in [%s]",
- me, map_name, mapset);
- G_warning(msg);
- return (-1);
- }
- }
-
- G_close_cell(map_fd);
- G_free(buffer);
-
- cseg->name = G_store(map_name);
- cseg->mapset = G_store(mapset);
-
- return 0;
-}
Deleted: grass/trunk/raster/r.surf.contour/cseg_write.c
===================================================================
--- grass/trunk/raster/r.surf.contour/cseg_write.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/cseg_write.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,36 +0,0 @@
-#include <grass/gis.h>
-#include "cseg.h"
-
-static char *me = "cseg_write_cell";
-
-int cseg_write_cellfile(CSEG * cseg, const char *map_name)
-{
- int map_fd;
- int row, nrows;
- char msg[100];
- CELL *buffer;
-
- map_fd = G_open_cell_new(map_name);
- if (map_fd < 0) {
- sprintf(msg, "%s(): unable to open new map layer [%s]", me, map_name);
- G_warning(msg);
- return -1;
- }
- nrows = G_window_rows();
- buffer = G_allocate_cell_buf();
- for (row = 0; row < nrows; row++) {
- segment_get_row(&(cseg->seg), buffer, row);
- if (G_put_raster_row(map_fd, buffer, CELL_TYPE) < 0) {
- G_free(buffer);
- G_unopen_cell(map_fd);
- sprintf(msg,
- "%s(): unable to write new map layer [%s], row %d",
- me, map_name, row);
- G_warning(msg);
- return -2;
- }
- }
- G_free(buffer);
- G_close_cell(map_fd);
- return 0;
-}
Modified: grass/trunk/raster/r.surf.contour/find_con.c
===================================================================
--- grass/trunk/raster/r.surf.contour/find_con.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/find_con.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -1,79 +1,6 @@
#include <math.h>
#include "contour.h"
-int find_con_slow(int r, int c, double *d1, double *d2, CELL * con1,
- CELL * con2)
-{
- int ct, low_ct, node_ct;
- int rr, cc, dor, doc;
- double dd, shortest;
- CELL value;
-
- *con1 = 0;
- *con2 = 0;
- *d1 = *d2 = 1.0;
- shortest = nrows * ncols;
- for (rr = minr; rr <= maxr; rr++) {
- for (cc = minc; cc <= maxc; cc++) {
- /* FLAG_UNSET (seen, rr, cc); */
- bseg_put(&bseen, &off, rr, cc);
- }
- }
- minr = nrows;
- minc = ncols;
- maxr = maxc = -1;
- /* set_seen_slow (r,c); */
- bseg_put(&bseen, &on, r, c);
- if (r < minr)
- minr = r;
- if (r > maxr)
- maxr = r;
- if (c < minc)
- minc = c;
- if (c > maxc)
- maxc = c;
- node_ct = 0;
- zero = addpts_slow(zero, r, c, r, c, &node_ct);
- low_ct = 0;
- while (1) {
- ct = low_ct++;
- if (node_ct <= ct)
- return 1;
- rr = zero[ct].r;
- cc = zero[ct].c;
- dor = ABS(rr - r);
- doc = ABS(cc - c);
- bseg_get(&bmask, &value, rr, cc);
- if (!value && rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
- && zero[ct].d < shortest) {
- cseg_get(&con, rr, cc, &value);
- if (value == 0)
- zero = addpts_slow(zero, r, c, rr, cc, &node_ct);
- else if (*con1 == 0) {
- *con1 = value;
- *d1 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
- shortest = *d1 * 2.0 * i_val_l_f;
- }
- else if (*con1 == value) {
- dd = MIN(dor, doc) * 1.414 + ABS(dor - doc);
- if (dd < *d1) {
- *d1 = dd;
- shortest = dd * 2.0 * i_val_l_f;
- }
- }
- else if (*con2 == 0) {
- *con2 = value;
- *d2 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
- shortest = *d2;
- }
- else {
- dd = MIN(dor, doc) * 1.414 + ABS(dor - doc);
- shortest = MIN(shortest, dd);
- }
- }
- }
-}
-
int find_con(int r, int c, double *d1, double *d2, CELL * con1, CELL * con2)
{
int ct, low_ct, node_ct;
@@ -114,7 +41,7 @@
doc = ABS(cc - c);
if (rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
&& zero[ct].d < shortest && !flag_get(mask, rr, cc)) {
- cseg_get(&con, rr, cc, &value);
+ value = con[rr][cc];
if (value == 0)
zero = addpts(zero, r, c, rr, cc, &node_ct);
else if (*con1 == 0) {
Modified: grass/trunk/raster/r.surf.contour/main.c
===================================================================
--- grass/trunk/raster/r.surf.contour/main.c 2009-02-07 22:42:05 UTC (rev 35800)
+++ grass/trunk/raster/r.surf.contour/main.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -35,9 +35,8 @@
int maxr;
int array_size;
double i_val_l_f;
-CSEG con;
+CELL **con;
FLAG *seen, *mask;
-BSEG bseen, bmask;
NODE *zero;
CELL on, off;
@@ -49,11 +48,10 @@
CELL *alt_row;
const char *con_name, *alt_name, *con_mapset;
int file_fd;
- int fast_mode;
CELL value;
struct History history;
struct GModule *module;
- struct Flag *flag1, *flag_slow;
+ struct Flag *flag1;
struct Option *opt1, *opt2;
G_gisinit(argv[0]);
@@ -82,11 +80,6 @@
flag1->description = _("Unused; retained for compatibility purposes, "
"will be removed in future");
- flag_slow = G_define_flag();
- flag_slow->key = 's';
- flag_slow->description = _("Invoke slow, but memory frugal operation "
- "(generally not needed, will be removed in future)");
-
on = 1;
off = 0;
@@ -96,12 +89,6 @@
con_name = opt1->answer;
alt_name = opt2->answer;
- if (flag_slow->answer)
- fast_mode = 0;
- else
- fast_mode = 1;
-
-
con_mapset = G_find_cell2(con_name, "");
if (!con_mapset)
G_fatal_error("Contour raster map [%s] not found", con_name);
@@ -109,36 +96,19 @@
nrows = G_window_rows();
ncols = G_window_cols();
i_val_l_f = nrows + ncols;
- cseg_open(&con, 256, 256, 64);
- cseg_read_cell(&con, con_name, con_mapset);
+ con = read_cell(con_name, con_mapset);
alt_row = (CELL *) G_malloc(ncols * sizeof(CELL));
- if (fast_mode) {
- seen = flag_create(nrows, ncols);
- mask = flag_create(nrows, ncols);
- }
- else {
- bseg_open(&bseen, 64, 64, 16);
- bseg_open(&bmask, 64, 64, 16);
- }
+ seen = flag_create(nrows, ncols);
+ mask = flag_create(nrows, ncols);
if (NULL != G_find_file("cell", "MASK", G_mapset())) {
if ((file_fd = G_open_cell_old("MASK", G_mapset())) < 0)
G_fatal_error("Unable to open MASK");
- if (fast_mode) {
- for (r = 0; r < nrows; r++) {
- G_get_map_row_nomask(file_fd, alt_row, r);
- for (c = 0; c < ncols; c++)
- if (!alt_row[c])
- FLAG_SET(mask, r, c);
- }
+ for (r = 0; r < nrows; r++) {
+ G_get_map_row_nomask(file_fd, alt_row, r);
+ for (c = 0; c < ncols; c++)
+ if (!alt_row[c])
+ FLAG_SET(mask, r, c);
}
- else {
- for (r = 0; r < nrows; r++) {
- G_get_map_row_nomask(file_fd, alt_row, r);
- for (c = 0; c < ncols; c++)
- if (!alt_row[c])
- bseg_put(&bmask, &off, r, c);
- }
- }
G_close_cell(file_fd);
}
zero = (NODE *) G_malloc(INIT_AR * sizeof(NODE));
@@ -152,24 +122,14 @@
for (r = 0; r < nrows; r++) {
G_percent(r, nrows, 1);
for (c = 0; c < ncols; c++) {
- if (fast_mode) {
- if (FLAG_GET(mask, r, c))
- continue;
- }
- else {
- bseg_get(&bmask, &value, r, c);
- if (value)
- continue;
- }
- cseg_get(&con, r, c, &value);
+ if (FLAG_GET(mask, r, c))
+ continue;
+ value = con[r][c];
if (value != 0) {
alt_row[c] = value;
continue;
}
- if (fast_mode)
- find_con(r, c, &d1, &d2, &con1, &con2);
- else
- find_con_slow(r, c, &d1, &d2, &con1, &con2);
+ find_con(r, c, &d1, &d2, &con1, &con2);
if (con2 > 0)
alt_row[c] = (CELL) (d2 * con1 / (d1 + d2) +
d1 * con2 / (d1 + d2) + 0.5);
@@ -179,15 +139,9 @@
G_put_raster_row(file_fd, alt_row, CELL_TYPE);
}
G_percent(r, nrows, 1);
- cseg_close(&con);
- if (fast_mode) {
- flag_destroy(seen);
- flag_destroy(mask);
- }
- else {
- bseg_close(&bseen);
- bseg_close(&bmask);
- }
+ free_cell(con);
+ flag_destroy(seen);
+ flag_destroy(mask);
G_close_cell(file_fd);
G_short_history(alt_name, "raster", &history);
Added: grass/trunk/raster/r.surf.contour/read_cell.c
===================================================================
--- grass/trunk/raster/r.surf.contour/read_cell.c (rev 0)
+++ grass/trunk/raster/r.surf.contour/read_cell.c 2009-02-08 08:08:41 UTC (rev 35801)
@@ -0,0 +1,38 @@
+#include "contour.h"
+#include <grass/glocale.h>
+
+CELL **read_cell(const char *name, const char *mapset)
+{
+ int nrows = G_window_rows();
+ int ncols = G_window_cols();
+ CELL *buf, **idx;
+ int fd;
+ int row;
+
+ fd = G_open_cell_old(name, mapset);
+ if (fd < 0)
+ G_fatal_error(_("unable to open map <%s> in <%s>"),
+ name, mapset);
+
+ buf = G_malloc((size_t) nrows * ncols * sizeof(CELL));
+ idx = G_malloc(nrows * sizeof(CELL *));
+
+ for (row = 0; row < nrows; row++) {
+ idx[row] = &buf[row * ncols];
+
+ if (G_get_map_row(fd, idx[row], row) < 0)
+ G_fatal_error(_("unable to read map <%s> in <%s>"),
+ name, mapset);
+ }
+
+ G_close_cell(fd);
+
+ return idx;
+}
+
+void free_cell(CELL **idx)
+{
+ G_free(idx[0]);
+ G_free(idx);
+}
+
More information about the grass-commit
mailing list