Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.path: Support bitmask encoding CW from East #4943

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions raster/r.path/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ int main(int argc, char **argv)
struct Option *vect;
} opt;
struct {
struct Flag *east;
struct Flag *brk;
struct Flag *copy;
struct Flag *accum;
struct Flag *count;
Expand Down Expand Up @@ -196,6 +198,18 @@ int main(int argc, char **argv)
opt.vpoint->label = _("Name of starting vector points map(s)");
opt.vpoint->guisection = _("Start");

flag.east = G_define_flag();
flag.east->key = 'e';
flag.east->description =
_("Start bitmask encoded directions from East (e.g., r.terraflow)");
flag.east->guisection = _("Direction settings");

flag.brk = G_define_flag();
flag.brk->key = 'b';
flag.brk->description =
_("Do not break lines (faster for single-direction bitmask encoding)");
flag.brk->guisection = _("Direction settings");

flag.copy = G_define_flag();
flag.copy->key = 'c';
flag.copy->description = _("Copy input cell values on output");
Expand All @@ -216,6 +230,7 @@ int main(int argc, char **argv)
G_option_requires_all(flag.copy, opt.rast, opt.val, NULL);
G_option_requires_all(flag.accum, opt.rast, opt.val, NULL);
G_option_requires_all(flag.count, opt.rast, NULL);
G_option_requires(flag.brk, opt.vect, NULL);

if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -457,6 +472,13 @@ int main(int argc, char **argv)
dir_buf = Rast_allocate_c_buf();
for (i = 0; i < nrows; i++) {
Rast_get_c_row(dir_id, dir_buf, i);
if (flag.east->answer) {
CELL *p;

p = (CELL *)dir_buf;
for (j = 0; j < ncols; j++, p++)
*p = pow(2, ((int)log2(*p) + 1) % 8);
}
if (write(dir_fd, dir_buf, ncols * sizeof(CELL)) !=
ncols * (int)sizeof(CELL)) {
G_fatal_error(_("Unable to write to tempfile"));
Expand Down Expand Up @@ -503,7 +525,7 @@ int main(int argc, char **argv)
if (dir_format == DIR_BIT) {
struct Map_info Tmp;

if (pvout) {
if (!flag.brk->answer && pvout) {
if (Vect_open_tmp_new(&Tmp, NULL, 0) < 0)
G_fatal_error(_("Unable to create temporary vector map"));
pvout = &Tmp;
Expand All @@ -514,7 +536,7 @@ int main(int argc, char **argv)
G_warning(_("No path at row %d, col %d"), next_start_pt->row,
next_start_pt->col);
}
if (pvout) {
if (!flag.brk->answer && pvout) {
Vect_build_partial(&Tmp, GV_BUILD_BASE);
G_message(_("Breaking lines..."));
Vect_break_lines(&Tmp, GV_LINE, NULL);
Expand Down Expand Up @@ -711,8 +733,8 @@ int dir_bitmask(int dir_fd, int val_fd, struct point *startp,
struct ppoint pp;
int is_stack;
int cur_dir, i, npaths;
struct line_pnts *Points;
struct line_cats *Cats;
struct line_pnts *Points = NULL;
struct line_cats *Cats = NULL;
double x, y;
double value;

Expand Down
Loading