Skip to content

Commit

Permalink
r.geomorphon: Run grass_indent.sh on the source (#1102)
Browse files Browse the repository at this point in the history
* r.geomorphon: Run grass_indent.sh on the source
  • Loading branch information
neteler committed Nov 19, 2020
1 parent 191521e commit fa1e07d
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 743 deletions.
144 changes: 72 additions & 72 deletions raster/r.geomorphon/geom.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "local_proto.h"
/* static double dirs[8] = { 0.7854, 0., 5.4978, 4.7124, 3.9270, 3.1416, 2.3562, 1.5708 };*/ /* radians */
static double sins[8] = { 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0, 0.7071067812, 1 }; /* sinus */
static double coss[8] = { 0.7071067812, 1, 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0 }; /* cosinus */
/* static double dirs[8] = { 0.7854, 0., 5.4978, 4.7124, 3.9270, 3.1416, 2.3562, 1.5708 }; *//* radians */
static double sins[8] = { 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0, 0.7071067812, 1 }; /* sinus */
static double coss[8] = { 0.7071067812, 1, 0.7071067812, 0, -0.7071067812, -1, -0.7071067812, 0 }; /* cosinus */

/* DIRS in DEGREES from NORTH: 45,0,315,270,225,180,135,90 */

Expand All @@ -21,25 +21,25 @@ unsigned int ternary_rotate(unsigned int value)
int i, j, k;

for (i = 0; i < 8; i++) {
pattern[i] = value % 3;
rev_pattern[7 - i] = value % 3;
value /= 3;
pattern[i] = value % 3;
rev_pattern[7 - i] = value % 3;
value /= 3;
}

for (j = 0; j < 8; j++) {
power = 1;
tmp_code = 0;
tmp_rev_code = 0;
for (i = 0; i < 8; i++) {
k = (i - j) < 0 ? j - 8 : j;
tmp_pattern[i] = pattern[i - k];
tmp_rev_pattern[i] = rev_pattern[i - k];
tmp_code += tmp_pattern[i] * power;
tmp_rev_code += tmp_rev_pattern[i] * power;
power *= 3;
}
code = tmp_code < code ? tmp_code : code;
rev_code = tmp_rev_code < rev_code ? tmp_rev_code : rev_code;
power = 1;
tmp_code = 0;
tmp_rev_code = 0;
for (i = 0; i < 8; i++) {
k = (i - j) < 0 ? j - 8 : j;
tmp_pattern[i] = pattern[i - k];
tmp_rev_pattern[i] = rev_pattern[i - k];
tmp_code += tmp_pattern[i] * power;
tmp_rev_code += tmp_rev_pattern[i] * power;
power *= 3;
}
code = tmp_code < code ? tmp_code : code;
rev_code = tmp_rev_code < rev_code ? tmp_rev_code : rev_code;
}
return code < rev_code ? code : rev_code;
}
Expand All @@ -50,17 +50,17 @@ int determine_form(int num_minus, int num_plus)
* simple approach to determine form pattern */

const FORMS forms[9][9] = {
/* minus ------------- plus ---------------- */
/* 0 1 2 3 4 5 6 7 8 */
/* 0 */ {FL, FL, FL, FS, FS, VL, VL, VL, PT},
/* 1 */ {FL, FL, FS, FS, FS, VL, VL, VL, __},
/* 2 */ {FL, SH, SL, SL, CN, CN, VL, __, __},
/* 3 */ {SH, SH, SL, SL, SL, CN, __, __, __},
/* 4 */ {SH, SH, CV, SL, SL, __, __, __, __},
/* 5 */ {RI, RI, CV, CV, __, __, __, __, __},
/* 6 */ {RI, RI, RI, __, __, __, __, __, __},
/* 7 */ {RI, RI, __, __, __, __, __, __, __},
/* 8 */ {PK, __, __, __, __, __, __, __, __},
/* minus ------------- plus ---------------- */
/* 0 1 2 3 4 5 6 7 8 */
/* 0 */ {FL, FL, FL, FS, FS, VL, VL, VL, PT},
/* 1 */ {FL, FL, FS, FS, FS, VL, VL, VL, __},
/* 2 */ {FL, SH, SL, SL, CN, CN, VL, __, __},
/* 3 */ {SH, SH, SL, SL, SL, CN, __, __, __},
/* 4 */ {SH, SH, CV, SL, SL, __, __, __, __},
/* 5 */ {RI, RI, CV, CV, __, __, __, __, __},
/* 6 */ {RI, RI, RI, __, __, __, __, __, __},
/* 7 */ {RI, RI, __, __, __, __, __, __, __},
/* 8 */ {PK, __, __, __, __, __, __, __, __},
};

