The goal of this project is to compute the viewshed of a point on a grid terrain.
[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.
The elevation grid is assumed to be in the asciiformat.
The output viewshed grid (in the exampel above,
For example, write your code to use a function get(g, i, j) any time you need to access element [i][j], which you could define as:
float get(Grid* g, int i, int j) { get_rowmajor(g, i, j); }In other words, your code should not assume a particular layout, but instead should use a getter to get the element at [i][j]. Later when we want to use a different layout, we'll simply swap another getter:
float get(Grid* g, int i, int j) { //get_rowmajor(g, i, j); get_blocked(g, i, j); }
/* return NODATA if g[i][j] or g[k][l] is NODATA; return 0 if (k,l) is not visible from (i,j) return 1 if (k,l) otherwie (is visible from (i,j)) */ float is_visible(Grid *g, int i, int j, int k, int l);
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 ... }
I rendered the viewshed ascii files using some old render code, which you can find here. Run as:
cd render make ./render2d set1.asc (press q to quit) ./render2d set1vis.100.100.asc (pree q to quit)If you need more sample viewsheds for any of the test grids, I can generate them, just ask.
So for example, if I were to turn in my helloworld project I would hand in one sheet with:
Laura Toma Github username lauratoma Worked alone To clone: https://github.com/lauratoma/helloworld.git