grass.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 _GRASS_H
  36. #define _GRASS_H
  37. #include <math.h>
  38. extern "C"
  39. {
  40. #include <grass/gis.h>
  41. #include <grass/raster.h>
  42. #include <grass/glocale.h>
  43. }
  44. #include "eventlist.h"
  45. #include "grid.h"
  46. #include "visibility.h"
  47. /* ------------------------------------------------------------ */
  48. /* if viewOptions.doCurv is on then adjust the passed height for
  49. curvature of the earth; otherwise return the passed height
  50. unchanged.
  51. */
  52. float adjust_for_curvature(Viewpoint vp, double row,
  53. double col, float h,
  54. ViewOptions viewOptions);
  55. /* helper function to deal with GRASS writing to a row buffer */
  56. void writeValue(void *ptr, int j, double x, RASTER_MAP_TYPE data_type);
  57. void writeNodataValue(void *ptr, int j, RASTER_MAP_TYPE data_type);
  58. /*return a GridHeader with all the relevant data filled in from GRASS */
  59. GridHeader *read_header(char *rastName, Cell_head * region);
  60. /* calculate ENTER and EXIT event elevation */
  61. surface_type calculate_event_elevation(AEvent e, int nrows, int ncols,
  62. dimensionType vprow, dimensionType vpcol,
  63. G_SURFACE_T **inrast, RASTER_MAP_TYPE data_type);
  64. /* ************************************************************ */
  65. /* input: an array capable to hold the max number of events, a raster
  66. name, a viewpoint and the viewOptions; action: figure out all events
  67. in the input file, and write them to the event list. data is
  68. allocated and initialized with all the cells on the same row as the
  69. viewpoint. it returns the number of events. initialize and fill
  70. AEvent* with all the events for the map. Used when solving in
  71. memory, so the AEvent* should fit in memory. */
  72. size_t
  73. init_event_list_in_memory(AEvent * eventList, char *rastName,
  74. Viewpoint * vp, GridHeader * hd,
  75. ViewOptions viewOptions, surface_type ***data,
  76. MemoryVisibilityGrid * visgrid);
  77. /* ************************************************************ */
  78. /* input: an arcascii file, a grid header and a viewpoint; action:
  79. figure out all events in the input file, and write them to the
  80. stream. It assumes the file pointer is positioned rigth after the
  81. grid header so that this function can read all grid elements.
  82. if data is not NULL, it creates an array that stores all events on
  83. the same row as the viewpoint.
  84. */
  85. AMI_STREAM < AEvent > *init_event_list(char *rastName, Viewpoint * vp,
  86. GridHeader * hd,
  87. ViewOptions viewOptions,
  88. surface_type ***data,
  89. IOVisibilityGrid * visgrid);
  90. /* ************************************************************ */
  91. /* saves the grid into a GRASS raster. Loops through all elements x
  92. in row-column order and writes fun(x) to file. */
  93. void
  94. save_grid_to_GRASS(Grid * grid, char *filename, RASTER_MAP_TYPE type,
  95. float (*fun) (float));
  96. /* ************************************************************ */
  97. /* using the visibility information recorded in visgrid, it creates an
  98. output viewshed raster with name outfname; for every point p that
  99. is visible in the grid, the corresponding value in the output
  100. raster is elevation(p) - viewpoint_elevation(p); the elevation
  101. values are read from elevfname raster */
  102. void
  103. save_vis_elev_to_GRASS(Grid * visgrid, char *elevfname, char *visfname,
  104. float vp_elev);
  105. /* ************************************************************ */
  106. /* write the visibility grid to GRASS. assume all cells that are not
  107. in stream are NOT visible. assume stream is sorted in (i,j) order.
  108. for each value x it writes to grass fun(x) */
  109. void
  110. save_io_visibilitygrid_to_GRASS(IOVisibilityGrid * visgrid,
  111. char *outfname, RASTER_MAP_TYPE type,
  112. float (*fun) (float));
  113. /* ************************************************************ */
  114. /* using the visibility information recorded in visgrid, it creates
  115. an output viewshed raster with name outfname; for every point p
  116. that is visible in the grid, the corresponding value in the output
  117. raster is elevation(p) - viewpoint_elevation(p); the elevation
  118. values are read from elevfname raster. assume stream is sorted in
  119. (i,j) order. */
  120. void
  121. save_io_vis_and_elev_to_GRASS(IOVisibilityGrid * visgrid, char *elevfname,
  122. char *visfname, float vp_elev);
  123. #endif/*_GRASS_H*/