indep.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* indep.c */
  2. #include <grass/gis.h>
  3. #include <grass/raster.h>
  4. #include <grass/glocale.h>
  5. #include "ransurf.h"
  6. void Indep(void)
  7. {
  8. int Count, DRow, DCol;
  9. int Found, R, C;
  10. double RowDist, RowDistSq, ColDist;
  11. struct History history;
  12. G_debug(2, "indep()");
  13. Count = 0;
  14. Found = 0;
  15. while (CellCount > 0) {
  16. G_debug(3, "(CellCount):%d", CellCount);
  17. G_debug(3, "(Count):%d", Count);
  18. DRow = DoNext[Count].R;
  19. DCol = DoNext[Count++].C;
  20. if (0 != FlagGet(Cells, DRow, DCol)) {
  21. /* FLAG_SET( Out, DRow, DCol); */
  22. Out[DRow][DCol] = ++Found;
  23. for (R = DRow; R < Rs; R++) {
  24. RowDist = NS * (R - DRow);
  25. if (RowDist > MaxDistSq) {
  26. R = Rs;
  27. }
  28. else {
  29. RowDistSq = RowDist * RowDist;
  30. for (C = DCol; C < Cs; C++) {
  31. ColDist = EW * (C - DCol);
  32. G_debug(3, "(RowDistSq):%.12lf", RowDistSq);
  33. G_debug(3, "(ColDist):%.12lf", ColDist);
  34. G_debug(3, "(MaxDistSq):%.12lf", MaxDistSq);
  35. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  36. if (0 != FlagGet(Cells, R, C)) {
  37. G_debug(2, "unset()");
  38. FLAG_UNSET(Cells, R, C);
  39. CellCount--;
  40. }
  41. }
  42. else {
  43. C = Cs;
  44. }
  45. }
  46. }
  47. }
  48. G_debug(2, "it1()");
  49. for (R = DRow - 1; R >= 0; R--) {
  50. RowDist = NS * (DRow - R);
  51. if (RowDist > MaxDistSq) {
  52. R = 0;
  53. }
  54. else {
  55. RowDistSq = RowDist * RowDist;
  56. for (C = DCol; C < Cs; C++) {
  57. ColDist = EW * (C - DCol);
  58. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  59. if (0 != FlagGet(Cells, R, C)) {
  60. G_debug(2, "unset()");
  61. FLAG_UNSET(Cells, R, C);
  62. CellCount--;
  63. }
  64. }
  65. else {
  66. C = Cs;
  67. }
  68. }
  69. }
  70. }
  71. G_debug(2, "it2()");
  72. for (R = DRow; R < Rs; R++) {
  73. RowDist = NS * (R - DRow);
  74. if (RowDist > MaxDistSq) {
  75. R = Rs;
  76. }
  77. else {
  78. RowDistSq = RowDist * RowDist;
  79. for (C = DCol - 1; C >= 0; C--) {
  80. ColDist = EW * (DCol - C);
  81. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  82. if (0 != FlagGet(Cells, R, C)) {
  83. G_debug(2, "unset()");
  84. FLAG_UNSET(Cells, R, C);
  85. CellCount--;
  86. }
  87. }
  88. else {
  89. C = 0;
  90. }
  91. }
  92. }
  93. }
  94. G_debug(2, "it3()");
  95. for (R = DRow - 1; R >= 0; R--) {
  96. RowDist = NS * (DRow - R);
  97. if (RowDist > MaxDistSq) {
  98. R = 0;
  99. }
  100. else {
  101. RowDistSq = RowDist * RowDist;
  102. for (C = DCol - 1; C >= 0; C--) {
  103. ColDist = EW * (DCol - C);
  104. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  105. if (0 != FlagGet(Cells, R, C)) {
  106. G_debug(2, "unset()");
  107. FLAG_UNSET(Cells, R, C);
  108. CellCount--;
  109. }
  110. }
  111. else {
  112. C = 0;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. G_debug(2, "outputting()");
  120. OutFD = Rast_open_c_new(Output->answer);
  121. G_message(_("Writing raster map <%s>..."),
  122. Output->answer);
  123. for (R = 0; R < Rs; R++) {
  124. G_percent(R, Rs, 2);
  125. for (C = 0; C < Cs; C++) {
  126. CellBuffer[C] = Out[R][C];
  127. }
  128. Rast_put_row(OutFD, CellBuffer, CELL_TYPE);
  129. }
  130. G_percent(1, 1, 1);
  131. Rast_close(OutFD);
  132. Rast_short_history(Output->answer, "raster", &history);
  133. Rast_command_history(&history);
  134. Rast_write_history(Output->answer, &history);
  135. }