~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.viewshed/visibility.h

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/****************************************************************************
 
3
 *
 
4
 * MODULE:       r.viewshed
 
5
 *
 
6
 * AUTHOR(S):    Laura Toma, Bowdoin College - ltoma@bowdoin.edu
 
7
 *               Yi Zhuang - yzhuang@bowdoin.edu
 
8
 
 
9
 *               Ported to GRASS by William Richard -
 
10
 *               wkrichar@bowdoin.edu or willster3021@gmail.com
 
11
 *               Markus Metz: surface interpolation
 
12
 *
 
13
 * Date:         april 2011 
 
14
 * 
 
15
 * PURPOSE: To calculate the viewshed (the visible cells in the
 
16
 * raster) for the given viewpoint (observer) location.  The
 
17
 * visibility model is the following: Two points in the raster are
 
18
 * considered visible to each other if the cells where they belong are
 
19
 * visible to each other.  Two cells are visible to each other if the
 
20
 * line-of-sight that connects their centers does not intersect the
 
21
 * terrain. The terrain is NOT viewed as a tesselation of flat cells, 
 
22
 * i.e. if the line-of-sight does not pass through the cell center, 
 
23
 * elevation is determined using bilinear interpolation.
 
24
 * The viewshed algorithm is efficient both in
 
25
 * terms of CPU operations and I/O operations. It has worst-case
 
26
 * complexity O(n lg n) in the RAM model and O(sort(n)) in the
 
27
 * I/O-model.  For the algorithm and all the other details see the
 
28
 * paper: "Computing Visibility on * Terrains in External Memory" by
 
29
 * Herman Haverkort, Laura Toma and Yi Zhuang.
 
30
 *
 
31
 * COPYRIGHT: (C) 2008 by the GRASS Development Team
 
32
 *
 
33
 * This program is free software under the GNU General Public License
 
34
 * (>=v2). Read the file COPYING that comes with GRASS for details.
 
35
 *
 
36
 *****************************************************************************/
 
37
 
 
38
#ifndef visibility_h
 
39
#define visibility_h
 
40
 
 
41
#include <grass/config.h>
 
42
#include <grass/iostream/ami.h>
 
43
 
 
44
 
 
45
#include "grid.h"
 
46
 
 
47
 
 
48
 
 
49
/*  default max distance */
 
50
#define  INFINITY_DISTANCE  -1
 
51
 
 
52
/* File/directory name lengths for GRASS compatibility */
 
53
#define GNAME_MAX 256
 
54
#define GPATH_MAX 4096
 
55
 
 
56
 
 
57
typedef struct viewpoint_
 
58
{
 
59
    dimensionType row, col;
 
60
    float elev;
 
61
    float target_offset;
 
62
} Viewpoint;
 
63
 
 
64
 
 
65
typedef enum
 
66
{
 
67
    VISIBLE = 1,
 
68
    INVISIBLE = -1,
 
69
 
 
70
    /*boolean values for output */
 
71
    BOOL_VISIBLE = 1,
 
72
    BOOL_INVISIBLE = 0
 
73
} VisMode;
 
74
 
 
75
 
 
76
typedef struct visCell_
 
77
{
 
78
    dimensionType row;
 
79
    dimensionType col;
 
80
    /*   VisMode vis; */
 
81
    float angle;
 
82
} VisCell;
 
83
 
 
84
 
 
85
 
 
86
typedef enum outputMode_
 
87
{
 
88
    OUTPUT_ANGLE = 0,
 
89
    OUTPUT_BOOL = 1,
 
90
    OUTPUT_ELEV = 2
 
91
} OutputMode;
 
92
 
 
93
 
 
94
typedef struct viewOptions_
 
95
{
 
96
 
 
97
    /* the name of the input raster */
 
98
    char inputfname[GNAME_MAX];
 
99
 
 
100
    /* the name of the output raster */
 
101
    char outputfname[GNAME_MAX];
 
102
 
 
103
    float obsElev;
 
104
    /* observer elevation above the terrain */
 
105
 
 
106
    float tgtElev;
 
107
    /* target elevation offset above the terrain */
 
108
 
 
109
    float maxDist;
 
110
    /* points that are farther than this distance from the viewpoint are
 
111
       not visible  */
 
112
 
 
113
    OutputMode outputMode;
 
114
    /* The mode the viewshed is output; 
 
115
       - in angle mode, the values recorded are   {NODATA, INVISIBLE, angle}
 
116
       - in boolean mode, the values recorded are {BOOL_INVISIBLE, BOOL_VISIBLE}
 
117
       - in elev mode, the values recorded are    {NODATA, INVISIBLE, elevation}
 
118
     */
 
119
 
 
120
    int doCurv;
 
121
    /*determines if the curvature of the earth should be considered
 
122
       when calculating.  Only implemented for GRASS version. */
 
123
 
 
124
    int doRefr;
 
125
    double refr_coef;
 
126
    /*determines if atmospheric refraction should be considered
 
127
       when calculating.  Only implemented for GRASS version. */
 
128
 
 
129
    double ellps_a;             /* the parameter of the ellipsoid */
 
130
    float cellsize;             /* the cell resolution */
 
131
    char streamdir[GPATH_MAX];  /* directory for tmp files */
 
132
} ViewOptions;
 
