GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
plus_line.c
Go to the documentation of this file.
1 
17 #include <stdlib.h>
18 #include <grass/Vect.h>
19 
20 static int add_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points,
21  long offset)
22 {
23  int node, lp;
24  P_LINE *line;
25  BOUND_BOX box;
26 
27  plus->Line[lineid] = dig_alloc_line();
28  line = plus->Line[lineid];
29 
30  /* Add nodes */
31  G_debug(3, "Register node: type = %d, %f,%f", type, Points->x[0],
32  Points->y[0]);
33 
34  node = dig_find_node(plus, Points->x[0], Points->y[0], Points->z[0]);
35  G_debug(3, "node = %d", node);
36  if (node == 0) {
37  node = dig_add_node(plus, Points->x[0], Points->y[0], Points->z[0]);
38  G_debug(3, "Add new node: %d", node);
39  }
40  else {
41  G_debug(3, "Old node found: %d", node);
42  }
43  line->N1 = node;
44  dig_node_add_line(plus, node, lineid, Points, type);
45  if (plus->do_uplist)
46  dig_node_add_updated(plus, node);
47 
48  if (type & GV_LINES) {
49  lp = Points->n_points - 1;
50  G_debug(3, "Register node %f,%f", Points->x[lp], Points->y[lp]);
51  node =
52  dig_find_node(plus, Points->x[lp], Points->y[lp], Points->z[lp]);
53  G_debug(3, "node = %d", node);
54  if (node == 0) {
55  node =
56  dig_add_node(plus, Points->x[lp], Points->y[lp],
57  Points->z[lp]);
58  G_debug(3, "Add new node: %d", node);
59  }
60  else {
61  G_debug(3, "Old node found: %d", node);
62  }
63  line->N2 = node;
64  dig_node_add_line(plus, node, -lineid, Points, type);
65  if (plus->do_uplist)
66  dig_node_add_updated(plus, node);
67  }
68  else {
69  line->N2 = 0;
70  }
71 
72  line->type = type;
73  line->offset = offset;
74  line->left = 0;
75  line->right = 0;
76  line->N = 0;
77  line->S = 0;
78  line->E = 0;
79  line->W = 0;
80 
81  dig_line_box(Points, &box);
82  dig_line_set_box(plus, lineid, &box);
83  dig_spidx_add_line(plus, lineid, &box);
84  if (plus->do_uplist)
85  dig_line_add_updated(plus, lineid);
86 
87  return (lineid);
88 }
89 
101 int
102 dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points,
103  long offset)
104 {
105  int ret;
106 
107  /* First look if we have space in array of pointers to lines
108  * and reallocate if necessary */
109  if (plus->n_lines >= plus->alloc_lines) { /* array is full */
110  if (dig_alloc_lines(plus, 1000) == -1)
111  return -1;
112  }
113 
114  ret = add_line(plus, plus->n_lines + 1, type, Points, offset);
115 
116  if (ret == -1)
117  return ret;
118 
119  plus->n_lines++;
120 
121  switch (type) {
122  case GV_POINT:
123  plus->n_plines++;
124  break;
125  case GV_LINE:
126  plus->n_llines++;
127  break;
128  case GV_BOUNDARY:
129  plus->n_blines++;
130  break;
131  case GV_CENTROID:
132  plus->n_clines++;
133  break;
134  case GV_FACE:
135  plus->n_flines++;
136  break;
137  case GV_KERNEL:
138  plus->n_klines++;
139  break;
140  }
141 
142  return ret;
143 }
144 
156 int
157 dig_restore_line(struct Plus_head *plus, int lineid,
158  int type, struct line_pnts *Points,
159  long offset)
160 {
161  if (lineid < 1 || lineid > plus->n_lines) {
162  return -1;
163  }
164 
165  return add_line(plus, lineid, type, Points, offset);
166 }
167 
183 int dig_del_line(struct Plus_head *plus, int line)
184 {
185  int i, mv;
186  P_LINE *Line;
187  P_NODE *Node;
188 
189  /* TODO: free structures */
190  G_debug(3, "dig_del_line() line = %d", line);
191 
192  Line = plus->Line[line];
193  dig_spidx_del_line(plus, line);
194 
195  /* Delete from nodes (and nodes) */
196  Node = plus->Node[Line->N1];
197  mv = 0;
198  for (i = 0; i < Node->n_lines; i++) {
199  if (mv) {
200  Node->lines[i - 1] = Node->lines[i];
201  Node->angles[i - 1] = Node->angles[i];
202  }
203  else {
204  if (abs(Node->lines[i]) == line)
205  mv = 1;
206  }
207  }
208  Node->n_lines--;
209  if (Node->n_lines == 0) {
210  G_debug(3, " node %d has 0 lines -> delete", Line->N1);
211  dig_spidx_del_node(plus, Line->N1);
212  plus->Node[Line->N1] = NULL;
213  }
214  else {
215  if (plus->do_uplist)
216  dig_node_add_updated(plus, Line->N1);
217  }
218 
219  if (Line->type & GV_LINES) {
220  Node = plus->Node[Line->N2];
221  mv = 0;
222  for (i = 0; i < Node->n_lines; i++) {
223  if (mv) {
224  Node->lines[i - 1] = Node->lines[i];
225  Node->angles[i - 1] = Node->angles[i];
226  }
227  else {
228  if (abs(Node->lines[i]) == line)
229  mv = 1;
230  }
231  }
232  Node->n_lines--;
233  if (Node->n_lines == 0) {
234  G_debug(3, " node %d has 0 lines -> delete", Line->N2);
235  dig_spidx_del_node(plus, Line->N2);
236  plus->Node[Line->N2] = NULL;
237  }
238  else {
239  if (plus->do_uplist)
240  dig_node_add_updated(plus, Line->N2);
241  }
242  }
243 
244  /* Delete line */
245  plus->Line[line] = NULL;
246 
247  return 0;
248 }
249 
261 plus_t dig_line_get_area(struct Plus_head * plus, plus_t line, int side)
262 {
263  P_LINE *Line;
264 
265  Line = plus->Line[line];
266  if (side == GV_LEFT) {
267  G_debug(3,
268  "dig_line_get_area(): line = %d, side = %d (left), area = %d",
269  line, side, Line->left);
270  return (Line->left);
271  }
272  if (side == GV_RIGHT) {
273  G_debug(3,
274  "dig_line_get_area(): line = %d, side = %d (right), area = %d",
275  line, side, Line->right);
276 
277  return (Line->right);
278  }
279 
280  return (-1);
281 }
282 
293 int
294 dig_line_set_area(struct Plus_head *plus, plus_t line, int side, plus_t area)
295 {
296  P_LINE *Line;
297 
298  Line = plus->Line[line];
299  if (side == GV_LEFT) {
300  Line->left = area;
301  }
302  else if (side == GV_RIGHT) {
303  Line->right = area;
304  }
305 
306  return (1);
307 }
308 
318 int dig_line_set_box(struct Plus_head *plus, plus_t line, BOUND_BOX * Box)
319 {
320  P_LINE *Line;
321 
322  Line = plus->Line[line];
323 
324  Line->N = Box->N;
325  Line->S = Box->S;
326  Line->E = Box->E;
327  Line->W = Box->W;
328  Line->T = Box->T;
329  Line->B = Box->B;
330 
331  return (1);
332 }
333 
343 int dig_line_get_box(struct Plus_head *plus, plus_t line, BOUND_BOX * Box)
344 {
345  P_LINE *Line;
346 
347  Line = plus->Line[line];
348 
349  Box->N = Line->N;
350  Box->S = Line->S;
351  Box->E = Line->E;
352  Box->W = Line->W;
353  Box->T = Line->T;
354  Box->B = Line->B;
355 
356  return (1);
357 }
int dig_line_box(struct line_pnts *Points, BOUND_BOX *Box)
Definition: diglib/box.c:24
int dig_spidx_add_line(struct Plus_head *Plus, int line, BOUND_BOX *box)
Add new line to spatial index.
Definition: spindex.c:148
float Box[8][3]
Vertices for box.
Definition: gsd_objs.c:1420
int dig_spidx_del_node(struct Plus_head *Plus, int node)
Delete node from spatial index.
Definition: spindex.c:228
int dig_add_line(struct Plus_head *plus, int type, struct line_pnts *Points, long offset)
Add new line to Plus_head structure.
Definition: plus_line.c:102
Definition: index.h:56
int dig_node_add_line(struct Plus_head *plus, int nodeid, int lineid, struct line_pnts *points, int type)
Add line info to node.
Definition: plus_node.c:42
tuple box
surface = wx.CheckBox(parent = panel, id = wx.ID_ANY, label = _(&quot;Follow source viewpoint&quot;)) pageSizer...
Definition: tools.py:1527
void dig_node_add_updated(struct Plus_head *Plus, int node)
Add node to updated.
int dig_add_node(struct Plus_head *plus, double x, double y, double z)
Add new node to plus structure.
Definition: plus_node.c:106
int dig_line_get_box(struct Plus_head *plus, plus_t line, BOUND_BOX *Box)
Get line bounding box saved in topo.
Definition: plus_line.c:343
int dig_line_set_area(struct Plus_head *plus, plus_t line, int side, plus_t area)
Set area number on line side.
Definition: plus_line.c:294
int GV_LINES
Definition: vdigit/main.py:24
int dig_del_line(struct Plus_head *plus, int line)
Delete line from Plus_head structure.
Definition: plus_line.c:183
int dig_restore_line(struct Plus_head *plus, int lineid, int type, struct line_pnts *Points, long offset)
Restore line in Plus_head structure.
Definition: plus_line.c:157
P_LINE * dig_alloc_line()
Definition: struct_alloc.c:110
return NULL
Definition: dbfopen.c:1394
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int dig_alloc_lines(struct Plus_head *Plus, int add)
Definition: struct_alloc.c:127
void dig_line_add_updated(struct Plus_head *Plus, int line)
Add new line to updated.
int dig_find_node(struct Plus_head *Plus, double x, double y, double z)
Find one node by coordinates.
Definition: spindex.c:420
plus_t dig_line_get_area(struct Plus_head *plus, plus_t line, int side)
Get area number on line side.
Definition: plus_line.c:261
int dig_line_set_box(struct Plus_head *plus, plus_t line, BOUND_BOX *Box)
Set line bounding box.
Definition: plus_line.c:318
int dig_spidx_del_line(struct Plus_head *Plus, int line)
Delete line from spatial index.
Definition: spindex.c:263