eventlist.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /****************************************************************************
  2. *
  3. * MODULE: r.viewshed
  4. *
  5. * AUTHOR(S): Laura Toma, Bowdoin College - ltoma@bowdoin.edu
  6. * Yi Zhuang - yzhuang@bowdoin.edu
  7. *
  8. * Ported to GRASS by William Richard -
  9. * wkrichar@bowdoin.edu or willster3021@gmail.com
  10. * Markus Metz: surface interpolation
  11. *
  12. * Date: april 2011
  13. *
  14. * PURPOSE: To calculate the viewshed (the visible cells in the
  15. * raster) for the given viewpoint (observer) location. The
  16. * visibility model is the following: Two points in the raster are
  17. * considered visible to each other if the cells where they belong are
  18. * visible to each other. Two cells are visible to each other if the
  19. * line-of-sight that connects their centers does not intersect the
  20. * terrain. The terrain is NOT viewed as a tesselation of flat cells,
  21. * i.e. if the line-of-sight does not pass through the cell center,
  22. * elevation is determined using bilinear interpolation.
  23. * The viewshed algorithm is efficient both in
  24. * terms of CPU operations and I/O operations. It has worst-case
  25. * complexity O(n lg n) in the RAM model and O(sort(n)) in the
  26. * I/O-model. For the algorithm and all the other details see the
  27. * paper: "Computing Visibility on * Terrains in External Memory" by
  28. * Herman Haverkort, Laura Toma and Yi Zhuang.
  29. *
  30. * COPYRIGHT: (C) 2008 - 2011 by the GRASS Development Team
  31. *
  32. * This program is free software under the GNU General Public License
  33. * (>=v2). Read the file COPYING that comes with GRASS for details.
  34. *
  35. *****************************************************************************/
  36. #ifndef _EVENTLIST_H
  37. #define _EVENTLIST_H
  38. #include "grid.h"
  39. #include "visibility.h"
  40. #include <grass/iostream/ami.h>
  41. #define ENTERING_EVENT 1
  42. #define EXITING_EVENT -1
  43. #define CENTER_EVENT 0
  44. typedef struct event_
  45. {
  46. dimensionType row, col; //location of the center of cell
  47. // 3 elevation values:
  48. // elev[0]: entering
  49. // elev[1]: center
  50. // elev[2]: exiting
  51. surface_type elev[3]; //elevation here
  52. double angle;
  53. char eventType;
  54. //type of the event: ENTERING_EVENT, EXITING_EVENT, CENTER_EVENT
  55. } AEvent;
  56. /* ------------------------------------------------------------ */
  57. /*determines if the point at row,col is outside the maximum distance
  58. limit wrt viewpoint. Return 1 if the point is outside
  59. limit, 0 if point is inside limit. */
  60. int
  61. is_point_outside_max_dist(Viewpoint vp, GridHeader hd,
  62. dimensionType row, dimensionType col,
  63. float maxDist);
  64. /*sort the event list by the angle around the viewpoint) */
  65. void sort_event_list(AMI_STREAM < AEvent > **eventList);
  66. class RadialCompare
  67. {
  68. public:int compare(const AEvent &, const AEvent &);
  69. };
  70. int radial_compare_events(const void *a, const void *b);
  71. /*sort the event list by the distance from the viewpoint */
  72. class DistanceCompare
  73. {
  74. public:int compare(const AEvent &, const AEvent &);
  75. };
  76. void print_event(AEvent a, int debug_level);
  77. /*computes the distance from the event to the viewpoint. Note: all 3
  78. //events associate to a cell are considered at the same distance, from
  79. //the center of teh cell to the viewpoint */
  80. double get_square_distance_from_viewpoint(const AEvent & a,
  81. const Viewpoint & vp);
  82. /*sort the event list in distance order */
  83. void sort_event_list_by_distance(AMI_STREAM < AEvent > **eventList,
  84. Viewpoint vp);
  85. /*return the angle from this event wrt viewpoint; the type of the
  86. //event is taken into position to compute a different amngle for each
  87. //event associated with a cell */
  88. double calculate_event_angle(AEvent * e, Viewpoint * vp);
  89. /*compute the gradient of the CENTER of this event wrt viewpoint. For
  90. //efficiency it does not compute the gradient, but the square of the
  91. //tan of the gradient. Assuming all gradients are computed the same
  92. //way, this is correct. */
  93. double calculate_center_gradient(AEvent * e, Viewpoint * vp);
  94. /*calculate the exit angle corresponding to this cell */
  95. double calculate_exit_angle(dimensionType row, dimensionType col,
  96. Viewpoint * vp);
  97. /*calculate the enter angle corresponding to this cell */
  98. double calculate_enter_angle(dimensionType row, dimensionType col,
  99. Viewpoint * vp);
  100. /*calculate the exact position of the given event, and store them in x
  101. //and y. */
  102. void calculate_event_position(AEvent e, dimensionType viewpointRow,
  103. dimensionType viewpointCol, double *y,
  104. double *x);
  105. /* calculate the neighbouring row, col of the given event, and store them in x
  106. //and y. */
  107. void
  108. calculate_event_row_col(AEvent e, dimensionType viewpointRow,
  109. dimensionType viewpointCol, int *y, int *x);
  110. double calculate_angle(double eventX, double eventY, double viewpointX,
  111. double viewpointY);
  112. #endif