133
 
 
134
 
 
135
 
 
136
 
 
137
/*memory visibility grid */
 
138
typedef struct memory_visibility_grid_
 
139
{
 
140
    Grid *grid;
 
141
    Viewpoint *vp;
 
142
} MemoryVisibilityGrid;
 
143
 
 
144
 
 
145
/*io-efficient visibility grid */
 
146
typedef struct IOvisibility_grid_
 
147
{
 
148
    GridHeader *hd;
 
149
    Viewpoint *vp;
 
150
      AMI_STREAM < VisCell > *visStr;
 
151
} IOVisibilityGrid;
 
152
 
 
153
 
 
154
 
 
155
 
 
156
/* ------------------------------------------------------------ */
 
157
/* visibility output functions */
 
158
 
 
159
/*  The following functions are used to convert the visibility results
 
160
   recorded during the viewshed computation into the output grid into
 
161
   the format required by the user.  x is assumed to be the
 
162
   visibility angle computed for a cell during the viewshed
 
163
   computation. 
 
164
 
 
165
   The value passed to this function is the following: x is NODATA if the
 
166
   cell is NODATA; x is INVISIBLE if the cell is invisible; x is the
 
167
   vertical angle of the cell wrt the viewpoint if the cell is
 
168
   visible---the angle is a value in (0,180).
 
169
 */
 
170
/* these functions assume that x is a value computed during the
 
171
   viewshed computation; right now x represents the vertical angle of a
 
172
   visible point wrt to the viewpoint; INVISIBLE if invisible; NODATA if
 
173
   nodata. They return true if x is visible, invisible but nodata,
 
174
   andnodata, respectively  */
 
175
int is_visible(float x);
 
176
int is_invisible_not_nodata(float x);
 
177
int is_invisible_nodata(float x);
 
178
 
 
179
/* This function is called when the program runs in
 
180
   viewOptions.outputMode == OUTPUT_BOOL. */
 
181
float booleanVisibilityOutput(float x);
 
182
 
 
183
/* This function is called when the program runs in
 
184
   viewOptions.outputMode == OUTPUT_ANGLE.   */
 
185
float angleVisibilityOutput(float x);
 
186
 
 
187
 
 
188
 
 
189
 
 
190
 
 
191
/* ------------------------------------------------------------ */
 
192
/* viewpoint functions */
 
193
 
 
194
void print_viewpoint(Viewpoint vp);
 
195
 
 
196
/*copy from b to a */
 
197
void copy_viewpoint(Viewpoint * a, Viewpoint b);
 
198
 
 
199
void
 
200
set_viewpoint_coord(Viewpoint * vp, dimensionType row, dimensionType col);
 
201
 
 
202
void set_viewpoint_elev(Viewpoint * vp, float elev);
 
203
 
 
204
 
 
205
 
 
206
/* ------------------------------------------------------------ */
 
207
/* MemoryVisibilityGrid functions */
 
208
 
 
209
MemoryVisibilityGrid *create_inmem_visibilitygrid(GridHeader hd,
 
210
                                                  Viewpoint vp);
 
211
 
 
212
void free_inmem_visibilitygrid(MemoryVisibilityGrid * visgrid);
 
213
 
 
214
void set_inmem_visibilitygrid(MemoryVisibilityGrid * visgrid, float val);
 
215
 
 
216
void add_result_to_inmem_visibilitygrid(MemoryVisibilityGrid * visgrid,
 
217
                                        dimensionType i, dimensionType j,
 
218
                                        float val);
 
219
 
 
220
void save_inmem_visibilitygrid(MemoryVisibilityGrid * vigrid,
 
221
                               ViewOptions viewopt, Viewpoint vp);
 
222
 
 
223
 
 
224
/* ------------------------------------------------------------ */
 
225
/* IOVisibilityGrid functions */
 
226
 
 
227
/*create grid from given header and viewpoint */
 
228
IOVisibilityGrid *init_io_visibilitygrid(GridHeader hd, Viewpoint vp);
 
229
 
 
230
/*frees a visibility grid */
 
231
void free_io_visibilitygrid(IOVisibilityGrid * grid);
 
232
 
 
233
/*write cell to stream */
 
234
void add_result_to_io_visibilitygrid(IOVisibilityGrid * visgrid,
 
235
                                     VisCell * cell);
 
236
 
 
237
/*void
 
238
   addResult(IOVisibilityGrid* visgrid, DimensionType row, DimensionType col, 
 
239
   VisMode vis);
 
240
 */
 
241
 
 
242
 
 
243
/* write visibility grid. assume all cells that are not in stream are
 
244
   NOT visible.  assume stream is sorted.  */
 
245
void
 
246
save_io_visibilitygrid(IOVisibilityGrid * visgrid,
 
247
                       ViewOptions viewoptions, Viewpoint vp);
 
248
 
 
249
 
 
250
/*sort stream in grid (i,j) order */
 
251
void sort_io_visibilitygrid(IOVisibilityGrid * visGrid);
 
252
 
 
253
class IJCompare
 
254
{
 
255
  public:
 
256
    int compare(const VisCell &, const VisCell &);
 
257
};
 
258
 
 
259
 
 
260
 
 
261
#endif