Project: Visibility on terrains

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 7

This 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.

Outline

As we moved from scripted assignments towards projects, I am providing no structure/guidelines on how to organize your code. Feel free to design your code as you like. My only suggestion is that you split the viewshed function into (at least) two functions: one that computes whether a specific point (i,j) is visible from (vprow,vpcol); and one that calls this function in a loop, for every point (i,j):
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
...
}


Testing

I am including the output for set1.asc from vp=(100,100) here and from vp=(250,250) here. Feel free to render it and see how it looks like.

Extensions

This is a project, and the goal is to be open-ended. The hope is that it will inspire you to add nice features. Some things that come to (my) mind:
• you could integrate the computation of the viewshed with the renderer so that you can see the viewshed after it's computed.
• you could have a moving point through the grid and render its viewshed as its moving (via timerfunc())
• instead of specifying the viewpoint on the command line, you coud click on the grid to specify the viewpoint, and then render it. If you do this, start with a default 2D orthographic projection, because it will be easy to go from gl screen coordinates to grid coordinates. If you render the grid in 3D, it will be more tricky, but still possible.
• allow the user to specify a height of the viewpoitn above ground (Think you are trying to find the area coveredby a cell tower).
• ?