indep.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (Found >= MaxCellsNum) {
  19. G_debug(1, "Hit maximum number of cells");
  20. break;
  21. }
  22. DRow = DoNext[Count].R;
  23. DCol = DoNext[Count++].C;
  24. if (0 != FlagGet(Cells, DRow, DCol)) {
  25. /* FLAG_SET( Out, DRow, DCol); */
  26. Out[DRow][DCol] = ++Found;
  27. for (R = DRow; R < Rs; R++) {
  28. RowDist = NS * (R - DRow);
  29. if (RowDist > MaxDistSq) {
  30. R = Rs;
  31. }
  32. else {
  33. RowDistSq = RowDist * RowDist;
  34. for (C = DCol; C < Cs; C++) {
  35. ColDist = EW * (C - DCol);
  36. G_debug(3, "(RowDistSq):%.12lf", RowDistSq);
  37. G_debug(3, "(ColDist):%.12lf", ColDist);
  38. G_debug(3, "(MaxDistSq):%.12lf", MaxDistSq);
  39. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  40. if (0 != FlagGet(Cells, R, C)) {
  41. G_debug(2, "unset()");
  42. FLAG_UNSET(Cells, R, C);
  43. CellCount--;
  44. }
  45. }
  46. else {
  47. C = Cs;
  48. }
  49. }
  50. }
  51. }
  52. G_debug(2, "it1()");
  53. for (R = DRow - 1; R >= 0; R--) {
  54. RowDist = NS * (DRow - R);
  55. if (RowDist > MaxDistSq) {
  56. R = 0;
  57. }
  58. else {
  59. RowDistSq = RowDist * RowDist;
  60. for (C = DCol; C < Cs; C++) {
  61. ColDist = EW * (C - DCol);
  62. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  63. if (0 != FlagGet(Cells, R, C)) {
  64. G_debug(2, "unset()");
  65. FLAG_UNSET(Cells, R, C);
  66. CellCount--;
  67. }
  68. }
  69. else {
  70. C = Cs;
  71. }
  72. }
  73. }
  74. }
  75. G_debug(2, "it2()");
  76. for (R = DRow; R < Rs; R++) {
  77. RowDist = NS * (R - DRow);
  78. if (RowDist > MaxDistSq) {
  79. R = Rs;
  80. }
  81. else {
  82. RowDistSq = RowDist * RowDist;
  83. for (C = DCol - 1; C >= 0; C--) {
  84. ColDist = EW * (DCol - C);
  85. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  86. if (0 != FlagGet(Cells, R, C)) {
  87. G_debug(2, "unset()");
  88. FLAG_UNSET(Cells, R, C);
  89. CellCount--;
  90. }
  91. }
  92. else {
  93. C = 0;
  94. }
  95. }
  96. }
  97. }
  98. G_debug(2, "it3()");
  99. for (R = DRow - 1; R >= 0; R--) {
  100. RowDist = NS * (DRow - R);
  101. if (RowDist > MaxDistSq) {
  102. R = 0;
  103. }
  104. else {
  105. RowDistSq = RowDist * RowDist;
  106. for (C = DCol - 1; C >= 0; C--) {
  107. ColDist = EW * (DCol - C);
  108. if (MaxDistSq >= RowDistSq + ColDist * ColDist) {
  109. if (0 != FlagGet(Cells, R, C)) {
  110. G_debug(2, "unset()");
  111. FLAG_UNSET(Cells, R, C);
  112. CellCount--;
  113. }
  114. }
  115. else {
  116. C = 0;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. G_debug(2, "outputting()");
  124. OutFD = Rast_open_c_new(Output->answer);
  125. G_message(_("Writing raster map <%s>..."),
  126. Output->answer);
  127. for (R = 0; R < Rs; R++) {
  128. G_percent(R, Rs, 2);
  129. for (C = 0; C < Cs; C++) {
  130. CellBuffer[C] = Out[R][C];
  131. if(CellBuffer[C] == 0)
  132. Rast_set_null_value(&CellBuffer[C], 1, CELL_TYPE);
  133. }
  134. Rast_put_row(OutFD, CellBuffer, CELL_TYPE);
  135. }
  136. G_percent(1, 1, 1);
  137. Rast_close(OutFD);
  138. Rast_short_history(Output->answer, "raster", &history);
  139. Rast_command_history(&history);
  140. Rast_write_history(Output->answer, &history);
  141. }