dt_write.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <float.h>
  5. #include <grass/gis.h>
  6. #include <grass/vector.h>
  7. #include <grass/display.h>
  8. #include "sw_defs.h"
  9. #include "defs.h"
  10. #include "write.h"
  11. int write_triple(struct Site *s1, struct Site *s2, struct Site *s3)
  12. {
  13. int i;
  14. int node;
  15. static struct line_pnts *Points = NULL;
  16. static struct line_cats *Cats = NULL;
  17. struct Site *sa, *sb;
  18. if (!Points) {
  19. Points = Vect_new_line_struct();
  20. Cats = Vect_new_cats_struct();
  21. }
  22. if (triangulate) {
  23. for (i = 0; i < 3; i++) {
  24. switch (i) {
  25. case 0:
  26. sa = s1;
  27. sb = s2;
  28. break;
  29. case 1:
  30. sa = s2;
  31. sb = s3;
  32. break;
  33. case 2:
  34. sa = s3;
  35. sb = s1;
  36. break;
  37. }
  38. /* Look if the line already exists */
  39. node =
  40. Vect_find_node(&Out, sa->coord.x, sa->coord.y, 0.0, 0.0, 0);
  41. if (node > 0) { /* node found */
  42. int j, nlines;
  43. int found = 0;
  44. double x, y, z;
  45. nlines = Vect_get_node_n_lines(&Out, node);
  46. for (j = 0; j < nlines; j++) {
  47. int line, node2;
  48. line = Vect_get_node_line(&Out, node, j);
  49. if (line > 0)
  50. Vect_get_line_nodes(&Out, line, NULL, &node2);
  51. else
  52. Vect_get_line_nodes(&Out, abs(line), &node2, NULL);
  53. Vect_get_node_coor(&Out, node2, &x, &y, &z);
  54. if (x == sb->coord.x && y == sb->coord.y) {
  55. found = 1;
  56. break;
  57. }
  58. }
  59. if (found)
  60. continue; /* next segment */
  61. }
  62. /* Not found, write it */
  63. Vect_reset_line(Points);
  64. if (mode3d) {
  65. G_debug(3, "sa->coord.z: %f", sa->coord.z);
  66. Vect_append_point(Points, sa->coord.x, sa->coord.y,
  67. sa->coord.z);
  68. Vect_append_point(Points, sb->coord.x, sb->coord.y,
  69. sb->coord.z);
  70. }
  71. else {
  72. Vect_append_point(Points, sa->coord.x, sa->coord.y, 0.0);
  73. Vect_append_point(Points, sb->coord.x, sb->coord.y, 0.0);
  74. }
  75. Vect_write_line(&Out, Type, Points, Cats);
  76. }
  77. }
  78. return 0;
  79. }