/* legend:
Expand All @@ -86,14 +86,14 @@ int determine_binary(int *pattern, int sign)
unsigned char binary = 0, result = 255, test = 0;

for (i = 0, n = 1; i < 8; i++, n *= 2)
binary += (pattern[i] == sign) ? n : 0;
binary += (pattern[i] == sign) ? n : 0;
/* rotate */
for (i = 0; i < 8; ++i) {
if ((i &= 7) == 0)
test = binary;
else
test = (binary << i) | (binary >> (8 - i));
result = (result < test) ? result : test;
if ((i &= 7) == 0)
test = binary;
else
test = (binary << i) | (binary >> (8 - i));
result = (result < test) ? result : test;
}
return (int)result;
}
Expand All @@ -106,11 +106,11 @@ int rotate(unsigned char binary)

/* rotate */
for (i = 0; i < 8; ++i) {
if ((i &= 7) == 0)
test = binary;
else
test = (binary << i) | (binary >> (8 - i));
result = (result < test) ? result : test;
if ((i &= 7) == 0)
test = binary;
else
test = (binary << i) | (binary >> (8 - i));
result = (result < test) ? result : test;
}
return (int)result;
}
Expand All @@ -122,7 +122,7 @@ int determine_ternary(int *pattern)
int power, i;

for (i = 0, power = 1; i < 8; ++i, power *= 3)
ternary_code += (pattern[i] + 1) * power;
ternary_code += (pattern[i] + 1) * power;
return global_ternary_codes[ternary_code];
}

Expand All @@ -133,7 +133,7 @@ float intensity(float *elevation, int pattern_size)
int i;

for (i = 0; i < 8; i++)
sum_elevation -= elevation[i];
sum_elevation -= elevation[i];

return sum_elevation / (float)pattern_size;
}
Expand All @@ -145,19 +145,19 @@ float exposition(float *elevation)
int i;

for (i = 0; i < 8; i++)
max = fabs(elevation[i]) > fabs(max) ? elevation[i] : max;
max = fabs(elevation[i]) > fabs(max) ? elevation[i] : max;
return -max;
}

float range(float *elevation)
{
/* calculate relative difference in visible range of central cell */
float max = -90000000000., min = 9000000000000.; /* should be enough */
float max = -90000000000., min = 9000000000000.; /* should be enough */
int i;

for (i = 0; i < 8; i++) {
max = elevation[i] > max ? elevation[i] : max;
min = elevation[i] < min ? elevation[i] : min;
max = elevation[i] > max ? elevation[i] : max;
min = elevation[i] < min ? elevation[i] : min;
}

return max - min;
Expand All @@ -171,11 +171,11 @@ float variance(float *elevation, int pattern_size)
int i;

for (i = 0; i < 8; i++)
sum_elevation += elevation[i];
sum_elevation += elevation[i];
sum_elevation /= (float)pattern_size;
for (i = 0; i < 8; i++)
variance +=
((sum_elevation - elevation[i]) * (sum_elevation - elevation[i]));
variance +=
((sum_elevation - elevation[i]) * (sum_elevation - elevation[i]));

return variance / (float)pattern_size;
}
Expand All @@ -188,14 +188,14 @@ int radial2cartesian(PATTERN * pattern)
int i;

for (i = 0; i < 8; ++i)
if (pattern->distance > 0) {
pattern->x[i] = pattern->distance[i] * sins[i];
pattern->y[i] = pattern->distance[i] * coss[i];
}
else {
pattern->x[i] = 0;
pattern->y[i] = 0;
}
if (pattern->distance > 0) {
pattern->x[i] = pattern->distance[i] * sins[i];
pattern->y[i] = pattern->distance[i] * coss[i];
}
else {
pattern->x[i] = 0;
pattern->y[i] = 0;
}
return 0;
}

Expand All @@ -205,15 +205,15 @@ float extends(PATTERN * pattern, int pattern_size)
float area = 0;

for (i = 0, j = 1; i < 8; ++i, ++j) {
j = j < 8 ? j : 0;
area +=
(pattern->x[i] * pattern->y[j] - pattern->x[j] * pattern->y[i]);
j = j < 8 ? j : 0;
area +=
(pattern->x[i] * pattern->y[j] - pattern->x[j] * pattern->y[i]);
}
return fabs(area) / 2.;
}

