20 static int debug_level = -1;
54 int prev_line, next_line;
57 static int array_size;
63 if (debug_level == -1) {
67 debug_level = atoi(dstr);
72 G_debug(3,
"dig_build_area_with_line(): first_line = %d, side = %d",
77 Line = plus->
Line[first_line];
85 G_debug(3,
"First line degenerated");
89 if (array_size == 0) {
97 first_line = -first_line;
99 array[0] = first_line;
100 prev_line = -first_line;
107 G_debug(3,
"next_line = %d", next_line);
109 if (next_line == 0) {
110 G_debug(3,
"Cannot build area, no next line for line %d",
118 "Cannot build area, a neighbour of the line %d has the "
119 "same angle at the node",
126 if (first_line == next_line) {
131 if (debug_level > 2) {
132 for (i = 0; i < n_lines; i++) {
133 G_debug(3,
" area line (%d) = %d", i, array[i]);
144 if (prev_line == next_line) {
150 for (i = 0; i < n_lines; i++)
151 if (abs(next_line) == abs(array[i])) {
157 if (n_lines >= array_size) {
165 array[n_lines++] = next_line;
166 prev_line = -next_line;
191 register int area, line;
206 G_debug(3,
" new area = %d", area);
216 for (i = 0; i < n_lines; i++) {
218 Area->
lines[i] = line;
219 Line = plus->
Line[abs(line)];
222 if (topo->
left != 0) {
223 G_warning(
_(
"Line %d already has area/isle %d to left"), line,
229 G_debug(3,
" Line %d left set to %d.", line, area);
233 if (topo->
right != 0) {
234 G_warning(
_(
"Line %d already has area/isle %d to right"), line,
240 G_debug(3,
" Line %d right set to %d.", line, area);
247 plus->
Area[area] = Area;
270 G_debug(3,
"dig_area_add_isle(): area = %d isle = %d", area, isle);
272 if (debug_level == -1) {
276 debug_level = atoi(dstr);
281 Area = plus->
Area[area];
285 if (debug_level > 0) {
286 for (i = 0; i < Area->
n_isles; i++) {
287 if (Area->
isles[i] == isle) {
289 G_warning(
_(
"Isle already registered in area"));
319 G_debug(3,
"dig_area_del_isle(): area = %d isle = %d", area, isle);
321 Area = plus->
Area[area];
332 _(
"Attempt to delete not registered isle %d from area %d"), isle,
387 for (i = 0; i < Area->
n_lines; i++) {
388 line = Area->
lines[i];
390 Line = plus->
Line[abs(line)];
393 G_debug(3,
" Set line %d right side to 0", line);
397 G_debug(3,
" Set line %d left side to 0", line);
417 Line = plus->
Line[line];
419 G_warning(
_(
"Dead centroid %d registered for area (bug in the "
440 for (i = 0; i < Area->
n_isles; i++) {
443 G_fatal_error(
_(
"Attempt to delete area %d info from dead isle %d"),
475 int type,
float *angle)
483 if (debug_level == -1) {
487 debug_level = atoi(dstr);
492 G_debug(3,
"dig__angle_next_line: line = %d, side = %d, type = %d",
493 current_line, side,
type);
495 Line = plus->
Line[abs(current_line)];
504 if (current_line > 0) {
529 G_debug(3,
" node = %d", node);
531 Node = plus->
Node[node];
534 if (debug_level > 2) {
537 for (i = 0; i < Node->
n_lines; i++) {
538 G_debug(3,
" i = %d line = %d angle = %f", i, Node->
lines[i],
545 while (next >= 0 && Node->
lines[next] != current_line) {
552 "dig_angle_next_line(): line %d not found at its own node %d",
559 G_debug(3,
" current position = %d", next);
573 G_debug(3,
" next = %d line = %d angle = %f", next, Node->
lines[next],
576 if (Node->
angles[next] == -9.) {
577 G_debug(3,
" point/degenerated -> skip");
578 if (Node->
lines[next] == current_line)
585 line = Node->
lines[next];
586 Line = plus->
Line[abs(line)];
588 if (Line->
type & type) {
591 *angle = Node->
angles[next];
597 if (line == current_line)
600 G_debug(3,
" No next line for line %d at node %d", current_line,
625 float angle1, angle2;
629 G_debug(3,
"dig_node_angle_check: line = %d, type = %d", line,
type);
631 Line = plus->
Line[abs(line)];
665 if (angle1 == angle2) {
668 " The line to the right has the same angle: node = %d, line = %d",
676 if (angle1 == angle2) {
679 " The line to the left has the same angle: node = %d, line = %d",
707 register int isle, line;
733 for (i = 0; i < n_lines; i++) {
735 G_debug(3,
" i = %d line = %d", i, line);
736 Isle->
lines[i] = line;
737 Line = plus->
Line[abs(line)];
740 if (topo->
left != 0) {
741 G_warning(
_(
"Line %d already has area/isle %d to left"), line,
749 if (topo->
right != 0) {
750 G_warning(
_(
"Line %d already has area/isle %d to right"), line,
762 plus->
Isle[isle] = Isle;
788 G_debug(3,
"dig_del_isle() isle = %d", isle);
789 Isle = plus->
Isle[isle];
794 for (i = 0; i < Isle->
n_lines; i++) {
795 line = Isle->
lines[i];
797 Line = plus->
Line[abs(line)];
807 if (Isle->
area > 0) {
809 G_fatal_error(
_(
"Attempt to delete isle %d info from dead area %d"),
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
const char * G_getenv_nofatal(const char *)
Get environment variable.
#define GV_LEFT
Boundary side indicator left/right.
void * dig__falloc(int, int)
int dig_spidx_add_isle(struct Plus_head *, int, const struct bound_box *)
Add new island to spatial index.
void * dig__frealloc(void *, int, int, int)
struct P_isle * dig_alloc_isle(void)
Allocate new isle structure.
float dig_node_line_angle(struct Plus_head *, int, int)
Return line angle.
int dig_spidx_del_area(struct Plus_head *, int)
Delete area from spatial index.
int dig_spidx_add_area(struct Plus_head *, int, const struct bound_box *)
Add new area to spatial index.
int dig_alloc_areas(struct Plus_head *, int)
Reallocate array of pointers to areas.
int dig_alloc_isles(struct Plus_head *, int)
Reallocate array of pointers to isles.
int dig_area_alloc_isle(struct P_area *, int)
Allocate space in P_area for add new isles.
int dig_spidx_del_isle(struct Plus_head *, int)
Delete isle from spatial index.
void dig_free_area(struct P_area *)
Free area structure.
struct P_area * dig_alloc_area(void)
Allocate new area structure.
int dig_isle_alloc_line(struct P_isle *, int)
Allocate space in P_isle for add new lines.
int dig_area_alloc_line(struct P_area *, int)
allocate space in P_area for add new lines
void dig_free_isle(struct P_isle *)
Free isle structure.
int dig_out_of_memory(void)
For now just print message and return error code.
int dig_angle_next_line(struct Plus_head *plus, plus_t current_line, int side, int type, float *angle)
Find line number of next angle to follow a line.
int dig_add_area(struct Plus_head *plus, int n_lines, plus_t *lines, struct bound_box *box)
Allocate space for new area and create boundary info from array.
int dig_area_add_isle(struct Plus_head *plus, int area, int isle)
Add isle to area if does not exist yet.
int dig_node_angle_check(struct Plus_head *plus, plus_t line, int type)
Check if angles of adjacent lines differ.
int dig_add_isle(struct Plus_head *plus, int n_lines, plus_t *lines, struct bound_box *box)
Allocate space for new island and create boundary info from array.
int dig_area_del_isle(struct Plus_head *plus, int area, int isle)
Delete isle from area.
int dig_del_area(struct Plus_head *plus, int area)
Delete area from Plus_head structure.
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_del_isle(struct Plus_head *plus, int isle)
Delete island from Plus_head structure.
plus_t n_isles
Number of islands inside.
plus_t * isles
1st generation interior islands
plus_t n_lines
Number of boundary lines.
plus_t * lines
List of boundary lines.
plus_t centroid
Number of first centroid within area.
plus_t alloc_isles
Allocated space for isles.
plus_t * lines
List of boundary lines.
plus_t n_lines
Number of boundary lines.
plus_t area
Area it exists w/in, if any.
void * topo
Topology info.
Topological feature - node.
plus_t n_lines
Number of attached lines (size of lines, angle)
float * angles
List of angles of connected lines.
plus_t * lines
List of connected lines.
plus_t left
Area number to the left, negative for isle.
plus_t right
Area number to the right, negative for isle.
plus_t area
Area number, negative for duplicate centroid.
Basic topology-related info.
struct P_line ** Line
Array of vector geometries.
plus_t alloc_areas
Number of allocated areas.
struct P_area ** Area
Array of areas.
plus_t alloc_isles
Number of allocated isles.
plus_t n_isles
Current number of isles.
struct P_isle ** Isle
Array of isles.
struct P_node ** Node
Array of nodes.
plus_t n_areas
Current number of areas.