Develop C/C++ code to compute the viewshed of a point on a grid terrain.
The default suggested interface: specify the (name of the) elevation grid, the viewshed grid and the viewpoint coordinates on the command line, like this:
[ltoma@dover:\~] ./viewshed test2.asc test2vis.asc 5 7This will read elevation grid test2.asc, compute the viewshed of viewpoint at row=5 and col=7 and save it as grid test2vis.asc. A point in the viewshed grid can have one or three values: NODATA (if the input point is NODATA), 0 if the point is not visible and 1 if the point is visible.
Implement the (straightforward) O(n \sqrt n) algorithm discussed in class, with linear interpolation.
void compute_viewshed (Grid* eg, Grid * vg, int vprow, int vpcol) {
...
for (i=0; i< g->nrows; i++) {
for (j=0; j< g-> ncols; j++) {
set (vg, i, j) = is_visible(eg, vprow, vpcol, i, j);
}//for j
}//for i
...
}
Enjoy!