int shape(PATTERN * pattern, int pattern_size, float *azimuth,
float *elongation, float *width)
float *elongation, float *width)
{
/* calculates azimuth, elongation and width of geomorphon's polygon */
int i;
Expand All @@ -226,10 +226,10 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
double rxmin, rxmax, rymin, rymax;

for (i = 0; i < 8; ++i) {
avg_y += pattern->y[i];
avg_x += pattern->x[i];
avg_x_square += pattern->x[i] * pattern->x[i];
avg_x_y += pattern->x[i] * pattern->y[i];
avg_y += pattern->y[i];
avg_x += pattern->x[i];
avg_x_square += pattern->x[i] * pattern->x[i];
avg_x_y += pattern->x[i] * pattern->y[i];
}
avg_y /= (float)pattern_size;
avg_x /= (float)pattern_size;
Expand All @@ -245,12 +245,12 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
rxmin = rxmax = pattern->x[0] * cosine - pattern->y[0] * sine;
rymin = rymax = pattern->x[0] * sine + pattern->y[0] * cosine;
for (i = 1; i < 8; ++i) {
rx = pattern->x[i] * cosine - pattern->y[i] * sine;
ry = pattern->x[i] * sine + pattern->y[i] * cosine;
rxmin = rx < rxmin ? rx : rxmin;
rxmax = rx > rxmax ? rx : rxmax;
rymin = ry < rymin ? ry : rymin;
rymax = ry > rymax ? ry : rymax;
rx = pattern->x[i] * cosine - pattern->y[i] * sine;
ry = pattern->x[i] * sine + pattern->y[i] * cosine;
rxmin = rx < rxmin ? rx : rxmin;
rxmax = rx > rxmax ? rx : rxmax;
rymin = ry < rymin ? ry : rymin;
rymax = ry > rymax ? ry : rymax;
}
rx = (rxmax - rxmin);
ry = (rymax - rymin);
Expand Down
48 changes: 24 additions & 24 deletions raster/r.geomorphon/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
#endif


#ifndef PI2 /* PI/2 */
#ifndef PI2 /* PI/2 */
#define PI2 (2*atan(1))
#endif

#ifndef PI4 /* PI/4 */
#ifndef PI4 /* PI/4 */
#define PI4 (atan(1))
#endif

#ifndef PI
#define PI (4*atan(1))
#endif

#ifndef M2PI /* 2*PI */
#ifndef M2PI /* 2*PI */
#define M2PI (8*atan(1))
#endif

Expand Down Expand Up @@ -60,11 +60,11 @@ typedef struct
char elevname[150];
RASTER_MAP_TYPE raster_type;
FCELL **elev;
int fd; /* file descriptor */
int fd; /* file descriptor */
} MAPS;

typedef struct
{ /* struct is used both for interface and output */
{ /* struct is used both for interface and output */
char *name;
int required;
char *description;
Expand All @@ -90,24 +90,24 @@ typedef struct
int pattern[8];
float elevation[8];
double distance[8];
double x[8], y[8]; /* cartesian coordinates of geomorphon */
double x[8], y[8]; /* cartesian coordinates of geomorphon */
} PATTERN;

typedef enum
{
ZERO, /* zero cats do not accept zero category */
FL, /* flat */
PK, /* peak, summit */
RI, /* ridge */
SH, /* shoulder */
CV, /* convex slope */
SL, /* slope */
CN, /* concave slope */
FS, /* footslope */
VL, /* valley */
PT, /* pit, depression */
__, /* error */
CNT /* counter */
ZERO, /* zero cats do not accept zero category */
FL, /* flat */
PK, /* peak, summit */
RI, /* ridge */
SH, /* shoulder */
CV, /* convex slope */
SL, /* slope */
CN, /* concave slope */
FS, /* footslope */
VL, /* valley */
PT, /* pit, depression */
__, /* error */
CNT /* counter */
} FORMS;

typedef struct
Expand All @@ -134,7 +134,7 @@ GLOBAL int nrows, ncols, row_radius_size, row_buffer_size;
GLOBAL int search_cells, skip_cells, step_cells, start_cells;
GLOBAL int num_of_steps;
GLOBAL double search_distance, skip_distance, flat_distance;
GLOBAL double start_distance, step_distance; /* multiresolution mode */
GLOBAL double start_distance, step_distance; /* multiresolution mode */
GLOBAL double flat_threshold, flat_threshold_height;
GLOBAL double H, V;
GLOBAL struct Cell_head window;
Expand Down Expand Up @@ -164,16 +164,16 @@ float exposition(float *elevation);
float range(float *elevation);
float variance(float *elevation, int n);
int shape(PATTERN * pattern, int pattern_size, float *azimuth,
float *elongation, float *width);
float *elongation, float *width);
float extends(PATTERN * pattern, int pattern_size);
int radial2cartesian(PATTERN *);

/* multires */
int reset_multi_patterns(void);
int calc_multi_patterns(int row, int cur_row, int col);
int update_pattern(int k, int i,
double zenith_height, double zenith_distance,
double zenith_angle, double nadir_height,
double nadir_distance, double nadir_angle);
double zenith_height, double zenith_distance,
double zenith_angle, double nadir_height,
double nadir_distance, double nadir_angle);

#endif
Loading

0 comments on commit fa1e07d

Please sign in to comment.