statusstructure.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /****************************************************************************
  2. *
  3. * MODULE: r.viewshed
  4. *
  5. * AUTHOR(S): Laura Toma, Bowdoin College - ltoma@bowdoin.edu
  6. * Yi Zhuang - yzhuang@bowdoin.edu
  7. * Ported to GRASS by William Richard -
  8. * wkrichar@bowdoin.edu or willster3021@gmail.com
  9. * Markus Metz: surface interpolation
  10. *
  11. * Date: april 2011
  12. *
  13. * PURPOSE: To calculate the viewshed (the visible cells in the
  14. * raster) for the given viewpoint (observer) location. The
  15. * visibility model is the following: Two points in the raster are
  16. * considered visible to each other if the cells where they belong are
  17. * visible to each other. Two cells are visible to each other if the
  18. * line-of-sight that connects their centers does not intersect the
  19. * terrain. The terrain is NOT viewed as a tesselation of flat cells,
  20. * i.e. if the line-of-sight does not pass through the cell center,
  21. * elevation is determined using bilinear interpolation.
  22. * The viewshed algorithm is efficient both in
  23. * terms of CPU operations and I/O operations. It has worst-case
  24. * complexity O(n lg n) in the RAM model and O(sort(n)) in the
  25. * I/O-model. For the algorithm and all the other details see the
  26. * paper: "Computing Visibility on * Terrains in External Memory" by
  27. * Herman Haverkort, Laura Toma and Yi Zhuang.
  28. *
  29. * COPYRIGHT: (C) 2008 by the GRASS Development Team
  30. *
  31. * This program is free software under the GNU General Public License
  32. * (>=v2). Read the file COPYING that comes with GRASS for details.
  33. *
  34. *****************************************************************************/
  35. #ifndef _YZ__STATUSSTRUCTURE_H
  36. #define _YZ__STATUSSTRUCTURE_H
  37. /*
  38. This header file defines the status structure and related functions.
  39. */
  40. #include <grass/gis.h>
  41. #include "grid.h"
  42. #include "rbbst.h"
  43. #include "visibility.h"
  44. typedef struct statusnode_
  45. {
  46. dimensionType row, col; /*position of the cell */
  47. /* float elev; */ /*elevation of cell */
  48. double dist2vp; /*distance to the viewpoint */
  49. double gradient[3]; /*ENTER, CENTER, EXIT gradients of the Line of Sight */
  50. double angle[3]; /*ENTER, CENTER, EXIT angles of the Line of Sight */
  51. /* double gradient_offset; */ /*gradient of the Line of Sight with local elevation offset */
  52. } StatusNode;
  53. typedef struct statuslist_
  54. {
  55. RBTree *rbt; /*pointer to the root of the bst */
  56. } StatusList;
  57. /* ------------------------------------------------------------ */
  58. /*return an estimate of the size of active structure */
  59. long long get_active_str_size_bytes(GridHeader * hd);
  60. /*given a StatusNode, fill in its dist2vp and gradient */
  61. void calculate_dist_n_gradient(StatusNode * sn, double elev,
  62. Viewpoint * vp, GridHeader hd);
  63. /* calculate gradient for ENTERING or EXITING event */
  64. void calculate_event_gradient(StatusNode * sn, int e_idx,
  65. double row, double col, double elev,
  66. Viewpoint * vp, GridHeader hd);
  67. /*create an empty status list. */
  68. StatusList *create_status_struct();
  69. void delete_status_structure(StatusList * sl);
  70. /*returns true is it is empty */
  71. int is_empty(StatusList * sl);
  72. /*delete the statusNode with the given key */
  73. void delete_from_status_struct(StatusList * sl, double dist2vp);
  74. /*insert the element into the status structure */
  75. void insert_into_status_struct(StatusNode sn, StatusList * sl);
  76. /*find the node with max Gradient. The node must be
  77. //within the distance (from viewpoint) given */
  78. double find_max_gradient_in_status_struct(StatusList * sl, double dist, double angle, double gradient);
  79. /*find the vertical angle in degrees between the viewpoint and the
  80. point represented by the StatusNode. Assumes all values (except
  81. gradient) in sn have been filled. */
  82. float get_vertical_angle(Viewpoint vp, StatusNode sn, surface_type elev, int doCurv);
  83. #endif