18 #include <grass/Vect.h>
19 #include <grass/glocale.h>
53 int prev_line, next_line;
56 static int array_size;
66 debug_level = atoi(dstr);
70 G_debug(3,
"dig_build_area_with_line(): first_line = %d, side = %d",
75 Line = plus->Line[first_line];
78 G_debug(3,
"First line degenerated");
82 if (array_size == 0) {
84 array = (plus_t *)
dig__falloc(array_size,
sizeof(plus_t));
89 if (side == GV_LEFT) {
90 first_line = -first_line;
92 array[0] = first_line;
93 prev_line = -first_line;
100 G_debug(3,
"next_line = %d", next_line);
108 "Cannot build area, a neighbour of the line %d has the same angle at the node",
114 if (first_line == next_line) {
119 if (debug_level > 2) {
120 for (i = 0; i < n_lines; i++) {
121 G_debug(3,
" area line (%d) = %d", i, array[i]);
131 if (prev_line == next_line) {
137 for (i = 0; i < n_lines; i++)
138 if (abs(next_line) == abs(array[i])) {
144 if (n_lines >= array_size) {
149 array = (plus_t *) p;
152 array[n_lines++] = next_line;
153 prev_line = -next_line;
176 register int area, line;
184 if (plus->n_areas >= plus->alloc_areas) {
190 area = plus->n_areas + 1;
191 G_debug(3,
" new area = %d", area);
199 for (i = 0; i < n_lines; i++) {
201 Area->lines[i] = line;
202 Line = plus->Line[abs(line)];
206 if (Line->left != 0) {
207 G_warning(_(
"Line %d already has area/isle %d to left"), line,
212 G_debug(3,
" Line %d left set to %d.", line, area);
216 if (Line->right != 0) {
217 G_warning(_(
"Line %d already has area/isle %d to right"),
222 G_debug(3,
" Line %d right set to %d.", line, area);
231 Area->n_lines = n_lines;
234 plus->Area[area] = Area;
258 G_debug(3,
"dig_area_add_isle(): area = %d isle = %d", area, isle);
260 Area = plus->Area[area];
264 for (i = 0; i < Area->n_isles; i++) {
265 if (Area->isles[i] == isle) {
266 G_debug(3,
"isle already registered in area");
271 if (Area->alloc_isles <= Area->n_isles)
274 Area->isles[Area->n_isles] = isle;
276 G_debug(3,
" -> n_isles = %d", Area->n_isles);
295 G_debug(3,
"dig_area_del_isle(): area = %d isle = %d", area, isle);
297 Area = plus->Area[area];
302 for (i = 0; i < Area->n_isles; i++) {
304 Area->isles[i - 1] = Area->isles[i];
307 if (Area->isles[i] == isle)
316 G_fatal_error(_(
"Attempt to delete not registered isle %d from area %d"),
350 G_debug(3,
"dig_del_area() area = %d", area);
351 Area = plus->Area[area];
354 G_warning(_(
"Attempt to delete dead area"));
362 for (i = 0; i < Area->n_lines; i++) {
363 line = Area->lines[i];
364 Line = plus->Line[abs(line)];
368 G_debug(3,
" Set line %d right side to 0", line);
372 G_debug(3,
" Set line %d left side to 0", line);
390 line = Area->centroid;
392 Line = plus->Line[line];
394 G_warning(_(
"Dead centroid %d registered for area (bug in the vector library)"),
414 G_debug(3,
" n_isles = %d", Area->n_isles);
415 for (i = 0; i < Area->n_isles; i++) {
416 Isle = plus->Isle[Area->isles[i]];
418 G_fatal_error(_(
"Attempt to delete area %d info from dead isle %d"),
419 area, Area->isles[i]);
428 plus->Area[area] =
NULL;
445 Area = plus->Area[area];
489 debug_level = atoi(dstr);
493 G_debug(3,
"dig__angle_next_line: line = %d, side = %d, type = %d",
494 current_line, side, type);
496 Line = plus->Line[abs(current_line)];
497 if (current_line > 0)
502 G_debug(3,
" node = %d", node);
504 Node = plus->Node[node];
505 G_debug(3,
" n_lines = %d", Node->n_lines);
507 if (debug_level > 2) {
508 for (i = 0; i < Node->n_lines; i++) {
509 G_debug(3,
" i = %d line = %d angle = %f", i, Node->lines[i],
516 for (current = 0; current < Node->n_lines; current++) {
517 if (Node->lines[current] == current_line)
523 G_debug(3,
" current position = %d", next);
525 if (side == GV_RIGHT) {
526 if (next == Node->n_lines - 1)
533 next = Node->n_lines - 1;
537 G_debug(3,
" next = %d line = %d angle = %f", next,
538 Node->lines[next], Node->angles[next]);
540 if (Node->angles[next] == -9.) {
541 G_debug(3,
" point/degenerated -> skip");
542 if (Node->lines[next] == current_line)
548 line = abs(Node->lines[next]);
549 Line = plus->Line[line];
551 if (Line->type & type) {
553 return (Node->lines[next]);
557 if (Node->lines[next] == current_line)
560 G_debug(3,
" Line NOT found at node %d", (
int)node);
581 float angle1, angle2;
585 G_debug(3,
"dig_node_angle_check: line = %d, type = %d", line, type);
587 Line = plus->Line[abs(line)];
599 if (angle1 == angle2) {
601 " The line to the right has the same angle: node = %d, line = %d",
609 if (angle1 == angle2) {
611 " The line to the left has the same angle: node = %d, line = %d",
637 register int isle, line;
645 if (plus->n_isles >= plus->alloc_isles) {
651 isle = plus->n_isles + 1;
666 for (i = 0; i < n_lines; i++) {
668 G_debug(3,
" i = %d line = %d", i, line);
669 Isle->lines[i] = line;
670 Line = plus->Line[abs(line)];
674 if (Line->left != 0) {
675 G_warning(_(
"Line %d already has area/isle %d to left"), line,
682 if (Line->right != 0) {
683 G_warning(_(
"Line %d already has area/isle %d to left"), line,
697 Isle->n_lines = n_lines;
699 plus->Isle[isle] = Isle;
724 Isle = plus->Isle[isle];
752 G_debug(3,
"dig_del_isle() isle = %d", isle);
753 Isle = plus->Isle[isle];
758 for (i = 0; i < Isle->n_lines; i++) {
759 line = Isle->lines[i];
760 Line = plus->Line[abs(line)];
770 G_debug(3,
" area outside isle = %d", Isle->area);
771 if (Isle->area > 0) {
772 if (plus->Area[Isle->area] ==
NULL) {
773 G_fatal_error(_(
"Attempt to delete isle %d info from dead area %d"),
783 plus->Isle[isle] =
NULL;
int dig_area_alloc_isle(P_AREA *area, int add)
void * dig__frealloc(void *oldptr, int nelem, int elsize, int oldnelem)
char * G__getenv(const char *name)
Get environment variable.
int dig_del_isle(struct Plus_head *plus, int isle)
Delete island from Plus_head structure.
float Box[8][3]
Vertices for box.
float dig_node_line_angle(struct Plus_head *plus, int nodeid, int lineid)
Return line angle.
int dig_del_area(struct Plus_head *plus, int area)
Delete area from Plus_head structure.
void * dig__falloc(int nelem, int elsize)
int dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side, int type)
Find number line of next angle to follow an line.
int dig_alloc_areas(struct Plus_head *Plus, int add)
int dig_box_extend(BOUND_BOX *A, BOUND_BOX *B)
int dig_spidx_add_area(struct Plus_head *Plus, int area, BOUND_BOX *box)
Add new area to spatial index.
int dig_line_get_box(struct Plus_head *plus, plus_t line, BOUND_BOX *Box)
Get line bounding box saved in topo.
int dig_spidx_add_isle(struct Plus_head *Plus, int isle, BOUND_BOX *box)
Add new island to spatial index.
int dig_area_add_isle(struct Plus_head *plus, int area, int isle)
Add isle to area if does not exist yet.
int dig_build_area_with_line(struct Plus_head *plus, plus_t first_line, int side, plus_t **lines)
Build topo for area from lines.
int dig_spidx_del_area(struct Plus_head *Plus, int area)
Delete area from spatial index.
P_ISLE * dig_alloc_isle()
int dig_area_alloc_line(P_AREA *area, int add)
int dig_alloc_isles(struct Plus_head *Plus, int add)
int dig_isle_set_box(struct Plus_head *plus, plus_t isle, BOUND_BOX *Box)
Set isle bounding box.
int dig_isle_alloc_line(P_ISLE *isle, int add)
int dig_spidx_del_isle(struct Plus_head *Plus, int isle)
Delete isle from spatial index.
int dig_box_copy(BOUND_BOX *A, BOUND_BOX *B)
P_AREA * dig_alloc_area()
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
int dig_node_angle_check(struct Plus_head *plus, plus_t line, int type)
Checks if angles of adjacent lines differ.
void dig_line_add_updated(struct Plus_head *Plus, int line)
Add new line to updated.
int dig_area_set_box(struct Plus_head *plus, plus_t area, BOUND_BOX *Box)
Set area bounding box.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t *lines)
Allocate space for new island and create boundary info from array.
int dig_add_area(struct Plus_head *plus, int n_lines, plus_t *lines)
Allocate space for new area and create boundary info from array.
int dig_area_del_isle(struct Plus_head *plus, int area, int isle)
Delete isle from area.