grid.h 3.3 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. /*
  36. A grid in ArcInfo Ascii Grid Format
  37. */
  38. #ifndef __GRID_H
  39. #define __GRID_H
  40. #include <stdio.h>
  41. #include <limits.h>
  42. extern "C"
  43. {
  44. #include <grass/gis.h>
  45. #include <grass/raster.h>
  46. }
  47. #define G_SURFACE_TYPE FCELL_TYPE
  48. typedef float surface_type;
  49. typedef FCELL G_SURFACE_T;
  50. /* this should accomodate grid sizes up to 2^16-1=65,535
  51. If this is not enough, change type and recompile */
  52. typedef unsigned short int dimensionType;
  53. static const dimensionType maxDimension = USHRT_MAX - 1;
  54. typedef struct grid_header
  55. {
  56. dimensionType ncols; /*number of columns in the grid */
  57. dimensionType nrows; /*number of rows in the grid */
  58. double xllcorner; /*xllcorner refers to the western edge of grid */
  59. double yllcorner; /*yllcorner refers to the southern edge of grid */
  60. double ew_res; /*the ew resolution of the grid */
  61. double ns_res; /*the ns resolution of the grid */
  62. surface_type nodata_value; /*the value that represents missing data */
  63. struct Cell_head window;
  64. } GridHeader;
  65. typedef struct grid_
  66. {
  67. GridHeader *hd;
  68. /*two dimensional array holding all the values in the grid */
  69. float **grid_data;
  70. float minvalue; /*the minimum value in the grid */
  71. float maxvalue; /*the maximum value in the grid */
  72. } Grid;
  73. /*copy from b to a */
  74. void copy_header(GridHeader * a, GridHeader b);
  75. /*returns 1 if value is Nodata, 0 if it is not */
  76. int is_nodata(GridHeader * hd, float value);
  77. int is_nodata(Grid * grid, float value);
  78. /* create and return an empty grid */
  79. Grid *create_empty_grid();
  80. /*allocate memory for grid data, grid must have a header */
  81. void alloc_grid_data(Grid * grid);
  82. /*destroy the structure and reclaim all memory allocated */
  83. void destroy_grid(Grid * grid);
  84. #endif