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:

Submitting your work

Make a folder called viewshed in your svn folder on microwave, and update it with your work.

Enjoy!