[GRASS-SVN] r40772 - in grass/trunk: include lib/raster
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 1 17:49:27 EST 2010
Author: glynn
Date: 2010-02-01 17:49:26 -0500 (Mon, 01 Feb 2010)
New Revision: 40772
Modified:
grass/trunk/include/rasterdefs.h
grass/trunk/lib/raster/R.h
grass/trunk/lib/raster/gdal.c
grass/trunk/lib/raster/get_row.c
grass/trunk/lib/raster/opencell.c
grass/trunk/lib/raster/put_row.c
grass/trunk/lib/raster/set_window.c
grass/trunk/lib/raster/window.c
grass/trunk/lib/raster/window_map.c
Log:
Have lib/raster maintain its own windows
Use separate windows for input and output
Modified: grass/trunk/include/rasterdefs.h
===================================================================
--- grass/trunk/include/rasterdefs.h 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/include/rasterdefs.h 2010-02-01 22:49:26 UTC (rev 40772)
@@ -518,7 +518,10 @@
DCELL Rast_get_sample(int, const struct Cell_head *, struct Categories *, double, double, int, INTERP_TYPE);
/* set_window.c */
+void Rast__init_window(void);
void Rast_set_window(struct Cell_head *);
+void Rast_set_output_window(struct Cell_head *);
+void Rast_set_input_window(struct Cell_head *);
/* window.c */
double Rast_northing_to_row(double, const struct Cell_head *);
@@ -527,6 +530,10 @@
double Rast_col_to_easting(double, const struct Cell_head *);
int Rast_window_rows(void);
int Rast_window_cols(void);
+int Rast_input_window_rows(void);
+int Rast_input_window_cols(void);
+int Rast_output_window_rows(void);
+int Rast_output_window_cols(void);
/* window_map.c */
void Rast__create_window_mapping(int);
Modified: grass/trunk/lib/raster/R.h
===================================================================
--- grass/trunk/lib/raster/R.h 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/R.h 2010-02-01 22:49:26 UTC (rev 40772)
@@ -78,6 +78,10 @@
int want_histogram;
int nbytes;
int compression_type;
+ int window_set; /* Flag: window set? */
+ int split_window; /* Separate windows for input and output */
+ struct Cell_head rd_window; /* Window used for input */
+ struct Cell_head wr_window; /* Window used for ouput */
int fileinfo_count;
struct fileinfo *fileinfo;
Modified: grass/trunk/lib/raster/gdal.c
===================================================================
--- grass/trunk/lib/raster/gdal.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/gdal.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -8,7 +8,6 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include "../gis/G.h"
#include "R.h"
#ifndef HAVE_GDAL
@@ -375,7 +374,7 @@
struct Key_Value *key_val;
char buf[32];
- Rast__init();
+ Rast__init_window();
Rast_init_gdal();
@@ -438,8 +437,9 @@
/* Does driver support GDALCreate ? */
if ((*pGDALGetMetadataItem) (driver, GDAL_DCAP_CREATE, NULL)) {
gdal->data =
- (*pGDALCreate) (driver, gdal->filename, G__.window.cols,
- G__.window.rows, 1, gdal->type, st->opts.options);
+ (*pGDALCreate)(driver, gdal->filename,
+ R__.wr_window.cols, R__.wr_window.rows,
+ 1, gdal->type, st->opts.options);
if (!gdal->data)
G_fatal_error(_("Unable to create <%s> dataset using <%s> driver"),
name, st->opts.format);
@@ -458,8 +458,9 @@
G_fatal_error(_("Unable to get in-memory raster driver"));
gdal->data =
- (*pGDALCreate) (mem_driver, "", G__.window.cols, G__.window.rows,
- 1, gdal->type, st->opts.options);
+ (*pGDALCreate)(mem_driver, "",
+ R__.wr_window.cols, R__.wr_window.rows,
+ 1, gdal->type, st->opts.options);
if (!gdal->data)
G_fatal_error(_("Unable to create <%s> dataset using memory driver"),
name);
@@ -473,12 +474,12 @@
(*pGDALSetRasterNoDataValue) (gdal->band, gdal->null_val);
/* Set Geo Transform */
- transform[0] = G__.window.west;
- transform[1] = G__.window.ew_res;
+ transform[0] = R__.wr_window.west;
+ transform[1] = R__.wr_window.ew_res;
transform[2] = 0.0;
- transform[3] = G__.window.north;
+ transform[3] = R__.wr_window.north;
transform[4] = 0.0;
- transform[5] = -G__.window.ns_res;
+ transform[5] = -R__.wr_window.ns_res;
if ((*pGDALSetGeoTransform) (gdal->data, transform) >= CE_Failure)
G_warning(_("Unable to set geo transform"));
Modified: grass/trunk/lib/raster/get_row.c
===================================================================
--- grass/trunk/lib/raster/get_row.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/get_row.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -22,7 +22,6 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include "../gis/G.h"
#include "R.h"
static void embed_nulls(int, void *, int, RASTER_MAP_TYPE, int, int);
@@ -34,7 +33,7 @@
int r;
/* check for row in window */
- if (row < 0 || row >= G__.window.rows) {
+ if (row < 0 || row >= R__.rd_window.rows) {
G_fatal_error(_("Reading raster map <%s@%s> request for row %d is outside region"),
fcb->name, fcb->mapset, row);
}
@@ -62,7 +61,7 @@
CELL max = fcb->reclass.max;
int i;
- for (i = 0; i < G__.window.cols; i++) {
+ for (i = 0; i < R__.rd_window.cols; i++) {
if (Rast_is_c_null_value(&c[i])) {
if (null_is_zero)
c[i] = 0;
@@ -478,23 +477,23 @@
if (fcb->gdal)
(gdal_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
fcb->cur_nbytes, cell,
- G__.window.cols);
+ R__.rd_window.cols);
else
#endif
(cell_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
fcb->cur_nbytes, cell,
- G__.window.cols);
+ R__.rd_window.cols);
}
static void transfer_to_cell_fi(int fd, void *cell)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
- FCELL *work_buf = G__alloca(G__.window.cols * sizeof(FCELL));
+ FCELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(FCELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((CELL *) cell)[i] = (fcb->col_map[i] == 0)
? 0 : Rast_quant_get_cell_value(&fcb->quant, work_buf[i]);
@@ -504,12 +503,12 @@
static void transfer_to_cell_di(int fd, void *cell)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
- DCELL *work_buf = G__alloca(G__.window.cols * sizeof(DCELL));
+ DCELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(DCELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((CELL *) cell)[i] = (fcb->col_map[i] == 0)
? 0 : Rast_quant_get_cell_value(&fcb->quant, work_buf[i]);
@@ -518,12 +517,12 @@
static void transfer_to_cell_if(int fd, void *cell)
{
- CELL *work_buf = G__alloca(G__.window.cols * sizeof(CELL));
+ CELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(CELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((FCELL *) cell)[i] = work_buf[i];
G__freea(work_buf);
@@ -531,12 +530,12 @@
static void transfer_to_cell_df(int fd, void *cell)
{
- DCELL *work_buf = G__alloca(G__.window.cols * sizeof(DCELL));
+ DCELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(DCELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((FCELL *) cell)[i] = work_buf[i];
G__freea(work_buf);
@@ -544,12 +543,12 @@
static void transfer_to_cell_id(int fd, void *cell)
{
- CELL *work_buf = G__alloca(G__.window.cols * sizeof(CELL));
+ CELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(CELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((DCELL *) cell)[i] = work_buf[i];
G__freea(work_buf);
@@ -557,12 +556,12 @@
static void transfer_to_cell_fd(int fd, void *cell)
{
- FCELL *work_buf = G__alloca(G__.window.cols * sizeof(FCELL));
+ FCELL *work_buf = G__alloca(R__.rd_window.cols * sizeof(FCELL));
int i;
transfer_to_cell_XX(fd, work_buf);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
((DCELL *) cell)[i] = work_buf[i];
G__freea(work_buf);
@@ -623,7 +622,7 @@
int i;
if (fcb->reclass_flag && data_type != CELL_TYPE) {
- temp_buf = G__alloca(G__.window.cols * sizeof(CELL));
+ temp_buf = G__alloca(R__.rd_window.cols * sizeof(CELL));
buf = temp_buf;
type = CELL_TYPE;
}
@@ -645,7 +644,7 @@
if (data_type == CELL_TYPE)
return;
- for (i = 0; i < G__.window.cols; i++) {
+ for (i = 0; i < R__.rd_window.cols; i++) {
Rast_set_c_value(rast, temp_buf[i], data_type);
rast = G_incr_void_ptr(rast, size);
}
@@ -879,10 +878,10 @@
struct fileinfo *fcb = &R__.fileinfo[fd];
int j;
- if (row > G__.window.rows || row < 0) {
+ if (row > R__.rd_window.rows || row < 0) {
G_warning(_("Reading raster map <%s@%s> request for row %d is outside region"),
fcb->name, fcb->mapset, row);
- for (j = 0; j < G__.window.cols; j++)
+ for (j = 0; j < R__.rd_window.cols; j++)
flags[j] = 1;
return;
}
@@ -892,17 +891,17 @@
fcb->null_cur_row = -1;
if (fcb->map_type == CELL_TYPE) {
/* If can't read null row, assume that all map 0's are nulls */
- CELL *mask_buf = G__alloca(G__.window.cols * sizeof(CELL));
+ CELL *mask_buf = G__alloca(R__.rd_window.cols * sizeof(CELL));
get_map_row_nomask(fd, mask_buf, row, CELL_TYPE);
- for (j = 0; j < G__.window.cols; j++)
+ for (j = 0; j < R__.rd_window.cols; j++)
flags[j] = (mask_buf[j] == 0);
G__freea(mask_buf);
}
else { /* fp map */
/* if can't read null row, assume that all data is valid */
- G_zero(flags, sizeof(char) * G__.window.cols);
+ G_zero(flags, sizeof(char) * R__.rd_window.cols);
/* the flags row is ready now */
}
@@ -913,7 +912,7 @@
}
/* copy null row to flags row translated by window column mapping */
- for (j = 0; j < G__.window.cols; j++) {
+ for (j = 0; j < R__.rd_window.cols; j++) {
if (!fcb->col_map[j])
flags[j] = 1;
else
@@ -932,12 +931,12 @@
int i;
if (get_map_row_nomask(fd, tmp_buf, row, DCELL_TYPE) <= 0) {
- memset(flags, 1, G__.window.cols);
+ memset(flags, 1, R__.rd_window.cols);
G_free(tmp_buf);
return;
}
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
/* note: using == won't work if the null value is NaN */
flags[i] = !fcb->col_map[i] ||
memcmp(&tmp_buf[i], &fcb->gdal->null_val, sizeof(DCELL)) == 0;
@@ -953,7 +952,7 @@
static void embed_mask(char *flags, int row)
{
- CELL *mask_buf = G__alloca(G__.window.cols * sizeof(CELL));
+ CELL *mask_buf = G__alloca(R__.rd_window.cols * sizeof(CELL));
int i;
if (R__.auto_mask <= 0)
@@ -967,7 +966,7 @@
if (R__.fileinfo[R__.mask_fd].reclass_flag)
do_reclass_int(R__.mask_fd, mask_buf, 1);
- for (i = 0; i < G__.window.cols; i++)
+ for (i = 0; i < R__.rd_window.cols; i++)
if (mask_buf[i] == 0)
flags[i] = 1;
@@ -1003,11 +1002,11 @@
&& (R__.auto_mask <= 0 || !with_mask))
return;
- null_buf = G__alloca(G__.window.cols);
+ null_buf = G__alloca(R__.rd_window.cols);
get_null_value_row(fd, null_buf, row, with_mask);
- for (i = 0; i < G__.window.cols; i++) {
+ for (i = 0; i < R__.rd_window.cols; i++) {
/* also check for nulls which might be already embedded by quant
rules in case of fp map. */
if (null_buf[i] || Rast_is_null_value(buf, map_type)) {
Modified: grass/trunk/lib/raster/opencell.c
===================================================================
--- grass/trunk/lib/raster/opencell.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/opencell.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -25,7 +25,6 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include "../gis/G.h"
#include "R.h"
#define FORMAT_FILE "f_format"
#define NULL_FILE "null"
@@ -211,16 +210,16 @@
r_name, r_mapset);
}
- if (cellhd.proj != G__.window.proj)
+ if (cellhd.proj != R__.rd_window.proj)
G_fatal_error(_("Raster map <%s> is in different projection than current region. "
"Found <%s>, should be <%s>."),
G_fully_qualified_name(name, mapset),
G__projection_name(cellhd.proj),
- G__projection_name(G__.window.proj));
+ G__projection_name(R__.rd_window.proj));
- if (cellhd.zone != G__.window.zone)
+ if (cellhd.zone != R__.rd_window.zone)
G_fatal_error(_("Raster map <%s> is in different zone (%d) than current region (%d)"),
- G_fully_qualified_name(name, mapset), cellhd.zone, G__.window.zone);
+ G_fully_qualified_name(name, mapset), cellhd.zone, R__.rd_window.zone);
/* when map is int warn if too large cell size */
if (MAP_TYPE == CELL_TYPE && (unsigned int)CELL_nbytes > sizeof(CELL))
@@ -499,12 +498,12 @@
if (!fcb->gdal)
G_fatal_error(_("Unable to create GDAL link"));
- fcb->cellhd = G__.window;
+ fcb->cellhd = R__.wr_window;
fcb->cellhd.compressed = 0;
fcb->nbytes = Rast_cell_size(fcb->map_type);
- /* for writing fcb->data is allocated to be G__.window.cols *
+ /* for writing fcb->data is allocated to be R__.wr_window.cols *
sizeof(CELL or DCELL or FCELL) */
- fcb->data = G_calloc(G__.window.cols, fcb->nbytes);
+ fcb->data = G_calloc(R__.wr_window.cols, fcb->nbytes);
fcb->name = map;
fcb->mapset = mapset;
@@ -609,9 +608,9 @@
fcb->open_mode = -1;
fcb->gdal = NULL;
- /* for writing fcb->data is allocated to be G__.window.cols *
+ /* for writing fcb->data is allocated to be R__.wr_window.cols *
sizeof(CELL or DCELL or FCELL) */
- fcb->data = (unsigned char *)G_calloc(G__.window.cols,
+ fcb->data = (unsigned char *)G_calloc(R__.wr_window.cols,
Rast_cell_size(fcb->map_type));
/*
@@ -620,7 +619,7 @@
* for compressed writing
* allocate space to hold the row address array
*/
- G_copy((char *)&fcb->cellhd, (char *)&G__.window, sizeof(fcb->cellhd));
+ G_copy(&fcb->cellhd, &R__.wr_window, sizeof(fcb->cellhd));
if (open_mode == OPEN_NEW_COMPRESSED && fcb->map_type == CELL_TYPE) {
fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));
Modified: grass/trunk/lib/raster/put_row.c
===================================================================
--- grass/trunk/lib/raster/put_row.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/put_row.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -26,7 +26,6 @@
#include <grass/raster.h>
#include <grass/glocale.h>
-#include "../gis/G.h"
#include "R.h"
static void put_raster_row(int, const void *, RASTER_MAP_TYPE, int);
@@ -196,7 +195,7 @@
if (n <= 0)
return;
- work_buf = G__alloca(G__.window.cols * fcb->nbytes + 1);
+ work_buf = G__alloca(fcb->cellhd.cols * fcb->nbytes + 1);
if (compressed)
set_file_pointer(fd, row);
@@ -357,7 +356,7 @@
if (n <= 0)
return;
- work_buf = G__alloca(G__.window.cols * sizeof(CELL) + 1);
+ work_buf = G__alloca(fcb->cellhd.cols * sizeof(CELL) + 1);
wk = work_buf;
if (compressed)
Modified: grass/trunk/lib/raster/set_window.c
===================================================================
--- grass/trunk/lib/raster/set_window.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/set_window.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -15,30 +15,95 @@
#include <grass/raster.h>
#include <grass/glocale.h>
+#include "../gis/G.h"
#include "R.h"
+static void update_window_mappings(void);
+
+void Rast__init_window(void)
+{
+ Rast__init();
+
+ if (G_is_initialized(&R__.window_set))
+ return;
+
+ G__init_window();
+
+ R__.rd_window = G__.window;
+ R__.wr_window = G__.window;
+
+ G_initialize_done(&R__.window_set);
+}
+
/*!
* \brief Establishes 'window' as the current working window.
*
+ * \param window window to become operative window
+ */
+void Rast_set_window(struct Cell_head *window)
+{
+ Rast__init_window();
+
+ if (R__.split_window)
+ G_warning(_("Rast_set_window() called while window split"));
+
+ G_adjust_Cell_head(window, 0, 0);
+
+ R__.wr_window = *window;
+ R__.rd_window = *window;
+ R__.split_window = 0;
+
+ update_window_mappings();
+}
+
+/*!
+ * \brief Establishes 'window' as the current working window for output.
+ *
+ * \param window window to become operative window
+ */
+void Rast_set_output_window(struct Cell_head *window)
+{
+ Rast__init_window();
+
+ G_adjust_Cell_head(window, 0, 0);
+
+ R__.wr_window = *window;
+ R__.split_window = 1;
+
+ G_set_window(window);
+}
+
+/*!
+ * \brief Establishes 'window' as the current working window for input.
+ *
* Any opened cell files has its file-to-window mapping reworked.
*
* \param window window to become operative window
*/
-void Rast_set_window(struct Cell_head *window)
+
+void Rast_set_input_window(struct Cell_head *window)
{
+ Rast__init_window();
+
+ G_adjust_Cell_head(window, 0, 0);
+
+ R__.rd_window = *window;
+ R__.split_window = 1;
+
+ update_window_mappings();
+}
+
+static void update_window_mappings(void)
+{
int i;
int maskfd;
- Rast__init();
-
/* adjust window, check for valid window */
/* adjust the real one, not a copy
G_copy (&twindow, window, sizeof(struct Cell_head));
window = &twindow;
*/
- G_adjust_Cell_head(window, 0, 0);
-
/* except for MASK, cell files open for read must have same projection
* and zone as new window
*/
@@ -47,11 +112,11 @@
struct fileinfo *fcb = &R__.fileinfo[i];
if (fcb->open_mode == OPEN_OLD) {
- if (fcb->cellhd.zone == window->zone &&
- fcb->cellhd.proj == window->proj)
+ if (fcb->cellhd.zone == R__.rd_window.zone &&
+ fcb->cellhd.proj == R__.rd_window.proj)
continue;
if (i != maskfd)
- G_fatal_error(_("Rast_set_window(): projection/zone differs from that of "
+ G_fatal_error(_("Rast_set_read_window(): projection/zone differs from that of "
"currently open raster maps"));
}
}
@@ -64,9 +129,6 @@
R__.auto_mask = -1; /* turn off masking */
}
- /* copy the window to the current window */
- G_set_window(window);
-
/* now for each possible open cell file, recreate the window mapping */
/*
* also the memory for reading and writing must be reallocated for all opened
@@ -82,35 +144,9 @@
if (fcb->open_mode == OPEN_OLD)
Rast__create_window_mapping(i);
- /* code commented 10/1999 due to problems */
-#if 0
- else {
- /* opened for writing */
- G_free(fcb->data);
- fcb->data = G_calloc(G__.window.cols,
- Rast_cell_size(fcb-> map_type));
- }
-
- /* allocate null bitstream buffers for reading/writing null rows */
- for (j = 0; j < NULL_ROWS_INMEM; j++) {
- G_free(fcb->NULL_ROWS[j]);
- fcb->NULL_ROWS[j] = (G__.window.cols);
- }
-
-
- /* initialize : no NULL rows in memory */
- fcb->min_null_row = (-1) * NULL_ROWS_INMEM;
- if (fcb->null_cur_row > 0) {
- G_warning(_("Calling Rast_set_window() in the middle of writing map %s"),
- fcb->name);
- fcb->null_cur_row = 0;
- }
-#endif
}
/* turn masking (back) on if necessary */
Rast__check_for_auto_masking();
+}
- /* we want the number of bytes per cell to be maximum
- so that there is enough memory for reading and writing rows */
-}
Modified: grass/trunk/lib/raster/window.c
===================================================================
--- grass/trunk/lib/raster/window.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/window.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -1,7 +1,7 @@
#include <grass/gis.h>
#include <grass/raster.h>
+#include <grass/glocale.h>
-#include "../gis/G.h"
#include "R.h"
/*!
@@ -28,9 +28,13 @@
*/
int Rast_window_rows(void)
{
- G__init_window();
+ Rast__init_window();
- return G__.window.rows;
+ if (R__.split_window)
+ G_fatal_error(_("Internal error: Rast_window_rows() called with split window."
+ "Use Rast_input_window_rows() or Rast_output_window_rows() instead."));
+
+ return R__.wr_window.rows;
}
/*!
@@ -59,12 +63,72 @@
*/
int Rast_window_cols(void)
{
- G__init_window();
+ Rast__init_window();
- return G__.window.cols;
+ if (R__.split_window)
+ G_fatal_error(_("Internal error: Rast_window_cols() called with split window."
+ "Use Rast_input_window_cols() or Rast_output_window_cols() instead."));
+
+ return R__.wr_window.cols;
}
/*!
+ * \brief Number of rows in active input window.
+ *
+ * This routine returns the number of rows in the active input window.
+ *
+ * \return number of rows
+ */
+int Rast_input_window_rows(void)
+{
+ Rast__init_window();
+
+ return R__.rd_window.rows;
+}
+
+/*!
+ * \brief Number of columns in active input window.
+ *
+ * This routine returns the number of columns in the active input window.
+ *
+ * \return number of columns
+ */
+int Rast_input_window_cols(void)
+{
+ Rast__init_window();
+
+ return R__.rd_window.cols;
+}
+
+/*!
+ * \brief Number of rows in active output window.
+ *
+ * This routine returns the number of rows in the active output window.
+ *
+ * \return number of rows
+ */
+int Rast_output_window_rows(void)
+{
+ Rast__init_window();
+
+ return R__.wr_window.rows;
+}
+
+/*!
+ * \brief Number of columns in active output window.
+ *
+ * This routine returns the number of columns in the active output window.
+ *
+ * \return number of columns
+ */
+int Rast_output_window_cols(void)
+{
+ Rast__init_window();
+
+ return R__.wr_window.cols;
+}
+
+/*!
* \brief Northing to row.
*
* Converts a <i>north</i>ing relative to a <i>window</i> to a row.
Modified: grass/trunk/lib/raster/window_map.c
===================================================================
--- grass/trunk/lib/raster/window_map.c 2010-02-01 17:53:15 UTC (rev 40771)
+++ grass/trunk/lib/raster/window_map.c 2010-02-01 22:49:26 UTC (rev 40772)
@@ -15,7 +15,6 @@
#include <grass/gis.h>
#include <grass/raster.h>
-#include "../gis/G.h"
#include "R.h"
@@ -45,7 +44,7 @@
if (fcb->open_mode == OPEN_OLD) /* already open ? */
G_free(fcb->col_map);
- col = fcb->col_map = alloc_index(G__.window.cols);
+ col = fcb->col_map = alloc_index(R__.rd_window.cols);
/*
* for each column in the window, go to center of the cell,
@@ -55,18 +54,18 @@
* for lat/lon move window so that west is bigger than
* cellhd west.
*/
- west = G__.window.west;
- if (G__.window.proj == PROJECTION_LL) {
+ west = R__.rd_window.west;
+ if (R__.rd_window.proj == PROJECTION_LL) {
while (west > fcb->cellhd.west + 360.0)
west -= 360.0;
while (west < fcb->cellhd.west)
west += 360.0;
}
- C1 = G__.window.ew_res / fcb->cellhd.ew_res;
+ C1 = R__.rd_window.ew_res / fcb->cellhd.ew_res;
C2 = (west - fcb->cellhd.west +
- G__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
- for (i = 0; i < G__.window.cols; i++) {
+ R__.rd_window.ew_res / 2.0) / fcb->cellhd.ew_res;
+ for (i = 0; i < R__.rd_window.cols; i++) {
x = C2;
if (C2 < x) /* adjust for rounding of negatives */
x--;
@@ -77,11 +76,11 @@
}
/* do wrap around for lat/lon */
- if (G__.window.proj == PROJECTION_LL) {
+ if (R__.rd_window.proj == PROJECTION_LL) {
col = fcb->col_map;
C2 = (west - 360.0 - fcb->cellhd.west +
- G__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
- for (i = 0; i < G__.window.cols; i++) {
+ R__.rd_window.ew_res / 2.0) / fcb->cellhd.ew_res;
+ for (i = 0; i < R__.rd_window.cols; i++) {
x = C2;
if (C2 < x) /* adjust for rounding of negatives */
x--;
@@ -94,17 +93,17 @@
}
}
- G_debug(3, "create window mapping (%d columns)", G__.window.cols);
- /* for (i = 0; i < G__.window.cols; i++)
+ G_debug(3, "create window mapping (%d columns)", R__.rd_window.cols);
+ /* for (i = 0; i < R__.rd_window.cols; i++)
fprintf(stderr, "%s%ld", i % 15 ? " " : "\n", (long)fcb->col_map[i]);
fprintf(stderr, "\n");
*/
/* compute C1,C2 for row window mapping */
- fcb->C1 = G__.window.ns_res / fcb->cellhd.ns_res;
+ fcb->C1 = R__.rd_window.ns_res / fcb->cellhd.ns_res;
fcb->C2 =
- (fcb->cellhd.north - G__.window.north +
- G__.window.ns_res / 2.0) / fcb->cellhd.ns_res;
+ (fcb->cellhd.north - R__.rd_window.north +
+ R__.rd_window.ns_res / 2.0) / fcb->cellhd.ns_res;
}
@@ -139,7 +138,7 @@
if (f < r1)
r1--;
- while (++row < G__.window.rows) {
+ while (++row < R__.rd_window.rows) {
f = row * fcb->C1 + fcb->C2;
r2 = f;
if (f < r2)
More information about the grass-commit
mailing list