[GRASS-SVN] r47919 - grass-addons/grass7/imagery/i.topo.corr
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 28 10:05:20 EDT 2011
Author: neteler
Date: 2011-08-28 07:05:20 -0700 (Sun, 28 Aug 2011)
New Revision: 47919
Modified:
grass-addons/grass7/imagery/i.topo.corr/illumination.c
grass-addons/grass7/imagery/i.topo.corr/local_proto.h
grass-addons/grass7/imagery/i.topo.corr/main.c
Log:
simplify code
Modified: grass-addons/grass7/imagery/i.topo.corr/illumination.c
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/illumination.c 2011-08-28 13:09:05 UTC (rev 47918)
+++ grass-addons/grass7/imagery/i.topo.corr/illumination.c 2011-08-28 14:05:20 UTC (rev 47919)
@@ -18,197 +18,11 @@
#include "local_proto.h"
-void eval_c_cosi(Gfile * out, Gfile * dem, double zenith, double azimuth)
+void eval_cosi(Gfile * out, Gfile * dem, double zenith, double azimuth)
{
struct Cell_head window;
int row, col, nrows, ncols;
- CELL *cell[3], *temp;
- CELL *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8, *c9;
- double H, V, dx, dy, key, north, east, south, west, center;
- double cos_i, cos_z, sin_z, slope, aspect;
-
- Rast_get_window(&window);
-
- G_begin_distance_calculations();
- north = Rast_row_to_northing(0.5, &window);
- center = Rast_row_to_northing(1.5, &window);
- south = Rast_row_to_northing(2.5, &window);
- east = Rast_col_to_easting(2.5, &window);
- west = Rast_col_to_easting(0.5, &window);
- V = G_distance(east, north, east, south) * 4;
- H = G_distance(east, center, west, center) * 4;
-
- zenith *= D2R;
- azimuth *= D2R;
-
- cos_z = cos(zenith);
- sin_z = sin(zenith);
-
- /* Making cos_i raster ... */
- nrows = Rast_window_rows();
- ncols = Rast_window_cols();
-
- cell[0] = (CELL *) G_calloc(ncols + 1, sizeof(CELL));
- Rast_set_c_null_value(cell[0], ncols);
- cell[1] = (CELL *) G_calloc(ncols + 1, sizeof(CELL));
- Rast_set_c_null_value(cell[1], ncols);
- cell[2] = (CELL *) G_calloc(ncols + 1, sizeof(CELL));
- Rast_set_c_null_value(cell[2], ncols);
-
- /* First row is null */
- Rast_set_null_value((DCELL *) out->rast, Rast_window_cols(), DCELL_TYPE);
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
- /* Next rows ... */
- for (row = 2; row < nrows; row++) {
- G_percent(row, nrows, 2);
- temp = cell[0];
- cell[0] = cell[1];
- cell[1] = cell[2];
- cell[2] = temp;
- Rast_get_c_row_nomask(dem->fd, cell[2], row);
-
- c1 = cell[0];
- c2 = c1 + 1;
- c3 = c1 + 2;
- c4 = cell[1];
- c5 = c4 + 1;
- c6 = c4 + 2;
- c7 = cell[2];
- c8 = c7 + 1;
- c9 = c7 + 2;
-
- for (col = 1; col < ncols - 1;
- col++, c1++, c2++, c3++, c4++, c5++, c6++, c7++, c8++, c9++) {
- if (Rast_is_c_null_value(c1) || Rast_is_c_null_value(c2) ||
- Rast_is_c_null_value(c3) || Rast_is_c_null_value(c4) ||
- Rast_is_c_null_value(c5) || Rast_is_c_null_value(c6) ||
- Rast_is_c_null_value(c7) || Rast_is_c_null_value(c8) ||
- Rast_is_c_null_value(c9)) {
- Rast_set_d_null_value((DCELL *) out->rast + col, 1);
- }
- else {
- dx = ((*c1 + *c4 + *c4 + *c7) - (*c3 + *c6 + *c6 + *c9)) / H;
- dy = ((*c1 + *c2 + *c2 + *c3) - (*c7 + *c8 + *c8 + *c9)) / V;
- key = dx * dx + dy * dy;
- slope = atan(sqrt(key));
- aspect = atan2(dx, -dy);
- if (aspect < 0.0)
- aspect += 2 * PI;
-
- cos_i =
- cos_z * cos(slope) + sin_z * sin(slope) * cos(azimuth -
- aspect);
-
- ((DCELL *) out->rast)[col] = (DCELL) cos_i;
- }
- }
-
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
- }
- /* Last row is null */
- Rast_set_null_value((DCELL *) out->rast, Rast_window_cols(), DCELL_TYPE);
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
-}
-
-void eval_f_cosi(Gfile * out, Gfile * dem, double zenith, double azimuth)
-{
- struct Cell_head window;
-
- int row, col, nrows, ncols;
- FCELL *cell[3], *temp;
- FCELL *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8, *c9;
- double H, V, dx, dy, key, north, east, south, west, center;
- double cos_i, cos_z, sin_z, slope, aspect;
-
- Rast_get_window(&window);
-
- G_begin_distance_calculations();
- north = Rast_row_to_northing(0.5, &window);
- center = Rast_row_to_northing(1.5, &window);
- south = Rast_row_to_northing(2.5, &window);
- east = Rast_col_to_easting(2.5, &window);
- west = Rast_col_to_easting(0.5, &window);
- V = G_distance(east, north, east, south) * 4;
- H = G_distance(east, center, west, center) * 4;
-
- zenith *= D2R;
- azimuth *= D2R;
-
- cos_z = cos(zenith);
- sin_z = sin(zenith);
-
- /* Making cos_i raster ... */
- nrows = Rast_window_rows();
- ncols = Rast_window_cols();
-
- cell[0] = (FCELL *) G_calloc(ncols + 1, sizeof(FCELL));
- Rast_set_f_null_value(cell[0], ncols);
- cell[1] = (FCELL *) G_calloc(ncols + 1, sizeof(FCELL));
- Rast_set_f_null_value(cell[1], ncols);
- cell[2] = (FCELL *) G_calloc(ncols + 1, sizeof(FCELL));
- Rast_set_f_null_value(cell[2], ncols);
-
- /* First row is null */
- Rast_set_null_value((DCELL *) out->rast, Rast_window_cols(), DCELL_TYPE);
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
- /* Next rows ... */
- for (row = 2; row < nrows; row++) {
- G_percent(row, nrows, 2);
- temp = cell[0];
- cell[0] = cell[1];
- cell[1] = cell[2];
- cell[2] = temp;
- Rast_get_f_row_nomask(dem->fd, cell[2], row);
-
- c1 = cell[0];
- c2 = c1 + 1;
- c3 = c1 + 2;
- c4 = cell[1];
- c5 = c4 + 1;
- c6 = c4 + 2;
- c7 = cell[2];
- c8 = c7 + 1;
- c9 = c7 + 2;
-
- for (col = 1; col < ncols - 1;
- col++, c1++, c2++, c3++, c4++, c5++, c6++, c7++, c8++, c9++) {
- if (Rast_is_f_null_value(c1) || Rast_is_f_null_value(c2) ||
- Rast_is_f_null_value(c3) || Rast_is_f_null_value(c4) ||
- Rast_is_f_null_value(c5) || Rast_is_f_null_value(c6) ||
- Rast_is_f_null_value(c7) || Rast_is_f_null_value(c8) ||
- Rast_is_f_null_value(c9)) {
- Rast_set_d_null_value((DCELL *) out->rast + col, 1);
- }
- else {
- dx = ((*c1 + *c4 + *c4 + *c7) - (*c3 + *c6 + *c6 + *c9)) / H;
- dy = ((*c1 + *c2 + *c2 + *c3) - (*c7 + *c8 + *c8 + *c9)) / V;
- key = dx * dx + dy * dy;
- slope = atan(sqrt(key));
- aspect = atan2(dx, -dy);
- if (aspect < 0.0)
- aspect += 2 * PI;
-
- cos_i =
- cos_z * cos(slope) + sin_z * sin(slope) * cos(azimuth -
- aspect);
-
- ((DCELL *) out->rast)[col] = (DCELL) cos_i;
- }
- }
-
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
- }
- /* Last row is null */
- Rast_set_null_value((DCELL *) out->rast, Rast_window_cols(), DCELL_TYPE);
- Rast_put_row(out->fd, out->rast, DCELL_TYPE);
-}
-
-void eval_d_cosi(Gfile * out, Gfile * dem, double zenith, double azimuth)
-{
- struct Cell_head window;
-
- int row, col, nrows, ncols;
DCELL *cell[3], *temp;
DCELL *c1, *c2, *c3, *c4, *c5, *c6, *c7, *c8, *c9;
double H, V, dx, dy, key, north, east, south, west, center;
Modified: grass-addons/grass7/imagery/i.topo.corr/local_proto.h
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/local_proto.h 2011-08-28 13:09:05 UTC (rev 47918)
+++ grass-addons/grass7/imagery/i.topo.corr/local_proto.h 2011-08-28 14:05:20 UTC (rev 47919)
@@ -18,13 +18,11 @@
#define LAMBERTIAN 0
#define COSINE 1
#define PERCENT 2
-#define NON_LAMBERTIAN 10
+#define NON_LAMBERTIAN 10
#define MINNAERT 11
#define C_CORRECT 12
-void eval_c_cosi(Gfile *, Gfile *, double, double);
-void eval_f_cosi(Gfile *, Gfile *, double, double);
-void eval_d_cosi(Gfile *, Gfile *, double, double);
+void eval_cosi(Gfile *, Gfile *, double, double);
void eval_tcor(int, Gfile *, Gfile *, Gfile *, double);
#endif
Modified: grass-addons/grass7/imagery/i.topo.corr/main.c
===================================================================
--- grass-addons/grass7/imagery/i.topo.corr/main.c 2011-08-28 13:09:05 UTC (rev 47918)
+++ grass-addons/grass7/imagery/i.topo.corr/main.c 2011-08-28 14:05:20 UTC (rev 47919)
@@ -120,21 +120,8 @@
out.fd = Rast_open_new(output->answer, DCELL_TYPE);
out.rast = Rast_allocate_buf(out.type);
/* Open and buffer of the elevation file */
- if (dem.type == CELL_TYPE) {
- dem.rast = Rast_allocate_buf(CELL_TYPE);
- eval_c_cosi(&out, &dem, zenith, azimuth);
- }
- else if (dem.type == FCELL_TYPE) {
- dem.rast = Rast_allocate_buf(FCELL_TYPE);
- eval_f_cosi(&out, &dem, zenith, azimuth);
- }
- else if (dem.type == DCELL_TYPE) {
- dem.rast = Rast_allocate_buf(DCELL_TYPE);
- eval_d_cosi(&out, &dem, zenith, azimuth);
- }
- else {
- G_fatal_error(_("Elevation file of unknown type"));
- }
+ dem.rast = Rast_allocate_buf(DCELL_TYPE);
+ eval_cosi(&out, &dem, zenith, azimuth);
/* Close files, buffers, and write history */
G_free(dem.rast);
Rast_close(dem.fd);
More information about the grass-commit
mailing list